Subversion Repositories svn.mios

Rev

Rev 290 | Rev 753 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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