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.displayables;
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.DeleteDependencyPresenter;
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.MidpAcceptTrensferableKindPresenter;
054: import org.netbeans.modules.vmd.midp.components.MidpTypes;
055: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
056: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
057: import org.netbeans.modules.vmd.midp.components.handlers.SwitchDisplayableEventHandlerCD;
058: import org.netbeans.modules.vmd.midp.components.items.GaugeCD;
059: import org.netbeans.modules.vmd.midp.components.resources.ImageCD;
060: import org.netbeans.modules.vmd.midp.components.resources.ImageFileAcceptPresenter;
061: import org.netbeans.modules.vmd.midp.flow.FlowAlertViaPinOrderPresenter;
062: import org.netbeans.modules.vmd.midp.general.AbstractEventHandlerCreatorPresenter;
063: import org.netbeans.modules.vmd.midp.propertyeditors.*;
064: import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.PropertyEditorResource;
065: import org.netbeans.modules.vmd.midp.screen.display.AlertDisplayPresenter;
066: import org.openide.util.NbBundle;
067:
068: import java.util.*;
069:
070: /**
071: * @author Karol Harezlak
072: */
073: // TODO - ValidatorPresenter: timeout has to be -2 or positive number
074: public final class AlertCD extends ComponentDescriptor {
075:
076: public static final TypeID TYPEID = new TypeID(
077: TypeID.Kind.COMPONENT, "javax.microedition.lcdui.Alert"); // NOI18N
078:
079: public static final String ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/alert_16.png"; // NOI18N
080: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midp/resources/components/alert_32.png"; // NOI18N
081:
082: public static final PropertyValue FOREVER_VALUE = MidpTypes
083: .createIntegerValue(-2);
084:
085: public static final String PROP_STRING = "string"; // NOI18N
086: public static final String PROP_TIMEOUT = "timeout"; // NOI18N
087: public static final String PROP_IMAGE = ImageCD.PROP_IMAGE; // NOI18N
088: public static final String PROP_ALERT_TYPE = "type"; // NOI18N
089: public static final String PROP_INDICATOR = "indicator"; // NOI18N
090:
091: private static Map<String, PropertyValue> alertTypes;
092:
093: static {
094: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
095: }
096:
097: public TypeDescriptor getTypeDescriptor() {
098: return new TypeDescriptor(ScreenCD.TYPEID, TYPEID, true, true);
099: }
100:
101: public VersionDescriptor getVersionDescriptor() {
102: return MidpVersionDescriptor.MIDP;
103: }
104:
105: @Override
106: public void postInitialize(DesignComponent component) {
107: component.writeProperty(PROP_TIMEOUT, FOREVER_VALUE);
108: }
109:
110: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
111: return Arrays.asList(new PropertyDescriptor(PROP_IMAGE,
112: ImageCD.TYPEID, PropertyValue.createNull(), true, true,
113: MidpVersionable.MIDP), new PropertyDescriptor(
114: PROP_STRING, MidpTypes.TYPEID_JAVA_LANG_STRING,
115: PropertyValue.createNull(), true, true,
116: MidpVersionable.MIDP), new PropertyDescriptor(
117: PROP_TIMEOUT, MidpTypes.TYPEID_INT, PropertyValue
118: .createNull(), false, true,
119: MidpVersionable.MIDP), new PropertyDescriptor(
120: PROP_ALERT_TYPE, MidpTypes.TYPEID_ALERT_TYPE,
121: PropertyValue.createNull(), true, true,
122: MidpVersionable.MIDP), new PropertyDescriptor(
123: PROP_INDICATOR, GaugeCD.TYPEID, PropertyValue
124: .createNull(), true, true,
125: MidpVersionable.MIDP_2));
126: }
127:
128: private static DefaultPropertiesPresenter createPropertiesPresenter() {
129: return new DefaultPropertiesPresenter().addPropertiesCategory(
130: MidpPropertiesCategories.CATEGORY_PROPERTIES)
131: .addProperty(
132: NbBundle.getMessage(AlertCD.class,
133: "DISP_Alert_Image"),
134: PropertyEditorResource
135: .createImagePropertyEditor(),
136: PROP_IMAGE) // NOI18N
137: .addProperty(
138: NbBundle.getMessage(AlertCD.class,
139: "DISP_Alert_String"), // NOI18N
140: PropertyEditorString.createInstance(NbBundle
141: .getMessage(AlertCD.class,
142: "LBL_Alert_String")),
143: PROP_STRING) // NOI18N
144: .addProperty(
145: NbBundle.getMessage(AlertCD.class,
146: "DISP_Alert_Type"), // NOI18N
147: PropertyEditorComboBox.createInstance(
148: getKindTypes(), TYPEID,
149: NbBundle.getMessage(AlertCD.class,
150: "DISP_Alert_Type_RB_LABEL"), // NOI18N
151: NbBundle.getMessage(AlertCD.class,
152: "DISP_Alert_Type_UCLABEL")),
153: PROP_ALERT_TYPE) // NOI18N
154: .addProperty(
155: NbBundle.getMessage(AlertCD.class,
156: "DISP_Alert_Use_Indicator"), // NOI18N
157: PropertyEditorAlertIndicator
158: .createInstance(NbBundle.getMessage(
159: AlertCD.class,
160: "LBL_Alert_Use_Indicator")),
161: PROP_INDICATOR) // NOI18N
162: .addProperty(
163: NbBundle.getMessage(AlertCD.class,
164: "DISP_Alert_Timeout"),
165: PropertyEditorTimeout.createInstance(),
166: PROP_TIMEOUT); // NOI18N
167: }
168:
169: // TODO override Displayable.addCommand, see DesignerMIDP document
170: private static Presenter createSetterPresenter() {
171: return new CodeSetterPresenter().addParameters(
172: MidpParameter.create(PROP_IMAGE, PROP_STRING,
173: PROP_ALERT_TYPE, PROP_INDICATOR))
174: .addParameters(new AlertTimeoutParameter()).addSetters(
175: MidpSetter.createConstructor(TYPEID,
176: MidpVersionable.MIDP).addParameters(
177: DisplayableCD.PROP_TITLE)).addSetters(
178: MidpSetter.createConstructor(TYPEID,
179: MidpVersionable.MIDP).addParameters(
180: DisplayableCD.PROP_TITLE, PROP_STRING,
181: PROP_IMAGE, PROP_ALERT_TYPE))
182: .addSetters(
183: MidpSetter.createSetter("setImage",
184: MidpVersionable.MIDP).addParameters(
185: PROP_IMAGE)) //NOI18N
186: .addSetters(
187: MidpSetter.createSetter("setIndicator",
188: MidpVersionable.MIDP_2).addParameters(
189: PROP_INDICATOR)) //NOI18N
190: .addSetters(
191: MidpSetter.createSetter("setString",
192: MidpVersionable.MIDP).addParameters(
193: PROP_STRING)) //NOI18N
194: .addSetters(
195: MidpSetter.createSetter("setTimeout",
196: MidpVersionable.MIDP).addParameters(
197: AlertTimeoutParameter.PARAM_TIMEOUT)) //NOI18N
198: .addSetters(
199: MidpSetter.createSetter("setType",
200: MidpVersionable.MIDP).addParameters(
201: PROP_ALERT_TYPE)); //NOI18N
202: }
203:
204: @Override
205: protected void gatherPresenters(ArrayList<Presenter> presenters) {
206: DocumentSupport.removePresentersOfClass(presenters,
207: AbstractEventHandlerCreatorPresenter.class);
208: DocumentSupport.removePresentersOfClass(presenters,
209: ScreenDisplayPresenter.class);
210: super .gatherPresenters(presenters);
211: }
212:
213: protected List<? extends Presenter> createPresenters() {
214: return Arrays
215: .asList(
216: // general
217: SwitchDisplayableEventHandlerCD
218: .createSwitchAlertEventHandlerCreatorPresenter(),
219: // properties
220: createPropertiesPresenter(),
221: // code
222: createSetterPresenter(),
223: // delete
224: DeleteDependencyPresenter
225: .createNullableComponentReferencePresenter(PROP_IMAGE),
226: DeleteDependencyPresenter
227: .createNullableComponentReferencePresenter(PROP_INDICATOR),
228: // flow
229: new FlowAlertViaPinOrderPresenter(),
230: // screen
231: new AlertDisplayPresenter(),
232: //accept
233: new MidpAcceptTrensferableKindPresenter()
234: .addType(ImageCD.TYPEID, PROP_IMAGE),
235: new ImageFileAcceptPresenter(
236: ImageCD.PROP_IMAGE, ImageCD.TYPEID,
237: "jpg", "png", "gif") //NOI18N
238: );
239: }
240:
241: public static Map<String, PropertyValue> getKindTypes() {
242: if (alertTypes == null) {
243: alertTypes = new TreeMap<String, PropertyValue>();
244: for (MidpTypes.AlertType type : MidpTypes.AlertType
245: .values()) {
246: alertTypes.put(type.toString(), MidpTypes
247: .createAlertTypeValue(type));
248: }
249: }
250: return alertTypes;
251: }
252:
253: private static class AlertTimeoutParameter extends MidpParameter {
254:
255: public static final String PARAM_TIMEOUT = "timeout"; // NOI18N
256:
257: public AlertTimeoutParameter() {
258: super (PARAM_TIMEOUT);
259: }
260:
261: @Override
262: public void generateParameterCode(DesignComponent component,
263: MultiGuardedSection section, int index) {
264: PropertyValue propertyValue = component
265: .readProperty(PROP_TIMEOUT);
266: if (propertyValue.getKind() == PropertyValue.Kind.VALUE) {
267: int timeout = MidpTypes.getInteger(propertyValue);
268: if (timeout == -2) {
269: section.getWriter().write("Alert.FOREVER"); // NOI18N
270: return;
271: }
272: }
273: super .generateParameterCode(component, section, index);
274: }
275:
276: @Override
277: public boolean isRequiredToBeSet(DesignComponent component) {
278: return true;
279: }
280: }
281:
282: }
|