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.CodeReferencePresenter;
045: import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter;
046: import org.netbeans.modules.vmd.api.model.*;
047: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
048: import org.netbeans.modules.vmd.api.model.presenters.actions.DeleteDependencyPresenter;
049: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
050: import org.netbeans.modules.vmd.api.properties.DesignEventFilterResolver;
051: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
052: import org.netbeans.modules.vmd.midp.codegen.MidpCodePresenterSupport;
053: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
054: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
055: import org.netbeans.modules.vmd.midp.codegen.SwitchDisplayableParameterPresenter;
056: import org.netbeans.modules.vmd.midp.components.*;
057: import org.netbeans.modules.vmd.midpnb.components.SVGImageAcceptTrensferableKindPresenter;
058: import org.netbeans.modules.vmd.midp.components.displayables.CanvasCD;
059: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
060: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorBooleanUC;
061: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorNumber;
062: import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.PropertyEditorResource;
063: import org.netbeans.modules.vmd.midpnb.codegen.MidpCustomCodePresenterSupport;
064: import org.netbeans.modules.vmd.midpnb.general.SVGFileAcceptPresenter;
065: import org.netbeans.modules.vmd.midpnb.propertyeditors.SVGImageEditorElement;
066: import org.netbeans.modules.vmd.midpnb.screen.display.SVGPlayerDisplayPresenter;
067: import org.openide.util.NbBundle;
068: import java.util.ArrayList;
069: import java.util.Arrays;
070: import java.util.List;
071: import org.netbeans.modules.vmd.api.model.presenters.actions.ActionsPresenter;
072: import org.netbeans.modules.vmd.midpnb.actions.EditSVGFileAction;
073: import org.openide.util.actions.SystemAction;
074:
075: /**
076: *
077: * @author Karol Harezlak
078: */
079: public class SVGPlayerCD extends ComponentDescriptor {
080:
081: public static final TypeID TYPEID = new TypeID(
082: TypeID.Kind.COMPONENT,
083: "org.netbeans.microedition.svg.SVGPlayer"); // NOI18N
084:
085: public static final String ICON_PATH = "org/netbeans/modules/vmd/midpnb/resources/svg_player_16.png"; // NOI18N
086: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midpnb/resources/svg_player_32.png"; // NOI18N
087:
088: public static final String PROP_SVG_IMAGE = "svgImage"; //NOI18N
089: public static final String PROP_START_ANIM_IMMEDIATELY = "startAnimationImmediately"; //NOI18N
090: public static final String PROP_TIME_INCREMENT = "animationTimeIncrement"; //NOI18N
091: public static final String PROP_RESET_ANIMATION_WHEN_STOPPED = "resetAnimationWhenStopped"; //NOI18N
092:
093: public static final String PROP_OLD_START_ANIM_IMMEDIATELY = "startAnimationImmideately"; //NOI18N
094:
095: public static final String[] MIDP_NB_SVG_LIBRARY = { "nb_svg_midp_components" }; //NOI18N
096:
097: static {
098: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
099: }
100:
101: public TypeDescriptor getTypeDescriptor() {
102: return new TypeDescriptor(CanvasCD.TYPEID, TYPEID, true, true);
103: }
104:
105: public VersionDescriptor getVersionDescriptor() {
106: return MidpVersionDescriptor.FOREVER;
107: }
108:
109: @Override
110: public void postInitialize(DesignComponent component) {
111: component.writeProperty(PROP_START_ANIM_IMMEDIATELY, MidpTypes
112: .createBooleanValue(true));
113: MidpProjectSupport.addLibraryToProject(component.getDocument(),
114: MIDP_NB_SVG_LIBRARY);
115: }
116:
117: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
118: return Arrays.asList(new PropertyDescriptor(PROP_SVG_IMAGE,
119: SVGImageCD.TYPEID, PropertyValue.createNull(), true,
120: true, Versionable.FOREVER), new PropertyDescriptor(
121: PROP_START_ANIM_IMMEDIATELY, MidpTypes.TYPEID_BOOLEAN,
122: MidpTypes.createBooleanValue(true), false, true,
123: Versionable.FOREVER), new PropertyDescriptor(
124: PROP_TIME_INCREMENT, MidpTypes.TYPEID_FLOAT, MidpTypes
125: .createFloatValue(0.1f), false, true,
126: Versionable.FOREVER), new PropertyDescriptor(
127: PROP_RESET_ANIMATION_WHEN_STOPPED,
128: MidpTypes.TYPEID_BOOLEAN, MidpTypes
129: .createBooleanValue(true), false, true,
130: Versionable.FOREVER));
131: }
132:
133: @Override
134: protected void gatherPresenters(ArrayList<Presenter> presenters) {
135: DocumentSupport.removePresentersOfClass(presenters,
136: ScreenDisplayPresenter.class);
137: super .gatherPresenters(presenters);
138: }
139:
140: private static DefaultPropertiesPresenter createPropertiesPresenter() {
141: return new DefaultPropertiesPresenter(
142: DesignEventFilterResolver.THIS_COMPONENT)
143: .addPropertiesCategory(
144: MidpPropertiesCategories.CATEGORY_PROPERTIES)
145: .addProperty(
146: NbBundle.getMessage(SVGPlayerCD.class,
147: "DISP_SVGPlayer_SVGImage"), //NOI18N
148: PropertyEditorResource.createInstance(
149: new SVGImageEditorElement(), NbBundle
150: .getMessage(
151: SVGWaitScreenCD.class,
152: "LBL_SVGIMAGE_NEW"), //NOI18N
153: NbBundle.getMessage(
154: SVGWaitScreenCD.class,
155: "LBL_SVGIMAGE_NONE"), //NOI18N
156: NbBundle.getMessage(
157: SVGWaitScreenCD.class,
158: "LBL_SVGIMAGE_UCLABEL")),
159: PROP_SVG_IMAGE) //NOI18N
160: .addProperty(
161: NbBundle
162: .getMessage(SVGPlayerCD.class,
163: "DISP_SVGPlayer_StartAnimationImmediately"), // NOI18N
164: PropertyEditorBooleanUC
165: .createInstance(NbBundle
166: .getMessage(SVGPlayerCD.class,
167: "LBL_SVGPlayer_StartAnimationImmediately")),
168: PROP_START_ANIM_IMMEDIATELY) // NOI18N
169: .addProperty(
170: NbBundle
171: .getMessage(SVGPlayerCD.class,
172: "DISP_SVGPlayer_AnimationTimeIncrement"), // NOI18N
173: PropertyEditorNumber
174: .createFloatInstance(NbBundle
175: .getMessage(SVGPlayerCD.class,
176: "LBL_SVGPlayer_AnimationTimeIncrement")),
177: PROP_TIME_INCREMENT) // NOI18N
178: .addProperty(
179: NbBundle
180: .getMessage(SVGPlayerCD.class,
181: "DISP_SVGPlayer_ResetAnimationWhenStopped"), // NOI18N
182: PropertyEditorBooleanUC
183: .createInstance(NbBundle
184: .getMessage(SVGPlayerCD.class,
185: "LBL_SVGPlayer_ResetAnimationWhenStopped")),
186: PROP_RESET_ANIMATION_WHEN_STOPPED); // NOI18N
187: }
188:
189: private Presenter createSetterPresenter() {
190: return new CodeSetterPresenter()
191: .addParameters(
192: MidpCustomCodePresenterSupport
193: .createDisplayParameter())
194: .addParameters(
195: MidpParameter.create(PROP_SVG_IMAGE,
196: PROP_START_ANIM_IMMEDIATELY,
197: PROP_TIME_INCREMENT,
198: PROP_RESET_ANIMATION_WHEN_STOPPED))
199: .addSetters(
200: MidpSetter
201: .createConstructor(TYPEID,
202: MidpVersionable.MIDP_2)
203: .addParameters(
204: PROP_SVG_IMAGE,
205: MidpCustomCodePresenterSupport.PARAM_DISPLAY))
206: .addSetters(
207: MidpSetter.createSetter("setTimeIncrement",
208: MidpVersionable.MIDP_2).addParameters(
209: PROP_TIME_INCREMENT)) // NOI18N
210: .addSetters(
211: MidpSetter.createSetter(
212: "setStartAnimationImmediately",
213: MidpVersionable.MIDP_2).addParameters(
214: PROP_START_ANIM_IMMEDIATELY)) //NOI18N
215: .addSetters(
216: MidpSetter.createSetter(
217: "setResetAnimationWhenStopped",
218: MidpVersionable.MIDP_2).addParameters(
219: PROP_RESET_ANIMATION_WHEN_STOPPED)); //NOI18N
220: }
221:
222: protected List<? extends Presenter> createPresenters() {
223: return Arrays.asList(
224: // properties
225: createPropertiesPresenter(),
226: //accept
227: new SVGFileAcceptPresenter(),
228: new MidpAcceptProducerKindPresenter().addType(
229: SVGImageCD.TYPEID, PROP_SVG_IMAGE),
230: new SVGImageAcceptTrensferableKindPresenter().addType(
231: SVGImageCD.TYPEID, PROP_SVG_IMAGE),
232: // code
233: createSetterPresenter(), MidpCodePresenterSupport
234: .createAddImportPresenter(),
235: new SwitchDisplayableParameterPresenter() {
236: public String generateSwitchDisplayableParameterCode() {
237: return CodeReferencePresenter
238: .generateAccessCode(getComponent())
239: + ".getSvgCanvas ()"; // NOI18N
240: }
241: },
242: // delete
243: DeleteDependencyPresenter
244: .createNullableComponentReferencePresenter(PROP_SVG_IMAGE),
245: // screen
246: new SVGPlayerDisplayPresenter(),
247: //actions
248: ActionsPresenter.create(20, SystemAction
249: .get(EditSVGFileAction.class)));
250: }
251:
252: }
|