summaryrefslogtreecommitdiff
path: root/java/gjt/Toolbar.java
blob: 4d6ebddc217717b71714c73e1bdc701e3cb13e53 (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
package gjt;

import java.awt.*;

/**
 * A toolbar containing image buttons which are laid out to the
 * north of (horizontal) separator.<p>
 *
 * @version 1.0, Apr 1 1996
 * @author  David Geary
 * @see     ImageButton
 * @see     ImageButtonPanel
 * @see     gjt.test.ToolbarTest
 */
public class Toolbar extends Panel {
    static private int _defaultGap       = 0;
    static private int _defaultLeftInset = 0;

    private ToolbarButtonPanel buttonPanel;

    public Toolbar() {
        this(_defaultLeftInset, _defaultGap);
    }
    public Toolbar(int leftInset, int gap) {
        buttonPanel = new ToolbarButtonPanel(leftInset, gap);
        
        setLayout(new BorderLayout());
        add      ("North", buttonPanel);
        add      ("South", new Separator());
    }
    public ImageButton add(Image image) {
        return buttonPanel.add(image);
    }
    public void add(ImageButton button) {
        buttonPanel.add(button);      
    }
    public void addSpacer(int sizeInPixels) {
        Assert.notFalse(sizeInPixels > 0);
        buttonPanel.addSpacer(sizeInPixels);
    }
}

class ToolbarButtonPanel extends ImageButtonPanel {
    private int leftInset;

    public ToolbarButtonPanel(int leftInset, int gap) {
        super(Orientation.HORIZONTAL,
              Orientation.LEFT,         
              Orientation.CENTER,
              gap);

        this.leftInset = leftInset;
        setController(null);
    }
    public Insets insets() {
        return new Insets(5,leftInset,5,5);
    }
}