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.ComponentProducer;
043: import org.netbeans.modules.vmd.api.model.Debug;
044: import org.netbeans.modules.vmd.api.model.DesignComponent;
045: import org.netbeans.modules.vmd.api.model.DesignDocument;
046: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
047: import org.netbeans.modules.vmd.api.model.support.ArraySupport;
048: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
049: import org.netbeans.modules.vmd.midp.components.MidpTypes;
050: import org.netbeans.modules.vmd.midp.components.categories.ResourcesCategoryCD;
051: import org.netbeans.modules.vmd.midpnb.components.displayables.WaitScreenCD;
052: import org.netbeans.modules.vmd.midpnb.components.sources.*;
053: import org.netbeans.modules.vmd.midpnb.components.svg.*;
054: import org.netbeans.modules.vmd.midpnb.producers.SVGWaitScreenProducer;
055:
056: import java.util.ArrayList;
057: import java.util.HashMap;
058: import java.util.List;
059:
060: /**
061: * @author David Kaspar
062: */
063: public class ConverterSVG {
064:
065: // Created: YES, Adds: YES
066: static void convertImage(HashMap<String, ConverterItem> id2item,
067: ConverterItem item, DesignDocument document) {
068: DesignComponent image = document
069: .createComponent(SVGImageCD.TYPEID);
070: Converter.convertClass(item, image);
071: MidpDocumentSupport.getCategoryComponent(document,
072: ResourcesCategoryCD.TYPEID).addComponent(image);
073:
074: ConverterUtil.convertString(image,
075: SVGImageCD.PROP_RESOURCE_PATH, item
076: .getPropertyValue("imageResourcePath")); // NOI18N
077:
078: String handler = item
079: .getPropertyValue("externalResourceHandler"); // NOI18N
080: if (handler != null)
081: image.writeProperty(
082: SVGImageCD.PROP_EXTERNAL_RESOURCE_HANDLER,
083: MidpTypes.createJavaCodeValue(handler));
084: }
085:
086: // Created: NO, Adds: NO
087: static void convertAnimatorWrapper(
088: HashMap<String, ConverterItem> id2item, ConverterItem item,
089: DesignComponent wrapper) {
090: ConverterDisplayables.convertCanvas(id2item, item, wrapper);
091:
092: ConverterUtil.convertConverterItemComponent(wrapper,
093: SVGPlayerCD.PROP_SVG_IMAGE, id2item, item
094: .getPropertyValue("svgImage")); // NOI18N
095: ConverterUtil.convertBoolean(wrapper,
096: SVGPlayerCD.PROP_START_ANIM_IMMEDIATELY, item
097: .getPropertyValue("startAnimationImmediately")); // NOI18N
098: ConverterUtil.convertBoolean(wrapper,
099: SVGPlayerCD.PROP_RESET_ANIMATION_WHEN_STOPPED, item
100: .getPropertyValue("resetAnimationWhenStopped")); // NOI18N
101: ConverterUtil.convertFloat(wrapper,
102: SVGPlayerCD.PROP_TIME_INCREMENT, item
103: .getPropertyValue("animationIncrement")); // NOI18N
104: }
105:
106: // Created: YES, Adds: NO
107: static void convertPlayer(HashMap<String, ConverterItem> id2item,
108: ConverterItem item, DesignDocument document) {
109: DesignComponent player = document
110: .createComponent(SVGPlayerCD.TYPEID);
111: convertAnimatorWrapper(id2item, item, player);
112: }
113:
114: // Created: YES, Adds: NO
115: static void convertMenu(HashMap<String, ConverterItem> id2item,
116: ConverterItem item, DesignDocument document) {
117: ComponentProducer producer = DocumentSupport
118: .getComponentProducer(document, SVGMenuCD.TYPEID
119: .toString());
120: DesignComponent menu = producer.createComponent(document)
121: .getMainComponent();
122: convertAnimatorWrapper(id2item, item, menu);
123:
124: ConverterUtil.convertBoolean(menu,
125: SVGMenuCD.PROP_INDEX_BASED_SWITCH, item
126: .getPropertyValue("indexBasedSwitch")); // NOI18N
127:
128: ConverterItem selectCommandActionItem = id2item.get(item
129: .getPropertyValue("selectCommandAction")); // NOI18N
130: List<DesignComponent> selectCommandEventSourceComponents = DocumentSupport
131: .gatherSubComponentsOfType(menu,
132: SVGMenuSelectCommandEventSourceCD.TYPEID);
133: DesignComponent selectCommandEventSource = selectCommandEventSourceComponents
134: .get(0);
135: Converter.convertObject(selectCommandActionItem,
136: selectCommandEventSource);
137: // ConverterActions.convertCommandActionHandler (id2item, selectCommandActionItem, selectCommandEventSource); // HINT - handler is not used in mvd file
138:
139: ArrayList<String> elementsList = item
140: .getContainerPropertyValue("menuElements"); // NOI18N
141: if (elementsList != null)
142: for (String elementValue : elementsList) {
143: DesignComponent menuElement = Converter
144: .convertConverterItemComponent(id2item,
145: elementValue, document);
146: if (menuElement == null) {
147: Debug
148: .warning("MenuElement not found",
149: elementValue); // NOI18N
150: continue;
151: }
152: menu.addComponent(menuElement);
153: ArraySupport.append(menu, SVGMenuCD.PROP_ELEMENTS,
154: menuElement);
155: }
156: }
157:
158: // Created: YES, Adds: NO
159: static void convertMenuElement(
160: HashMap<String, ConverterItem> id2item, ConverterItem item,
161: DesignDocument document) {
162: DesignComponent menuElement = document
163: .createComponent(SVGMenuElementEventSourceCD.TYPEID);
164: Converter.convertObject(item, menuElement);
165:
166: ConverterUtil.convertStringWithUserCode(menuElement,
167: SVGMenuElementEventSourceCD.PROP_STRING, item
168: .getPropertyValue("elementName")); // NOI18N
169:
170: ConverterItem commandActionItem = id2item.get(item
171: .getPropertyValue("commandAction")); // NOI18N
172: if (commandActionItem != null) {
173: Converter.convertObject(commandActionItem, menuElement);
174: ConverterActions.convertCommandActionHandler(id2item,
175: commandActionItem, menuElement);
176: }
177: }
178:
179: // Created: YES, Adds: NO
180: static void convertSplashScreen(
181: HashMap<String, ConverterItem> id2item, ConverterItem item,
182: DesignDocument document) {
183: ComponentProducer producer = DocumentSupport
184: .getComponentProducer(document,
185: SVGSplashScreenCD.TYPEID.toString());
186: DesignComponent screen = producer.createComponent(document)
187: .getMainComponent();
188: convertAnimatorWrapper(id2item, item, screen);
189:
190: ConverterUtil.convertBoolean(screen,
191: SVGSplashScreenCD.PROP_ALLOW_TIMEOUT_INTERRUPT, item
192: .getPropertyValue("allowTimeoutInterrupt")); // NOI18N
193: ConverterUtil.convertInteger(screen,
194: SVGSplashScreenCD.PROP_TIMEOUT, item
195: .getPropertyValue("timeout")); // NOI18N
196:
197: ConverterItem dismissActionItem = id2item.get(item
198: .getPropertyValue("dismissCommandAction")); // NOI18N
199: List<DesignComponent> dismissCommandEventSourceComponents = DocumentSupport
200: .gatherSubComponentsOfType(
201: screen,
202: SVGSplashScreenDismissCommandEventSourceCD.TYPEID);
203: DesignComponent dismissEventSource = dismissCommandEventSourceComponents
204: .get(0);
205: Converter.convertObject(dismissActionItem, dismissEventSource);
206: ConverterActions.convertCommandActionHandler(id2item,
207: dismissActionItem, dismissEventSource);
208: }
209:
210: // Created: YES, Adds: NO
211: static void convertWaitScreen(
212: HashMap<String, ConverterItem> id2item, ConverterItem item,
213: DesignDocument document) {
214: DesignComponent screen = SVGWaitScreenProducer
215: .produceSVGWaitScreen(
216: document,
217: document
218: .createComponent(SVGWaitScreenCD.TYPEID),
219: false).getMainComponent();
220: convertAnimatorWrapper(id2item, item, screen);
221:
222: ConverterUtil.convertConverterItemComponent(screen,
223: WaitScreenCD.PROP_TASK, id2item, item
224: .getPropertyValue("task")); // NOI18N
225:
226: ConverterItem successActionItem = id2item.get(item
227: .getPropertyValue("successCommandAction")); // NOI18N
228: List<DesignComponent> successCommandEventSourceComponents = DocumentSupport
229: .gatherSubComponentsOfType(screen,
230: SVGWaitScreenSuccessCommandEventSourceCD.TYPEID);
231: DesignComponent successEventSource = successCommandEventSourceComponents
232: .get(0);
233: Converter.convertObject(successActionItem, successEventSource);
234: ConverterActions.convertCommandActionHandler(id2item,
235: successActionItem, successEventSource);
236:
237: ConverterItem failureActionItem = id2item.get(item
238: .getPropertyValue("failureCommandAction")); // NOI18N
239: List<DesignComponent> failureCommandEventSourceComponents = DocumentSupport
240: .gatherSubComponentsOfType(screen,
241: SVGWaitScreenFailureCommandEventSourceCD.TYPEID);
242: DesignComponent failureEventSource = failureCommandEventSourceComponents
243: .get(0);
244: Converter.convertObject(failureActionItem, failureEventSource);
245: ConverterActions.convertCommandActionHandler(id2item,
246: failureActionItem, failureEventSource);
247: }
248:
249: }
|