summaryrefslogtreecommitdiff
path: root/java/gjt/test/ToolbarTest.java
blob: f739ce96236bcf30746923ac77b7f81e225012d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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;
    }
}