16 package net.squiz.matrix.ui;
19 import java.awt.event.*;
21 import javax.swing.event.*;
25 private JPopupMenu popup;
27 private Icon depressedIcon;
28 public ButtonMenu(String text, JPopupMenu popup) {
30 addActionListener(buttonAction);
36 addActionListener(buttonAction);
39 public ButtonMenu(Icon icon, Icon depressedIcon) {
42 this.depressedIcon = depressedIcon;
43 addActionListener(buttonAction);
46 public void setPopupMenu(JPopupMenu newPopup) {
48 popup.removePopupMenuListener(popupListener);
52 popup.addPopupMenuListener(popupListener);
56 protected void showPopup() {
58 popup.show(
ButtonMenu.this, 0, getSize().height);
62 protected void hidePopup() {
64 popup.setVisible(
false);
68 private ActionListener buttonAction =
new ActionListener() {
69 public void actionPerformed(ActionEvent event) {
72 if (depressedIcon != null)
73 setIcon(depressedIcon);
76 if (depressedIcon != null)
82 private PopupMenuListener popupListener =
new PopupMenuListener() {
83 public void popupMenuWillBecomeInvisible(PopupMenuEvent event) {
86 SwingUtilities.invokeLater(
new Runnable() {
93 public void popupMenuWillBecomeVisible(PopupMenuEvent event) {}
94 public void popupMenuCanceled(PopupMenuEvent event) {}