home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
TestBdk.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
12KB
|
374 lines
/*
* Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland as part
* of a Borland product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
* COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
* OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
* OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
* OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
* OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
* CODE FILE.
*/
package borland.samples.bdk;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.beans.*;
import java.io.*;
import com.sun.java.swing.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import sunw.demo.buttons.*;
import sunw.demo.juggler.*;
import jclass.bwt.*;
import sunw.demo.jelly.*;
import sunw.demo.misc.*;
import sunw.demo.test.*;
import sunw.demo.molecule.*;
import java.lang.*;
public class TestBdk extends JApplet {
/* {
try {
UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
} catch (Exception e) {e.printStackTrace();}
} */
static final int INITIAL_ANIMATION = 300;
XYLayout xYLayout1 = new XYLayout();
boolean isStandalone = false;
TabsetPanel tabsetPanel1 = new TabsetPanel();
Panel bevelPanel1 = new Panel();
Panel bevelPanel2 = new Panel();
Panel bevelPanel3 = new Panel();
OurButton ourButton1 = new OurButton();
//Designer generated code for Juggler bean
//Juggler juggler1 = new Juggler();
//Replacement to use beans.instantiate
Juggler juggler1;
Button start = new Button();
Button stop = new Button();
JCSlider jCSlider1 = new JCSlider();
JellyBean jellyBean1 = new JellyBean();
ChangeReporter changeReporter1 = new ChangeReporter();
Button changeColor = new Button();
ColorChooser colorChooser1 = new ColorChooser();
Label label1 = new Label();
Voter voter1 = new Voter();
Button vote = new Button();
Button changePrice = new Button();
ExplicitButton explicitButton1 = new ExplicitButton();
Panel bevelPanel4 = new Panel();
BridgeTester bridgeTester1 = new BridgeTester();
ChangeReporter changeReporter2 = new ChangeReporter();
XYLayout xYLayout2 = new XYLayout();
Panel bevelPanel5 = new Panel();
Molecule molecule1 = new Molecule();
ChoiceControl choiceControl1 = new ChoiceControl();
XYLayout xYLayout3 = new XYLayout();
XYLayout xYLayout4 = new XYLayout();
XYLayout xYLayout5 = new XYLayout();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public TestBdk() {
}
//Initialize the applet
public void init() {
try {
jbInit();
} catch (Exception e) { e.printStackTrace(); }
}
public void start() {
}
//Component initialization
public void jbInit() throws Exception{
xYLayout1.setWidth(400);
xYLayout1.setHeight(300);
bevelPanel5.setLayout(xYLayout5);
bevelPanel3.setLayout(xYLayout4);
bevelPanel2.setLayout(xYLayout3);
this.getContentPane().setLayout(xYLayout1);
this.getContentPane().add(tabsetPanel1, new XYConstraints(12, 13, 373, 270));
//Buttons setup
ourButton1.setLabel("ourButton1");
explicitButton1.setLabel("explicitButton1");
bevelPanel1.add(ourButton1, new XYConstraints(12, 9, 87, 37));
bevelPanel1.add(explicitButton1, new XYConstraints(116, 8, 93, 40));
tabsetPanel1.add(bevelPanel1, "Buttons");
//Juggler setup
//Required for beans which need an Applet context to run
try {
juggler1 = (Juggler)Beans.instantiate(null,"sunw.demo.juggler.Juggler");
} catch (IOException ex) {
juggler1 = new Juggler();
juggler1.init();
}
juggler1.setAnimationRate(INITIAL_ANIMATION);
start.setLabel("Start");
start.addActionListener(new TestBdk_start_actionAdapter(this));
stop.setLabel("Stop");
stop.addActionListener(new TestBdk_stop_actionAdapter(this));
jCSlider1.setMaximum(INITIAL_ANIMATION);
jCSlider1.setMaximumLabelString("Slow");
jCSlider1.setMinimum(50);
jCSlider1.setMinimumLabelString("Fast");
jCSlider1.setOrientation(jclass.bwt.BWTEnum.VERTICAL);
jCSlider1.setValue(INITIAL_ANIMATION);
jCSlider1.addAdjustmentListener(new TestBdk_jCSlider1_adjustmentAdapter(this));
tabsetPanel1.add(bevelPanel2, "Juggler");
bevelPanel2.add(juggler1, new XYConstraints(3, 3, -1, -1));
bevelPanel2.add(start, new XYConstraints(28, 141, -1, -1));
bevelPanel2.add(stop, new XYConstraints(81, 141, -1, -1));
bevelPanel2.add(jCSlider1, new XYConstraints(167, 4, -1, 162));
//Jellybean setup
jellyBean1.addVetoableChangeListener(new TestBdk_jellyBean1_vetoableChangeAdapter(this));
changeColor.setLabel("Change Color");
label1.setText("Change Reporter");
voter1.setVisible(false);
voter1.setBackground(Color.lightGray);
voter1.setVetoAll(false);
vote.setLabel("Veto price Change");
changePrice.setLabel("Change Price");
bevelPanel4.setLayout(xYLayout2);
changePrice.addActionListener(new TestBdk_changePrice_actionAdapter(this));
vote.addActionListener(new TestBdk_vote_actionAdapter(this));
changeColor.addActionListener(new TestBdk_changeColor_actionAdapter(this));
jellyBean1.addPropertyChangeListener(new TestBdk_jellyBean1_propertyChangeAdapter(this));
bevelPanel3.add(changeReporter1, new XYConstraints(4, 69, 335, -1));
bevelPanel3.add(changeColor, new XYConstraints(4, 105, -1, -1));
bevelPanel3.add(label1, new XYConstraints(131, 43, -1, -1));
bevelPanel3.add(voter1, new XYConstraints(0, 0, 0, 0));
bevelPanel3.add(vote, new XYConstraints(105, 135, -1, 24));
bevelPanel3.add(changePrice, new XYConstraints(3, 135, 91, 24));
tabsetPanel1.add(bevelPanel3, "Jelly Bean");
bevelPanel3.add(jellyBean1, new XYConstraints(147, 1, -1, -1));
//Bridge Tester
bridgeTester1.addPropertyChangeListener(new TestBdk_bridgeTester1_propertyChangeAdapter(this));
bevelPanel4.add(bridgeTester1, new XYConstraints(9, 13, 342, 168));
bevelPanel4.add(changeReporter2, new XYConstraints(4, 207, 348, -1));
tabsetPanel1.add(bevelPanel4, "Bridge Tester");
//Molecule
tabsetPanel1.add(bevelPanel5, "Molecule");
bevelPanel5.add(molecule1, new XYConstraints(75, 15, 219, 162));
bevelPanel5.add(choiceControl1, new XYConstraints(75, 188, 219, -1));
//Use the property editor from the Molecule bean to get the name []
//for our choice control
choiceControl1.setItems(new MoleculeNameEditor().getTags());
choiceControl1.addItemListener(new TestBdk_choiceControl1_itemAdapter(this));
tabsetPanel1.setSelectedIndex(0);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
void start_actionPerformed(ActionEvent e) {
juggler1.start();
}
void stop_actionPerformed(ActionEvent e) {
juggler1.stop();
}
void jCSlider1_adjustmentValueChanged(JCAdjustmentEvent e) {
juggler1.setAnimationRate(e.getValue());
}
//Example of bound properties
void jellyBean1_propertyChange(PropertyChangeEvent e) {
changeReporter1.reportChange(e);
}
//Changing the color property should result in the change reporter
//being notified through the propertyChange event
void changeColor_actionPerformed(ActionEvent e) {
colorChooser1.setFrame(new Frame());
colorChooser1.setValue(jellyBean1.getColor());
colorChooser1.show();
if (colorChooser1.getResult() == ColorChooser.OK)
jellyBean1.setColor(colorChooser1.getValue());
}
//Let voter determine if property can be set
void jellyBean1_vetoableChange(PropertyChangeEvent e) throws PropertyVetoException{
voter1.vetoableChange(e);
}
//Toggles the voter component
void vote_actionPerformed(ActionEvent e) {
if (voter1.getVetoAll()) {
vote.setLabel("Veto price change");
voter1.setVetoAll(false);
} else {
vote.setLabel("Accept price change");
voter1.setVetoAll(true);
}
}
void changePrice_actionPerformed(ActionEvent e) {
try {
jellyBean1.setPriceInCents(jellyBean1.getPriceInCents()+1);
} catch (Exception x) {x.printStackTrace();}
}
void bridgeTester1_propertyChange(PropertyChangeEvent e) {
changeReporter2.reportChange(e);
}
void choiceControl1_itemStateChanged(ItemEvent e) {
molecule1.setMoleculeName(choiceControl1.getSelectedItem());
}
}
class TestBdk_start_actionAdapter implements java.awt.event.ActionListener {
TestBdk adaptee;
TestBdk_start_actionAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.start_actionPerformed(e);
}
}
class TestBdk_stop_actionAdapter implements java.awt.event.ActionListener {
TestBdk adaptee;
TestBdk_stop_actionAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.stop_actionPerformed(e);
}
}
class TestBdk_jCSlider1_adjustmentAdapter implements jclass.bwt.JCAdjustmentListener {
TestBdk adaptee;
TestBdk_jCSlider1_adjustmentAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void adjustmentValueChanged(JCAdjustmentEvent e) {
adaptee.jCSlider1_adjustmentValueChanged(e);
}
}
class TestBdk_jellyBean1_propertyChangeAdapter implements java.beans.PropertyChangeListener{
TestBdk adaptee;
TestBdk_jellyBean1_propertyChangeAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void propertyChange(PropertyChangeEvent e) {
adaptee.jellyBean1_propertyChange(e);
}
}
class TestBdk_changeColor_actionAdapter implements java.awt.event.ActionListener {
TestBdk adaptee;
TestBdk_changeColor_actionAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.changeColor_actionPerformed(e);
}
}
class TestBdk_jellyBean1_vetoableChangeAdapter implements java.beans.VetoableChangeListener {
TestBdk adaptee;
TestBdk_jellyBean1_vetoableChangeAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException{
adaptee.jellyBean1_vetoableChange(e);
}
}
class TestBdk_vote_actionAdapter implements java.awt.event.ActionListener {
TestBdk adaptee;
TestBdk_vote_actionAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.vote_actionPerformed(e);
}
}
class TestBdk_changePrice_actionAdapter implements java.awt.event.ActionListener {
TestBdk adaptee;
TestBdk_changePrice_actionAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.changePrice_actionPerformed(e);
}
}
class TestBdk_bridgeTester1_propertyChangeAdapter implements java.beans.PropertyChangeListener {
TestBdk adaptee;
TestBdk_bridgeTester1_propertyChangeAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void propertyChange(PropertyChangeEvent e) {
adaptee.bridgeTester1_propertyChange(e);
}
}
class TestBdk_choiceControl1_itemAdapter implements java.awt.event.ItemListener {
TestBdk adaptee;
TestBdk_choiceControl1_itemAdapter(TestBdk adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
adaptee.choiceControl1_itemStateChanged(e);
}
}