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: */package org.netbeans.modules.vmd.midp.converter.wizard;
041:
042: import org.netbeans.modules.vmd.api.model.DesignComponent;
043: import org.netbeans.modules.vmd.api.model.DesignDocument;
044: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
045: import org.netbeans.modules.vmd.midp.components.MidpTypes;
046: import org.netbeans.modules.vmd.midp.components.categories.ResourcesCategoryCD;
047: import org.netbeans.modules.vmd.midp.components.categories.CommandsCategoryCD;
048: import org.netbeans.modules.vmd.midp.components.commands.CommandCD;
049: import org.netbeans.modules.vmd.midp.components.resources.FontCD;
050: import org.netbeans.modules.vmd.midp.components.resources.TickerCD;
051: import org.netbeans.modules.vmd.midp.components.resources.ImageCD;
052:
053: /**
054: * @author David Kaspar
055: */
056: public class ConverterResources {
057:
058: // Created: YES, Adds: YES
059: static void convertFont(ConverterItem item, DesignDocument document) {
060: DesignComponent font = document.createComponent(FontCD.TYPEID);
061: Converter.convertClass(item, font);
062: MidpDocumentSupport.getCategoryComponent(document,
063: ResourcesCategoryCD.TYPEID).addComponent(font);
064:
065: String specifier = item.getPropertyValue("specifier"); // NOI18N
066: if ("FONT_INPUT_TEXT".equals(specifier)) { // NOI18N
067: font.writeProperty(FontCD.PROP_FONT_KIND, MidpTypes
068: .createIntegerValue(FontCD.VALUE_KIND_INPUT));
069: } else if ("FONT_STATIC_TEXT".equals(specifier)) { // NOI18N
070: font.writeProperty(FontCD.PROP_FONT_KIND, MidpTypes
071: .createIntegerValue(FontCD.VALUE_KIND_STATIC));
072: } else {
073: ConverterUtil.convertInteger(font, FontCD.PROP_STYLE, item
074: .getPropertyValue("style")); // NOI18N
075:
076: String face = item.getPropertyValue("face"); // NOI18N
077: if ("FACE_MONOSPACE".equals(face)) // NOI18N
078: font
079: .writeProperty(
080: FontCD.PROP_FACE,
081: MidpTypes
082: .createIntegerValue(FontCD.VALUE_FACE_MONOSPACE));
083: else if ("FACE_PROPORTIONAL".equals(face)) // NOI18N
084: font
085: .writeProperty(
086: FontCD.PROP_FACE,
087: MidpTypes
088: .createIntegerValue(FontCD.VALUE_FACE_PROPORTIONAL));
089: else if ("FACE_SYSTEM".equals(face)) // NOI18N
090: font.writeProperty(FontCD.PROP_FACE, MidpTypes
091: .createIntegerValue(FontCD.VALUE_FACE_SYSTEM));
092:
093: String size = item.getPropertyValue("size"); // NOI18N
094: if ("SIZE_SMALL".equals(size)) // NOI18N
095: font.writeProperty(FontCD.PROP_SIZE, MidpTypes
096: .createIntegerValue(FontCD.VALUE_SIZE_SMALL));
097: else if ("SIZE_MEDIUM".equals(size)) // NOI18N
098: font.writeProperty(FontCD.PROP_SIZE, MidpTypes
099: .createIntegerValue(FontCD.VALUE_SIZE_MEDIUM));
100: else if ("SIZE_LARGE".equals(size)) // NOI18N
101: font.writeProperty(FontCD.PROP_SIZE, MidpTypes
102: .createIntegerValue(FontCD.VALUE_SIZE_LARGE));
103:
104: boolean nonDefault = item.isPropertyValueSet("style")
105: || item.isPropertyValueSet("face")
106: || item.isPropertyValueSet("size"); // NOI18N
107: font
108: .writeProperty(
109: FontCD.PROP_FONT_KIND,
110: MidpTypes
111: .createIntegerValue(nonDefault ? FontCD.VALUE_KIND_STATIC
112: : FontCD.VALUE_KIND_DEFAULT));
113: }
114: }
115:
116: // Created: YES, Adds: YES
117: static void convertImage(ConverterItem item, DesignDocument document) {
118: DesignComponent image = document
119: .createComponent(ImageCD.TYPEID);
120: Converter.convertClass(item, image);
121: MidpDocumentSupport.getCategoryComponent(document,
122: ResourcesCategoryCD.TYPEID).addComponent(image);
123:
124: ConverterUtil.convertString(image, ImageCD.PROP_RESOURCE_PATH,
125: item.getPropertyValue("imageResourcePath")); // NOI18N
126: }
127:
128: // Created: YES, Adds: YES
129: static void convertTicker(ConverterItem item,
130: DesignDocument document) {
131: DesignComponent ticker = document
132: .createComponent(TickerCD.TYPEID);
133: Converter.convertClass(item, ticker);
134: MidpDocumentSupport.getCategoryComponent(document,
135: ResourcesCategoryCD.TYPEID).addComponent(ticker);
136:
137: ConverterUtil.convertStringWithUserCode(ticker,
138: TickerCD.PROP_STRING, item.getPropertyValue("string")); // NOI18N
139: }
140:
141: // Created: YES, Adds: YES
142: static void convertCommand(ConverterItem item,
143: DesignDocument document) {
144: DesignComponent command = document
145: .createComponent(CommandCD.TYPEID);
146: Converter.convertClass(item, command);
147: MidpDocumentSupport.getCategoryComponent(document,
148: CommandsCategoryCD.TYPEID).addComponent(command);
149:
150: ConverterUtil.convertStringWithUserCode(command,
151: CommandCD.PROP_LABEL, item.getPropertyValue("label")); // NOI18N
152: ConverterUtil.convertStringWithUserCode(command,
153: CommandCD.PROP_LONG_LABEL, item
154: .getPropertyValue("longLabel")); // NOI18N
155: ConverterUtil.convertInteger(command, CommandCD.PROP_PRIORITY,
156: item.getPropertyValue("priority")); // NOI18N
157:
158: String typeValue = item.getPropertyValue("type"); // NOI18N
159: int type;
160: if ("SCREEN".equals(typeValue)) // NOI18N
161: type = CommandCD.VALUE_SCREEN;
162: else if ("BACK".equals(typeValue)) // NOI18N
163: type = CommandCD.VALUE_BACK;
164: else if ("CANCEL".equals(typeValue)) // NOI18N
165: type = CommandCD.VALUE_CANCEL;
166: else if ("OK".equals(typeValue)) // NOI18N
167: type = CommandCD.VALUE_OK;
168: else if ("HELP".equals(typeValue)) // NOI18N
169: type = CommandCD.VALUE_HELP;
170: else if ("STOP".equals(typeValue)) // NOI18N
171: type = CommandCD.VALUE_STOP;
172: else if ("EXIT".equals(typeValue)) // NOI18N
173: type = CommandCD.VALUE_EXIT;
174: else if ("ITEM".equals(typeValue)) // NOI18N
175: type = CommandCD.VALUE_ITEM;
176: else
177: type = CommandCD.VALUE_OK;
178: command.writeProperty(CommandCD.PROP_TYPE, MidpTypes
179: .createIntegerValue(type));
180: }
181:
182: }
|