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.vmd.midpnb.components.svg;
043:
044: import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter;
045: import org.netbeans.modules.vmd.api.model.*;
046: import org.netbeans.modules.vmd.api.model.support.ArraySupport;
047: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
048: import org.netbeans.modules.vmd.api.properties.DesignEventFilterResolver;
049: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
050: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
051: import org.netbeans.modules.vmd.midp.components.MidpProjectSupport;
052: import org.netbeans.modules.vmd.midp.components.MidpTypes;
053: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
054: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
055: import org.netbeans.modules.vmd.midp.general.AcceptTypePresenter;
056: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
057: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorBooleanUC;
058: import org.netbeans.modules.vmd.midpnb.codegen.MidpCustomCodePresenterSupport;
059: import org.netbeans.modules.vmd.midpnb.components.sources.SVGMenuElementEventSourceCD;
060: import org.netbeans.modules.vmd.midpnb.flow.FlowSVGMenuElementPinOrderPresenter;
061: import org.openide.util.NbBundle;
062:
063: import java.util.ArrayList;
064: import java.util.Arrays;
065: import java.util.List;
066:
067: /**
068: *
069: * @author Karol Harezlak
070: */
071: public class SVGMenuCD extends ComponentDescriptor {
072:
073: public static final TypeID TYPEID = new TypeID(
074: TypeID.Kind.COMPONENT,
075: "org.netbeans.microedition.svg.SVGMenu"); // NOI18N
076:
077: public static final String ICON_PATH = "org/netbeans/modules/vmd/midpnb/resources/svg_menu_16.png"; // NOI18N
078: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midpnb/resources/svg_menu_32.png"; // NOI18N
079:
080: public static final String PROP_ELEMENTS = "elements"; // NOI18N
081: public static final String PROP_INDEX_BASED_SWITCH = "indexBasedSwitch"; // NOI18N
082:
083: static {
084: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
085: }
086:
087: @Override
088: public void postInitialize(DesignComponent component) {
089: MidpProjectSupport.addLibraryToProject(component.getDocument(),
090: SVGPlayerCD.MIDP_NB_SVG_LIBRARY);
091: }
092:
093: public TypeDescriptor getTypeDescriptor() {
094: return new TypeDescriptor(SVGAnimatorWrapperCD.TYPEID, TYPEID,
095: true, true);
096: }
097:
098: public VersionDescriptor getVersionDescriptor() {
099: return MidpVersionDescriptor.MIDP_2;
100: }
101:
102: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
103: return Arrays
104: .asList(
105: new PropertyDescriptor(
106: PROP_ELEMENTS,
107: SVGMenuElementEventSourceCD.TYPEID
108: .getArrayType(),
109: PropertyValue
110: .createEmptyArray(SVGMenuElementEventSourceCD.TYPEID),
111: false, true, MidpVersionable.MIDP_2),
112: new PropertyDescriptor(PROP_INDEX_BASED_SWITCH,
113: MidpTypes.TYPEID_BOOLEAN, MidpTypes
114: .createBooleanValue(false),
115: false, false, Versionable.FOREVER));
116: }
117:
118: private static DefaultPropertiesPresenter createPropertiesPresenter() {
119: return new DefaultPropertiesPresenter(
120: DesignEventFilterResolver.THIS_COMPONENT)
121: .addPropertiesCategory(
122: MidpPropertiesCategories.CATEGORY_CODE_PROPERTIES)
123: .addProperty(
124: NbBundle.getMessage(SVGMenuCD.class,
125: "DISP_SVGMenu_IndexBasedSwitch"),
126: PropertyEditorBooleanUC.createInstance(),
127: PROP_INDEX_BASED_SWITCH); //NOI18N
128:
129: }
130:
131: private static Presenter createSetterPresenter() {
132: return new CodeSetterPresenter()
133: .addParameters(
134: MidpCustomCodePresenterSupport
135: .createSVGMenuElementParameter())
136: .addSetters(
137: MidpSetter
138: .createConstructor(TYPEID,
139: MidpVersionable.MIDP_2)
140: .addParameters(
141: SVGPlayerCD.PROP_SVG_IMAGE,
142: MidpCustomCodePresenterSupport.PARAM_DISPLAY))
143: .addSetters(
144: MidpSetter
145: .createSetter("addMenuElement",
146: MidpVersionable.MIDP_2)
147: .setArrayParameter(
148: MidpCustomCodePresenterSupport.PARAM_SVG_MENU_ELEMENT)
149: .addParameters(
150: MidpCustomCodePresenterSupport.PARAM_SVG_MENU_ELEMENT)); // NOI18N
151: }
152:
153: @Override
154: protected void gatherPresenters(ArrayList<Presenter> presenters) {
155: MidpActionsSupport.addNewActionPresenter(presenters,
156: SVGMenuElementEventSourceCD.TYPEID);
157: super .gatherPresenters(presenters);
158: }
159:
160: protected List<? extends Presenter> createPresenters() {
161: return Arrays.asList(
162: // accept
163: new AcceptTypePresenter(
164: SVGMenuElementEventSourceCD.TYPEID) {
165: @Override
166: protected void notifyCreated(
167: DesignComponent component) {
168: super .notifyCreated(component);
169: ArraySupport.append(getComponent(),
170: SVGMenuCD.PROP_ELEMENTS, component);
171: if (component
172: .isDefaultValue(SVGMenuElementEventSourceCD.PROP_STRING)) {
173: List<PropertyValue> list = getComponent()
174: .readProperty(
175: SVGMenuCD.PROP_ELEMENTS)
176: .getArray();
177: component
178: .writeProperty(
179: SVGMenuElementEventSourceCD.PROP_STRING,
180: MidpTypes
181: .createStringValue(NbBundle
182: .getMessage(
183: SVGMenuCD.class,
184: "DISP_SVGMenu_NewMenuItem",
185: list
186: .size()))); // NOI18N
187: }
188: }
189: },
190: // properties
191: createPropertiesPresenter(),
192: // code
193: createSetterPresenter(), MidpCustomCodePresenterSupport
194: .createSVGMenuCodePresenter(),
195: MidpCustomCodePresenterSupport
196: .createSVGMenuEventHandlerCodeNamePresenter(),
197: // flow
198: new FlowSVGMenuElementPinOrderPresenter()
199:
200: );
201: }
202:
203: }
|