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.inspector.InspectorFolderComponentPresenter;
046: import org.netbeans.modules.vmd.api.inspector.InspectorFolderPresenter;
047: import org.netbeans.modules.vmd.api.model.*;
048: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
049: import org.netbeans.modules.vmd.api.model.presenters.actions.ActionsPresenter;
050: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
051: import org.netbeans.modules.vmd.api.properties.DesignPropertyDescriptor;
052: import org.netbeans.modules.vmd.api.properties.PropertiesPresenter;
053: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
054: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
055: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
056: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
057: import org.netbeans.modules.vmd.midp.components.MidpTypes;
058: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
059: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
060: import org.netbeans.modules.vmd.midp.components.displayables.FormCD;
061: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
062: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorLayout;
063: import org.netbeans.modules.vmd.midp.screen.display.SpacerDisplayPresenter;
064: import org.openide.util.NbBundle;
065:
066: import java.util.ArrayList;
067: import java.util.Arrays;
068: import java.util.List;
069: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorNumber;
070: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorPreferredSize;
071:
072: /**
073: *
074: * @author Karol Harezlak
075: */
076:
077: public class SpacerCD extends ComponentDescriptor {
078:
079: public static final TypeID TYPEID = new TypeID(
080: TypeID.Kind.COMPONENT, "javax.microedition.lcdui.Spacer"); // NOI18N
081:
082: public static final String PROP_MIN_WIDTH = "minWidth"; // NOI18N
083: public static final String PROP_MIN_HEIGHT = "minHeight"; // NOI18N
084:
085: public TypeDescriptor getTypeDescriptor() {
086: return new TypeDescriptor(ItemCD.TYPEID, TYPEID, true, true);
087: }
088:
089: public VersionDescriptor getVersionDescriptor() {
090: return MidpVersionDescriptor.MIDP_2;
091: }
092:
093: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
094: return Arrays.asList(new PropertyDescriptor(PROP_MIN_HEIGHT,
095: MidpTypes.TYPEID_INT, MidpTypes.createIntegerValue(1),
096: false, true, MidpVersionable.MIDP_2),
097: new PropertyDescriptor(PROP_MIN_WIDTH,
098: MidpTypes.TYPEID_INT, MidpTypes
099: .createIntegerValue(16), false, true,
100: MidpVersionable.MIDP_2));
101: }
102:
103: private static DefaultPropertiesPresenter createPropertiesPresenter() {
104: return new DefaultPropertiesPresenter()
105: .addPropertiesCategory(
106: MidpPropertiesCategories.CATEGORY_PROPERTIES)
107: .addProperty(
108: NbBundle.getMessage(SpacerCD.class,
109: "DISP_Spacer_Layout"),
110: PropertyEditorLayout.createInstance(),
111: ItemCD.PROP_LAYOUT)
112: // NOI18N
113: .addProperty(
114: NbBundle.getMessage(SpacerCD.class,
115: "DISP_Spacer_Preferred_Width"), // NOI18N
116: PropertyEditorPreferredSize.createInstance(
117: NbBundle.getMessage(SpacerCD.class,
118: "LBL_Spacer_Preferred_Width"), // NOI18N
119: NbBundle.getMessage(SpacerCD.class,
120: "DISP_Spacer_Preferred_Width")),
121: ItemCD.PROP_PREFERRED_WIDTH) // NOI18N
122: .addProperty(
123: NbBundle.getMessage(SpacerCD.class,
124: "DISP_Spacer_Preferred_Height"), // NOI18N
125: PropertyEditorPreferredSize
126: .createInstance(
127: NbBundle
128: .getMessage(
129: SpacerCD.class,
130: "LBL_Spacer_Preferred_Height"), // NOI18N
131: NbBundle
132: .getMessage(
133: SpacerCD.class,
134: "DISP_Spacer_Preferred_Height")),
135: ItemCD.PROP_PREFERRED_HEIGHT) // NOI18N
136: .addProperty(
137: NbBundle.getMessage(SpacerCD.class,
138: "DISP_Spacer_Minimum_Width"), // NOI18N
139: PropertyEditorNumber.createIntegerInstance(
140: false, NbBundle.getMessage(
141: SpacerCD.class,
142: "LBL_Spacer_Minimum_Width")),
143: PROP_MIN_WIDTH) // NOI18N
144: .addProperty(
145: NbBundle.getMessage(SpacerCD.class,
146: "DISP_Spacer_Minimum_Height"), // NOI18N
147: PropertyEditorNumber.createIntegerInstance(
148: false, NbBundle.getMessage(
149: SpacerCD.class,
150: "LBL_Spacer_Minimum_Height")),
151: PROP_MIN_HEIGHT); // NOI18N
152: }
153:
154: private static Presenter createSetterPresenter() {
155: return new CodeSetterPresenter()
156: .addParameters(
157: MidpParameter.create(ItemCD.PROP_LABEL,
158: ItemCD.PROP_PREFERRED_WIDTH,
159: ItemCD.PROP_PREFERRED_HEIGHT))
160: .addParameters(ItemCode.createCommandParameter())
161: .addParameters(
162: ItemCode.createItemCommandListenerParameter())
163: .addParameters(ItemCode.createItemLayoutParameter())
164: .addParameters(ItemCode.createDefaultCommandParameter())
165: .addSetters(
166: MidpSetter.createSetter(
167: "setItemCommandListener",
168: MidpVersionable.MIDP_2).addParameters(
169: ItemCode.PARAM_ITEM_COMMAND_LISTENER))
170: // NOI18N
171: .addSetters(
172: MidpSetter.createSetter("setLayout",
173: MidpVersionable.MIDP_2).addParameters(
174: ItemCode.PARAM_LAYOUT))
175: // NOI18N
176: .addSetters(
177: MidpSetter.createSetter("setPreferredSize",
178: MidpVersionable.MIDP_2).addParameters(
179: ItemCD.PROP_PREFERRED_WIDTH,
180: ItemCD.PROP_PREFERRED_HEIGHT))
181: // NOI18N
182: .addParameters(
183: MidpParameter.create(PROP_MIN_WIDTH,
184: PROP_MIN_HEIGHT)).addSetters(
185: MidpSetter.createConstructor(TYPEID,
186: MidpVersionable.MIDP_2).addParameters(
187: PROP_MIN_WIDTH, PROP_MIN_HEIGHT))
188: .addSetters(
189: MidpSetter.createSetter("setSetMinimumSize",
190: MidpVersionable.MIDP_2).addParameters(
191: PROP_MIN_WIDTH, PROP_MIN_HEIGHT)); // NOI18N
192: }
193:
194: @Override
195: protected void gatherPresenters(ArrayList<Presenter> presenters) {
196: Presenter[] pa = presenters.toArray(new Presenter[presenters
197: .size()]);
198: for (Presenter presenter : pa) {
199: if (presenter instanceof PropertiesPresenter) {
200: for (DesignPropertyDescriptor pd : ((PropertiesPresenter) presenter)
201: .getDesignPropertyDescriptors()) {
202: if (pd.getPropertyDisplayName().equalsIgnoreCase(
203: NbBundle.getMessage(SpacerCD.class,
204: "DISP_Spacer_Label")))
205: presenters.remove(presenter);
206: }
207: }
208: }
209: DocumentSupport.removePresentersOfClass(presenters,
210: CodeSetterPresenter.class);
211: DocumentSupport.removePresentersOfClass(presenters,
212: InspectorFolderPresenter.class);
213: DocumentSupport.removePresentersOfClass(presenters,
214: ActionsPresenter.class);
215: DocumentSupport.removePresentersOfClass(presenters,
216: ScreenDisplayPresenter.class);
217: MidpActionsSupport.addCommonActionsPresenters(presenters, true,
218: true, true, true, true);
219: MidpActionsSupport.addMoveActionPresenter(presenters,
220: FormCD.PROP_ITEMS);
221: super .gatherPresenters(presenters);
222: }
223:
224: protected List<? extends Presenter> createPresenters() {
225: return Arrays.asList(
226: // properties
227: createPropertiesPresenter(),
228: // code
229: createSetterPresenter(),
230: new InspectorFolderComponentPresenter(true),
231: // screen
232: new SpacerDisplayPresenter());
233: }
234: }
|