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.model.*;
046: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
047: import org.netbeans.modules.vmd.api.model.presenters.actions.DeleteDependencyPresenter;
048: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
049: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
050: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
051: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
052: import org.netbeans.modules.vmd.midp.components.*;
053: import org.netbeans.modules.vmd.midp.components.resources.ImageCD;
054: import org.netbeans.modules.vmd.midp.components.resources.ImageFileAcceptPresenter;
055: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
056: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorComboBox;
057: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorString;
058: import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.PropertyEditorResource;
059: import org.netbeans.modules.vmd.midp.screen.display.ImageItemDisplayPresenter;
060: import org.netbeans.modules.vmd.midp.screen.display.injector.ImageItemInjectorPresenter;
061: import org.openide.util.NbBundle;
062:
063: import java.util.*;
064:
065: /**
066: *
067: * @author Karol Harezlak
068: */
069: public class ImageItemCD extends ComponentDescriptor {
070:
071: private static Map<String, PropertyValue> appearanceValues;
072:
073: public static final TypeID TYPEID = new TypeID(
074: TypeID.Kind.COMPONENT, "javax.microedition.lcdui.ImageItem"); // NOI18N
075:
076: public static final String PROP_ALT_TEXT = "altText"; // NOI18N
077: public static final String PROP_IMAGE = ImageCD.PROP_IMAGE; // NOI18N
078:
079: public TypeDescriptor getTypeDescriptor() {
080: return new TypeDescriptor(ItemCD.TYPEID, TYPEID, true, true);
081: }
082:
083: public VersionDescriptor getVersionDescriptor() {
084: return MidpVersionDescriptor.MIDP;
085: }
086:
087: @Override
088: public void postInitialize(DesignComponent component) {
089: component.writeProperty(PROP_ALT_TEXT, MidpTypes
090: .createStringValue(NbBundle.getMessage(
091: ImageItemCD.class,
092: "DISP_ImageItem_Missing_Image"))); // NOI18N
093: }
094:
095: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
096: return Arrays.asList(new PropertyDescriptor(PROP_IMAGE,
097: ImageCD.TYPEID, PropertyValue.createNull(), false,
098: true, MidpVersionable.MIDP), new PropertyDescriptor(
099: PROP_ALT_TEXT, MidpTypes.TYPEID_JAVA_LANG_STRING,
100: PropertyValue.createNull(), false, true,
101: MidpVersionable.MIDP), new PropertyDescriptor(
102: ItemCD.PROP_APPEARANCE_MODE, MidpTypes.TYPEID_INT,
103: MidpTypes.createIntegerValue(ItemCD.VALUE_PLAIN),
104: false, true, MidpVersionable.MIDP_2));
105: }
106:
107: @Override
108: protected void gatherPresenters(ArrayList<Presenter> presenters) {
109: DocumentSupport.removePresentersOfClass(presenters,
110: ScreenDisplayPresenter.class);
111: super .gatherPresenters(presenters);
112: }
113:
114: private static DefaultPropertiesPresenter createPropertiesPresenter() {
115: return new DefaultPropertiesPresenter()
116: .addPropertiesCategory(
117: MidpPropertiesCategories.CATEGORY_PROPERTIES)
118: .addProperty(
119: NbBundle.getMessage(ImageItemCD.class,
120: "DISP_ImageItem_Alternate_Text"), // NOI18N
121: PropertyEditorString
122: .createInstance(NbBundle.getMessage(
123: ImageItemCD.class,
124: "LBL_ImageItem_Alternate_Text")),
125: PROP_ALT_TEXT) // NOI18N
126: .addProperty(
127: NbBundle.getMessage(ImageItemCD.class,
128: "DISP_ImageItem_Appearance"), // NOI18N
129: PropertyEditorComboBox
130: .createInstance(
131: getAppearanceValues(),
132: TYPEID,
133: NbBundle
134: .getMessage(
135: ImageItemCD.class,
136: "DISP_ImageItem_Appearance_RB_LABEL"), // NOI18N
137: NbBundle
138: .getMessage(
139: ImageItemCD.class,
140: "DISP_ImageItem_Appearance_UCLABEL")),
141: ItemCD.PROP_APPEARANCE_MODE) // NOI18N
142: .addProperty(
143: NbBundle.getMessage(ImageItemCD.class,
144: "DISP_ImageItem_Image"),
145: PropertyEditorResource
146: .createImagePropertyEditor(),
147: PROP_IMAGE); // NOI18N
148: }
149:
150: private static Presenter createSetterPresenter() {
151: return new CodeSetterPresenter()
152: .addParameters(
153: MidpParameter.create(PROP_ALT_TEXT, PROP_IMAGE))
154: .addParameters(ItemCode.createAppearanceModeParameter())
155: .addSetters(
156: MidpSetter.createConstructor(TYPEID,
157: MidpVersionable.MIDP).addParameters(
158: ItemCD.PROP_LABEL, PROP_IMAGE,
159: ItemCD.PROP_LAYOUT, PROP_ALT_TEXT))
160: .addSetters(
161: MidpSetter.createConstructor(TYPEID,
162: MidpVersionable.MIDP_2).addParameters(
163: ItemCD.PROP_LABEL, PROP_IMAGE,
164: ItemCD.PROP_LAYOUT, PROP_ALT_TEXT,
165: ItemCode.PARAM_APPEARANCE_MODE))
166: .addSetters(
167: MidpSetter.createSetter("setAltText",
168: MidpVersionable.MIDP).addParameters(
169: PROP_ALT_TEXT)) // NOI18N
170: .addSetters(
171: MidpSetter.createSetter("setImage",
172: MidpVersionable.MIDP).addParameters(
173: PROP_IMAGE)); // NOI18N
174: }
175:
176: protected List<? extends Presenter> createPresenters() {
177: return Arrays
178: .asList(
179: // properties
180: createPropertiesPresenter(),
181: // code
182: createSetterPresenter(),
183: // delete
184: DeleteDependencyPresenter
185: .createNullableComponentReferencePresenter(PROP_IMAGE),
186: //accept
187: new ImageFileAcceptPresenter(
188: ImageItemCD.PROP_IMAGE, ImageCD.TYPEID,
189: "jpg", "gif", "png"), //NOI18N
190: new MidpAcceptProducerKindPresenter().addType(
191: ImageCD.TYPEID, PROP_IMAGE),
192: new MidpAcceptTrensferableKindPresenter()
193: .addType(ImageCD.TYPEID, PROP_IMAGE),
194: // screen
195: new ImageItemDisplayPresenter(),
196: new ImageItemInjectorPresenter());
197: }
198:
199: public static Map<String, PropertyValue> getAppearanceValues() {
200: if (appearanceValues == null) {
201: appearanceValues = new TreeMap<String, PropertyValue>();
202: appearanceValues.put("PLAIN", MidpTypes
203: .createIntegerValue(ItemCD.VALUE_PLAIN)); // NOI18N
204: appearanceValues.put("HYPERLINK", MidpTypes
205: .createIntegerValue(ItemCD.VALUE_HYPERLINK)); // NOI18N
206: appearanceValues.put("BUTTON", MidpTypes
207: .createIntegerValue(ItemCD.VALUE_BUTTON)); // NOI18N
208: }
209: return appearanceValues;
210: }
211:
212: }
|