diff options
Diffstat (limited to 'java/gjt/test/ColumnLayoutTest.java')
-rw-r--r-- | java/gjt/test/ColumnLayoutTest.java | 126 |
1 files changed, 126 insertions, 0 deletions
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; + } +} |