Source code: com/virtuosotechnologies/lib/basiccommand/builder/PopupMenuBuilderNode.java
1 /*
2 ================================================================================
3
4 FILE: PopupMenuBuilderNode.java
5
6 PROJECT:
7
8 Virtuoso Utilities
9
10 CONTENTS:
11
12 A builder that creates a popup menu. Useful for building contextual
13 menus
14
15 PROGRAMMERS:
16
17 Daniel Azuma (DA) <dazuma@kagi.com>
18
19 COPYRIGHT:
20
21 Copyright (C) 2003 Daniel Azuma (dazuma@kagi.com)
22
23 This program is free software; you can redistribute it and/or
24 modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation; either version 2
26 of the License, or (at your option) any later version.
27
28 This program is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
32
33 You should have received a copy of the GNU General Public
34 License along with this program; if not, write to
35 Free Software Foundation, Inc.
36 59 Temple Place, Suite 330
37 Boston, MA 02111-1307 USA
38
39 ================================================================================
40 */
41
42
43 package com.virtuosotechnologies.lib.basiccommand.builder;
44
45
46 import javax.swing.JPopupMenu;
47
48 import com.virtuosotechnologies.lib.command.CommandNode;
49 import com.virtuosotechnologies.lib.command.CommandNodeFlavor;
50 import com.virtuosotechnologies.lib.basiccommand.BasicCommandNode;
51
52
53 /**
54 * A builder that creates a popup menu. Useful for building contextual
55 * menus
56 */
57 public class PopupMenuBuilderNode
58 extends AbstractAWTContainerBuilderNode
59 {
60 /**
61 * Public constructor
62 */
63 public PopupMenuBuilderNode(
64 CommandNode commandNode)
65 {
66 super(commandNode, null, END_POSITION);
67 }
68
69
70 /**
71 * Public constructor
72 */
73 public PopupMenuBuilderNode(
74 CommandNode commandNode,
75 JPopupMenu menu)
76 {
77 super(commandNode, null, END_POSITION, menu);
78 }
79
80
81 /**
82 * Override this method to create the initial element object.
83 */
84 protected Object createInitialElement()
85 {
86 return new JPopupMenu();
87 }
88
89
90 /**
91 * Create a child node
92 */
93 protected AbstractBuilderNode createChildNode(
94 CommandNode cn,
95 int index)
96 {
97 AbstractBuilderNode child = null;
98 CommandNodeFlavor flavor = cn.getFlavor();
99 if (flavor.equalsOrExtends(BasicCommandNode.SEPARATOR_FLAVOR))
100 {
101 child = new MenuSeparatorBuilderNode(cn, this, index);
102 }
103 else if (flavor.equalsOrExtends(BasicCommandNode.ACTIONITEM_FLAVOR))
104 {
105 child = new MenuItemBuilderNode(cn, this, index);
106 }
107 else if (flavor.equalsOrExtends(BasicCommandNode.TOGGLEITEM_FLAVOR))
108 {
109 child = new MenuCheckBoxItemBuilderNode(cn, this, index);
110 }
111 else if (flavor.equalsOrExtends(BasicCommandNode.RADIOGROUP_FLAVOR))
112 {
113 child = new MenuRadioGroupBuilderNode(cn, this, index);
114 }
115 else if (flavor.equalsOrExtends(BasicCommandNode.GROUP_FLAVOR))
116 {
117 child = new MenuGroupBuilderNode(cn, this, index);
118 }
119 else if (flavor.equalsOrExtends(BasicCommandNode.RADIOCONTAINER_FLAVOR))
120 {
121 child = new MenuRadioMenuBuilderNode(cn, this, index);
122 }
123 else if (flavor.equalsOrExtends(BasicCommandNode.CONTAINER_FLAVOR))
124 {
125 child = new MenuBuilderNode(cn, this, index);
126 }
127 return child;
128 }
129
130
131 /**
132 * Get the built menu
133 */
134 public JPopupMenu getJPopupMenu()
135 {
136 return (JPopupMenu)getElement();
137 }
138 }