Subversion Repositories svn.mios

Rev

Rev 753 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 753 Rev 762
1
package org.midibox.utils.gui;
1
package org.midibox.utils.gui;
2
2
3
import java.awt.Component;
3
import java.awt.Component;
4
import java.awt.Dimension;
-
 
5
import java.awt.Insets;
4
import java.awt.Insets;
6
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
6
import java.awt.event.ActionListener;
8
7
9
import javax.swing.ImageIcon;
8
import javax.swing.ImageIcon;
10
import javax.swing.JButton;
9
import javax.swing.JButton;
11
import javax.swing.JPopupMenu;
10
import javax.swing.JPopupMenu;
12
import javax.swing.JToolBar;
11
import javax.swing.JToolBar;
13
12
14
public class SplitButton extends JToolBar implements ActionListener {
13
public class SplitButton extends JToolBar implements ActionListener {
15
    private JButton button, splitButton;
14
    private JButton button, splitButton;
16
    private JPopupMenu dropMenu;
15
    private JPopupMenu dropMenu;
17
16
18
    public SplitButton(JButton button, JPopupMenu dropMenu) {
17
    public SplitButton(JButton button, JPopupMenu dropMenu) {
19
        this.button = button;
18
        this.button = button;
20
        this.dropMenu = dropMenu;
19
        this.dropMenu = dropMenu;
21
        setFloatable(false);
20
        setFloatable(false);
22
        this.setBorderPainted(false);
21
        this.setBorderPainted(false);
23
        ImageIcon icon = ImageLoader.getImageIcon("pulldown.png");
22
        ImageIcon icon = ImageLoader.getImageIcon("pulldown.png");
24
        splitButton = new JButton();
23
        splitButton = new JButton();
25
        splitButton.setIcon(icon);
24
        splitButton.setIcon(icon);
26
        splitButton.addActionListener(this);
25
        splitButton.addActionListener(this);
27
        splitButton.setFocusPainted(false);
26
        splitButton.setFocusPainted(false);
28
        splitButton.setMargin(new Insets(2, 0, 2, 0));
27
        splitButton.setMargin(new Insets(2, 0, 2, 0));
29
        setOpaque(false);
28
        setOpaque(false);
30
        add(button);
29
        add(button);
31
        add(splitButton);
30
        add(splitButton);
32
    }
31
    }
33
32
34
    public void actionPerformed(ActionEvent e) {
33
    public void actionPerformed(ActionEvent e) {
35
        if (e.getSource() == splitButton) {
34
        if (e.getSource() == splitButton) {
36
            Component c = (Component) button;
35
            Component c = (Component) button;
37
            dropMenu.show(c, 0, c.getHeight());
36
            dropMenu.show(c, 0, c.getHeight());
38
        }
37
        }
39
    }
38
    }
40
}
39
}
41
 
40