2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.form;
44
import org.openide.util.datatransfer.NewType;
50
import org.netbeans.modules.form.project.ClassSource;
54
* @author Ian Formanek
57
public class RADMenuComponent extends RADMenuItemComponent implements ComponentContainer {
59
/** Map of possible combinations of menus in menus. Menu types (as Integer)
60
* are mapped to supported (sub)menu types (as Class[]).
62
static Map supportedMenus;
64
/** Initialization of supportedMenus map. */
66
supportedMenus = new HashMap();
67
supportedMenus.put(new Integer(T_MENUBAR),
68
new Class[] { Menu.class });
69
supportedMenus.put(new Integer(T_MENU),
70
new Class[] { MenuItem.class,
71
CheckboxMenuItem.class,
74
supportedMenus.put(new Integer(T_POPUPMENU),
75
new Class[] { MenuItem.class,
76
CheckboxMenuItem.class,
79
// supportedMenus.put(new Integer(T_JMENUBAR),
80
// new Class[] { JMenu.class });
81
// supportedMenus.put(new Integer(T_JMENU),
82
// new Class[] { JMenuItem.class,
83
// JCheckBoxMenuItem.class,
84
// JRadioButtonMenuItem.class,
86
// JSeparator.class });
87
// supportedMenus.put(new Integer(T_JPOPUPMENU),
88
// new Class[] { JMenuItem.class,
89
// JCheckBoxMenuItem.class,
90
// JRadioButtonMenuItem.class,
92
// JSeparator.class });
95
// -----------------------------------------------------------------------------
98
private ArrayList subComponents;
100
// -----------------------------------------------------------------------------
103
/** Support for new types that can be created in this node.
104
* @return array of new type operations that are allowed
106
public NewType[] getNewTypes() {
108
return RADComponent.NO_NEW_TYPES;
110
Class[] classes = (Class[])
111
supportedMenus.get(new Integer(getMenuItemType()));
114
return RADComponent.NO_NEW_TYPES;
116
NewType[] types = new NewType[classes.length];
117
for (int i = 0; i < types.length; i++)
118
types[i] = new NewMenuType(classes[i]);
123
public boolean canAddItem(Class itemType) {
124
Class[] classes = (Class[])
125
supportedMenus.get(new Integer(getMenuItemType()));
128
for (int i=0; i < classes.length; i++)
129
if (classes[i] == itemType) // or more general isAssignableFrom ??
135
// -----------------------------------------------------------------------------
136
// SubComponents Management
138
public RADComponent[] getSubBeans() {
139
RADComponent[] components = new RADComponent [subComponents.size()];
140
subComponents.toArray(components);
144
public void initSubComponents(RADComponent[] initComponents) {
145
if (subComponents == null)
146
subComponents = new ArrayList(initComponents.length);
148
subComponents.clear();
149
subComponents.ensureCapacity(initComponents.length);
152
for (int i = 0; i < initComponents.length; i++) {
153
RADComponent comp = initComponents[i];
154
if (comp instanceof RADMenuItemComponent) {
155
subComponents.add(comp);
156
comp.setParentComponent(this);
161
public void reorderSubComponents(int[] perm) {
162
RADComponent[] components = new RADComponent[subComponents.size()];
163
for (int i=0; i < perm.length; i++)
164
components[perm[i]] = (RADComponent) subComponents.get(i);
166
subComponents.clear();
167
subComponents.addAll(Arrays.asList(components));
170
public void add(RADComponent comp) {
171
if (comp instanceof RADMenuItemComponent) {
172
subComponents.add(comp);
173
comp.setParentComponent(this);
174
// getNodeReference().updateChildren();
178
public void remove(RADComponent comp) {
179
if (subComponents.remove(comp))
180
comp.setParentComponent(null);
181
// getNodeReference().updateChildren();
184
public int getIndexOf(RADComponent comp) {
185
return subComponents.indexOf(comp);
191
/** NewType for creating sub-MenuItem. */
192
class NewMenuType extends NewType {
193
/** Class which represents the menu class for this NewType */
196
/** Constructs new NewType for the given menu class */
197
public NewMenuType(Class item) {
201
/** Display name for the creation action. This should be
202
* presented as an item in a menu.
204
* @return the name of the action
206
public String getName() {
207
String s = item.getName();
209
int index = s.lastIndexOf('.');
211
return s.substring(index + 1);
216
/** Create the object.
217
* @exception IOException if something fails
219
public void create() throws java.io.IOException {
220
getFormModel().getComponentCreator()
221
.createComponent(new ClassSource(item.getName(), null, null),
222
RADMenuComponent.this,