diff options
author | pjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-07 18:12:58 +0000 |
---|---|---|
committer | pjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-07 18:12:58 +0000 |
commit | 28fdfa0225c92310a6f0d60f0cf8c334380e0828 (patch) | |
tree | ba4b0a7a26bf46ea298496a434496695db55bdc1 /java/gjt/test | |
parent | 9c4a1450aec6c149f6491194a48f34a57ed4c39b (diff) | |
download | ATCD-28fdfa0225c92310a6f0d60f0cf8c334380e0828.tar.gz |
Added gjt to CVS
Diffstat (limited to 'java/gjt/test')
31 files changed, 3033 insertions, 0 deletions
diff --git a/java/gjt/test/AttributesPanel.java b/java/gjt/test/AttributesPanel.java new file mode 100644 index 00000000000..535a12edaeb --- /dev/null +++ b/java/gjt/test/AttributesPanel.java @@ -0,0 +1,78 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; +import gjt.*; + +class AttributesPanel extends Panel { + private Applet applet; + private Box iconbox, labelbox, checkboxbox; + private Panel panelInLabelbox = new Panel(); + private Panel panelInCheckboxbox = new Panel(); + private ExclusiveImageButtonPanel panelInIconbox; + + public AttributesPanel(Applet applet) { + GridBagLayout gbl = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + + this.applet = applet; + panelInIconbox = new ExclusiveImageButtonPanel( + Orientation.HORIZONTAL); + + populateIconPanel (); + populateLabelPanel (); + populateCheckboxPanel(); + + iconbox = new Box(panelInIconbox, + "Meaningless Images"); + labelbox = new Box(panelInLabelbox, "Labels"); + checkboxbox = new Box(panelInCheckboxbox, "Fruits"); + iconbox.etchedOut(); + + setLayout(gbl); + gbc.anchor = GridBagConstraints.NORTH; + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.weighty = 0.50; + gbl.setConstraints(iconbox, gbc); + add(iconbox); + gbl.setConstraints(labelbox, gbc); + add(labelbox); + + gbc.anchor = GridBagConstraints.SOUTH; + gbc.weighty = 0; + gbl.setConstraints(panelInCheckboxbox, gbc); + add(checkboxbox); + } + private void populateIconPanel() { + Image ballot, film, ticket; + + ballot = applet.getImage(applet.getCodeBase(), + "gifs/ballot_box.gif"); + ticket = applet.getImage(applet.getCodeBase(), + "gifs/movie_ticket.gif"); + film = applet.getImage(applet.getCodeBase(), + "gifs/filmstrip.gif"); + + panelInIconbox.add(ballot); + panelInIconbox.add(ticket); + panelInIconbox.add(film); + } + private void populateLabelPanel() { + panelInLabelbox.add(new Label("Label One")); + panelInLabelbox.add(new Label("Label Two")); + panelInLabelbox.add(new Label("Label Three")); + panelInLabelbox.add(new Label("Label Four")); + panelInLabelbox.add(new Label("Label Five")); + } + private void populateCheckboxPanel() { + CheckboxGroup group = new CheckboxGroup(); + + panelInCheckboxbox.setLayout(new GridLayout(3,0)); + panelInCheckboxbox.add(new Checkbox("apples", + group, false)); + panelInCheckboxbox.add(new Checkbox("oranges", + group, false)); + panelInCheckboxbox.add(new Checkbox("pears", + group, true)); + } +} diff --git a/java/gjt/test/BargaugeTest.java b/java/gjt/test/BargaugeTest.java new file mode 100644 index 00000000000..47733d6b0bf --- /dev/null +++ b/java/gjt/test/BargaugeTest.java @@ -0,0 +1,130 @@ +package gjt.test; + +import java.awt.*; +import java.applet.*; +import gjt.Bargauge; + +/** + * An array of either horizontal or vertical animated bargauges. + * The orientation of the bargauges is controlled by a parameter + * passed into the applet.<p> + * + * <em> + * Warning: An AWT bug causes this test to be a gluttenous + * consumer of resources (especially under Win95). A mouse down + * will halt the animation thread along with its consumption of + * resources.<p> + * </em> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.Bargauge + */ +public class BargaugeTest extends UnitTest { + private Bargauge[] gauges = new Bargauge[10]; + private Thread animatorThread; + private boolean running; + + public String title() { + return "Bargauge Test"; + } + public Panel centerPanel() { + return new BargaugeTestPanel( + gauges, getParameter("orientation")); + } + public boolean mouseDown(Event event, int x, int y) { + if(running == true) { + animatorThread.suspend(); + running = false; + } + else { + animatorThread.resume (); + running = true; + } + return true; + } + public void start() { + super.start(); + animatorThread = new BargaugeAnimator(gauges); + animatorThread.start(); + running = true; + } + public void stop() { + super.stop(); + animatorThread.suspend(); + running = false; + } +} + +class BargaugeTestPanel extends Panel { + public BargaugeTestPanel(Bargauge[] gauges, String orient) { + Panel bargaugePanel = new Panel(); + + setLayout(new BorderLayout()); + add("North", + new Label("Mouse Down Starts/Stops",Label.CENTER)); + add("Center", bargaugePanel); + + bargaugePanel.add(new BargaugeGridPanel(gauges,orient)); + } +} + +class BargaugeGridPanel extends Panel { + private Dimension preferredSize = new Dimension(200, 250); + + public BargaugeGridPanel(Bargauge[] gauges, String orient) { + Bargauge nextGauge; + Color color = Color.gray; + + if("horizontal".equals(orient)) + setLayout(new GridLayout(gauges.length,0,5,5)); + else + setLayout(new GridLayout(0,gauges.length,5,5)); + + for(int i=0; i < gauges.length; ++i) { + switch(i) { + case 1: color = Color.darkGray; break; + case 2: color = Color.blue; break; + case 3: color = Color.magenta; break; + case 4: color = Color.yellow; break; + case 5: color = Color.green; break; + case 6: color = Color.cyan; break; + case 7: color = Color.orange; break; + case 8: color = Color.pink; break; + case 9: color = Color.red; break; + case 10: color = Color.yellow; break; + } + nextGauge = new Bargauge(color); + gauges[i] = nextGauge; + add(nextGauge); + } + } + public Dimension preferredSize() { return preferredSize; } + public Dimension minimumSize () { return preferredSize; } +} + +class BargaugeAnimator extends Thread { + private Bargauge[] gauges; + private boolean firstAnimation = true; + + public BargaugeAnimator(Bargauge[] gauges) { + this.gauges = gauges; + } + public void run() { + int count = gauges.length; + + while(true) { + try { Thread.currentThread().sleep(500,0); } + catch(InterruptedException e) { } + for(int i=0; i < count; ++i) { + gauges[i].setFillPercent(Math.random() * 100); + gauges[i].fill(); + + if(firstAnimation) + System.out.println(gauges[i].toString()); + } + firstAnimation = false; + } + } +} diff --git a/java/gjt/test/BleachImageFilterTest.java b/java/gjt/test/BleachImageFilterTest.java new file mode 100644 index 00000000000..08fda725a08 --- /dev/null +++ b/java/gjt/test/BleachImageFilterTest.java @@ -0,0 +1,86 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; +import java.awt.image.FilteredImageSource; + +import gjt.Util; +import gjt.image.BleachImageFilter; + +/** + * Initially displays an unbleached image. Subsequent mouse + * clicks in the canvas containing the image toggle between + * a bleached version of the image and an unbleached version.<p> + * + * @version 1.0, Apr 1 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.image.BleachImageFilter + */ +public class BleachImageFilterTest extends UnitTest { + public String title() { + return "BleachImageFilter Test " + + "(Click below to Bleach/Unbleach Picture)"; + } + public Panel centerPanel() { + return new BleachImageFilterTestPanel(this); + } +} + +class BleachImageFilterTestPanel extends Panel { + BleachImageFilterTestCanvas canvas; + + public BleachImageFilterTestPanel(Applet applet) { + add(canvas = new BleachImageFilterTestCanvas(applet)); + } + public boolean mouseDown(Event event, int x, int y) { + canvas.toggleBleaching(); + canvas.repaint(); + return true; + } +} + +class BleachImageFilterTestCanvas extends Canvas { + private Image im; + private Image bleached; + private boolean showingBleached = false; + + public BleachImageFilterTestCanvas(Applet applet) { + int bp; + String bleachPercent = + applet.getParameter("bleachPercent"); + + if(bleachPercent != null) + bp = new Integer(bleachPercent).intValue(); + else + bp = 50; + + im = applet.getImage(applet.getCodeBase(), + "gifs/saint.gif"); + Util.waitForImage(this, im); + + FilteredImageSource source = + new FilteredImageSource(im.getSource(), + new BleachImageFilter(bp)); + + bleached = createImage(source); + Util.waitForImage(this, bleached); + + showImageSize(); + } + public Dimension preferredSize() { + return new Dimension(im.getWidth(this), + im.getHeight(this)); + } + public void paint(Graphics g) { + if(showingBleached) g.drawImage(bleached,0,0,this); + else g.drawImage(im, 0,0,this); + } + public void toggleBleaching() { + showingBleached = showingBleached ? false : true; + } + private void showImageSize() { + System.out.print ("Image width=" + im.getWidth(this)); + System.out.println(" height=" + im.getHeight(this)); + } +} diff --git a/java/gjt/test/BorderTest.java b/java/gjt/test/BorderTest.java new file mode 100644 index 00000000000..450b5ffc7ea --- /dev/null +++ b/java/gjt/test/BorderTest.java @@ -0,0 +1,202 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; +import gjt.Border; +import gjt.Box; +import gjt.EtchedBorder; +import gjt.ImageButton; +import gjt.ThreeDBorder; + +/** + * Creates 10 bordered Components: + * <dl> + * <dd> A Canvas (click in canvas to depress/raise the border). + * <dd> A Label with an etched out border. + * <dd> A TextField with an inset 3D border. + * <dd> A CheckBox with a default border. + * <dd> A List with a raised 3D border. + * <dd> A Choice with an etched in border. + * <dd> A Box with a raised 3D border. + * <dd> An ImageButton with a thick, red border. + * <dd> An AWT Button with a cyan border. + * <dd> A TextArea with a blue default-width border. + * </dl> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.Border + * @see gjt.ThreeDBorder + * @see gjt.EtchedBorder + */ +public class BorderTest extends UnitTest { + public String title() { + return "Border Test"; + } + public Panel centerPanel() { + return new BorderTestPanel(this); + } +} + +class BorderTestPanel extends Panel { + TextField tf = new TextField( + "Inset TextField: border 5 pixels, gap 5 pixels "); + ThreeDBorder threeDBorder; + EtchedBorder etchedLabel; + Border border; + + public BorderTestPanel(Applet applet) { + setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); + + add(new BorderedCanvas()); + add(etchedLabel = + new EtchedBorder(new Label("Etched Label"))); + add(threeDBorder = new ThreeDBorder(tf, 5, 5)); + add(new Border(new Checkbox("Check Me Out"))); + add(makeThreeDBorderedList ()); + add(makeEtchedBorderedChoice ()); + add(makeThreeDBorderedCheckboxes()); + add(makeBorderedImageButton (applet)); + add(makeBorderedAWTButton ()); + add(makeBorderedTextArea ()); + + threeDBorder.inset(); + etchedLabel.etchedOut(); + } + private Border makeThreeDBorderedList() { + List list = new List(10, true); + + list.addItem("One"); + list.addItem("Two"); + list.addItem("Three"); + list.addItem("Four"); + list.addItem("Five"); + list.addItem("Six"); + list.addItem("Seven"); + list.addItem("Eight"); + list.addItem("Nine"); + list.addItem("Ten"); + list.addItem("Eleven"); + list.addItem("Twelve"); + list.addItem("Thirteen"); + list.addItem("Fourteen"); + list.addItem("Fiveteen"); + list.addItem("Sixteen"); + list.addItem("Seventeen"); + list.addItem("Eightteen"); + list.addItem("Nineteen"); + list.addItem("Twenty"); + + return new ThreeDBorder(list); + } + private Border makeEtchedBorderedChoice() { + Choice choice = new Choice(); + + choice.addItem("Toadies"); + choice.addItem("SilverChair"); + choice.addItem("Rug Burns"); + choice.addItem("Cracker"); + choice.addItem("Seven Mary Three"); + choice.addItem("Dishwalla"); + choice.addItem("Blues Traveler"); + choice.addItem("BottleRockets"); + choice.addItem("SpaceHog"); + + return new EtchedBorder(choice); + } + private Border makeBorderedImageButton(Applet applet) { + Image snail; + Border border; + + snail = applet.getImage(applet.getCodeBase(), + "gifs/snail.gif"); + border = new Border(new ImageButton(snail), 10); + border.setLineColor(Color.red); + + return border; + } + private Border makeBorderedAWTButton() { + Button button; + Border cyanBorder, blackBorder; + + button = new Button("Button Inside Two Borders"); + cyanBorder = new Border(button, 7); + cyanBorder.setLineColor(Color.cyan); + + blackBorder = new Border(cyanBorder); + + return blackBorder; + } + private Border makeThreeDBorderedCheckboxes() { + Panel panel = new Panel(); + Box box = new Box(panel, "Options"); + CheckboxGroup group = new CheckboxGroup(); + + panel.setLayout(new GridLayout(3,0)); + panel.add(new Checkbox("bordered", group, false)); + panel.add(new Checkbox("transparent", group, false)); + panel.add(new Checkbox("continuous", group, true)); + + return new ThreeDBorder(box, 4); + } + private Border makeBorderedTextArea() { + Border border; + + border = new Border( + new TextArea("Blue Bordered TextArea", 5, 30)); + border.setLineColor(Color.blue); + + return border; + } +} + +class BorderedCanvas extends ThreeDBorder { + public BorderedCanvas() { + super(new TestCanvas()); + } + public boolean mouseDown(Event event, int x, int y) { + if(isRaised()) paintInset (); + else paintRaised(); + return true; + } +} + +class TestCanvas extends Canvas { + private boolean centeredShowing = false; + private String centered = new String ("Red Centered Text"); + + public void paint(Graphics g) { + String canvas = "Canvas"; + String click = "Click Me"; + Dimension size = size(); + FontMetrics fm = g.getFontMetrics(); + + g.drawString(canvas, (size.width/2) - + (fm.stringWidth(canvas)/2), + fm.getHeight() - fm.getDescent()); + + g.drawString(click, (size.width/2) - + (fm.stringWidth(click)/2), + size.height - fm.getHeight() + + fm.getAscent()); + + if(centeredShowing == true) { + g.setColor(Color.red); + g.drawString(centered, + size.width/2-(fm.stringWidth(centered)/2), + size.height/2 - (fm.getHeight()/2) + + fm.getAscent()); + } + } + public Dimension preferredSize() { + FontMetrics fm = getGraphics().getFontMetrics(); + return new Dimension(fm.stringWidth(centered)+10, 100); + } + public boolean mouseUp(Event event, int x, int y) { + if(centeredShowing == false) centeredShowing = true; + else centeredShowing = false; + repaint(); + return true; + } +} diff --git a/java/gjt/test/BoxTest.java b/java/gjt/test/BoxTest.java new file mode 100644 index 00000000000..24e3de9213e --- /dev/null +++ b/java/gjt/test/BoxTest.java @@ -0,0 +1,100 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; +import gjt.Box; +import gjt.ExclusiveImageButtonPanel; +import gjt.Orientation; + +/** + * Three Boxes, each of which surrounds either: ImageButtons, + * Labels or Checkboxes. The Box surrounding the ImageButtons + * is etched out, while the other two Boxes are etched in.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.ImageButton + * @see gjt.Box + */ +public class BoxTest extends UnitTest { + public String title() { + return "Box Test"; + } + public Panel centerPanel() { + return new BoxTestPanel(this); + } +} + +class BoxTestPanel extends Panel { + private Applet applet; + private Box iconbox, labelbox, checkboxbox; + private Panel panelInLabelbox = new Panel(); + private Panel panelInCheckboxbox = new Panel(); + private ExclusiveImageButtonPanel panelInIconbox; + + public BoxTestPanel(Applet applet) { + GridBagLayout gbl = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + + this.applet = applet; + panelInIconbox = new ExclusiveImageButtonPanel( + Orientation.HORIZONTAL); + + populateIconPanel (); + populateLabelPanel (); + populateCheckboxPanel(); + + iconbox = new Box(panelInIconbox, + "Meaningless Images"); + labelbox = new Box(panelInLabelbox, "Labels"); + checkboxbox = new Box(panelInCheckboxbox, "Fruits"); + iconbox.etchedOut(); + + setLayout(gbl); + gbc.anchor = GridBagConstraints.NORTH; + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.weighty = 0.50; + gbl.setConstraints(iconbox, gbc); + add(iconbox); + gbl.setConstraints(labelbox, gbc); + add(labelbox); + + gbc.anchor = GridBagConstraints.SOUTH; + gbc.weighty = 0; + gbl.setConstraints(checkboxbox, gbc); + add(checkboxbox); + } + private void populateIconPanel() { + Image ballot, film, ticket; + + ballot = applet.getImage(applet.getCodeBase(), + "gifs/ballot_box.gif"); + ticket = applet.getImage(applet.getCodeBase(), + "gifs/movie_ticket.gif"); + film = applet.getImage(applet.getCodeBase(), + "gifs/filmstrip.gif"); + + panelInIconbox.add(ballot); + panelInIconbox.add(ticket); + panelInIconbox.add(film); + } + private void populateLabelPanel() { + panelInLabelbox.add(new Label("Label One")); + panelInLabelbox.add(new Label("Label Two")); + panelInLabelbox.add(new Label("Label Three")); + panelInLabelbox.add(new Label("Label Four")); + panelInLabelbox.add(new Label("Label Five")); + } + private void populateCheckboxPanel() { + CheckboxGroup group = new CheckboxGroup(); + + panelInCheckboxbox.setLayout(new GridLayout(3,0)); + panelInCheckboxbox.add(new Checkbox("apples", + group, false)); + panelInCheckboxbox.add(new Checkbox("oranges", + group, false)); + panelInCheckboxbox.add(new Checkbox("pears", + group, true)); + } +} diff --git a/java/gjt/test/BumpAnimationTest.java b/java/gjt/test/BumpAnimationTest.java new file mode 100644 index 00000000000..81b6fb5ce8e --- /dev/null +++ b/java/gjt/test/BumpAnimationTest.java @@ -0,0 +1,107 @@ +package gjt.test; + +import java.net.URL; +import java.applet.Applet; +import java.awt.*; + +import gjt.Util; +import gjt.Orientation; +import gjt.animation.*; + +/** + * A simple animation playfield with one sprite that bounces + * off the boundaries of the playfield.<p> + * + * When the sprite bounces off the left wall, it plays a + * bump sequence once; when it bounces off the right wall + * it plays the bump sequence twice.<p> + * + * @version 1.0, Apr 1 1996 + * @author David Geary + * @see gjt.animation.Playfield + * @see gjt.animation.Sprite + */ +public class BumpAnimationTest extends UnitTest { + public String title() { + return "Bump Animation - Mouse Down Starts/Stops"; + } + public Panel centerPanel() { + return new BumpAnimationTestPanel(this); + } +} + +class BumpAnimationTestPanel extends Panel { + public BumpAnimationTestPanel(Applet applet) { + setLayout(new BorderLayout()); + add("Center", new BumpPlayfield(applet)); + } +} + +class BumpPlayfield extends Playfield { + private Applet applet; + private URL cb; + private Sprite javaDrinker; + private Sequence spinSequence, bumpSequence; + + public BumpPlayfield(Applet applet) { + this.applet = applet; + cb = applet.getCodeBase(); + makeSequencesAndSprites(); + } + public void paintBackground(Graphics g) { + Image bg = applet.getImage(cb, "gifs/background.gif"); + Util.wallPaper(this, g, bg); + } + public boolean mouseDown(Event event, int x, int y) { + if(running() == true) stop (); + else start(); + return true; + } + public void spriteCollision(Sprite sprite, Sprite sprite2) { + // Nothing to do: only 1 sprite! + } + public void edgeCollision(Sprite sprite, + Orientation orientation) { + if(orientation == Orientation.RIGHT || + orientation == Orientation.LEFT) { + if(sprite.getSequence() != bumpSequence) { + sprite.reverseX(); + + if(orientation == Orientation.RIGHT) + sprite.play(bumpSequence, 1); + else + sprite.play(bumpSequence, 2); + } + } + else + sprite.reverseY(); + } + private void makeSequencesAndSprites() { + String file; + Point startLoc = new Point(10, 10); + Image[] spinImages = new Image[19]; + Image[] bumpImages = new Image[6]; + + for(int i=0; i < spinImages.length; ++i) { + file = "gifs/spin"; + + if(i < 10) file += "0" + i + ".gif"; + else file += i + ".gif"; + + spinImages[i] = applet.getImage(cb, file); + } + for(int i=0; i < bumpImages.length; ++i) { + file = "gifs/bump0" + i + ".gif"; + bumpImages[i] = applet.getImage(cb, file); + } + spinSequence = new Sequence(this, spinImages); + bumpSequence = new Sequence(this, bumpImages); + javaDrinker = new Sprite(this, spinSequence, startLoc); + + spinSequence.setAdvanceInterval(100); + bumpSequence.setAdvanceInterval(200); + + javaDrinker.setMoveVector(new Point(2,2)); + addSprite(javaDrinker); + } +} diff --git a/java/gjt/test/ChoiceCardPanelTest.java b/java/gjt/test/ChoiceCardPanelTest.java new file mode 100644 index 00000000000..4ec27ac8945 --- /dev/null +++ b/java/gjt/test/ChoiceCardPanelTest.java @@ -0,0 +1,34 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; +import gjt.ChoiceCardPanel; + +/** + * A ChoiceCardPanel that controls three Panels.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.ChoiceCardPanel + */ +public class ChoiceCardPanelTest extends UnitTest { + public String title() { return "Choice CardPanel Test"; } + public Panel centerPanel() { + return new ChoiceCardPanelTestPanel(this); + } +} + +class ChoiceCardPanelTestPanel extends Panel { + private ChoiceCardPanel mvp = new ChoiceCardPanel(); + + public ChoiceCardPanelTestPanel(Applet applet) { + setLayout(new BorderLayout()); + + mvp.addChoice("Attributes", + new AttributesPanel(applet)); + mvp.addChoice("Connections", new ConnectionsPanel()); + mvp.addChoice("Oracle", new OccupationOracle()); + add("Center", mvp); + } +} diff --git a/java/gjt/test/ColumnLayoutTest.java b/java/gjt/test/ColumnLayoutTest.java new file mode 100644 index 00000000000..fcef2151a25 --- /dev/null +++ b/java/gjt/test/ColumnLayoutTest.java @@ -0,0 +1,126 @@ +package gjt.test; + +import java.applet.Applet; +import java.net.URL; +import java.awt.*; +import gjt.*; + +/** + * Lays out 3 image buttons, and provides controls for setting + * orientations and gaps on the fly.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.ImageButton + * @see gjt.Box + */ +public class ColumnLayoutTest extends UnitTest { + public String title() { + return "ColumnLayout Test"; + } + public Panel centerPanel() { + ColumnButtonPanel buttonPanel; + Panel panel = new Panel(); + + buttonPanel = new ColumnButtonPanel(this); + + panel.setLayout(new BorderLayout()); + panel.add("Center", buttonPanel); + panel.add("North", new Box(new ColumnPicker(buttonPanel), + "Column Layout Settings")); + return panel; + } +} + +class ColumnButtonPanel extends Panel implements DialogClient { + private ImageButton one, two, three; + private Panel panel = new Panel(); + private TenPixelBorder border = new TenPixelBorder(panel); + + public ColumnButtonPanel(Applet applet) { + URL cb = applet.getCodeBase(); + + one = new ImageButton(applet.getImage(cb, + "gifs/one.gif")); + two = new ImageButton(applet.getImage(cb, + "gifs/two.gif")); + three = new ImageButton(applet.getImage(cb, + "gifs/three.gif")); + + panel.setLayout(new ColumnLayout(0)); + panel.add(one); + panel.add(two); + panel.add(three); + + setLayout(new BorderLayout()); + add ("Center", border); + } + public void updateOrientations(Orientation horient, + Orientation vorient, + int gap) { + panel.setLayout(new ColumnLayout(horient, vorient, gap)); + border.validate(); + } + public void dialogDismissed(Dialog d) { } +} + +class ColumnPicker extends Panel { + private Label horientLabel = new Label("Horizontal:"); + private Label vorientLabel = new Label("Vertical:"); + private Label gapLabel = new Label("Gap:"); + + private Choice hchoice = new Choice(); + private Choice vchoice = new Choice(); + private Choice gapChoice = new Choice(); + + private ColumnButtonPanel buttonPanel; + + public ColumnPicker(ColumnButtonPanel buttonPanel) { + Panel orientations = new Panel(); + Panel gap = new Panel(); + + this.buttonPanel = buttonPanel; + hchoice.addItem("left"); + hchoice.addItem("center"); + hchoice.addItem("right"); + hchoice.select(1); + + vchoice.addItem("top"); + vchoice.addItem("center"); + vchoice.addItem("bottom"); + vchoice.select(1); + + gapChoice.addItem("0"); + gapChoice.addItem("5"); + gapChoice.addItem("10"); + gapChoice.addItem("15"); + gapChoice.addItem("20"); + + orientations.add(horientLabel); + orientations.add(hchoice); + orientations.add(vorientLabel); + orientations.add(vchoice); + + gap.add(gapLabel); + gap.add(gapChoice); + + add(new Box(orientations, "Orientations")); + add(new Box(gap, "Gap")); + } + public boolean action(Event event, Object what) { + String horient, vorient; + int gap; + + horient = hchoice.getSelectedItem(); + vorient = vchoice.getSelectedItem(); + gap = + (new Integer(gapChoice.getSelectedItem())).intValue(); + + buttonPanel.updateOrientations( + Orientation.fromString(horient), + Orientation.fromString(vorient), gap); + + return true; + } +} diff --git a/java/gjt/test/ComponentScrollerTest.java b/java/gjt/test/ComponentScrollerTest.java new file mode 100644 index 00000000000..4f0e4a2ec70 --- /dev/null +++ b/java/gjt/test/ComponentScrollerTest.java @@ -0,0 +1,205 @@ +package gjt.test; + +import java.awt.*; +import java.util.Vector; +import java.applet.Applet; +import java.net.URL; + +import gjt.Border; +import gjt.ButtonPanel; +import gjt.ColumnLayout; +import gjt.ComponentScroller; +import gjt.EtchedBorder; +import gjt.ImageButton; +import gjt.RowLayout; +import gjt.Separator; +import gjt.StickyImageButtonController; + +/** + * A phony image store, where you can purchase images.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see Border + * @see ButtonPanel + * @see ImageButton + * @see Separator + * @see StickyImageButtonController + * @see ComponentScroller + */ +public class ComponentScrollerTest extends UnitTest { + public String title() { + return "ComponentScroller Test"; + } + public Panel centerPanel() { + return new ComponentScrollerTestPanel(this); + } +} + +class ComponentScrollerTestPanel extends Panel { + private ComponentScroller scroller; + private Panel purchasePanel; + private ImageButtonRow nextRow; + private String[][] imageNames = { + { "gifs/ballot_box.gif", "gifs/filmstrip.gif", + "gifs/fly.gif", "gifs/eagle.gif", + "gifs/bullet_hole.gif" }, + { "gifs/mad_hacker.gif", "gifs/tricycle.gif", + "gifs/light_bulb1.gif", "gifs/scissors.gif", + "gifs/palette.gif" }, + { "gifs/frog.gif", "gifs/gear.gif", + "gifs/wrench.gif", "gifs/www.gif", + "gifs/Dining.gif" }, + { "gifs/ant.gif", "gifs/abomb.gif", + "gifs/basketball.gif", "gifs/soccer.gif", + "gifs/skelly.gif" }, + }; + public ComponentScrollerTestPanel(Applet applet) { + URL base = applet.getCodeBase(); + Image nextImage; + Border border, blackBorder; + + purchasePanel = new Panel(); + purchasePanel.setLayout(new ColumnLayout()); + + for(int r=0; r < imageNames.length; ++r) { + nextRow = new ImageButtonRow(); + nextRow.setLayout(new RowLayout()); + + for(int c=0; c < imageNames[r].length; ++c) { + nextImage = applet.getImage(base, + imageNames[r][c]); + nextRow.add(nextImage); + } + purchasePanel.add(nextRow); + } + purchasePanel.add(new ButtonPurchaseForm()); + + scroller = new ComponentScroller(); + border = new Border(purchasePanel, 3, 2); + blackBorder = new Border(border, 1, 0); + + border.setLineColor(Color.gray); + blackBorder.setLineColor(Color.black); + scroller.setComponent(blackBorder); + + setLayout(new BorderLayout()); + add("Center", scroller); + } +} + +class ButtonPurchaseForm extends Panel { + TextField nameField = new TextField(25); + TextField addressField = new TextField(25); + TextField cityField = new TextField(15); + TextField stateField = new TextField(2); + + Choice paymentChoice = new Choice(); + + Button paymentButton = new Button("Purchase"); + Button cancelButton = new Button("Cancel"); + + public ButtonPurchaseForm() { + GridBagLayout gbl = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + + Separator sep = new Separator(); + Label title = + new Label("Purchase A Fine Image Today"); + Label name = new Label("Name:"); + Label address = new Label("Address:"); + Label payment = new Label("Purchase Method:"); + Label phone = new Label("Phone:"); + Label city = new Label("City:"); + Label state = new Label("State:"); + + setLayout(gbl); + + paymentChoice.addItem("Visa"); + paymentChoice.addItem("MasterCard"); + paymentChoice.addItem("COD"); + + title.setFont(new Font("Times-Roman", + Font.BOLD + Font.ITALIC, + 16)); + gbc.anchor = GridBagConstraints.NORTH; + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbl.setConstraints(title, gbc); + add(title); + + gbc.anchor = GridBagConstraints.NORTH; + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.insets = new Insets(0,0,10,0); + gbl.setConstraints(sep, gbc); + add(sep); + + gbc.anchor = GridBagConstraints.WEST; + gbc.gridwidth = 1; + gbc.insets = new Insets(0,0,0,10); + gbl.setConstraints(name, gbc); + add(name); + + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbl.setConstraints(nameField, gbc); + add(nameField); + + gbc.gridwidth = 1; + gbl.setConstraints(address, gbc); + add(address); + + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbl.setConstraints(addressField, gbc); + add(addressField); + + gbc.gridwidth = 1; + gbl.setConstraints(city, gbc); + add(city); + + gbl.setConstraints(cityField, gbc); + add(cityField); + + gbl.setConstraints(state, gbc); + add(state); + + gbl.setConstraints(stateField, gbc); + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbl.setConstraints(stateField, gbc); + add(stateField); + + gbc.gridwidth = 1; + gbl.setConstraints(payment, gbc); + gbc.insets = new Insets(5,0,5,0); + add(payment); + + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.fill = GridBagConstraints.NONE; + gbl.setConstraints(paymentChoice, gbc); + add(paymentChoice); + + ButtonPanel buttonPanel = new ButtonPanel(); + + buttonPanel.add(paymentButton); + buttonPanel.add(cancelButton); + + gbc.anchor = GridBagConstraints.SOUTH; + gbc.insets = new Insets(5,0,0,0); + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.gridwidth = 4; + gbl.setConstraints(buttonPanel, gbc); + add(buttonPanel); + } +} +class ImageButtonRow extends Panel { + public ImageButtonRow() { + setLayout(new RowLayout()); + } + public void add(Image image) { + ImageButton button = new ImageButton(image); + add(button); + button.setController( + new StickyImageButtonController(button)); + } +} diff --git a/java/gjt/test/ConnectionsPanel.java b/java/gjt/test/ConnectionsPanel.java new file mode 100644 index 00000000000..7790d0709b1 --- /dev/null +++ b/java/gjt/test/ConnectionsPanel.java @@ -0,0 +1,9 @@ +package gjt.test; + +import java.awt.*; + +class ConnectionsPanel extends Panel { + public ConnectionsPanel() { + add(new Label("Connections")); + } +} diff --git a/java/gjt/test/DialogTest.java b/java/gjt/test/DialogTest.java new file mode 100644 index 00000000000..f92069b7c49 --- /dev/null +++ b/java/gjt/test/DialogTest.java @@ -0,0 +1,140 @@ +package gjt.test; + +import java.awt.*; +import java.applet.Applet; + +import gjt.Util; +import gjt.DialogClient; +import gjt.MessageDialog; +import gjt.ProgressDialog; +import gjt.QuestionDialog; +import gjt.YesNoDialog; + +/** + * Tests 4 gjt custom dialogs: + * <dl> + * <dd> MessageDialog (a dialog which displays a message) + * <dd> QuestionDialog (a dialog which asks a question) + * <dd> YesNoDialog (a dialog with yes/no buttons) + * <dd> ProgressDialog (a dialog which records progress of task) + * </dl> + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.DialogClient + * @see gjt.MessageDialog + * @see gjt.ProgressDialog; + * @see gjt.QuestionDialog; + * @see gjt.YesNoDialog; + */ +public class DialogTest extends UnitTest { + public String title() { + return "Graphic Java Toolkit Dialog Test"; + } + public Panel centerPanel() { + return new DialogLauncher(); + } +} + +class DialogLauncher extends Panel implements DialogClient { + private MessageDialog messageDialog; + private QuestionDialog questionDialog; + private YesNoDialog yesNoDialog; + private ProgressDialog progressDialog; + + private Button messageDialogButton, questionDialogButton, + yesNoDialogButton, progressDialogButton; + + public DialogLauncher() { + setLayout(new GridLayout(0,1)); + + add(messageDialogButton = + new Button("Message Dialog")); + + add(questionDialogButton = + new Button("Question Dialog")); + + add(yesNoDialogButton = + new Button("YesNo Dialog")); + + add(progressDialogButton = + new Button("Progress Dialog")); + } + public boolean action(Event event, Object what) { + if(event.target == messageDialogButton) { + messageDialog = MessageDialog.getMessageDialog( + Util.getFrame(this), this, + "Example Message Dialog", + "This is an example of a message dialog."); + + messageDialog.show(); + } + else if(event.target == questionDialogButton) { + questionDialog = + new QuestionDialog(Util.getFrame(this), this, + "Example Question Dialog", + "Name: ", "Gumby", 45); + questionDialog.show(); + } + else if(event.target == yesNoDialogButton) { + yesNoDialog = + YesNoDialog.getYesNoDialog(Util.getFrame(this), + this, + "Example YesNo Dialog", + "Another cup of Java?"); + yesNoDialog.show(); + } + else if(event.target == progressDialogButton) { + progressDialog = + ProgressDialog.getProgressDialog( + Util.getFrame(this), + "Example Progress Dialog", + Color.blue); + + progressDialog.show(); + + ProgressThread thread = + new ProgressThread(progressDialog); + thread.start(); + } + + return true; + } + public void dialogDismissed(Dialog d) { + if(d == messageDialog) { + System.out.println("MessageDialog Down"); + } + if(d == questionDialog) { + if(questionDialog.wasCancelled()) + System.out.println("CANCELLED"); + else + System.out.println( + "Name: " + + questionDialog.getTextField().getText()); + } + if(d == yesNoDialog) { + if(yesNoDialog.answeredYes()) + System.out.println("YES"); + else + System.out.println("NO"); + } + } +} + +class ProgressThread extends Thread { + private ProgressDialog dialog; + private double percentComplete = 0; + + public ProgressThread(ProgressDialog dialog) { + this.dialog = dialog; + } + public void run() { + while(percentComplete <= 100) { + try { Thread.currentThread().sleep(500); } + catch(InterruptedException e) { } + + dialog.setPercentComplete(percentComplete); + percentComplete += 10; + } + } +} diff --git a/java/gjt/test/DrawnRectangleTest.java b/java/gjt/test/DrawnRectangleTest.java new file mode 100644 index 00000000000..19e3c195f7c --- /dev/null +++ b/java/gjt/test/DrawnRectangleTest.java @@ -0,0 +1,119 @@ +package gjt.test; + +import java.awt.*; +import gjt.DrawnRectangle; +import gjt.EtchedRectangle; +import gjt.ThreeDRectangle; + +/** + * 9 DrawnRectangles (some of which are EtchedRectangles + * and ThreeDRectangles) with varying characteristics such + * as line widths and colors.<p> + * + * A mouse down (any mouse button) in any of the rectangles + * causes information about the rectangle to be printed to + * System.out. (Output will go to Java Console in Netscape).<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.DrawnRectangle + * @see gjt.EtchedRectangle + * @see gjt.ThreeDRectangle + */ +public class DrawnRectangleTest extends UnitTest { + public String title() { + return "Drawn Rectangle Test"; + } + public Panel centerPanel() { + return new DrawnRectangleTestPanel(); + } +} + +class DrawnRectangleTestPanel extends Panel { + private DrawnRectangle drawnFilledOrange, + drawnFilledBlue, drawnBlue; + private EtchedRectangle etchedOut, + etchedIn, etchedFilledCyan; + private ThreeDRectangle thinRaised, + thinInset, thickRaised, thickInset; + + public DrawnRectangleTestPanel() { + drawnFilledOrange = + new DrawnRectangle (this, 10, 10, 100, 100); + drawnFilledBlue = + new DrawnRectangle (this, 135, 135, 100, 100); + drawnBlue = + new DrawnRectangle (this, 505, 135, 100, 100); + etchedFilledCyan = + new EtchedRectangle(this, 10, 135, 100, 100); + + etchedIn = new EtchedRectangle(this, 385, 10, 100, 100); + etchedOut= new EtchedRectangle(this, 505, 10, 100, 100); + + thinRaised = + new ThreeDRectangle(this, 135, 10, 100, 100); + thinInset = + new ThreeDRectangle(this, 260, 10, 100, 100); + thickRaised = + new ThreeDRectangle(this, 385, 135, 100, 100); + thickInset = + new ThreeDRectangle(this, 260, 135, 100, 100); + + drawnFilledOrange.setLineColor(Color.black); + + drawnFilledBlue.setLineColor(Color.yellow); + drawnFilledBlue.setThickness(3); + + drawnBlue.setLineColor(Color.blue); + drawnBlue.setThickness(5); + + thickRaised.setThickness(5); + thickInset.setThickness (5); + } + public Dimension preferredSize() { + return new Dimension(610, 270); + } + public void paint(Graphics g) { + drawnFilledOrange.paint(); + drawnFilledOrange.fill (Color.orange); + + drawnFilledBlue.paint (); + drawnFilledBlue.fill (Color.blue); + + drawnBlue.paint (); + + etchedIn.paintEtchedIn (); + etchedOut.paintEtchedOut(); + + etchedFilledCyan.paintEtchedIn(); + etchedFilledCyan.fill(Color.cyan); + + thinRaised.paintRaised (); + thinInset.paintInset (); + + thickRaised.paintRaised (); + + thickInset.paintInset (); + thickInset.fill (Color.red); + } + public boolean mouseDown(Event event, int x, int y) { + if(drawnFilledOrange.inside(x,y)) + show(drawnFilledOrange); + + if(drawnFilledBlue.inside(x,y)) show(drawnFilledBlue); + if(drawnBlue.inside(x,y)) show(drawnBlue); + if(etchedIn.inside(x,y)) show(etchedIn); + if(etchedOut.inside(x,y)) show(etchedOut); + if(etchedFilledCyan.inside(x,y)) show(etchedFilledCyan); + if(thinRaised.inside(x,y)) show(thinRaised); + if(thickRaised.inside(x,y)) show(thickRaised); + if(thinInset.inside(x,y)) show(thinInset); + if(thickInset.inside(x,y)) show(thickInset); + + return true; + } + private void show(DrawnRectangle drawnRectangle) { + System.out.println(drawnRectangle); + } +} diff --git a/java/gjt/test/FontDialogTest.java b/java/gjt/test/FontDialogTest.java new file mode 100644 index 00000000000..d0b535c27f9 --- /dev/null +++ b/java/gjt/test/FontDialogTest.java @@ -0,0 +1,95 @@ +package gjt.test; + +import java.awt.*; + +import gjt.FontDialog; +import gjt.DialogClient; +import gjt.Util; + +/** + * Activating the button causes the FontDialog to be displayed. + * Selecting a font from the FontDialog causes the button to + * use the selected font.<p> + * + * This unit test overrides FontDialog to reset the labels + * displayed in the buttons, and to reset the list of font + * sizes displayed. See FontDialog for a discussion of the + * overridden methods.<p> + * + *<em>Note: The FontDialog takes forever to come up in + * Netscape.</em> + * + * @version 1.0, Apr 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.Util + * @see gjt.FontDialog + * @see gjt.DialogClient + */ +class LotsOfSizesFontDialog extends FontDialog { + private static String _defaultSizes[] = + { "8", "10", "12", "14", "16", + "18", "20", "22", "24", + "26", "28", "30", "32", "34", + "36", "38", "40", "42", "44", + "46", "48", "50", "52", "54", + "56", "58", "60", "62", "64", + "66", "68", "70", "72", "74", + "76", "78", "80", "82", "84", + "86", "88", "90", "92", "94", + "96", "98", "100" }; + + public LotsOfSizesFontDialog(Frame frame, + DialogClient client, + Font font) { + super(frame, client, font, true); + } + public String getPreviewButtonLabel() { + return "Preview Selected Font"; + } + public String getOkButtonLabel () { + return "I'll Take It"; + } + public String getCancelButtonLabel () { + return "Nevermind"; + } + public String[] getFontSizes () { + return _defaultSizes; + } +} + +public class FontDialogTest extends UnitTest { + public String title() { return "Font Dialog Test"; } + public Panel centerPanel() { + return new FontDialogTestPanel(); + } +} + +class FontDialogTestPanel extends Panel + implements DialogClient { + private Button fontButton; + + public FontDialogTestPanel() { + setLayout(new BorderLayout()); + add("Center", fontButton = new Button("Fonts ...")); + } + public boolean handleEvent(Event event) { + if(event.id == Event.ACTION_EVENT) { + LotsOfSizesFontDialog d; + d = new LotsOfSizesFontDialog(Util.getFrame(this), + this, + fontButton.getFont()); + d.show(); + } + return true; + } + public void dialogDismissed(Dialog d) { + FontDialog fontDialog = (FontDialog)d; + Font fontSelected = fontDialog.getFontSelected(); + + if(fontSelected != null) + fontButton.setFont(fontSelected); + + fontButton.requestFocus(); + } +} diff --git a/java/gjt/test/IconCardPanelTest.java b/java/gjt/test/IconCardPanelTest.java new file mode 100644 index 00000000000..33a65e1939c --- /dev/null +++ b/java/gjt/test/IconCardPanelTest.java @@ -0,0 +1,47 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; +import java.net.URL; +import gjt.IconCardPanel; + +/** + * A gjt.IconCardPanel that controls 3 Panels.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.IconCardPanel + */ +public class IconCardPanelTest extends UnitTest { + public String title() { return "IconCardPanel Test"; } + public Panel centerPanel() { + return new CardPanelTestPanel(this); + } +} +class CardPanelTestPanel extends Panel { + IconCardPanel mvp = new IconCardPanel(); + + public CardPanelTestPanel(Applet applet) { + URL cb = applet.getCodeBase(); + + setLayout(new BorderLayout()); + + Image folks = applet.getImage(cb,"gifs/cell_phone.gif"); + Image pencil = applet.getImage(cb,"gifs/clipboard.gif"); + Image library = + applet.getImage(cb, "gifs/mad_hacker.gif"); + + mvp.addImageButton(folks, + "Attributes", + new AttributesPanel(applet)); + mvp.addImageButton(pencil, + "Connections", + new ConnectionsPanel()); + mvp.addImageButton(library, + "Oracle", + new OccupationOracle()); + + add("Center", mvp); + } +} diff --git a/java/gjt/test/ImageButtonTest.java b/java/gjt/test/ImageButtonTest.java new file mode 100644 index 00000000000..52df6efeba0 --- /dev/null +++ b/java/gjt/test/ImageButtonTest.java @@ -0,0 +1,130 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; +import gjt.Box; +import gjt.ImageButton; +import gjt.ImageButtonEvent; +import gjt.SpringyImageButtonController; +import gjt.StickyImageButtonController; + +/** + * 2 ImageButtons, one springy and the other sticky, both + * crabby.<p> + * + * Both ImageButtons come with an awt.Button that is used to + * enable/disable the ImageButton it's associated with.<p> + * + * ImageButtonEvents, along with mouse enter and mouse exit + * events for the two image buttons are printed out.<p> + * + * @version 1.0, Apr 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.ImageButton + * @see gjt.ImageButtonEvent + * @see gjt.SpringyImageButtonController + * @see gjt.StickyImageButtonController + */ +public class ImageButtonTest extends UnitTest { + public String title() { + return "ImageButton Test"; + } + public Panel centerPanel() { + return new ImageButtonTestPanel(this); + } +} + +class ImageButtonTestPanel extends Panel { + private ImageButton springyButton; + private Button springyButtonEnabler; + private ImageButton stickyButton; + private Button stickyButtonEnabler; + + public ImageButtonTestPanel(Applet applet) { + Image image; + Box springyBox, stickyBox; + GridBagLayout gbl = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + + image = + applet.getImage(applet.getCodeBase(), "gifs/crab.gif"); + + springyButton = new ImageButton(image); + springyButtonEnabler = new Button ("Disable"); + stickyButton = new ImageButton(image); + stickyButtonEnabler = new Button ("Disable"); + + stickyButton.setController( + new StickyImageButtonController(stickyButton)); + + setLayout(gbl); + + gbc.anchor = GridBagConstraints.NORTH; + springyBox = new Box(springyButton, "Springy"); + gbc.insets = new Insets(10,0,0,0); + gbl.setConstraints(springyBox, gbc); add(springyBox); + + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.insets = new Insets(45,10,0,0); + gbl.setConstraints(springyButtonEnabler, gbc); + add(springyButtonEnabler); + + gbc.anchor = GridBagConstraints.NORTH; + gbc.gridwidth = 1; + stickyBox = new Box(stickyButton, "Sticky"); + gbc.insets = new Insets(10,0,0,0); + gbc.weighty = 1.0; + gbl.setConstraints(stickyBox, gbc); add(stickyBox); + + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.insets = new Insets(45,10,0,0); + gbl.setConstraints(stickyButtonEnabler, gbc); + add(stickyButtonEnabler); + } + public boolean action(Event event, Object what) { + Button button = (Button)event.target; + String label = (String)what; + + if(button == stickyButtonEnabler) { + if(label.equals("Disable")) stickyButton.disable(); + else stickyButton.enable(); + } + else { + if(label.equals("Disable")) springyButton.disable(); + else springyButton.enable(); + } + if(label.equals("Disable")) button.setLabel("Enable"); + else button.setLabel("Disable"); + + return true; + } + public boolean handleEvent(Event event) { + boolean eventHandled = false; + + if(event instanceof ImageButtonEvent) { + System.out.println("ImageButton " + event); + eventHandled = true; + } + if(event.id == Event.MOUSE_ENTER) { + if(event.target == stickyButton) + System.out.println("Sticky Button Entered"); + + else if(event.target == springyButton) + System.out.println("Springy Button Entered"); + + eventHandled = true; + } + if(event.id == Event.MOUSE_EXIT) { + if(event.target == stickyButton) + System.out.println("Sticky Button Exited"); + + else if(event.target == springyButton) + System.out.println("Springy Button Exited"); + + eventHandled = true; + } + if(eventHandled) return true; + else return super.handleEvent(event); + } +} diff --git a/java/gjt/test/ImageDissolverTest.java b/java/gjt/test/ImageDissolverTest.java new file mode 100644 index 00000000000..c157408d2af --- /dev/null +++ b/java/gjt/test/ImageDissolverTest.java @@ -0,0 +1,69 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; +import java.awt.image.FilteredImageSource; + +import gjt.Util; +import gjt.image.ImageDissolver; + +/** + * Initially displays an image. Subsequent mouse clicks in the + * canvas containing the image cause the image to fade in or + * fade out, depending upon it's current state.<p> + * + * @version 1.0, Apr 1 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.image.DissolveFilter + * @see gjt.image.ImageDissolver + */ +public class ImageDissolverTest extends UnitTest { + public String title() { + return "ImageDissolver Test " + + "(Click Below to Fade Picture In/Out)"; + } + public Panel centerPanel() { + return new ImageDissolverTestPanel(this); + } +} + +class ImageDissolverTestPanel extends Panel { + ImageDissolverTestCanvas canvas; + + public ImageDissolverTestPanel(Applet applet) { + add(canvas = new ImageDissolverTestCanvas(applet)); + } + public boolean mouseDown(Event event, int x, int y) { + canvas.doFade(); + return true; + } +} + +class ImageDissolverTestCanvas extends Canvas { + private boolean isFaded = false; + private Image image; + private ImageDissolver dissolver; + + public ImageDissolverTestCanvas(Applet applet) { + image = + applet.getImage(applet.getCodeBase(),"gifs/saint.gif"); + + Util.waitForImage(this, image); + dissolver = new ImageDissolver(this, image); + } + public void paint(Graphics g) { + if( ! isFaded) + g.drawImage(image, 0, 0, this); + } + public Dimension preferredSize() { + return new Dimension(image.getWidth(this), + image.getHeight(this)); + } + public void doFade() { + if(isFaded) dissolver.fadeIn (0,0); + else dissolver.fadeOut(0,0); + + isFaded = isFaded ? false : true; + } +} diff --git a/java/gjt/test/ImageScrollerTest.java b/java/gjt/test/ImageScrollerTest.java new file mode 100644 index 00000000000..0476682eb6d --- /dev/null +++ b/java/gjt/test/ImageScrollerTest.java @@ -0,0 +1,55 @@ +package gjt.test; + +import java.awt.*; +import java.applet.Applet; +import java.net.URL; + +import gjt.ImageScroller; +import gjt.Util; + +/** + * Four images are loaded; subsequent mouse clicks cycle + * through the images, that are displayed in an ImageScroller. + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.Scroller + * @see gjt.ImageScroller + */ +public class ImageScrollerTest extends UnitTest { + public String title() { + return "ImageScroller Test"; + } + public Panel centerPanel() { + return new ImageScrollerTestPanel(this); + } +} + +class ImageScrollerTestPanel extends Panel { + private Image[] images = new Image[4]; + private int imageIndex = 0; + private ImageScroller scroller; + + public ImageScrollerTestPanel(Applet applet) { + URL cb = applet.getCodeBase(); + + images[0]=applet.getImage(cb,"gifs/ashleyAndRoy.gif"); + images[1]=applet.getImage(cb,"gifs/ashleyAndSabre.gif"); + images[2]=applet.getImage(cb,"gifs/anjinAndMariko.gif"); + images[3]=applet.getImage(cb,"gifs/ashleyAndAnjin.gif"); + + setLayout(new BorderLayout()); + add("Center", scroller = new ImageScroller(images[0])); + } + public boolean mouseUp(Event event, int x, int y) { + if(imageIndex == images.length-1) imageIndex = 0; + else imageIndex++; + + Util.setCursor(Frame.WAIT_CURSOR, this); + scroller.resetImage(images[imageIndex]); + Util.setCursor(Frame.DEFAULT_CURSOR, this); + + return true; + } +} diff --git a/java/gjt/test/LabelCanvasTest.java b/java/gjt/test/LabelCanvasTest.java new file mode 100644 index 00000000000..cb4c0a857ae --- /dev/null +++ b/java/gjt/test/LabelCanvasTest.java @@ -0,0 +1,75 @@ +package gjt.test; +import java.applet.Applet; +import java.awt.Event; +import java.awt.Panel; +import java.awt.Insets; +import java.awt.Graphics; +import gjt.LabelCanvas; +import gjt.SelectionEvent; +import gjt.Util; + +/** + * Four LabelCanvases, each with different insets. The leftmost + * LabelCanvas has standard insets (2 all around), while the + * other three were constructed as follows: + * <pre> + * insetFive.setInsets (new Insets(5,5,5,5)); + * insetTen.setInsets (new Insets(10,10,10,10)); + * insetFifteen.setInsets(new Insets(15,15,15,15)); + * </pre><p> + * + * LabelCanvases generate SelectionEvents, that we watch + * for in our handleEvent() method, and print out.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.LabelCanvas + */ +public class LabelCanvasTest extends UnitTest { + public String title() { return "LabelCanvas Test"; } + public Panel centerPanel() { + return new LabelCanvasTestPanel(this); + } +} + +class LabelCanvasTestPanel extends Panel { + Applet applet; + public LabelCanvasTestPanel(Applet applet) { + this.applet = applet; + LabelCanvas standard = + new LabelCanvas("Standard Insets"); + LabelCanvas insetFive = + new LabelCanvas("Insets = Five"); + LabelCanvas insetTen = + new LabelCanvas("Insets = Ten"); + LabelCanvas insetFifteen = + new LabelCanvas("Insets = Fifteen"); + + insetFive.setInsets (new Insets(5,5,5,5)); + insetTen.setInsets (new Insets(10,10,10,10)); + insetFifteen.setInsets(new Insets(15,15,15,15)); + + add(standard); + add(insetFive); + add(insetTen); + add(insetFifteen); + } + public boolean handleEvent(Event event) { + if(event instanceof SelectionEvent) { + SelectionEvent sevent = (SelectionEvent)event; + LabelCanvas canvas = (LabelCanvas)event.target; + + if(sevent.isSelected()) + System.out.println("LabelCanvas " + + canvas.getLabel() + + " selected"); + else + System.out.println("LabelCanvas " + + canvas.getLabel() + + " deselected"); + return true; + } + return super.handleEvent(event); + } +} diff --git a/java/gjt/test/MessageDialogTest.java b/java/gjt/test/MessageDialogTest.java new file mode 100644 index 00000000000..6efddd08cb4 --- /dev/null +++ b/java/gjt/test/MessageDialogTest.java @@ -0,0 +1,50 @@ + +package gjt.test; + +import java.awt.*; +import java.applet.Applet; + +import gjt.MessageDialog; +import gjt.DialogClient; +import gjt.Util; + +/** + * Simple unit test that exercises gjt.MessageDialog. This + * unit test serves to illustrate the use of gjt.DialogClient. + * For a unit test which covers all of the gjt dialogs, + * see gjt.test.DialogTest. + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.DialogClient + * @see gjt.MessageDialog + */ +public class MessageDialogTest extends UnitTest { + public String title() { + return "Message Dialog Test"; + } + public Panel centerPanel() { + return new MessageDialogLauncher(); + } +} + +class MessageDialogLauncher extends Panel + implements DialogClient { + private MessageDialog messageDialog; + + public MessageDialogLauncher() { + add(new Button("Show Message Dialog")); + } + public boolean action(Event event, Object what) { + messageDialog = MessageDialog.getMessageDialog( + Util.getFrame(this), this, + "Example Message Dialog", + "This is an example of a message dialog."); + messageDialog.show(); + return true; + } + public void dialogDismissed(Dialog d) { + System.out.println("MessageDialog Down"); + } +} diff --git a/java/gjt/test/OccupationOracle.java b/java/gjt/test/OccupationOracle.java new file mode 100644 index 00000000000..a34c2ad2064 --- /dev/null +++ b/java/gjt/test/OccupationOracle.java @@ -0,0 +1,334 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; + +// The OccupationOracle class makes a guess at a person's occupation +// within an engineering organization based on a few "key" traits. +// Invalid entries in numeric fields result in an "Unknown" occupation. +// This applet uses the awt.GridBagLayout class to structure the +// occupation form. The awt.GridBagLayout class allows fields to +// be placed in rows and columns within a form. Each component +// is given a "display area" based on the constraints in effect +// when it is added to the layout. + +// Author: Jerry Jackson (thanks, sifu) + +public class OccupationOracle extends Panel { + + // Construct the form. Create each component of the form and + // add it to the layout. Initialize the occupation to "Unknown". + + public OccupationOracle() { + + // Use the GridBagLayout layout to construct rows and + // columns. + + GridBagLayout gridbag = new GridBagLayout(); + + // Create a new set of constraints to use when adding + // a component to the layout. The constraint values + // in effect when a component is added to the layout + // are cloned and stored in conjunction with the component + // by the layout. + + GridBagConstraints constraints = new GridBagConstraints(); + + // Set the font for the form. + + //setFont(new Font("TimesRoman", Font.BOLD, 12)); + + // Associate the GridBagLayout object with the applet. + + setLayout(gridbag); + + // The "anchor" constraint determines how a component + // is justified within its display area. + + constraints.anchor = GridBagConstraints.WEST; + + // Determines how much space should be given to this component. + // if left at 0.0, all components clump up in the middle as the + // padding is applied to the outside. + + constraints.weightx = 1.0; + + // Create a name label and text field. + + makeNameField(); + + // Setting the "gridwidth" constraint to 1 will + // cause the component to take up the minimum + // horizontal space in its row. + + constraints.gridwidth = 1; + + // "addFormComponent" will associate the current constraints + // with a component and add the component to the form. + + addFormComponent(gridbag, nameLabel, constraints); + + // Setting the "gridwidth" constraint to REMAINDER will + // cause the component to fill up the remainder of its row. + // i.e. it will be the last entry in the row. + + constraints.gridwidth = GridBagConstraints.REMAINDER; + + // The "fill" constraint tells what to do if the item is in + // a area larger than it is. In this case we want to fill + // any extra horizontal space. + + constraints.fill = GridBagConstraints.HORIZONTAL; + + addFormComponent(gridbag, nameField, constraints); + + // Create and add an age label and text field. + + makeAgeField(); + + constraints.gridwidth = 1; + constraints.fill = GridBagConstraints.NONE; + constraints.weightx = 0.0; + addFormComponent(gridbag, ageLabel, constraints); + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weightx = 1.0; + addFormComponent(gridbag, ageField, constraints); + + // Create and add a world view label and a single checkbox + // for a true/false value. + + makeWorldViewField(); + + constraints.gridwidth = 1; + constraints.weightx = 0.0; + addFormComponent(gridbag, worldViewLabel, constraints); + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weightx = 1.0; + addFormComponent(gridbag, worldViewField, constraints); + + + // Create and add a coffee consumption label and text field. + + makeCoffeeField(); + + constraints.gridwidth = 1; + constraints.weightx = 0.0; + addFormComponent(gridbag, coffeeLabel, constraints); + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weightx = 1.0; + addFormComponent(gridbag, coffeeField, constraints); + + + // Create and add a fashion sense label and a checkbox + // group that has three mutually exclusive values. + + makeFashionField(); + + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weightx = 0.0; + constraints.weighty = 0.0; + addFormComponent(gridbag, fashionLabel, constraints); + + // The three checkboxes that represent fashion sense. + + addFormComponent(gridbag, low, constraints); + addFormComponent(gridbag, medium, constraints); + addFormComponent(gridbag, high, constraints); + + // The Occupation field is output only. + + makeOccupationField(); + + constraints.gridwidth = 1; + constraints.weightx = 0.0; + constraints.weighty = 1.0; + constraints.fill = GridBagConstraints.NONE; + addFormComponent(gridbag, occupationLabel, constraints); + constraints.fill = GridBagConstraints.HORIZONTAL; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.weightx = 1.0; + addFormComponent(gridbag, occupationField, constraints); + + // Display the initial "Unknown" occupation. + + recalculateOccupation(); + + resize(400, 250); + } + + // The paint() method for this applet just calls the paintComponents() + // method which is defined by the Container class. It causes all + // the components visible within the Container to get painted. + + public void paint(Graphics g) { + paintComponents(g); + } + + // When any action occurs within the form we do the same thing: + // recalculate the person's occupation. + + public boolean action(Event event, Object arg) { + recalculateOccupation(); + return true; + } + + // A helper function that associates constraints with a component + // and adds it to the form. + + private void addFormComponent(GridBagLayout grid, Component comp, + GridBagConstraints c) { + grid.setConstraints(comp, c); + add(comp); + } + + + // recalculateOccupation() fetches the values of each component + // and computes an occupation based on some truly stupid heuristics. + + private void recalculateOccupation() { + + // If we don't have a name yet we might incorrectly categorize + // the CEO! + + if (nameField.getText() == "") { + occupationField.setText("Unknown"); + } + + // Fetch other important values that we'll use in our + // calculations. + + int age; + int coffeeConsumption; + boolean binaryView = worldViewField.getState(); + + + // Try to fetch integer values for age and coffeeConsumption. + // If the values in the fields can't be parsed as integers, + // set the occupation to "Unknown". + + try { + age = Integer.parseInt(ageField.getText()); + coffeeConsumption = Integer.parseInt(coffeeField.getText()); + } catch (Exception e) { + occupationField.setText("Unknown"); + return; + } + + // Check for the CEO. + + String name = nameField.getText(); + + if (name.endsWith("II") || + name.endsWith("III") || + name.endsWith("IV")) { + + if (age < 35 || coffeeConsumption < 4) { + occupationField.setText("Junior Executive"); + } else { + occupationField.setText("CEO"); + } + + return; + } + + // Fashion sense is a critical piece of information. + // The getCurrent() method of CheckboxGroup returns whichever + // Checkbox in the group is currently selected. Only one + // can be selected at a time. + + Checkbox fashionValue = fashionGroup.getCurrent(); + + if (fashionValue == low || fashionValue == medium) { + + // There are two kinds of people in the world: those who + // divide people into two kinds and those who don't. + + if (binaryView && coffeeConsumption >= 4) { + occupationField.setText("Engineer"); + + } else if ((age > 40 && binaryView) || + (age < 40 && coffeeConsumption >= 4)) { + occupationField.setText("Engineering Manager"); + + } else { + occupationField.setText("Product Manager"); + } + + } else { + + // High fashion sense. Not an engineer! + + if (binaryView || coffeeConsumption >= 4) { + occupationField.setText("Vice President"); + + } else { + occupationField.setText("Product Marketing"); + } + } + } + + // Helper functions to create form components. + + private void makeNameField() { + nameLabel = new Label("Name: "); + nameField = new TextField(40); + } + + private void makeAgeField() { + ageLabel = new Label("Age: "); + ageField = new TextField(3); + } + + private void makeOccupationField() { + occupationLabel = new Label("Occupation: "); + occupationField = new TextField(40); + } + + private void makeWorldViewField() { + worldViewLabel = new Label("Binary World View: "); + worldViewField = new Checkbox(); + } + + private void makeCoffeeField() { + coffeeLabel = new Label("Coffee consumption: "); + coffeeField = new TextField(3); + } + + private void makeFashionField() { + fashionLabel = new Label("Fashion sense:"); + + fashionGroup = new CheckboxGroup(); + low = new Checkbox("Low ", fashionGroup, false); + medium = new Checkbox("Medium", fashionGroup, true); + high = new Checkbox("High ", fashionGroup, false); + } + + // Text fields. + + private TextField nameField; + private TextField ageField; + private TextField coffeeField; + private TextField occupationField; + + // Labels. + + private Label nameLabel; + private Label ageLabel; + private Label coffeeLabel; + private Label fashionLabel; + private Label worldViewLabel; + private Label occupationLabel; + + // Checkboxes. + + private Checkbox worldViewField; + private Checkbox low; + private Checkbox medium; + private Checkbox high; + + // The fashion sense checkbox group. + + private CheckboxGroup fashionGroup; +} + + diff --git a/java/gjt/test/RowLayoutTest.java b/java/gjt/test/RowLayoutTest.java new file mode 100644 index 00000000000..eb7b419ca17 --- /dev/null +++ b/java/gjt/test/RowLayoutTest.java @@ -0,0 +1,124 @@ +package gjt.test; + +import java.applet.Applet; +import java.net.URL; +import java.awt.*; +import gjt.*; + +/** + * Lays out 3 image buttons, and provides controls for setting + * orientations and gaps on the fly.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.ImageButton + * @see gjt.Box + */ +public class RowLayoutTest extends UnitTest { + public String title() { + return "RowLayout Test"; + } + public Panel centerPanel() { + RowButtonPanel buttonPanel = new RowButtonPanel(this); + Panel panel = new Panel(); + + panel.setLayout(new BorderLayout()); + panel.add("Center", buttonPanel); + panel.add("North", new Box(new RowPicker(buttonPanel), + "Row Layout Settings")); + return panel; + } +} + +class RowButtonPanel extends Panel implements DialogClient { + private ImageButton one, two, three; + private Panel panel = new Panel(); + private TenPixelBorder border = new TenPixelBorder(panel); + + public RowButtonPanel(Applet applet) { + URL cb = applet.getCodeBase(); + + one = new ImageButton(applet.getImage(cb, + "gifs/one.gif")); + two = new ImageButton(applet.getImage(cb, + "gifs/two.gif")); + three = new ImageButton(applet.getImage(cb, + "gifs/three.gif")); + + panel.setLayout(new RowLayout(0)); + panel.add(one); + panel.add(two); + panel.add(three); + + setLayout(new BorderLayout()); + add ("Center", border); + } + public void updateOrientations(Orientation horient, + Orientation vorient, + int gap) { + panel.setLayout(new RowLayout(horient, vorient, gap)); + border.validate(); + } + public void dialogDismissed(Dialog d) { } +} + +class RowPicker extends Panel { + private Label horientLabel = new Label("Horizontal:"); + private Label vorientLabel = new Label("Vertical:"); + private Label gapLabel = new Label("Gap:"); + + private Choice hchoice = new Choice(); + private Choice vchoice = new Choice(); + private Choice gapChoice = new Choice(); + + private RowButtonPanel buttonPanel; + + public RowPicker(RowButtonPanel buttonPanel) { + Panel orientations = new Panel(); + Panel gap = new Panel(); + + this.buttonPanel = buttonPanel; + hchoice.addItem("left"); + hchoice.addItem("center"); + hchoice.addItem("right"); + hchoice.select(1); + + vchoice.addItem("top"); + vchoice.addItem("center"); + vchoice.addItem("bottom"); + vchoice.select(1); + + gapChoice.addItem("0"); + gapChoice.addItem("5"); + gapChoice.addItem("10"); + gapChoice.addItem("15"); + gapChoice.addItem("20"); + + orientations.add(horientLabel); + orientations.add(hchoice); + orientations.add(vorientLabel); + orientations.add(vchoice); + + gap.add(gapLabel); + gap.add(gapChoice); + + add(new Box(orientations, "Orientations")); + add(new Box(gap, "Gap")); + } + public boolean action(Event event, Object what) { + String horient, vorient; + int gap; + + horient = hchoice.getSelectedItem(); + vorient = vchoice.getSelectedItem(); + gap = + (new Integer(gapChoice.getSelectedItem())).intValue(); + + buttonPanel.updateOrientations( + Orientation.fromString(horient), + Orientation.fromString(vorient), gap); + + return true; + } +} diff --git a/java/gjt/test/RubberbandTest.java b/java/gjt/test/RubberbandTest.java new file mode 100644 index 00000000000..ae256fb2c3a --- /dev/null +++ b/java/gjt/test/RubberbandTest.java @@ -0,0 +1,112 @@ +package gjt.test; + +import java.awt.*; +import gjt.DrawingPanel; +import gjt.Separator; +import gjt.RowLayout; +import gjt.rubberband.*; + +/** + * A simple drawing applet that demonstrates the utility of + * the gjt.rubberband package.<p> + * + * Note that this unit test also serves as the unit test for + * gjt.DrawingPanel.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.DrawingPanel + * @see gjt.rubberband.Rubberband + * @see gjt.rubberband.RubberbandLine + * @see gjt.rubberband.RubberbandRectangle + * @see gjt.rubberband.RubberbandEllipse + * @see gjt.rubberband.RubberbandPanel + */ +public class RubberbandTest extends UnitTest { + public String title() { + return "Rubberband Test"; + } + public Panel centerPanel() { + return new RubberbandTestPanel(); + } +} + +class RubberbandTestPanel extends Panel { + private DrawingPanel drawingPanel; + private ChoicePanel choicePanel; + + public RubberbandTestPanel() { + drawingPanel = new DrawingPanel(); + choicePanel = new ChoicePanel(drawingPanel); + + setLayout(new BorderLayout()); + add("North", choicePanel); + add("Center", drawingPanel); + } +} + +class ChoicePanel extends Panel { + private DrawingPanel drawingPanel; + private Color color; + private Checkbox fillCheckbox = new Checkbox(); + + public ChoicePanel(DrawingPanel drawingPanel) { + Panel choicePanel = new Panel(); + Choice geometricChoice = new Choice(); + Choice colorChoice = new Choice(); + + this.drawingPanel = drawingPanel; + + geometricChoice.addItem("Lines"); + geometricChoice.addItem("Rectangles"); + geometricChoice.addItem("Ellipses"); + + colorChoice.addItem("Black"); + colorChoice.addItem("Red"); + colorChoice.addItem("Blue"); + colorChoice.addItem("Gray"); + colorChoice.addItem("White"); + + choicePanel.setLayout(new RowLayout(10)); + choicePanel.add(new Label("Shape:")); + choicePanel.add(geometricChoice); + choicePanel.add(new Label("Color:")); + choicePanel.add(colorChoice); + choicePanel.add(new Label("Fill:")); + choicePanel.add(fillCheckbox); + + setLayout(new BorderLayout()); + add("Center", choicePanel); + add("South", new Separator()); + } + public boolean action(Event event, Object what) { + if(event.target instanceof Checkbox) { + drawingPanel.setFill(fillCheckbox.getState()); + } + else if(event.target instanceof Choice) { + if(((String)what).equals("Lines")) { + fillCheckbox.setState(false); + drawingPanel.drawLines(); + } + else if(((String)what).equals("Rectangles")) { + System.out.println("Rectangles"); + drawingPanel.drawRectangles(); + } + else if(((String)what).equals("Ellipses")) + drawingPanel.drawEllipses (); + else if(((String)what).equals("Black")) + drawingPanel.setColor(Color.black); + else if(((String)what).equals("Red")) + drawingPanel.setColor(Color.red); + else if(((String)what).equals("Blue")) + drawingPanel.setColor(Color.blue); + else if(((String)what).equals("Gray")) + drawingPanel.setColor(Color.gray); + else if(((String)what).equals("White")) + drawingPanel.setColor(Color.white); + } + return true; + } + public Insets insets() { return new Insets(5,0,5,0); } +} diff --git a/java/gjt/test/SeparatorTest.java b/java/gjt/test/SeparatorTest.java new file mode 100644 index 00000000000..3dd80173ea3 --- /dev/null +++ b/java/gjt/test/SeparatorTest.java @@ -0,0 +1,64 @@ +package gjt.test; + +import java.awt.*; +import gjt.Etching; +import gjt.Separator; + +/** + * Two Separators, one horizontal and the other vertical, the + * former etched in, and the latter etched out are laid out with + * an adorning Label for each.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.UnitTest + * @see gjt.Separator + */ +public class SeparatorTest extends UnitTest { + public String title () { return "Separator Test"; } + public Panel centerPanel() { + return new SeparatorTestPanel(); + } +} + +class SeparatorTestPanel extends Panel { + public SeparatorTestPanel() { + setLayout(new BorderLayout()); + add("North", new SeparatorTestNorthPanel ()); + add("Center", new SeparatorTestCenterPanel()); + } +} + +class SeparatorTestNorthPanel extends Panel { + Separator separator = new Separator(); + + public SeparatorTestNorthPanel() { + setLayout(new BorderLayout()); + add("North", new Label("North Of Etched-In Separator")); + add("South", separator); + } +} + +class SeparatorTestCenterPanel extends Panel { + Separator separator = new Separator(Etching.OUT); + + public SeparatorTestCenterPanel() { + GridBagConstraints gbc = new GridBagConstraints(); + GridBagLayout gbl = new GridBagLayout(); + Label label = new Label("West Of Etched-Out Separator"); + + setLayout(gbl); + gbc.anchor = GridBagConstraints.WEST; + gbc.insets = new Insets(0,0,0,10); + gbl.setConstraints(label, gbc); + add(label); + + gbc.insets = new Insets(0,0,0,0); + gbc.weightx = 1.0; + gbc.weighty = 1.0; + gbc.fill = GridBagConstraints.VERTICAL; + gbl.setConstraints(separator, gbc); + add(separator); + + } +} diff --git a/java/gjt/test/SimpleAnimationTest.java b/java/gjt/test/SimpleAnimationTest.java new file mode 100644 index 00000000000..faf0c7c611c --- /dev/null +++ b/java/gjt/test/SimpleAnimationTest.java @@ -0,0 +1,87 @@ +package gjt.test; + +import java.net.URL; +import java.applet.Applet; +import java.awt.*; + +import gjt.Util; +import gjt.Orientation; +import gjt.animation.*; + +/** + * An animation playfield containing a lone sprite that bounces + * off the boundaries of the playfield.<p> + * + * @version 1.0, Apr 1 1996 + * @author David Geary + * @see gjt.test.AnimationTest + * @see gjt.animation.Playfield + * @see gjt.animation.Sprite + */ +public class SimpleAnimationTest extends UnitTest { + public String title() { + return "Simple Animation - Mouse Down Starts/Stops"; + } + public Panel centerPanel() { + return new SimpleAnimationTestPanel(this); + } +} + +class SimpleAnimationTestPanel extends Panel { + public SimpleAnimationTestPanel(Applet applet) { + setLayout(new BorderLayout()); + add("Center", new SimplePlayfield(applet)); + } +} + +class SimplePlayfield extends Playfield { + private Applet applet; + private URL cb; + private Sprite javaDrinker; + private Sequence spinSequence; + + public SimplePlayfield(Applet applet) { + this.applet = applet; + cb = applet.getCodeBase(); + makeSequencesAndSprites(); + } + public void paintBackground(Graphics g) { + Image bg = applet.getImage(cb, "gifs/background.gif"); + Util.wallPaper(this, g, bg); + } + public boolean mouseDown(Event event, int x, int y) { + if(running() == true) stop (); + else start(); + return true; + } + public void spriteCollision(Sprite sprite, Sprite sprite2) { + // Nothing to do: only 1 sprite! + } + public void edgeCollision(Sprite sprite, + Orientation orientation) { + if(orientation == Orientation.RIGHT || + orientation == Orientation.LEFT) + sprite.reverseX(); + else + sprite.reverseY(); + } + private void makeSequencesAndSprites() { + String file; + Point startLoc = new Point(10, 10); + Image[] spinImages = new Image[19]; + + for(int i=0; i < spinImages.length; ++i) { + file = "gifs/spin"; + + if(i < 10) file += "0" + i + ".gif"; + else file += i + ".gif"; + + spinImages[i] = applet.getImage(cb, file); + } + spinSequence = new Sequence(this, spinImages); + javaDrinker = new Sprite(this, spinSequence, startLoc); + + javaDrinker.setMoveVector(new Point(2,2)); + addSprite(javaDrinker); + } +} diff --git a/java/gjt/test/SimpleBargaugeTest.java b/java/gjt/test/SimpleBargaugeTest.java new file mode 100644 index 00000000000..57eb464f4b1 --- /dev/null +++ b/java/gjt/test/SimpleBargaugeTest.java @@ -0,0 +1,61 @@ +package gjt.test; + +import java.awt.*; +import gjt.Bargauge; + +/** + * A lone Barguage which animates. This unit test is meant to + * illustrate that a Bargauge can cope with having its + * orientation chanaged from horizontal to vertical or + * vice-versa. This test is best run in appletviewer, so that + * the window may be resized such that the Bargauge changes its + * orientation.<p> + * + * <em> + * Warning: An AWT bug causes this test to be a gluttenous + * consumer of resources (especially under Win95). A mouse down + * will halt the animation thread along with its consumption of + * resources.<p> + * </em> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.Bargauge + */ +public class SimpleBargaugeTest extends UnitTest { + public String title() { + return "Simple Bargauge Test"; + } + public Panel centerPanel() { + return new SimpleBargaugeTestPanel(); + } +} + +class SimpleBargaugeTestPanel extends Panel implements Runnable { + private Bargauge gauge = new Bargauge(Color.blue); + private boolean running = true; + private Thread t; + + public SimpleBargaugeTestPanel() { + setLayout(new BorderLayout()); + add("Center", gauge); + + t = new Thread(this); + t.start(); + } + public void run() { + while(true) { + try { Thread.currentThread().sleep(500,0); } + catch(InterruptedException e) { } + + gauge.setFillPercent(Math.random() * 100); + gauge.fill(); + } + } + public boolean mouseDown(Event event, int x, int y) { + if(running) { t.suspend(); running = false; } + else { t.resume (); running = true; } + return true; + } +} diff --git a/java/gjt/test/StateButtonTest.java b/java/gjt/test/StateButtonTest.java new file mode 100644 index 00000000000..508aee1682e --- /dev/null +++ b/java/gjt/test/StateButtonTest.java @@ -0,0 +1,41 @@ +package gjt.test; + +import java.applet.Applet; +import java.awt.*; +import java.net.URL; +import gjt.StateButton; +import gjt.ImageButtonEvent; + +/** + * A StateButton which cycles through a fascinating series of + * Images.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.StateButton + */ +public class StateButtonTest extends UnitTest { + public String title () { return "StateButton Test"; } + public Panel centerPanel() { + return new StateButtonTestPanel(this); + } +} + +class StateButtonTestPanel extends Panel { + private URL codeBase; + private Image[] images; + private StateButton button; + + public StateButtonTestPanel(Applet applet) { + codeBase = applet.getCodeBase(); + images = new Image[3]; + images[0] = applet.getImage(codeBase, "gifs/fly.gif"); + images[1] = applet.getImage(codeBase, "gifs/frog.gif"); + images[2] = applet.getImage(codeBase, "gifs/eagle.gif"); + button = new StateButton(images); + + setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20)); + add (button); + } +} diff --git a/java/gjt/test/TenPixelBorder.java b/java/gjt/test/TenPixelBorder.java new file mode 100644 index 00000000000..bab694d0fb1 --- /dev/null +++ b/java/gjt/test/TenPixelBorder.java @@ -0,0 +1,44 @@ +package gjt.test; + +import java.awt.*; + +public class TenPixelBorder extends Panel { + public TenPixelBorder(Component borderMe) { + setLayout(new BorderLayout()); + add("Center", borderMe); + } + public void paint(Graphics g) { + Dimension mySize = size(); + Insets myInsets = insets(); + + g.setColor(Color.gray); + + // Top Inset area + g.fillRect(0, + 0, + mySize.width, + myInsets.top); + + // Left Inset area + g.fillRect(0, + 0, + myInsets.left, + mySize.height); + + // Right Inset area + g.fillRect(mySize.width - myInsets.right, + 0, + myInsets.right, + mySize.height); + + // Bottom Inset area + g.fillRect(0, + mySize.height - myInsets.bottom, + mySize.width, + mySize.height); + } + public Insets insets() { + return new Insets(10,10,10,10); + } + +} diff --git a/java/gjt/test/TitledPanel.java b/java/gjt/test/TitledPanel.java new file mode 100644 index 00000000000..cb8d054e888 --- /dev/null +++ b/java/gjt/test/TitledPanel.java @@ -0,0 +1,22 @@ +package gjt.test; + +import java.awt.BorderLayout; +import java.awt.Label; +import java.awt.Panel; +import gjt.Separator; + +/** + * A Panel fitted with a BorderLayout that contains a Label + * (title) in the North, and a Separator in the South. + * + * @version 1.0, Apr 2 1996 + * @author David Geary + */ + +public class TitledPanel extends Panel { + public TitledPanel(String title) { + setLayout(new BorderLayout()); + add("North", new Label(title, Label.CENTER)); + add("South", new Separator()); + } +} diff --git a/java/gjt/test/ToolbarTest.java b/java/gjt/test/ToolbarTest.java new file mode 100644 index 00000000000..f739ce96236 --- /dev/null +++ b/java/gjt/test/ToolbarTest.java @@ -0,0 +1,111 @@ +package gjt.test; + +import java.net.URL; +import java.awt.*; +import java.applet.Applet; +import gjt.ExclusiveImageButtonPanel; +import gjt.ImageButton; +import gjt.ImageButtonEvent; +import gjt.Orientation; +import gjt.Toolbar; +import gjt.Separator; + +/** + * A Toolbar to the north, and an ExclusiveImageButtonPanel on + * the west give this little applet its own unique charm. + * Owner is motivated.<p> + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see gjt.test.UnitTest + * @see gjt.ExclusiveImageButtonPanel + * @see gjt.ImageButton + * @see gjt.Toolbar + */ +public class ToolbarTest extends UnitTest { + public String title() { + return "Toolbar/ImageButtonPanel Test"; + } + public Panel centerPanel() { + return new ToolbarTestPanel(this); + } +} + +class ToolbarTestPanel extends Panel { + ImageButton newButton, openButton, diskButton, + printButton, cutButton, copyButton, + pasteButton; + + public ToolbarTestPanel(Applet app) { + setLayout(new BorderLayout()); + add("North", makeToolbar(app, app.getCodeBase())); + add("West", makePalette(app, app.getCodeBase())); + } + public boolean handleEvent(Event event) { + if(event instanceof ImageButtonEvent) { + ImageButtonEvent ibevent = (ImageButtonEvent)event; + + if(ibevent.isActivated()) { + if(event.target == newButton) + System.out.println("New Button Activated"); + if(event.target == openButton) + System.out.println("Open Button Activated"); + if(event.target == diskButton) + System.out.println("Disk Button Activated"); + if(event.target == printButton) + System.out.println("Print Button Activated"); + if(event.target == cutButton) + System.out.println("Cut Button Activated"); + if(event.target == copyButton) + System.out.println("Copy Button Activated"); + if(event.target == pasteButton) + System.out.println("Paste Button Activated"); + + return true; + } + } + + return super.handleEvent(event); + } + private Toolbar makeToolbar(Applet app, URL cb) { + Toolbar tb = new Toolbar(10, 0); + + newButton = tb.add(app.getImage(cb, "gifs/new.gif")); + openButton = tb.add(app.getImage(cb, "gifs/open.gif")); + diskButton = tb.add(app.getImage(cb, "gifs/disk.gif")); + + tb.addSpacer(newButton.preferredSize().width); + + printButton = tb.add(app.getImage(cb, "gifs/print.gif")); + + tb.addSpacer(newButton.preferredSize().width); + + cutButton = tb.add(app.getImage(cb, "gifs/cut.gif")); + copyButton = tb.add(app.getImage(cb, "gifs/copy.gif")); + pasteButton = tb.add(app.getImage(cb, "gifs/paste.gif")); + + return tb; + } + private Panel makePalette(Applet app, URL cb) { + ExclusiveImageButtonPanel iconPalette; + Panel iconPalettePanel = new Panel(); + + iconPalette = new ExclusiveImageButtonPanel( + Orientation.VERTICAL, + Orientation.CENTER, + Orientation.TOP, 10); + + iconPalette.add(app.getImage(cb,"gifs/ballot_box.gif")); + iconPalette.add(app.getImage(cb,"gifs/palette.gif")); + iconPalette.add(app.getImage(cb,"gifs/light_bulb1.gif")); + iconPalette.add(app.getImage(cb,"gifs/Dining.gif")); + iconPalette.add(app.getImage(cb,"gifs/scissors.gif")); + iconPalette.add(app.getImage(cb,"gifs/tricycle.gif")); + + iconPalettePanel = new Panel(); + iconPalettePanel.setLayout(new BorderLayout()); + iconPalettePanel.add ("Center", iconPalette); + iconPalettePanel.add ("East", new Separator()); + return iconPalettePanel; + } +} diff --git a/java/gjt/test/TwoDrinkersAnimationTest.java b/java/gjt/test/TwoDrinkersAnimationTest.java new file mode 100644 index 00000000000..ae4041b9eb6 --- /dev/null +++ b/java/gjt/test/TwoDrinkersAnimationTest.java @@ -0,0 +1,130 @@ +package gjt.test; + +import java.net.URL; +import java.applet.Applet; +import java.awt.*; +import java.awt.Panel; + +import gjt.Util; +import gjt.Orientation; +import gjt.animation.*; + +/** + * An animation playfield containing two "java drinkers", that + * both bounce off the sides of the playfield.<p> + * + * One of the java drinkers moves slow and spins fast, while + * the other java drinker moves fast and spins slow. When + * the two java drinkers collide, they both play a bump + * sequence - at different speeds.<p> + * + * @version 1.0, Apr 1 1996 + * @author David Geary + * @see gjt.test.AnimationTest + * @see gjt.animation.Playfield + * @see gjt.animation.Sprite + */ +public class TwoDrinkersAnimationTest extends UnitTest { + public String title() { + return + "TwoDrinkers Animation - Mouse Down Starts/Stops"; + } + public Panel centerPanel() { + return new TwoDrinkersAnimationTestPanel(this); + } +} + +class TwoDrinkersAnimationTestPanel extends Panel { + public TwoDrinkersAnimationTestPanel(Applet applet) { + setLayout(new BorderLayout()); + add("Center", new TwoDrinkersPlayfield(applet)); + } +} + +class TwoDrinkersPlayfield extends Playfield { + private Applet applet; + private URL cb; + private Sprite moveFastSpinSlow, moveSlowSpinFast; + private Sequence fastSpinSequence, + slowSpinSequence, + fastBumpSequence, + slowBumpSequence; + + public TwoDrinkersPlayfield(Applet applet) { + this.applet = applet; + cb = applet.getCodeBase(); + makeSequencesAndSprites(); + } + public void paintBackground(Graphics g) { + Image bg = applet.getImage(cb, "gifs/background.gif"); + Util.wallPaper(this, g, bg); + } + public boolean mouseDown(Event event, int x, int y) { + if(running() == true) stop (); + else start(); + return true; + } + public void spriteCollision(Sprite sprite, Sprite sprite2) { + if(moveSlowSpinFast.getSequence() != fastBumpSequence) { + sprite.reverse(); + sprite2.reverse(); + + moveSlowSpinFast.play(fastBumpSequence, 3); + moveFastSpinSlow.play(slowBumpSequence, 3); + } + } + public void edgeCollision(Sprite sprite, + Orientation orientation) { + if(orientation == Orientation.RIGHT || + orientation == Orientation.LEFT) + sprite.reverseX(); + else + sprite.reverseY(); + } + private void makeSequencesAndSprites() { + String file; + Image[] spinImages = new Image[19]; + Image[] bumpImages = new Image[6]; + Image[] volleyball = new Image[4]; + + for(int i=0; i < spinImages.length; ++i) { + file = "gifs/spin"; + + if(i < 10) file += "0" + i + ".gif"; + else file += i + ".gif"; + + spinImages[i] = applet.getImage(cb, file); + } + for(int i=0; i < bumpImages.length; ++i) { + file = "gifs/bump0" + i + ".gif"; + bumpImages[i] = applet.getImage(cb, file); + } + fastSpinSequence = new Sequence(this, spinImages); + slowSpinSequence = new Sequence(this, spinImages); + + fastBumpSequence = new Sequence(this, bumpImages); + slowBumpSequence = new Sequence(this, bumpImages); + + moveFastSpinSlow = + new Sprite(this, + slowSpinSequence, new Point(25, 75)); + + moveSlowSpinFast = + new Sprite(this, + fastSpinSequence, new Point(250,250)); + + fastSpinSequence.setAdvanceInterval(50); + slowSpinSequence.setAdvanceInterval(300); + + fastBumpSequence.setAdvanceInterval(25); + slowBumpSequence.setAdvanceInterval(200); + + moveFastSpinSlow.setMoveVector(new Point(2,3)); + moveSlowSpinFast.setMoveVector(new Point(-1,-1)); + + moveSlowSpinFast.setMoveInterval(100); + + addSprite(moveFastSpinSlow); + addSprite(moveSlowSpinFast); + } +} diff --git a/java/gjt/test/UnitTest.java b/java/gjt/test/UnitTest.java new file mode 100644 index 00000000000..1fa262d5629 --- /dev/null +++ b/java/gjt/test/UnitTest.java @@ -0,0 +1,46 @@ +package gjt.test; + +import java.awt.BorderLayout; +import java.awt.Frame; +import java.awt.Panel; +import java.applet.Applet; +import gjt.*; + +/** + * An (abstract) Applet fitted with a BorderLayout that + * contains a TitledPanel in the North, and a Panel created by + * derived classes in the Center.<p> + * + * Since some Applets take awhile to load, UnitTest changes the + * cursor to a wait cursor in init(), changing it back to the + * default cursor in start(). Derived classes must be sure to + * call super.init() if they override init(); likewise for + * start().<p> + * + * Subclasses must implement: + * <dl> + * <dd>String title() + * <dd>Panel centerPanel() + * </dl> + * Subclasses should populate the Panel returned from + * centerPanel() with whatever makes sense for their unit test. + * + * @version 1.0, April 25, 1996 + * @author David Geary + * @see TitledPanel + */ +abstract public class UnitTest extends Applet { + abstract public String title(); + abstract public Panel centerPanel(); + + public void init() { + Util.getFrame(this).setCursor(Frame.WAIT_CURSOR); + Panel titledPanel = new TitledPanel(title()); + setLayout(new BorderLayout()); + add("North", titledPanel); + add("Center", centerPanel()); + } + public void start() { + Util.getFrame(this).setCursor(Frame.DEFAULT_CURSOR); + } +} |