File: PopupToolBox.java

package info (click to toggle)
libtoolbar-java 1.3-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 240 kB
  • ctags: 413
  • sloc: java: 2,284; xml: 64; makefile: 10
file content (70 lines) | stat: -rw-r--r-- 1,932 bytes parent folder | download
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
/*
 * PopupToolBox.java
 *
 * Created on 23 February 2003, 09:59
 */

package org.tigris.toolbar.toolbutton;

import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.Action;
import javax.swing.JButton;

import org.tigris.toolbar.ToolBarManager;

/**
 * A toolbox which appears when the user click the drop down image on
 * a PopupToolBoxButton
 *
 * @author  Bob Tarling
 */
public class PopupToolBox extends ToolBox {

    private static final long serialVersionUID = 6967167639464142577L;
    
    private ArrayList actions = new ArrayList();
    private MouseListener mouseListener;

    /** Creates a new instance of PopupToolBox */
    public PopupToolBox(int rows, int cols) {
        super(rows, cols);
    }

    /** Creates a new instance of PopupToolBox */
    public PopupToolBox(int rows, int cols, boolean rollover) {
        super(rows, cols, rollover);
    }

    public JButton add(Action action) {
        JButton button = super.add(action);
        actions.add(action);
        
        return button;
    }

    public void setButtonMouseListener(MouseListener mouseListener) {
        this.mouseListener = mouseListener;
    }

    /**
     * Occasionally the ToolBox gets in a state where a button
     * shows rollover status at the wrong time.
     * The only way to get around this is to rebuild the ToolBox.
     */
    public void rebuild() {
        super.removeAll();
        Iterator it = actions.iterator();
        while(it.hasNext()) {
            Action a = (Action)it.next();
            JButton button = super.add(a);
            if (!ToolBarManager.alwaysUseStandardRollover()) {
                button.setBorderPainted(false);
            }
            if (mouseListener != null) {
                button.addMouseListener(mouseListener);
            }
        }
    }
}