001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.form;
043:
044: import java.awt.*;
045:
046: /**
047: * RADMenuItemComponent represents one menu item component in the Form.
048: *
049: * @author Petr Hamernik, Ian Formanek
050: */
051:
052: public class RADMenuItemComponent extends RADComponent {
053:
054: /** Type of menu */
055: private int type;
056:
057: /** Possible constants for type variable */
058: static final int T_MENUBAR = 0x01110;
059: static final int T_MENUITEM = 0x00011;
060: static final int T_CHECKBOXMENUITEM = 0x00012;
061: static final int T_MENU = 0x00113;
062: static final int T_POPUPMENU = 0x01114;
063:
064: static final int T_SEPARATOR = 0x1001B;
065:
066: /** Masks for the T_XXX constants */
067: static final int MASK_AWT = 0x00010;
068: // static final int MASK_SWING = 0x00020;
069: static final int MASK_CONTAINER = 0x00100;
070: static final int MASK_ROOT = 0x01000;
071: static final int MASK_SEPARATOR = 0x10000;
072:
073: @Override
074: public Object initInstance(Class<? extends Object> beanClass)
075: throws Exception {
076: type = recognizeType(beanClass);
077: return super .initInstance(beanClass);
078: }
079:
080: @Override
081: protected org.openide.nodes.Node.Property[] createSyntheticProperties() {
082: // no synthetic properties for AWT Separator
083: if (type == T_SEPARATOR)
084: return RADComponent.NO_PROPERTIES;
085: else
086: return super .createSyntheticProperties();
087: }
088:
089: int getMenuItemType() {
090: return type;
091: }
092:
093: /** Recognizes type of the menu from its class.
094: * @return adequate T_XXX constant
095: */
096: static int recognizeType(Class cl) {
097: if (org.netbeans.modules.form.Separator.class
098: .isAssignableFrom(cl))
099: return T_SEPARATOR;
100: if (PopupMenu.class.isAssignableFrom(cl))
101: return T_POPUPMENU;
102: if (Menu.class.isAssignableFrom(cl))
103: return T_MENU;
104: if (CheckboxMenuItem.class.isAssignableFrom(cl))
105: return T_CHECKBOXMENUITEM;
106: if (MenuItem.class.isAssignableFrom(cl))
107: return T_MENUITEM;
108: if (MenuBar.class.isAssignableFrom(cl))
109: return T_MENUBAR;
110:
111: throw new IllegalArgumentException(
112: "Cannot create RADMenuItemComponent for class: "
113: + cl.getName()); // NOI18N
114: }
115:
116: @Override
117: public Object cloneBeanInstance(
118: java.util.Collection<RADProperty> relativeProperties) {
119: if (type == T_SEPARATOR)
120: return null; // don't clone artificial org.netbeans.modules.form.Separator
121: return super.cloneBeanInstance(relativeProperties);
122: }
123:
124: }
|