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.displayables;
043:
044: import java.util.ArrayList;
045: import java.util.Arrays;
046: import java.util.List;
047:
048: import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter;
049: import org.netbeans.modules.vmd.api.model.ComponentDescriptor;
050: import org.netbeans.modules.vmd.api.model.DesignComponent;
051: import org.netbeans.modules.vmd.api.model.Presenter;
052: import org.netbeans.modules.vmd.api.model.PropertyDescriptor;
053: import org.netbeans.modules.vmd.api.model.PropertyValue;
054: import org.netbeans.modules.vmd.api.model.TypeDescriptor;
055: import org.netbeans.modules.vmd.api.model.TypeID;
056: import org.netbeans.modules.vmd.api.model.VersionDescriptor;
057: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
058: import org.netbeans.modules.vmd.api.model.presenters.actions.AddActionPresenter;
059: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
060: import org.netbeans.modules.vmd.api.properties.DesignEventFilterResolver;
061: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
062: import org.netbeans.modules.vmd.midp.codegen.MidpCodePresenterSupport;
063: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
064: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
065: import org.netbeans.modules.vmd.midp.components.MidpProjectSupport;
066: import org.netbeans.modules.vmd.midp.components.MidpTypes;
067: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
068: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
069: import org.netbeans.modules.vmd.midp.components.commands.CommandCD;
070: import org.netbeans.modules.vmd.midp.components.displayables.CanvasCD;
071: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
072: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorBooleanUC;
073: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorColorChooser;
074: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorNumber;
075: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorString;
076: import org.netbeans.modules.vmd.midp.screen.display.DisplayableDisplayPresenter;
077: import org.netbeans.modules.vmd.midpnb.codegen.MidpCustomCodePresenterSupport;
078: import org.netbeans.modules.vmd.midpnb.propertyeditors.PropertyEditorPhoneNumber;
079: import org.netbeans.modules.vmd.midpnb.screen.display.SMSComposerDisplayPresenter;
080: import org.openide.util.NbBundle;
081:
082: /**
083: * @author Karol Harezlak
084: */
085:
086: public final class SMSComposerCD extends ComponentDescriptor {
087:
088: public static final TypeID TYPEID = new TypeID(
089: TypeID.Kind.COMPONENT,
090: "org.netbeans.microedition.lcdui.wma.SMSComposer"); // NOI18N
091:
092: public static final String ICON_PATH = "org/netbeans/modules/vmd/midpnb/resources/sms_composer_16.png"; // NOI18N
093: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midpnb/resources/sms_composer_32.png"; // NOI18N
094:
095: //private static final String ICON_PATH_SD = "org/netbeans/modules/vmd/midpnb/resources/sms_composer_sd.png"; // NOI18N
096:
097: public static final String PROP_PHONE_NUMBER = "phoneNumber"; //NOI18N
098: public static final String PROP_MESSAGE = "message"; //NOI18N
099: public static final String PROP_PORT_NUMBER = "portNumber"; //NOI18N
100: public static final String PROP_BGK_COLOR = "backgroundColor"; //NOI18N
101: public static final String PROP_FRG_COLOR = "foregroungColor"; //NOI18N
102: public static final String PROP_SEND_AUTOMATICALLY = "sendAutomatically"; //NOI18N
103: public static final String PROP_PHONE_NUMEBR_LABEL = "phoneNumberLabel"; //NOI18N
104: public static final String PROP_MESSAGE_LABEL = "messageLabel"; //NOI18N
105:
106: public static final String PHONE_NUMBER_LABEL = NbBundle
107: .getMessage(SMSComposerCD.class,
108: "DISP_SMSComposer_PhoneNumberLabel"); //NOI18N
109: public static final String MESSAGE_LABEL = NbBundle.getMessage(
110: SMSComposerCD.class, "DISP_SMSComposer_MessageLabel"); //NOI18N
111:
112: private static final String CATEGORIES_SMS = "SMS Properties"; //NOI18N
113:
114: static {
115: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
116: }
117:
118: public TypeDescriptor getTypeDescriptor() {
119: return new TypeDescriptor(CanvasCD.TYPEID, TYPEID, true, true);
120: }
121:
122: public VersionDescriptor getVersionDescriptor() {
123: return MidpVersionDescriptor.MIDP_2;
124: }
125:
126: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
127: return Arrays.asList(new PropertyDescriptor(PROP_MESSAGE,
128: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
129: .createNull(), true, true,
130: MidpVersionable.MIDP_2), new PropertyDescriptor(
131: PROP_PHONE_NUMBER, MidpTypes.TYPEID_JAVA_LANG_STRING,
132: PropertyValue.createNull(), true, true,
133: MidpVersionable.MIDP_2), new PropertyDescriptor(
134: PROP_PORT_NUMBER, MidpTypes.TYPEID_INT, MidpTypes
135: .createIntegerValue(50000), true, true,
136: MidpVersionable.MIDP_2), new PropertyDescriptor(
137: PROP_BGK_COLOR, MidpTypes.TYPEID_INT, MidpTypes
138: .createIntegerValue(-3355444), true, true,
139: MidpVersionable.MIDP_2), new PropertyDescriptor(
140: PROP_FRG_COLOR, MidpTypes.TYPEID_INT, MidpTypes
141: .createIntegerValue(-16777216), true, true,
142: MidpVersionable.MIDP_2), new PropertyDescriptor(
143: PROP_SEND_AUTOMATICALLY, MidpTypes.TYPEID_BOOLEAN,
144: MidpTypes.createBooleanValue(true), true, true,
145: MidpVersionable.MIDP_2), new PropertyDescriptor(
146: PROP_PHONE_NUMEBR_LABEL,
147: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
148: .createNull(), true, true,
149: MidpVersionable.MIDP_2), new PropertyDescriptor(
150: PROP_MESSAGE_LABEL, MidpTypes.TYPEID_JAVA_LANG_STRING,
151: PropertyValue.createNull(), true, true,
152: MidpVersionable.MIDP_2));
153: }
154:
155: private static DefaultPropertiesPresenter createPropertiesPresenter() {
156: return new DefaultPropertiesPresenter(
157: DesignEventFilterResolver.THIS_COMPONENT)
158: .addPropertiesCategory(CATEGORIES_SMS)
159: .addProperty(
160: NbBundle.getMessage(SMSComposerCD.class,
161: "DISP_SMSComposer_PhoneNumber"), //NOI18N
162: PropertyEditorPhoneNumber.createInstance(
163: NbBundle.getMessage(
164: SMSComposerCD.class,
165: "LBL_SMSComposer_PhoneNumber"),
166: "testing"), PROP_PHONE_NUMBER)
167: //NOI18N
168: .addProperty(
169: NbBundle.getMessage(SMSComposerCD.class,
170: "DISP_SMSComposer_Message"), //NOI18N
171: PropertyEditorString.createInstance(NbBundle
172: .getMessage(SMSComposerCD.class,
173: "LBL_SMSComposer_Message")),
174: PROP_MESSAGE)
175: //NOI18N
176: .addProperty(
177: NbBundle.getMessage(SMSComposerCD.class,
178: "DISP_SMSComposer_Port_Number"), //NOI18N
179: PropertyEditorNumber.createIntegerInstance(
180: true, NbBundle.getMessage(
181: SMSComposerCD.class,
182: "LBL_SMSComposer_Port_Number")),
183: PROP_PORT_NUMBER)
184: //NOI18N
185: .addProperty(
186: NbBundle.getMessage(SMSComposerCD.class,
187: "DISP_SMSComposer_AutomaticallySend"), //NOI18N
188: PropertyEditorBooleanUC
189: .createInstance(NbBundle
190: .getMessage(
191: SMSComposerCD.class,
192: "LBL_SMSComposer_AutomaticallySend")),
193: PROP_SEND_AUTOMATICALLY)
194: //NOI18N
195: .addPropertiesCategory(
196: MidpPropertiesCategories.CATEGORY_PROPERTIES)
197: .addProperty(
198: NbBundle.getMessage(SMSComposerCD.class,
199: "DISP_SMSComposer_BackgroundColor"), //NOI18N
200: new PropertyEditorColorChooser(true),
201: PROP_BGK_COLOR)
202: .addProperty(
203: NbBundle.getMessage(SMSComposerCD.class,
204: "DISP_SMSComposer_ForegroundColor"), //NOI18N
205: new PropertyEditorColorChooser(true),
206: PROP_FRG_COLOR)
207: .addProperty(
208: NbBundle.getMessage(SMSComposerCD.class,
209: "DISP_SMSComposer_PhoneNumberLabel"), //NOI18N
210: PropertyEditorString
211: .createInstanceWithDefaultValue(
212: PHONE_NUMBER_LABEL,
213: NbBundle
214: .getMessage(
215: SMSComposerCD.class,
216: "LBL_SMSComposer_PhoneNumberLabel")),
217: PROP_PHONE_NUMEBR_LABEL) //NOI18N
218: .addProperty(
219: NbBundle.getMessage(SMSComposerCD.class,
220: "DISP_SMSComposer_MessageLabel"), //NOI18N
221: PropertyEditorString
222: .createInstanceWithDefaultValue(
223: MESSAGE_LABEL,
224: NbBundle
225: .getMessage(
226: SMSComposerCD.class,
227: "LBL_SMSComposer_MessageLabel")),
228: PROP_MESSAGE_LABEL); //NOI18N
229: }
230:
231: private Presenter createSetterPresenter() {
232: return new CodeSetterPresenter()
233: .addParameters(
234: MidpCustomCodePresenterSupport
235: .createDisplayParameter())
236: .addParameters(
237: MidpParameter.create(PROP_MESSAGE,
238: PROP_PHONE_NUMBER, PROP_PORT_NUMBER,
239: PROP_BGK_COLOR, PROP_FRG_COLOR,
240: PROP_SEND_AUTOMATICALLY,
241: PROP_MESSAGE_LABEL,
242: PROP_PHONE_NUMEBR_LABEL))
243: .addSetters(
244: MidpSetter
245: .createConstructor(TYPEID,
246: MidpVersionable.MIDP_2)
247: .addParameters(
248: MidpCustomCodePresenterSupport.PARAM_DISPLAY))
249: .addSetters(
250: MidpSetter.createSetter("setBGColor",
251: MidpVersionable.MIDP).addParameters(
252: PROP_BGK_COLOR)) //NOI18N
253: .addSetters(
254: MidpSetter.createSetter("setFGColor",
255: MidpVersionable.MIDP).addParameters(
256: PROP_FRG_COLOR)) //NOI18N
257: .addSetters(
258: MidpSetter.createSetter("setPhoneNumber",
259: MidpVersionable.MIDP).addParameters(
260: PROP_PHONE_NUMBER)) //NOI18N
261: .addSetters(
262: MidpSetter.createSetter("setPort",
263: MidpVersionable.MIDP).addParameters(
264: PROP_PORT_NUMBER)) //NOI18N
265: .addSetters(
266: MidpSetter.createSetter("setMessage",
267: MidpVersionable.MIDP).addParameters(
268: PROP_MESSAGE)) //NOI18N
269: .addSetters(
270: MidpSetter.createSetter("setSendAutomatically",
271: MidpVersionable.MIDP).addParameters(
272: PROP_SEND_AUTOMATICALLY)) //NOI18N
273: .addSetters(
274: MidpSetter.createSetter("setPhoneNumberLabel",
275: MidpVersionable.MIDP).addParameters(
276: PROP_PHONE_NUMEBR_LABEL)) //NOI18N
277: .addSetters(
278: MidpSetter.createSetter("setMessageLabel",
279: MidpVersionable.MIDP).addParameters(
280: PROP_MESSAGE_LABEL)); //NOI18N
281: }
282:
283: protected List<? extends Presenter> createPresenters() {
284: return Arrays.asList(
285: // properties
286: createPropertiesPresenter(),
287: // code
288: createSetterPresenter(), MidpCodePresenterSupport
289: .createAddImportPresenter(),
290: // actions
291: AddActionPresenter.create(
292: AddActionPresenter.ADD_ACTION, 10,
293: CommandCD.TYPEID),
294: // screen
295: new SMSComposerDisplayPresenter());
296: }
297:
298: @Override
299: public void postInitialize(DesignComponent component) {
300: super .postInitialize(component);
301: MidpProjectSupport.addLibraryToProject(component.getDocument(),
302: AbstractInfoScreenCD.MIDP_NB_LIBRARY_BASIC);
303: MidpProjectSupport.addLibraryToProject(component.getDocument(),
304: AbstractInfoScreenCD.MIDP_NB_LIBRARY_WMA);
305: }
306:
307: @Override
308: protected void gatherPresenters(ArrayList<Presenter> presenters) {
309: DocumentSupport.removePresentersOfClass(presenters,
310: AddActionPresenter.class);
311: DocumentSupport.removePresentersOfClass(presenters,
312: DisplayableDisplayPresenter.class);
313: MidpActionsSupport
314: .addUnusedCommandsAddActionForDisplayable(presenters);
315: super.gatherPresenters(presenters);
316: }
317:
318: }
|