reorder children in save/load from xml
[scilab.git] / scilab / modules / graphic_objects / src / java / org / scilab / modules / graphic_objects / xmlloader / XmlSaver.java
1 package org.scilab.modules.graphic_objects.xmlloader;
2
3 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES__;
4 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT__;
5 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_PARENT__;
6 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
7 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTEXTMENU__;
8 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTROL__;
9 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIMENU__;
10
11 import java.io.File;
12
13 import javax.xml.parsers.DocumentBuilder;
14 import javax.xml.parsers.DocumentBuilderFactory;
15 import javax.xml.parsers.ParserConfigurationException;
16 import javax.xml.transform.OutputKeys;
17 import javax.xml.transform.Transformer;
18 import javax.xml.transform.TransformerException;
19 import javax.xml.transform.TransformerFactory;
20 import javax.xml.transform.dom.DOMSource;
21 import javax.xml.transform.stream.StreamResult;
22
23 import org.scilab.modules.graphic_objects.console.Console;
24 import org.scilab.modules.graphic_objects.figure.Figure;
25 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
26 import org.scilab.modules.graphic_objects.graphicModel.GraphicModel;
27 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
28 import org.scilab.modules.graphic_objects.uicontrol.Uicontrol;
29 import org.scilab.modules.graphic_objects.uicontrol.Uicontrol.UicontrolStyle;
30 import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorder;
31 import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorderType;
32 import org.scilab.modules.graphic_objects.utils.LayoutType;
33 import org.w3c.dom.Document;
34 import org.w3c.dom.Element;
35
36
37 public class XmlSaver {
38     static private Uicontrol defaultUi = null;
39     static private Figure defaultFig = null;
40     static private FrameBorder defaultBorder = null;
41
42     public static String save(int figure, String filename, boolean reverseChildren) {
43         try {
44             //init default values
45             defaultFig = GraphicModel.getFigureModel();
46             defaultBorder = new FrameBorder();
47
48             DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
49             DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
50
51             //root elements
52             Document doc = docBuilder.newDocument();
53             //standalone="yes"
54             doc.setXmlStandalone(true);
55
56             //scilab header
57             Element header = doc.createElement("scilabgui");
58             setAttribute(header, "version", "1.0", "");
59             setAttribute(header, "usedeprecatedskin", createAttribute(Console.getConsole().getUseDeprecatedLF()), "");
60
61             //figure
62             Element figureElement = createFigure(doc, figure, reverseChildren);
63             header.appendChild(figureElement);
64             doc.appendChild(header);
65
66             //write the content into xml file
67             TransformerFactory transformerFactory = TransformerFactory.newInstance();
68             Transformer transformer = transformerFactory.newTransformer();
69             transformer.setOutputProperty(OutputKeys.INDENT, "yes");
70             transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
71             doc.getDocumentElement().normalize();
72             DOMSource source = new DOMSource(doc);
73
74             StreamResult result =  new StreamResult(new File(filename));
75             transformer.transform(source, result);
76         } catch (ParserConfigurationException pce) {
77             return pce.getMessage();
78         } catch (TransformerException tfe) {
79             return tfe.getMessage();
80         }
81
82         defaultFig = null;
83         defaultUi = null;
84         defaultBorder = null;
85         return ""; //all good
86     }
87
88     private static Element createFigure(Document doc, int figure, boolean reverseChildren) {
89         GraphicController controller = GraphicController.getController();
90         Figure fig = (Figure)controller.getObjectFromId(figure);
91         Element elemFig = doc.createElement("figure");
92
93         //figure_position
94         setAttribute(elemFig, "figure_position", createAttribute(fig.getPosition()), createAttribute(defaultFig.getPosition()));
95         //figure_size
96         setAttribute(elemFig, "figure_size", createAttribute(fig.getSize()), createAttribute(defaultFig.getSize()));
97         //axes_size
98         setAttribute(elemFig, "axes_size", createAttribute(fig.getAxesSize()), createAttribute(defaultFig.getAxesSize()));
99         //auto_resize
100         setAttribute(elemFig, "auto_resize", createAttribute(fig.getAutoResize()), createAttribute(defaultFig.getAutoResize()));
101         //view_port
102         setAttribute(elemFig, "view_port", createAttribute(fig.getViewport()), createAttribute(defaultFig.getViewport()));
103         //figure_name
104         setAttribute(elemFig, "figure_name", createAttribute(fig.getName()), createAttribute(defaultFig.getName()));
105         //figure_id
106         setAttribute(elemFig, "figure_id", createAttribute(fig.getId()), createAttribute(defaultFig.getId()));
107         //info_message
108         setAttribute(elemFig, "info_message", createAttribute(fig.getInfoMessage()), createAttribute(defaultFig.getInfoMessage()));
109         //pixel_drawing_mode
110         setAttribute(elemFig, "pixel_drawing_mode", createAttribute(fig.getPixelDrawingMode()), createAttribute(defaultFig.getPixelDrawingMode()));
111         //anti_aliasing
112         setAttribute(elemFig, "anti_aliasing", createAttribute(fig.getAntialiasing()), createAttribute(defaultFig.getAntialiasing()));
113         //immediate_drawing
114         setAttribute(elemFig, "immediate_drawing", createAttribute(fig.getImmediateDrawing()), createAttribute(defaultFig.getImmediateDrawing()));
115         //background
116         setAttribute(elemFig, "background", createAttribute(fig.getBackground()), createAttribute(defaultFig.getBackground()));
117         //visible
118         setAttribute(elemFig, "visible", createAttribute(fig.getVisible()), createAttribute(defaultFig.getVisible()));
119         //rotation_style
120         setAttribute(elemFig, "rotation_style", createAttribute(fig.getRotation()), createAttribute(defaultFig.getRotation()));
121         //event_handler
122         setAttribute(elemFig, "event_handler", createAttribute(fig.getEventHandlerString()), createAttribute(defaultFig.getEventHandlerString()));
123         //event_handler_enable
124         setAttribute(elemFig, "event_handler_enable", createAttribute(fig.getEventHandlerEnable()), createAttribute(defaultFig.getEventHandlerEnable()));
125         //resizefcn
126         setAttribute(elemFig, "resizefcn", createAttribute(fig.getResizeFcn()), createAttribute(defaultFig.getResizeFcn()));
127         //closerequestfcn
128         setAttribute(elemFig, "closerequestfcn", createAttribute(fig.getCloseRequestFcn()), createAttribute(defaultFig.getCloseRequestFcn()));
129         //resize
130         setAttribute(elemFig, "resize", createAttribute(fig.getResize()), createAttribute(defaultFig.getResize()));
131         //toolbar
132         setAttribute(elemFig, "toolbar", createAttribute(fig.getToolbar()), createAttribute(defaultFig.getToolbar()));
133         //toolbar_visible
134         setAttribute(elemFig, "toolbar_visible", createAttribute(fig.getToolbarVisible()), createAttribute(defaultFig.getToolbarVisible()));
135         //menubar
136         setAttribute(elemFig, "menubar", createAttribute(fig.getMenubar()), createAttribute(defaultFig.getMenubar()));
137         //menubar_visible
138         setAttribute(elemFig, "menubar_visible", createAttribute(fig.getMenubarVisible()), createAttribute(defaultFig.getMenubarVisible()));
139         //infobar_visible
140         setAttribute(elemFig, "infobar_visible", createAttribute(fig.getInfobarVisible()), createAttribute(defaultFig.getInfobarVisible()));
141         //dockable
142         setAttribute(elemFig, "dockable", createAttribute(fig.getDockable()), createAttribute(defaultFig.getDockable()));
143         //layout
144         setAttribute(elemFig, "layout", createAttribute(fig.getLayout()), createAttribute(defaultFig.getLayout()));
145
146         //default_axes
147         setAttribute(elemFig, "default_axes", createAttribute(fig.hasDefaultAxes()), createAttribute(defaultFig.hasDefaultAxes()));
148         //icon
149         setAttribute(elemFig, "icon", createAttribute(fig.getIcon()), createAttribute(defaultFig.getIcon()));
150         //tag
151         setAttribute(elemFig, "tag", createAttribute(fig.getTag()), createAttribute(defaultFig.getTag()));
152
153         //layout_options
154         if (fig.getLayoutAsEnum() == LayoutType.GRID) {
155             setAttribute(elemFig, "grid_opt_grid", createAttribute(fig.getGridOptGrid()), createAttribute(defaultFig.getGridOptGrid()));
156             setAttribute(elemFig, "grid_opt_padding", createAttribute(fig.getGridOptPadding()), createAttribute(defaultFig.getGridOptPadding()));
157         } else if (fig.getLayoutAsEnum() == LayoutType.BORDER) {
158             setAttribute(elemFig, "border_opt_padding", createAttribute(fig.getBorderOptPadding()), createAttribute(defaultFig.getBorderOptPadding()));
159         }
160
161         //children
162         Integer[] children = fig.getChildren();
163
164         if (reverseChildren) {
165             for (int i = children.length - 1; i >= 0; i--) {
166                 elemFig.appendChild(createElement(doc, children[i], reverseChildren));
167             }
168         } else {
169             for (int i = 0; i < children.length; i++) {
170                 elemFig.appendChild(createElement(doc, children[i], reverseChildren));
171             }
172         }
173         return elemFig;
174     }
175
176     private static Element createElement(Document doc, int id, boolean reverseChildren) {
177         GraphicController controller = GraphicController.getController();
178         Integer type = (Integer)controller.getProperty(id, __GO_TYPE__);
179
180         switch (type) {
181             case __GO_UICONTROL__ : {
182                 return createUicontrol(doc, id, reverseChildren);
183             }
184             case __GO_UIMENU__ : {
185                 //Uimenu uim = (Uimenu)controller.getObjectFromId(id);
186                 return doc.createElement("menu");
187             }
188             case __GO_UICONTEXTMENU__ : {
189                 //Uicontextmenu uicm = (Uicontextmenu)controller.getObjectFromId(id);
190                 return doc.createElement("contextmenu");
191             }
192             case __GO_AXES__ : {
193                 //Axes axes = (Axes)controller.getObjectFromId(id);
194                 return doc.createElement("axes");
195             }
196         }
197
198         return doc.createElement("fake");
199     }
200
201     private static Element createBorders(Document doc, Integer id) {
202         return createBorders(doc, id, "borders");
203     }
204
205     private static Element createBorders(Document doc, Integer id, String borderName) {
206         GraphicController controller = GraphicController.getController();
207         FrameBorder border = (FrameBorder)controller.getObjectFromId(id);
208
209         if (border == null || border.getStyleAsEnum() == FrameBorderType.NONE) {
210             return null;
211         }
212
213         Element elemBorders = doc.createElement(borderName);
214
215         setAttribute(elemBorders, "style", createAttribute(border.getStyleAsEnum().toString().toLowerCase()), "");
216
217         switch (border.getStyleAsEnum()) {
218             case BEVEL: {
219                 setAttribute(elemBorders, "type", createAttribute(border.getBorderType()), createAttribute(defaultBorder.getBorderType()));
220                 setAttribute(elemBorders, "hlout", createAttribute(border.getHlOut()), createAttribute(defaultBorder.getHlOut()));
221                 setAttribute(elemBorders, "hlin", createAttribute(border.getHlIn()), createAttribute(defaultBorder.getHlIn()));
222                 setAttribute(elemBorders, "shadowout", createAttribute(border.getShadowOut()), createAttribute(defaultBorder.getShadowOut()));
223                 setAttribute(elemBorders, "shadowin", createAttribute(border.getShadowIn()), createAttribute(defaultBorder.getShadowIn()));
224                 break;
225             }
226             case COMPOUND: {
227                 Element out = createBorders(doc, border.getOutBorder(), "out");
228                 if (out != null) {
229                     elemBorders.appendChild(out);
230                 }
231
232                 Element in = createBorders(doc, border.getInBorder(), "in");
233                 if (in != null) {
234                     elemBorders.appendChild(in);
235                 }
236                 break;
237             }
238             case EMPTY: {
239                 setAttribute(elemBorders, "position", createAttribute(border.getPosition()), createAttribute(defaultBorder.getPosition()));
240                 break;
241             }
242             case ETCHED: {
243                 setAttribute(elemBorders, "type", createAttribute(border.getBorderType()), createAttribute(defaultBorder.getBorderType()));
244                 setAttribute(elemBorders, "hl", createAttribute(border.getHlOut()), createAttribute(defaultBorder.getHlOut()));
245                 setAttribute(elemBorders, "shadow", createAttribute(border.getShadowOut()), createAttribute(defaultBorder.getShadowOut()));
246                 break;
247             }
248             case LINE: {
249                 setAttribute(elemBorders, "color", createAttribute(border.getColor()), createAttribute(defaultBorder.getColor()));
250                 setAttribute(elemBorders, "thickness", createAttribute(border.getThickness()), createAttribute(defaultBorder.getThickness()));
251                 setAttribute(elemBorders, "rounded", createAttribute(border.getRounded()), createAttribute(defaultBorder.getRounded()));
252                 break;
253             }
254             case MATTE: {
255                 setAttribute(elemBorders, "position", createAttribute(border.getPosition()), createAttribute(defaultBorder.getPosition()));
256                 setAttribute(elemBorders, "color", createAttribute(border.getColor()), createAttribute(defaultBorder.getColor()));
257                 break;
258             }
259             case SOFTBEVEL: {
260                 setAttribute(elemBorders, "type", createAttribute(border.getBorderType()), createAttribute(defaultBorder.getBorderType()));
261                 setAttribute(elemBorders, "hlout", createAttribute(border.getHlOut()), createAttribute(defaultBorder.getHlOut()));
262                 setAttribute(elemBorders, "hlin", createAttribute(border.getHlIn()), createAttribute(defaultBorder.getHlIn()));
263                 setAttribute(elemBorders, "shadowout", createAttribute(border.getShadowOut()), createAttribute(defaultBorder.getShadowOut()));
264                 setAttribute(elemBorders, "shadowin", createAttribute(border.getShadowIn()), createAttribute(defaultBorder.getShadowIn()));
265                 break;
266             }
267             case TITLED: {
268                 setAttribute(elemBorders, "title", createAttribute(border.getTitle()), createAttribute(defaultBorder.getTitle()));
269                 setAttribute(elemBorders, "justification", createAttribute(border.getJustification()), createAttribute(defaultBorder.getJustification()));
270                 setAttribute(elemBorders, "titleposition", createAttribute(border.getTitlePosition()), createAttribute(defaultBorder.getTitlePosition()));
271                 setAttribute(elemBorders, "fontname", createAttribute(border.getFontName()), createAttribute(defaultBorder.getFontName()));
272                 setAttribute(elemBorders, "fontangle", createAttribute(border.getFontAngle()), createAttribute(defaultBorder.getFontAngle()));
273                 setAttribute(elemBorders, "fontsize", createAttribute(border.getFontSize()), createAttribute(defaultBorder.getFontSize()));
274                 setAttribute(elemBorders, "fontweight", createAttribute(border.getFontWeight()), createAttribute(defaultBorder.getFontWeight()));
275                 setAttribute(elemBorders, "color", createAttribute(border.getColor()), createAttribute(defaultBorder.getColor()));
276                 Element title = createBorders(doc, border.getTitleBorder(), "title");
277                 if (title != null) {
278                     elemBorders.appendChild(title);
279                 }
280                 break;
281             }
282             case NONE:
283             default: {
284                 break;
285             }
286         }
287         return elemBorders;
288     }
289
290     private static Element createUicontrol(Document doc, Integer id, boolean reverseChildren) {
291         GraphicController controller = GraphicController.getController();
292         Uicontrol uic = (Uicontrol)controller.getObjectFromId(id);
293         initDefaultui(uic.getStyle());
294         Element elemUi = doc.createElement(uic.getStyleAsEnum().toString().toLowerCase());
295
296         //BackgroundColor
297         setAttribute(elemUi, "backgroundcolor", createAttribute(uic.getBackgroundColor()), createAttribute(defaultUi.getBackgroundColor()));
298         //Enable
299         setAttribute(elemUi, "enable", createAttribute(uic.getEnable()), createAttribute(defaultUi.getEnable()));
300         //FontAngle
301         setAttribute(elemUi, "fontangle", createAttribute(uic.getFontAngle()), createAttribute(defaultUi.getFontAngle()));
302         //FontName
303         setAttribute(elemUi, "fontname", createAttribute(uic.getFontName()), createAttribute(defaultUi.getFontName()));
304         //FontSize
305         setAttribute(elemUi, "fontsize", createAttribute(uic.getFontSize()), createAttribute(defaultUi.getFontSize()));
306         //FontUnits
307         setAttribute(elemUi, "fontunits", createAttribute(uic.getFontUnits()), createAttribute(defaultUi.getFontUnits()));
308         //FontWeight
309         setAttribute(elemUi, "fontweight", createAttribute(uic.getFontWeight()), createAttribute(defaultUi.getFontWeight()));
310         //ForegroundColor
311         setAttribute(elemUi, "foregroundcolor", createAttribute(uic.getForegroundColor()), createAttribute(defaultUi.getForegroundColor()));
312         //HorizontalAlignment
313         setAttribute(elemUi, "horizontalalignment", createAttribute(uic.getHorizontalAlignment()), createAttribute(defaultUi.getHorizontalAlignment()));
314         //ListboxTop
315         setAttribute(elemUi, "listboxtop", createAttribute(uic.getListboxTop()), createAttribute(defaultUi.getListboxTop()));
316         //Max
317         setAttribute(elemUi, "max", createAttribute(uic.getMax()), createAttribute(defaultUi.getMax()));
318         //Min
319         setAttribute(elemUi, "min", createAttribute(uic.getMin()), createAttribute(defaultUi.getMin()));
320         //Relief
321         setAttribute(elemUi, "relief", createAttribute(uic.getRelief()), createAttribute(defaultUi.getRelief()));
322         //SliderStep
323         setAttribute(elemUi, "sliderstep", createAttribute(uic.getSliderStep()), createAttribute(defaultUi.getSliderStep()));
324         //String
325         setAttribute(elemUi, "string", createAttribute(uic.getString()), createAttribute(defaultUi.getString()));
326         //TooltipString
327         setAttribute(elemUi, "tooltipstring", createAttribute(uic.getTooltipString()), createAttribute(defaultUi.getTooltipString()));
328         //Units
329         setAttribute(elemUi, "units", createAttribute(uic.getUnits()), createAttribute(defaultUi.getUnits()));
330         //Value
331         setAttribute(elemUi, "value", createAttribute(uic.getUiValue()), createAttribute(defaultUi.getUiValue()));
332         //VerticalAlignment
333         setAttribute(elemUi, "verticalalignment", createAttribute(uic.getVerticalAlignment()), createAttribute(defaultUi.getVerticalAlignment()));
334         //Visible
335         setAttribute(elemUi, "visible", createAttribute(uic.getVisible()), createAttribute(!defaultUi.getVisible()));
336         //Callback
337         setAttribute(elemUi, "callback", createAttribute(uic.getCallbackString()), createAttribute(defaultUi.getCallbackString()));
338         //Callback_Type
339         setAttribute(elemUi, "callback_type", createAttribute(uic.getCallbackType()), createAttribute(defaultUi.getCallbackType()));
340
341         //Constraints
342         Integer parent = (Integer)controller.getProperty(uic.getIdentifier(), __GO_PARENT__);
343         Integer iLayout = (Integer)controller.getProperty(parent, __GO_LAYOUT__);
344         LayoutType layout = LayoutType.intToEnum(iLayout);
345
346         if (layout == LayoutType.GRIDBAG) {
347             setAttribute(elemUi, "gridbaggrid", createAttribute(uic.getGridBagGrid()), createAttribute(defaultUi.getGridBagGrid()));
348             setAttribute(elemUi, "gridbagweight", createAttribute(uic.getGridBagWeight()), createAttribute(defaultUi.getGridBagWeight()));
349             setAttribute(elemUi, "gridbagfill", createAttribute(uic.getGridBagFill()), createAttribute(defaultUi.getGridBagFill()));
350             setAttribute(elemUi, "gridbaganchor", createAttribute(uic.getGridBagAnchor()), createAttribute(defaultUi.getGridBagAnchor()));
351             setAttribute(elemUi, "gridbagpadding", createAttribute(uic.getGridBagPadding()), createAttribute(defaultUi.getGridBagPadding()));
352             setAttribute(elemUi, "gridbagpreferredsize", createAttribute(uic.getGridBagPreferredSize()), createAttribute(defaultUi.getGridBagPreferredSize()));
353         } else if (layout == LayoutType.BORDER) {
354             setAttribute(elemUi, "borderposition", createAttribute(uic.getBorderPosition()), createAttribute(defaultUi.getBorderPosition()));
355             setAttribute(elemUi, "borderpreferredsize", createAttribute(uic.getBorderPreferredSize()), createAttribute(defaultUi.getBorderPreferredSize()));
356         } else if (layout == LayoutType.NONE) {
357             //Position
358             setAttribute(elemUi, "position", createAttribute(uic.getUiPosition()), createAttribute(defaultUi.getUiPosition()));
359         }
360
361         //Margins
362         setAttribute(elemUi, "margins", createAttribute(uic.getMargins()), createAttribute(defaultUi.getMargins()));
363         //Groupname
364         setAttribute(elemUi, "groupname", createAttribute(uic.getGroupName()), createAttribute(defaultUi.getGroupName()));
365
366         //icon
367         setAttribute(elemUi, "icon", createAttribute(uic.getIcon()), createAttribute(defaultUi.getIcon()));
368         //Tag
369         setAttribute(elemUi, "tag", createAttribute(uic.getTag()), createAttribute(defaultUi.getTag()));
370
371         //only for frame type
372         if (uic.getStyleAsEnum() == UicontrolStyle.FRAME) {
373             //Borders
374             Integer iBorders = uic.getFrameBorder();
375             Element borders = createBorders(doc, iBorders);
376             if (borders != null) {
377                 elemUi.appendChild(createBorders(doc, iBorders));
378             }
379
380             //Scrollable
381             setAttribute(elemUi, "scrollable", createAttribute(uic.getScrollable()), createAttribute(defaultUi.getScrollable()));
382
383             //Layout
384             setAttribute(elemUi, "layout", createAttribute(uic.getLayout()), createAttribute(defaultUi.getLayout()));
385             //Layout_options
386             if (uic.getLayoutAsEnum() == LayoutType.GRID) {
387                 setAttribute(elemUi, "gridoptgrid", createAttribute(uic.getGridOptGrid()), createAttribute(defaultUi.getGridOptGrid()));
388                 setAttribute(elemUi, "gridoptpadding", createAttribute(uic.getGridOptPadding()), createAttribute(defaultUi.getGridOptPadding()));
389             } else if (uic.getLayoutAsEnum() == LayoutType.BORDER) {
390                 setAttribute(elemUi, "borderoptpadding", createAttribute(uic.getBorderOptPadding()), createAttribute(defaultUi.getBorderOptPadding()));
391             }
392         }
393
394         //children
395         Integer[] children = uic.getChildren();
396         if (reverseChildren) {
397             for (int i = children.length - 1 ; i >= 0 ; i--) {
398                 elemUi.appendChild(createElement(doc, children[i], reverseChildren));
399             }
400         } else {
401             for (int i = 0 ; i < children.length ; i++) {
402                 elemUi.appendChild(createElement(doc, children[i], reverseChildren));
403             }
404         }
405         return elemUi;
406     }
407
408     private static String createAttribute(Boolean val) {
409         if (val == null) {
410             return "off";
411         }
412
413         if (val) {
414             return "on";
415         } else {
416             return "off";
417         }
418     }
419
420     private static String createAttribute(Integer val) {
421         if (val == null) {
422             return null;
423         }
424
425         StringBuilder builder = new StringBuilder();
426         builder.append(val.intValue());
427         return builder.toString();
428     }
429
430     private static String createAttribute(String val) {
431         if (val == null) {
432             return null;
433         }
434         return val;
435     }
436
437     private static String createAttribute(Double val) {
438         if (val == null) {
439             return null;
440         }
441
442         StringBuilder builder = new StringBuilder();
443         builder.append(val.doubleValue());
444         return builder.toString();
445     }
446
447     //    private static String createAttribute(Boolean[] val) {
448     //        if(val == null || val.length == 0) {
449     //            return null;
450     //        }
451     //
452     //        StringBuilder onoff = new StringBuilder();
453     //
454     //        onoff.append(createAttribute(val[0]));
455     //
456     //        for(int i = 1 ; i < val.length; i++)
457     //        {
458     //            onoff.append(",");
459     //            onoff.append(createAttribute(val[i]));
460     //        }
461     //
462     //        return onoff.toString();
463     //    }
464
465
466     private static String createAttribute(String[] val) {
467         if (val == null || val.length == 0) {
468             return null;
469         }
470
471         StringBuilder onoff = new StringBuilder();
472
473         onoff.append(createAttribute(val[0]));
474
475         for (int i = 1 ; i < val.length; i++) {
476             onoff.append(",");
477             onoff.append(createAttribute(val[i]));
478         }
479
480         return onoff.toString();
481     }
482
483     private static String createAttribute(Double[] val) {
484         if (val == null || val.length == 0) {
485             return null;
486         }
487
488         StringBuilder onoff = new StringBuilder();
489
490         onoff.append(createAttribute(val[0]));
491
492         for (int i = 1 ; i < val.length; i++) {
493             onoff.append(",");
494             onoff.append(createAttribute(val[i]));
495         }
496
497         return onoff.toString();
498     }
499
500     private static String createAttribute(Integer[] val) {
501         if (val == null || val.length == 0) {
502             return null;
503         }
504
505         StringBuilder onoff = new StringBuilder();
506
507         onoff.append(createAttribute(val[0]));
508
509         for (int i = 1 ; i < val.length; i++) {
510             onoff.append(",");
511             onoff.append(createAttribute(val[i]));
512         }
513
514         return onoff.toString();
515     }
516
517     private static void setAttribute(Element elem, String property, String value, String ref) {
518         if (value == null || property == null || elem == null || (ref != null && value.equals(ref))) {
519             return;
520         }
521
522         elem.setAttribute(property, value);
523     }
524
525     private static void initDefaultui(Integer uicontrolStyle) {
526         Integer uic = GraphicController.getController().askObject(GraphicObject.getTypeFromName(uicontrolStyle));
527         defaultUi = (Uicontrol) GraphicController.getController().getObjectFromId(uic);
528     }
529
530 }