summaryrefslogtreecommitdiff
path: root/java/gjt/IconCardPanel.java
blob: 78940bf8f4f1528070cfbd6d28723bdd3502929b (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
package gjt;

import java.awt.*;

/**
 * A CardPanel whose Component viewSelector() returns
 * a panel with image buttons to control the selection of the
 * panel to be displayed beneath the view selector panel.<p>
 *
 * @version 1.0, Apr 1 1996
 * @author  David Geary
 * @see     CardPanel
 * @see     ChoiceCardpanel
 * @see     gjt.test.IconCardPanelTest
 */
public class IconCardPanel extends CardPanel {
    private ImageButtonPanel viewSelector;

    public IconCardPanel() {
        viewSelector = new IconViewSelector(this);
    }
    public Component viewSelector() {
        return viewSelector;
    }
    public void addImageButton(Image     image, 
                               String    name, 
                               Component component) {
        ImageButton newButton;

        viewSelector.add(
            newButton = new ImageButton(image), name);
        newButton.setController(
            new StickyImageButtonController(newButton));
        super.addView(name, component);
    }
}

class IconViewSelector extends ImageButtonPanel {
    private IconCardPanel mvp;

    public IconViewSelector(IconCardPanel panel) {
        super(Orientation.HORIZONTAL);
        setLayout(new FlowLayout());
        mvp = panel;
    }
    public boolean handleEvent(Event event) {
        if(event.id == Event.MOUSE_DOWN) {
            if(event.target instanceof ImageButton) {
                ImageButton ib = (ImageButton)event.target;
                    mvp.showView(getButtonName(ib)); 
            }
        }
        return super.handleEvent(event);
    }
}