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: package org.netbeans.modules.vmd.midp.components.resources;
042:
043: import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter;
044: import org.netbeans.modules.vmd.api.codegen.MultiGuardedSection;
045: import org.netbeans.modules.vmd.api.model.*;
046: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
047: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
048: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
049: import org.netbeans.modules.vmd.midp.components.MidpTypes;
050: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
051: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
052: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
053: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorImage;
054: import org.openide.util.NbBundle;
055: import java.util.Arrays;
056: import java.util.List;
057:
058: /**
059: * @author David Kaspar
060: */
061:
062: public final class ImageCD extends ComponentDescriptor {
063:
064: public static final TypeID TYPEID = new TypeID(
065: TypeID.Kind.COMPONENT, "javax.microedition.lcdui.Image"); // NOI18N
066:
067: public static final String PROP_RESOURCE_PATH = "resourcePath"; // NOI18N
068: // TODO - should be inlined to all CDs directly and should not be here
069: public static final String PROP_IMAGE = "image"; // NOI18N
070:
071: public TypeDescriptor getTypeDescriptor() {
072: return new TypeDescriptor(ResourceCD.TYPEID, TYPEID, true, true);
073: }
074:
075: public VersionDescriptor getVersionDescriptor() {
076: return MidpVersionDescriptor.MIDP;
077: }
078:
079: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
080: return Arrays.asList(new PropertyDescriptor(PROP_RESOURCE_PATH,
081: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
082: .createNull(), false, true,
083: MidpVersionable.MIDP));
084: }
085:
086: private static DefaultPropertiesPresenter createPropertiesPresenter() {
087: return new DefaultPropertiesPresenter().addPropertiesCategory(
088: MidpPropertiesCategories.CATEGORY_PROPERTIES)
089: .addProperty(
090: NbBundle.getMessage(ImageCD.class,
091: "DISP_Image_Resource_Path"),
092: PropertyEditorImage.createInstance(),
093: PROP_RESOURCE_PATH); // NOI18N
094: }
095:
096: private static Presenter createSetterPresenter() {
097: return new CodeSetterPresenter()
098: .addParameters(new ImageResourceParameter())
099: .addParameters(new NullImageResourceParameter())
100: .addSetters(
101: MidpSetter
102: .createFactoryMethod(TYPEID, null,
103: "Image", "createImage",
104: MidpVersionable.MIDP)
105: .addParameters(
106: ImageResourceParameter.PARAM_RESOURCE_PATH)
107: .addExceptions("java.io.IOException")) // NOI18N
108: .addSetters(
109: MidpSetter
110: .createFactoryMethod(TYPEID, null,
111: "Image", "createImage",
112: MidpVersionable.MIDP)
113: .addParameters(
114: NullImageResourceParameter.PARAM_NULL_RESOURCE_PATH)); // NOI18N
115: }
116:
117: protected List<? extends Presenter> createPresenters() {
118: return Arrays.asList(
119: // properties
120: createPropertiesPresenter(),
121: // code
122: createSetterPresenter());
123: }
124:
125: private static class ImageResourceParameter extends MidpParameter {
126:
127: static final String PARAM_RESOURCE_PATH = "resourcePath"; // NOI18N
128:
129: protected ImageResourceParameter() {
130: super (PARAM_RESOURCE_PATH);
131: }
132:
133: @Override
134: public boolean isRequiredToBeSet(DesignComponent component) {
135: return component.readProperty(PROP_RESOURCE_PATH).getKind() != PropertyValue.Kind.NULL;
136: }
137:
138: }
139:
140: private static class NullImageResourceParameter extends
141: MidpParameter {
142:
143: static final String PARAM_NULL_RESOURCE_PATH = "nullResourcePath"; // NOI18N
144:
145: protected NullImageResourceParameter() {
146: super (PARAM_NULL_RESOURCE_PATH);
147: }
148:
149: @Override
150: public void generateParameterCode(DesignComponent component,
151: MultiGuardedSection section, int index) {
152: section.getWriter().write("1, 1"); // NOI18N
153: }
154:
155: @Override
156: public boolean isRequiredToBeSet(DesignComponent component) {
157: return component.readProperty(PROP_RESOURCE_PATH).getKind() == PropertyValue.Kind.NULL;
158: }
159:
160: }
161:
162: }
|