1 package org.devaki.nextobjects.ui.components;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.awt.GridBagConstraints;
22 import java.awt.GridBagLayout;
23 import java.awt.Insets;
24 import java.awt.Point;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import javax.swing.JButton;
28 import javax.swing.JMenuItem;
29 import javax.swing.JPanel;
30 import javax.swing.JPopupMenu;
31 import org.devaki.nextobjects.NextObjects;
32 /***
33 * This class i sresponsible for a part of the drop menu
34 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
35 */
36 public class CustomButtonMenu extends JPanel
37 {
38 /***
39 * Internal popupmenu needed to make the button drop
40 */
41 private JPopupMenu jPopupMenu = new JPopupMenu();
42 /***
43 * Internal drop button
44 */
45 private CustomButton jDropButton =
46 new CustomButton(
47 NextObjects.getReference().loadIconResource("dropMenu.gif"),
48 "",
49 " ",
50 true);
51 /***
52 * Construct a new 'CustomButtonMenu' object
53 * @param defaultButton the default button
54 * @param pMenuItems the menu item
55 */
56 public CustomButtonMenu(
57 final JButton defaultButton,
58 final JMenuItem[] pMenuItems)
59 {
60
61
62 this.setLayout(new GridBagLayout());
63
64 this.jPopupMenu.setInvoker(this);
65 for (int i = 0; i < pMenuItems.length; i++)
66 {
67 this.jPopupMenu.add(pMenuItems[i]);
68 }
69
70 this.jDropButton.addActionListener(new ActionListener()
71 {
72 public final void actionPerformed(final ActionEvent ae)
73 {
74 Point p = getLocationOnScreen();
75 p.y += getHeight();
76 jPopupMenu.setLocation(p);
77 jPopupMenu.setVisible(true);
78 }
79 });
80
81 this.add(
82 defaultButton,
83 new GridBagConstraints(
84 0,
85 0,
86 1,
87 1,
88 1.0,
89 1.0,
90 GridBagConstraints.CENTER,
91 GridBagConstraints.BOTH,
92 new Insets(0, 0, 0, 0),
93 0,
94 0));
95 this.add(
96 jDropButton,
97 new GridBagConstraints(
98 1,
99 0,
100 1,
101 1,
102 0.0,
103 1.0,
104 GridBagConstraints.CENTER,
105 GridBagConstraints.VERTICAL,
106 new Insets(0, 0, 0, 0),
107 0,
108 0));
109 }
110 }