File: PopupToolBox.java

package info (click to toggle)
libswidgets-java 0.1.4-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, squeeze
  • size: 356 kB
  • ctags: 667
  • sloc: java: 3,436; xml: 64; makefile: 11
file content (69 lines) | stat: -rw-r--r-- 1,742 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
// $Id: PopupToolBox.java,v 1.1 2004/11/03 18:30:05 bobtarling Exp $

/*
 * PopupToolBox.java
 *
 * Created on 23 February 2003, 09:59
 */

package org.tigris.swidgets;

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

/**
 *
 * @author  Bob Tarling
 */
public class PopupToolBox extends Toolbox {

    private ArrayList actions = new ArrayList();
    private MouseListener mouseListener;

    /** 
     * Creates a new instance of PopupToolBox.
     * 
     * @param rows the number of rows
     * @param cols the number of columns
     */
    public PopupToolBox(int rows, int cols) {
        super(rows, cols);
    }

    /**
     * @see javax.swing.JToolBar#add(javax.swing.Action)
     */
    public JButton add(Action action) {
        JButton button = super.add(action);
        actions.add(action);
        
        return button;
    }

    /**
     * @param theMouseListener the new mouse listener
     */
    public void setButtonMouseListener(MouseListener theMouseListener) {
        mouseListener = theMouseListener;
    }

    /**
     * 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 (mouseListener != null) {
                button.addMouseListener(mouseListener);
            }
        }
    }
}