Subversion Repositories svn.mios

Rev

Rev 628 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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