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.midp.components.items;
043:
044: import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter;
045: import org.netbeans.modules.vmd.api.codegen.MultiGuardedSection;
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.DeletePresenter;
049: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
050: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
051: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
052: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
053: import org.netbeans.modules.vmd.midp.components.MidpTypes;
054: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
055: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
056: import org.netbeans.modules.vmd.midp.components.displayables.AlertCD;
057: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
058: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorBooleanUC;
059: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorGaugeMaxValue;
060: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorNumber;
061: import org.netbeans.modules.vmd.midp.screen.display.GaugeDisplayPresenter;
062: import org.openide.util.NbBundle;
063:
064: import java.util.ArrayList;
065: import java.util.Arrays;
066: import java.util.Collections;
067: import java.util.List;
068: import org.netbeans.modules.vmd.api.inspector.InspectorFolderCategoryPresenter;
069: import org.netbeans.modules.vmd.api.inspector.InspectorOrderingController;
070: import org.netbeans.modules.vmd.api.inspector.InspectorPositionPresenter;
071: import org.netbeans.modules.vmd.api.inspector.common.ArrayPropertyOrderingController;
072: import org.netbeans.modules.vmd.api.properties.PropertiesPresenter;
073: import org.netbeans.modules.vmd.midp.components.commands.CommandCD;
074: import org.netbeans.modules.vmd.midp.components.general.ClassCD;
075: import org.netbeans.modules.vmd.midp.components.sources.ItemCommandEventSourceCD;
076: import org.netbeans.modules.vmd.midp.inspector.controllers.GaugePC;
077: import org.netbeans.modules.vmd.midp.inspector.folders.MidpInspectorSupport;
078: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorDefaultCommand;
079: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorInstanceName;
080: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorLayout;
081: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorPreferredSize;
082: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorString;
083:
084: /**
085: *
086: * @author Karol Harezlak
087: */
088:
089: public class GaugeCD extends ComponentDescriptor {
090:
091: public static final TypeID TYPEID = new TypeID(
092: TypeID.Kind.COMPONENT, "javax.microedition.lcdui.Gauge"); // NOI18N
093:
094: public static final int VALUE_INDEFINITE = -1;
095:
096: public static final int VALUE_CONTINUOUS_IDLE = 0;
097: public static final int VALUE_INCREMENTAL_IDLE = 1;
098: public static final int VALUE_CONTINUOUS_RUNNING = 2;
099: public static final int VALUE_INCREMENTAL_UPDATING = 3;
100:
101: public static final String PROP_MAX_VALUE = "maxValue"; // NOI18N
102: public static final String PROP_VALUE = "value"; // NOI18N
103: public static final String PROP_INTERACTIVE = "interactive"; // NOI18N
104: public static final String PROP_USED_BY_ALERT = "usedByAlert"; // NOI18N
105:
106: public TypeDescriptor getTypeDescriptor() {
107: return new TypeDescriptor(ItemCD.TYPEID, TYPEID, true, true);
108: }
109:
110: public VersionDescriptor getVersionDescriptor() {
111: return MidpVersionDescriptor.MIDP;
112: }
113:
114: @Override
115: public void postInitialize(DesignComponent component) {
116: component.writeProperty(PROP_VALUE, MidpTypes
117: .createIntegerValue(50));
118: component.writeProperty(PROP_MAX_VALUE, MidpTypes
119: .createIntegerValue(100));
120: }
121:
122: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
123: return Arrays.asList(
124: new PropertyDescriptor(PROP_USED_BY_ALERT,
125: MidpTypes.TYPEID_BOOLEAN, MidpTypes
126: .createBooleanValue(false), false,
127: false, Versionable.FOREVER), // HINT - used for modelling Alert.indicator
128: new PropertyDescriptor(PROP_INTERACTIVE,
129: MidpTypes.TYPEID_BOOLEAN, MidpTypes
130: .createBooleanValue(false), false,
131: true, MidpVersionable.MIDP),
132: new PropertyDescriptor(PROP_VALUE,
133: MidpTypes.TYPEID_INT, PropertyValue
134: .createNull(), false, true,
135: MidpVersionable.MIDP), new PropertyDescriptor(
136: PROP_MAX_VALUE, MidpTypes.TYPEID_INT,
137: PropertyValue.createNull(), false, true,
138: MidpVersionable.MIDP));
139: }
140:
141: @Override
142: protected void gatherPresenters(ArrayList<Presenter> presenters) {
143: DocumentSupport.removePresentersOfClass(presenters,
144: ScreenDisplayPresenter.class);
145: DocumentSupport.removePresentersOfClass(presenters,
146: PropertiesPresenter.class);
147: DocumentSupport.removePresentersOfClass(presenters,
148: InspectorFolderCategoryPresenter.class);
149: super .gatherPresenters(presenters);
150: }
151:
152: private static DefaultPropertiesPresenter createPropertiesPresenter() {
153: return new DefaultPropertiesPresenter()
154: .addPropertiesCategory(
155: MidpPropertiesCategories.CATEGORY_PROPERTIES)
156: .addProperty(
157: NbBundle.getMessage(GaugeCD.class,
158: "DISP_Gauge_Is_Interactive"), // NOI18N
159: PropertyEditorBooleanUC
160: .createInstance(AlertCD.TYPEID,
161: NbBundle.getMessage(
162: GaugeCD.class,
163: "DISP_RB_Label")),
164: PROP_INTERACTIVE)
165: // NOI18N
166: .addProperty(
167: NbBundle.getMessage(GaugeCD.class,
168: "DISP_Gauge_Maximum_Value"), // NOI18N
169: PropertyEditorGaugeMaxValue.createInstance(),
170: PROP_MAX_VALUE)
171: .addProperty(
172: NbBundle.getMessage(GaugeCD.class,
173: "DISP_Gauge_Value"), // NOI18N
174: PropertyEditorNumber.createIntegerInstance(
175: false, NbBundle.getMessage(
176: GaugeCD.class,
177: "LBL_Gauge_Value")), PROP_VALUE)
178: // NOI18N
179: .addProperty(
180: NbBundle.getMessage(ItemCD.class,
181: "DISP_Item_Label"), // NOI18N
182: PropertyEditorString.createInstance(NbBundle
183: .getMessage(ItemCD.class,
184: "LBL_Item_Label"), // NOI18N
185: AlertCD.TYPEID), ItemCD.PROP_LABEL)
186: .addProperty(
187: NbBundle.getMessage(ItemCD.class,
188: "DISP_Item_Default_Command"), // NOI18N
189: PropertyEditorDefaultCommand
190: .createInstance(AlertCD.TYPEID),
191: ItemCD.PROP_DEFAULT_COMMAND)
192: // NOI18N
193: .addProperty(
194: NbBundle.getMessage(ItemCD.class,
195: "DISP_Item_Layout"), // NOI18N
196: PropertyEditorLayout
197: .createInstance(AlertCD.TYPEID),
198: ItemCD.PROP_LAYOUT)
199: .addProperty(
200: NbBundle.getMessage(ItemCD.class,
201: "DISP_Item_Preferred_Width"), // NOI18N
202: PropertyEditorPreferredSize.createInstance(
203: NbBundle.getMessage(ItemCD.class,
204: "LBL_Item_Preferred_Width"), // NOI18N
205: NbBundle.getMessage(ItemCD.class,
206: "DISP_Item_Preferred_Width"),
207: AlertCD.TYPEID),
208: ItemCD.PROP_PREFERRED_WIDTH)
209: // NOI18N
210: .addProperty(
211: NbBundle.getMessage(ItemCD.class,
212: "DISP_Item_Preferred_Height"), // NOI18N
213: PropertyEditorPreferredSize.createInstance(
214: NbBundle.getMessage(ItemCD.class,
215: "LBL_Item_Preferred_Height"), // NOI18N
216: NbBundle.getMessage(ItemCD.class,
217: "DISP_Item_Preferred_Height"),
218: AlertCD.TYPEID),
219: ItemCD.PROP_PREFERRED_HEIGHT)
220: // NOI18N
221: .addPropertiesCategory(
222: MidpPropertiesCategories.CATEGORY_CODE_PROPERTIES)
223: .addProperty(
224: NbBundle.getMessage(ClassCD.class,
225: "DISP_Class_Instance_Name"), // NOI18N
226: PropertyEditorInstanceName
227: .createInstance(ClassCD.TYPEID),
228: ClassCD.PROP_INSTANCE_NAME).addProperty(
229: NbBundle.getMessage(ClassCD.class,
230: "DISP_Class_Is_Lazy_Initialized"), // NOI18N
231: PropertyEditorBooleanUC.createInstance(),
232: ClassCD.PROP_LAZY_INIT); // NOI18N
233:
234: }
235:
236: private static Presenter createSetterPresenter() {
237: return new CodeSetterPresenter().addParameters(
238: MidpParameter.create(PROP_INTERACTIVE))
239: .addParameters(new GaugeValueParameter(),
240: new GaugeMaxValueParameter())
241: .addSetters(
242: MidpSetter.createConstructor(TYPEID,
243: MidpVersionable.MIDP).addParameters(
244: ItemCD.PROP_LABEL, PROP_INTERACTIVE,
245: GaugeMaxValueParameter.PARAM_MAX_VALUE,
246: GaugeValueParameter.PARAM_VALUE))
247: .addSetters(
248: MidpSetter.createSetter("setValue",
249: MidpVersionable.MIDP).addParameters(
250: GaugeValueParameter.PARAM_VALUE))
251: // NOI18N
252: .addSetters(
253: MidpSetter.createSetter("setMaxValue",
254: MidpVersionable.MIDP).addParameters(
255: GaugeMaxValueParameter.PARAM_MAX_VALUE)); // NOI18N
256: }
257:
258: protected List<? extends Presenter> createPresenters() {
259: return Arrays.asList(
260: // properties
261: createPropertiesPresenter(),
262: // code
263: createSetterPresenter(),
264: // delete
265: new DeletePresenter() {
266: protected void delete() {
267: DesignComponent component = getComponent();
268: if (MidpTypes.getBoolean(component
269: .readProperty(PROP_USED_BY_ALERT))) {
270: component.getParentComponent()
271: .writeProperty(
272: AlertCD.PROP_INDICATOR,
273: PropertyValue.createNull());
274: component
275: .writeProperty(
276: PROP_USED_BY_ALERT,
277: MidpTypes
278: .createBooleanValue(false));
279: }
280: }
281: },
282: // screen
283: new GaugeDisplayPresenter(),
284: //inspector
285: InspectorPositionPresenter.create(new GaugePC()),
286: MidpInspectorSupport
287: .createSpecialComponentCommandCategory(
288: createOrderingArrayController(),
289: AlertCD.TYPEID, CommandCD.TYPEID));
290: }
291:
292: private List<InspectorOrderingController> createOrderingArrayController() {
293: return Collections
294: .<InspectorOrderingController> singletonList(new ArrayPropertyOrderingController(
295: ItemCD.PROP_COMMANDS, 0,
296: ItemCommandEventSourceCD.TYPEID));
297: }
298:
299: private static class GaugeValueParameter extends MidpParameter {
300:
301: private static final String PARAM_VALUE = "value"; // NOI18N
302:
303: protected GaugeValueParameter() {
304: super (PARAM_VALUE);
305: }
306:
307: @Override
308: public void generateParameterCode(DesignComponent component,
309: MultiGuardedSection section, int index) {
310: PropertyValue propertyValue = component
311: .readProperty(PROP_MAX_VALUE);
312: if (propertyValue.getKind() == PropertyValue.Kind.VALUE) {
313: int value = MidpTypes.getInteger(propertyValue);
314: if (value == VALUE_INDEFINITE) {
315: propertyValue = component.readProperty(PROP_VALUE);
316: if (propertyValue.getKind() == PropertyValue.Kind.VALUE) {
317: value = MidpTypes.getInteger(propertyValue);
318: switch (value) {
319: case VALUE_CONTINUOUS_IDLE:
320: section.getWriter().write(
321: "Gauge.CONTINUOUS_IDLE");
322: return; // NOI18N
323: case VALUE_INCREMENTAL_IDLE:
324: section.getWriter().write(
325: "Gauge.INCREMENTAL_IDLE");
326: return; // NOI18N
327: case VALUE_CONTINUOUS_RUNNING:
328: section.getWriter().write(
329: "Gauge.CONTINUOUS_RUNNING");
330: return; // NOI18N
331: case VALUE_INCREMENTAL_UPDATING:
332: section.getWriter().write(
333: "Gauge.INCREMENTAL_UPDATING");
334: return; // NOI18N
335: default:
336: throw Debug.illegalState();
337: }
338: }
339: }
340: }
341: super .generateParameterCode(component, section, index);
342: }
343:
344: @Override
345: public boolean isRequiredToBeSet(DesignComponent component) {
346: return true;
347: }
348:
349: }
350:
351: private static class GaugeMaxValueParameter extends MidpParameter {
352:
353: private static final String PARAM_MAX_VALUE = "maxValue"; // NOI18N
354:
355: public GaugeMaxValueParameter() {
356: super (PARAM_MAX_VALUE);
357: }
358:
359: @Override
360: public void generateParameterCode(DesignComponent component,
361: MultiGuardedSection section, int index) {
362: PropertyValue propertyValue = component
363: .readProperty(PROP_MAX_VALUE);
364: if (propertyValue.getKind() == PropertyValue.Kind.VALUE) {
365: int value = MidpTypes.getInteger(propertyValue);
366: if (value == VALUE_INDEFINITE) {
367: section.getWriter().write("Gauge.INDEFINITE"); // NOI18N
368: return;
369: }
370: }
371: super .generateParameterCode(component, section, index);
372: }
373:
374: @Override
375: public boolean isRequiredToBeSet(DesignComponent component) {
376: return true;
377: }
378:
379: }
380:
381: }
|