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.model.*;
046: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
047: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
048: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
049: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
050: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
051: import org.netbeans.modules.vmd.midp.components.MidpTypes;
052: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
053: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
054: import org.netbeans.modules.vmd.midp.components.items.TextFieldCD;
055: import org.netbeans.modules.vmd.midp.propertyeditors.*;
056: import org.netbeans.modules.vmd.midp.screen.display.TextBoxDisplayPresenter;
057: import org.openide.util.NbBundle;
058:
059: import java.util.ArrayList;
060: import java.util.Arrays;
061: import java.util.List;
062:
063: /**
064: *
065: * @author Karol Harezlak
066: */
067: public class TextBoxCD extends ComponentDescriptor {
068:
069: public static final TypeID TYPEID = new TypeID(
070: TypeID.Kind.COMPONENT, "javax.microedition.lcdui.TextBox"); // NOI18N
071:
072: public static final String ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/textbox_16.png"; // NOI18N
073: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midp/resources/components/textbox_32.png"; // NOI18N
074:
075: public static final String PROP_STRING = "string"; // NOI18N
076: public static final String PROP_MAX_SIZE = "maxSize"; // NOI18N
077: public static final String PROP_CONSTRAINTS = "constraints"; //NOI18N
078: public static final String PROP_INITIAL_INPUT_MODE = "initialInputMode"; // NOI18N
079:
080: static {
081: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
082: }
083:
084: public TypeDescriptor getTypeDescriptor() {
085: return new TypeDescriptor(ScreenCD.TYPEID, TYPEID, true, true);
086: }
087:
088: public VersionDescriptor getVersionDescriptor() {
089: return MidpVersionDescriptor.MIDP;
090: }
091:
092: @Override
093: public void postInitialize(DesignComponent component) {
094: component.writeProperty(PROP_MAX_SIZE, MidpTypes
095: .createIntegerValue(100));
096: }
097:
098: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
099: return Arrays
100: .asList(
101: new PropertyDescriptor(PROP_STRING,
102: MidpTypes.TYPEID_JAVA_LANG_STRING,
103: PropertyValue.createNull(), true, true,
104: MidpVersionable.MIDP),
105: new PropertyDescriptor(PROP_MAX_SIZE,
106: MidpTypes.TYPEID_INT, PropertyValue
107: .createNull(), false, true,
108: MidpVersionable.MIDP),
109: new PropertyDescriptor(
110: PROP_CONSTRAINTS,
111: MidpTypes.TYPEID_INT,
112: MidpTypes
113: .createIntegerValue(TextFieldCD.VALUE_ANY),
114: false, true, MidpVersionable.MIDP),
115: new PropertyDescriptor(PROP_INITIAL_INPUT_MODE,
116: MidpTypes.TYPEID_JAVA_LANG_STRING,
117: PropertyValue.createNull(), true, true,
118: MidpVersionable.MIDP_2));
119: }
120:
121: @Override
122: protected void gatherPresenters(ArrayList<Presenter> presenters) {
123: DocumentSupport.removePresentersOfClass(presenters,
124: ScreenDisplayPresenter.class);
125: super .gatherPresenters(presenters);
126: }
127:
128: private static DefaultPropertiesPresenter createPropertiesPresenter() {
129: return new DefaultPropertiesPresenter()
130: .addPropertiesCategory(
131: MidpPropertiesCategories.CATEGORY_PROPERTIES)
132: .addProperty(
133: NbBundle.getMessage(TextBoxCD.class,
134: "DISP_TextBox_Text"), // NOI18N
135: PropertyEditorString
136: .createInstance(
137: PropertyEditorString.DEPENDENCE_TEXT_BOX,
138: NbBundle.getMessage(
139: TextBoxCD.class,
140: "LBL_TextBox_Text")),
141: PROP_STRING) // NOI18N
142: .addProperty(
143: NbBundle.getMessage(TextBoxCD.class,
144: "DISP_TextBox_Maximum_Size"), // NOI18N
145: PropertyEditorNumber.createIntegerInstance(
146: false, NbBundle.getMessage(
147: TextBoxCD.class,
148: "LBL_TextBox_Maximum_Size")),
149: PROP_MAX_SIZE) // NOI18N
150: .addProperty(
151: NbBundle.getMessage(TextBoxCD.class,
152: "DISP_TextBox_Input_Constraints"),
153: PropertyEditorConstraints.createInstance(),
154: PROP_CONSTRAINTS) // NOI18N
155: .addProperty(
156: NbBundle.getMessage(TextBoxCD.class,
157: "DISP_TextBox_Initial_Input_Mode"),
158: PropertyEditorInputMode.createInstance(),
159: PROP_INITIAL_INPUT_MODE); // NOI18N
160: }
161:
162: private static Presenter createSetterPresenter() {
163: return new CodeSetterPresenter()
164: .addParameters(
165: MidpParameter.create(PROP_STRING,
166: PROP_MAX_SIZE, PROP_INITIAL_INPUT_MODE))
167: .addParameters(
168: new TextFieldCD.TextFieldConstraintsParameter())
169: .addSetters(
170: MidpSetter
171: .createConstructor(TYPEID,
172: MidpVersionable.MIDP)
173: .addParameters(
174: DisplayableCD.PROP_TITLE,
175: PROP_STRING,
176: PROP_MAX_SIZE,
177: TextFieldCD.TextFieldConstraintsParameter.PARAM_CONSTRAINTS))
178: .addSetters(
179: MidpSetter.createSetter("setConstraint",
180: MidpVersionable.MIDP).addParameters(
181: PROP_CONSTRAINTS)) // NOI18N
182: .addSetters(
183: MidpSetter.createSetter("setInitialInputMode",
184: MidpVersionable.MIDP_2).addParameters(
185: PROP_INITIAL_INPUT_MODE)) // NOI18N
186: .addSetters(
187: MidpSetter.createSetter("setString",
188: MidpVersionable.MIDP).addParameters(
189: PROP_STRING)) // NOI18N
190: .addSetters(
191: MidpSetter.createSetter("setMaxSize",
192: MidpVersionable.MIDP).addParameters(
193: PROP_MAX_SIZE)); // NOI18N
194: }
195:
196: protected List<? extends Presenter> createPresenters() {
197: return Arrays.asList(
198: // properties
199: createPropertiesPresenter(),
200: // code
201: createSetterPresenter(),
202: // screen
203: new TextBoxDisplayPresenter());
204: }
205:
206: }
|