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 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.model.presenters.actions.AddActionPresenter;
048: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
049: import org.netbeans.modules.vmd.api.properties.DesignEventFilterResolver;
050: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
051: import org.netbeans.modules.vmd.midp.codegen.MidpCodePresenterSupport;
052: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
053: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
054: import org.netbeans.modules.vmd.midp.components.MidpProjectSupport;
055: import org.netbeans.modules.vmd.midp.components.MidpTypes;
056: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
057: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
058: import org.netbeans.modules.vmd.midp.components.commands.CommandCD;
059: import org.netbeans.modules.vmd.midp.components.displayables.CanvasCD;
060: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
061: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorBooleanUC;
062: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorColorChooser;
063: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorString;
064: import org.netbeans.modules.vmd.midp.screen.display.DisplayableDisplayPresenter;
065: import org.netbeans.modules.vmd.midpnb.codegen.MidpCustomCodePresenterSupport;
066: import org.netbeans.modules.vmd.midpnb.propertyeditors.MidpNbPropertiesCategories;
067: import org.openide.util.NbBundle;
068:
069: import java.util.ArrayList;
070: import java.util.Arrays;
071: import java.util.List;
072: import org.netbeans.modules.vmd.midpnb.screen.display.LoginScreenDisplayPresenter;
073:
074: /**
075: * @author Karol Harezlak
076: */
077:
078: public final class LoginScreenCD extends ComponentDescriptor {
079:
080: public static final TypeID TYPEID = new TypeID(
081: TypeID.Kind.COMPONENT,
082: "org.netbeans.microedition.lcdui.LoginScreen"); // NOI18N
083:
084: public static final String ICON_PATH = "org/netbeans/modules/vmd/midpnb/resources/login_screen_16.png"; // NOI18N
085: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midpnb/resources/login_screen_32.png"; // NOI18N
086:
087: // private static final String ICON_PATH_SD = "org/netbeans/modules/vmd/midpnb/resources/login_screen_sd.png"; // NOI18N
088:
089: public static final String PROP_USERNAME = "username"; //NOI18N
090: public static final String PROP_PASSWORD = "password"; //NOI18N
091: public static final String PROP_USE_LOGIN_BUTTON = "useButton"; //NOI18N
092: public static final String PROP_LOGIN_TITLE = "loginTitle"; //NOI18N
093: public static final String PROP_USERNAME_LABEL = "usernameLabel"; //NOI18N
094: public static final String PROP_PASSWORD_LABEL = "passwordLabel"; //NOI18N
095: public static final String PROP_BGK_COLOR = "backgroundColor"; //NOI18N
096: public static final String PROP_FRG_COLOR = "foregroungColor"; //NOI18N
097: public static final String PROP_LOGIN_BUTTON_TEXT = "loginButtonText"; //NOI18N
098:
099: public static final String USERNAME_LOGIN = NbBundle.getMessage(
100: LoginScreenCD.class, "DISP_LoginScreen_Username"); //NOI18N
101: public static final String PASSWORD_LOGIN = NbBundle.getMessage(
102: LoginScreenCD.class, "DISP_LoginScreen_Password"); //NOI18N
103:
104: static {
105: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
106: }
107:
108: public TypeDescriptor getTypeDescriptor() {
109: return new TypeDescriptor(CanvasCD.TYPEID, TYPEID, true, true);
110: }
111:
112: public VersionDescriptor getVersionDescriptor() {
113: return MidpVersionDescriptor.MIDP_2;
114: }
115:
116: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
117: return Arrays.asList(new PropertyDescriptor(PROP_USERNAME,
118: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
119: .createNull(), true, true,
120: MidpVersionable.MIDP_2), new PropertyDescriptor(
121: PROP_PASSWORD, MidpTypes.TYPEID_JAVA_LANG_STRING,
122: PropertyValue.createNull(), true, true,
123: MidpVersionable.MIDP_2), new PropertyDescriptor(
124: PROP_USE_LOGIN_BUTTON, MidpTypes.TYPEID_BOOLEAN,
125: PropertyValue.createNull(), true, true,
126: MidpVersionable.MIDP_2), new PropertyDescriptor(
127: PROP_LOGIN_TITLE, MidpTypes.TYPEID_JAVA_LANG_STRING,
128: PropertyValue.createNull(), true, true,
129: MidpVersionable.MIDP_2), new PropertyDescriptor(
130: PROP_BGK_COLOR, MidpTypes.TYPEID_INT, MidpTypes
131: .createIntegerValue(-3355444), true, true,
132: MidpVersionable.MIDP_2), new PropertyDescriptor(
133: PROP_FRG_COLOR, MidpTypes.TYPEID_INT, MidpTypes
134: .createIntegerValue(-16777216), true, true,
135: MidpVersionable.MIDP_2), new PropertyDescriptor(
136: PROP_USERNAME_LABEL, MidpTypes.TYPEID_JAVA_LANG_STRING,
137: PropertyValue.createNull(), true, true,
138: MidpVersionable.MIDP_2), new PropertyDescriptor(
139: PROP_PASSWORD_LABEL, MidpTypes.TYPEID_JAVA_LANG_STRING,
140: PropertyValue.createNull(), true, true,
141: MidpVersionable.MIDP_2), new PropertyDescriptor(
142: PROP_LOGIN_BUTTON_TEXT,
143: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
144: .createNull(), true, true,
145: MidpVersionable.MIDP_2)
146:
147: );
148: }
149:
150: private static DefaultPropertiesPresenter createPropertiesPresenter() {
151: return new DefaultPropertiesPresenter(
152: DesignEventFilterResolver.THIS_COMPONENT)
153: .addPropertiesCategory(
154: MidpNbPropertiesCategories.CATEGORY_LOGIN)
155: .addProperty(
156: NbBundle.getMessage(LoginScreenCD.class,
157: "DISP_LoginScreen_Username"), // NOI18N
158: PropertyEditorString.createInstance(NbBundle
159: .getMessage(LoginScreenCD.class,
160: "LBL_LoginScreen_Username")),
161: PROP_USERNAME)
162: // NOI18N
163: .addProperty(
164: NbBundle.getMessage(LoginScreenCD.class,
165: "DISP_LoginScreen_Password"), // NOI18N
166: PropertyEditorString
167: .createTextFieldInstance(NbBundle
168: .getMessage(
169: LoginScreenCD.class,
170: "LBL_LoginScreen_Password")),
171: PROP_PASSWORD)
172: // NOI18N
173: .addPropertiesCategory(
174: MidpPropertiesCategories.CATEGORY_PROPERTIES)
175: .addProperty(
176: NbBundle.getMessage(LoginScreenCD.class,
177: "DISP_LoginScreen_UsernameLabel"), // NOI18N
178: PropertyEditorString.createInstance(NbBundle
179: .getMessage(LoginScreenCD.class,
180: "LBL_LoginScreen_Username")),
181: PROP_USERNAME_LABEL)
182: // NOI18N
183: .addProperty(
184: NbBundle.getMessage(LoginScreenCD.class,
185: "DISP_LoginScreen_PasswordLabel"), // NOI18N
186: PropertyEditorString.createInstance(NbBundle
187: .getMessage(LoginScreenCD.class,
188: "LBL_LoginScreen_Password")),
189: PROP_PASSWORD_LABEL)
190: // NOI18N
191: .addProperty(
192: NbBundle.getMessage(LoginScreenCD.class,
193: "DISP_LoginScreen_UseLoginButton"), // NOI18N
194: PropertyEditorBooleanUC.createInstance(),
195: PROP_USE_LOGIN_BUTTON)
196: .addProperty(
197: NbBundle.getMessage(LoginScreenCD.class,
198: "DISP_LoginScreen_LoginTitle"), // NOI18N
199: PropertyEditorString.createInstance(NbBundle
200: .getMessage(LoginScreenCD.class,
201: "LBL_LoginScreen_LoginTitle")),
202: PROP_LOGIN_TITLE)
203: // NOI18N
204: .addProperty(
205: NbBundle.getMessage(LoginScreenCD.class,
206: "DISP_LoginScreen_BackgroundColor"), // NOI18N
207: new PropertyEditorColorChooser(true),
208: PROP_BGK_COLOR)
209: .addProperty(
210: NbBundle.getMessage(LoginScreenCD.class,
211: "DISP_LoginScreen_ForegroundColor"), // NOI18N
212: new PropertyEditorColorChooser(true),
213: PROP_FRG_COLOR)
214: .addProperty(
215: NbBundle.getMessage(LoginScreenCD.class,
216: "DISP_LoginScreen_LoginButtonText"), // NOI18N
217: PropertyEditorString
218: .createInstance(NbBundle
219: .getMessage(
220: LoginScreenCD.class,
221: "DISP_LoginScreen_LoginButtonText_LABEL")),
222: PROP_LOGIN_BUTTON_TEXT); //NOI18N
223: }
224:
225: private Presenter createSetterPresenter() {
226: return new CodeSetterPresenter()
227: .addParameters(
228: MidpCustomCodePresenterSupport
229: .createDisplayParameter())
230: .addParameters(
231: MidpParameter.create(PROP_BGK_COLOR,
232: PROP_FRG_COLOR, PROP_USERNAME,
233: PROP_PASSWORD, PROP_LOGIN_TITLE,
234: PROP_USE_LOGIN_BUTTON,
235: PROP_USERNAME_LABEL,
236: PROP_PASSWORD_LABEL,
237: PROP_LOGIN_BUTTON_TEXT))
238: .addSetters(
239: MidpSetter
240: .createConstructor(TYPEID,
241: MidpVersionable.MIDP_2)
242: .addParameters(
243: MidpCustomCodePresenterSupport.PARAM_DISPLAY))
244: .addSetters(
245: MidpSetter.createSetter("setBGColor",
246: MidpVersionable.MIDP).addParameters(
247: PROP_BGK_COLOR)) //NOI18N
248: .addSetters(
249: MidpSetter.createSetter("setFGColor",
250: MidpVersionable.MIDP).addParameters(
251: PROP_FRG_COLOR)) //NOI18N
252: .addSetters(
253: MidpSetter.createSetter("setPassword",
254: MidpVersionable.MIDP).addParameters(
255: PROP_PASSWORD)) //NOI18N
256: .addSetters(
257: MidpSetter.createSetter("setUsername",
258: MidpVersionable.MIDP).addParameters(
259: PROP_USERNAME)) //NOI18N
260: .addSetters(
261: MidpSetter.createSetter("setLoginTitle",
262: MidpVersionable.MIDP).addParameters(
263: PROP_LOGIN_TITLE)) //NOI18N
264: .addSetters(
265: MidpSetter.createSetter("setUseLoginButton",
266: MidpVersionable.MIDP).addParameters(
267: PROP_USE_LOGIN_BUTTON)) //NOI18N
268: .addSetters(
269: MidpSetter.createSetter("setLabelTexts",
270: MidpVersionable.MIDP).addParameters(
271: PROP_USERNAME_LABEL,
272: PROP_PASSWORD_LABEL)) //NOI18N
273: .addSetters(
274: MidpSetter.createSetter("setLoginButtonText",
275: MidpVersionable.MIDP).addParameters(
276: PROP_LOGIN_BUTTON_TEXT)); //NOI18N
277: }
278:
279: protected List<? extends Presenter> createPresenters() {
280: return Arrays.asList(
281: //properties
282: createPropertiesPresenter(),
283: // code
284: createSetterPresenter(), MidpCodePresenterSupport
285: .createAddImportPresenter(),
286: // actions
287: AddActionPresenter.create(
288: AddActionPresenter.ADD_ACTION, 10,
289: CommandCD.TYPEID),
290: // screen
291: new LoginScreenDisplayPresenter());
292: }
293:
294: @Override
295: public void postInitialize(DesignComponent component) {
296: super .postInitialize(component);
297: MidpProjectSupport.addLibraryToProject(component.getDocument(),
298: AbstractInfoScreenCD.MIDP_NB_LIBRARY_BASIC); //NOI18N
299: }
300:
301: @Override
302: protected void gatherPresenters(ArrayList<Presenter> presenters) {
303: DocumentSupport.removePresentersOfClass(presenters,
304: AddActionPresenter.class);
305: DocumentSupport.removePresentersOfClass(presenters,
306: DisplayableDisplayPresenter.class);
307: MidpActionsSupport
308: .addUnusedCommandsAddActionForDisplayable(presenters);
309: super.gatherPresenters(presenters);
310: }
311:
312: }
|