add savegui as xml file, change xml format to manage all figure/uicontrol properties
[scilab.git] / scilab / modules / graphic_objects / src / java / org / scilab / modules / graphic_objects / xmlloader / GOBuilder.java
1 package org.scilab.modules.graphic_objects.xmlloader;
2
3 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_DOCKABLE__;
4 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACK__;
5 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACKTYPE__;
6 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BORDER_OPT_PADDING__;
7 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_GRID__;
8 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_PADDING__;
9 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_INFOBAR_VISIBLE__;
10 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT__;
11 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LINE_THICKNESS__;
12 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_MARGINS__;
13 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_MENUBAR_VISIBLE__;
14 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_NAME__;
15 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
16 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_RESIZE__;
17 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_SIZE__;
18 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_STYLE__;
19 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TAG__;
20 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TITLE__;
21 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TOOLBAR_VISIBLE__;
22 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
23 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BACKGROUNDCOLOR__;
24 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BORDER_POSITION__;
25 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_CHECKBOX__;
26 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
27 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTANGLE__;
28 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTNAME__;
29 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTSIZE__;
30 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTWEIGHT__;
31 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_COLOR__;
32 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_HIGHLIGHT_IN__;
33 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__;
34 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_IN_BORDER__;
35 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_JUSTIFICATION__;
36 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_OUT_BORDER__;
37 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_POSITION__;
38 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_ROUNDED__;
39 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_SHADOW_IN__;
40 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_SHADOW_OUT__;
41 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_STYLE__;
42 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_TITLE__;
43 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
44 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_SCROLLABLE__;
45 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME__;
46 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_GRIDBAG_ANCHOR__;
47 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_GRIDBAG_FILL__;
48 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_GRIDBAG_GRID__;
49 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_GRIDBAG_PADDING__;
50 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_GRIDBAG_PREFERREDSIZE__;
51 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_GRIDBAG_WEIGHT__;
52 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_HORIZONTALALIGNMENT__;
53 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ICON__;
54 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MAX__;
55 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MIN__;
56 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_PUSHBUTTON__;
57 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SCROLLABLE__;
58 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
59 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_TAB__;
60 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_TEXT__;
61 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_EDIT__;
62 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_POPUPMENU__;
63 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LISTBOX__;
64 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_RADIOBUTTON__;
65 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_GROUP_NAME__;
66 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
67
68 import java.awt.Color;
69 import java.lang.reflect.Field;
70 import java.util.Map;
71
72 import org.scilab.modules.graphic_objects.builder.Builder;
73 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
74 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
75 import org.scilab.modules.graphic_objects.uicontrol.Uicontrol;
76 import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorder;
77 import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorder.BorderType;
78 import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorderType;
79 import org.scilab.modules.graphic_objects.utils.LayoutType;
80 import org.xml.sax.Attributes;
81
82 public class GOBuilder {
83     public static Integer figureBuilder(GraphicController controller, Attributes attributes) {
84         Integer fig = Builder.createFigure(false, 0, 0, false, false);
85         //Integer fig = Builder.createNewFigureWithAxes();
86         String item = null;
87
88         // hide toolbar
89         controller.setProperty(fig, __GO_TOOLBAR_VISIBLE__, false);
90
91         // hide menubar
92         controller.setProperty(fig, __GO_MENUBAR_VISIBLE__, false);
93
94         // hide infobar
95         controller.setProperty(fig, __GO_INFOBAR_VISIBLE__, false);
96
97         // remove docking bar
98         controller.setProperty(fig, __GO_DOCKABLE__, false);
99
100         // id
101         XmlTools.setPropAsString(fig, __GO_TAG__, attributes.getValue("id"));
102
103         // position
104         Integer[] position = (Integer[]) controller.getProperty(fig, __GO_POSITION__);
105
106         // posX
107         item = attributes.getValue("posX");
108         if (item != null) {
109             position[0] = Integer.parseInt(item);
110         }
111
112         // posY
113         item = attributes.getValue("posY");
114         if (item != null) {
115             position[1] = Integer.parseInt(item);
116         }
117
118         // set position
119         controller.setProperty(fig, __GO_POSITION__, position);
120
121         Integer[] size = (Integer[]) controller.getProperty(fig, __GO_SIZE__);
122         // width
123         item = attributes.getValue("width");
124         if (item != null) {
125             size[0] = Integer.parseInt(item);
126         }
127
128         // height
129         item = attributes.getValue("height");
130         if (item != null) {
131             size[1] = Integer.parseInt(item);
132         }
133
134         // set size
135         controller.setProperty(fig, __GO_SIZE__, size);
136
137         // title
138         XmlTools.setPropAsString(fig, __GO_NAME__, attributes.getValue("title"));
139
140         // icon
141         // XmlTools.setPropAsString(fig, __GO_ICON__,
142         // attributes.getValue("icon"));
143
144         // resizable
145         XmlTools.setPropAsBoolean(fig, __GO_RESIZE__, attributes.getValue("resizable"));
146
147         // layout and layout_options
148         item = attributes.getValue("layout");
149         if (item == null) {
150             item = "name:border"; //default layout is border
151         }
152
153         setLayoutProperty(controller, fig, item);
154
155
156         //icon
157         item = attributes.getValue("icon");
158         if (item != null) {
159             controller.setProperty(fig, __GO_UI_ICON__, item);
160         }
161
162         // visible
163         XmlTools.setPropAsBoolean(fig, __GO_VISIBLE__, attributes.getValue("visible"));
164
165         return fig;
166     }
167
168     public static Integer uicontrolBuilder(GraphicController controller, int type, Attributes attributes, int parent) {
169         if (type == __GO_UI_FRAME__) {
170             String item = attributes.getValue("scrollable");
171             if (item != null && item.equals("true")) {
172                 type = __GO_UI_FRAME_SCROLLABLE__;
173             }
174         }
175
176         Integer uic = controller.askObject(GraphicObject.getTypeFromName(type));
177         return uicontrolUpdater(controller, uic, attributes, parent);
178     }
179
180     public static Integer uicontrolUpdater(GraphicController controller, int uic, Attributes attributes, int parent) {
181         return uicontrolUpdater(controller, uic, attributes, parent, null);
182     }
183
184     public static Integer uicontrolUpdater(GraphicController controller, int uic, Attributes attributes, int parent, Map<String, String> fromModel) {
185         String item = null;
186
187         try {
188             Map<String, String> map = null;
189             // Common attributes
190
191             // id
192             XmlTools.setPropAsString(uic, __GO_TAG__, attributes.getValue("id"));
193
194             // layout and layout_options
195             item = attributes.getValue("layout");
196             if (item == null) {
197                 if (fromModel != null) {
198                     item = fromModel.get("layout");
199                 }
200             }
201
202             if (item == null) {
203                 item = "name:none";
204             }
205             setLayoutProperty(controller, uic, item);
206
207             //visible
208             item = attributes.getValue("visible");
209             if (item == null || item.equals("true") || item.equals("on")) {
210                 controller.setProperty(uic, __GO_VISIBLE__, true);
211             } else {
212                 controller.setProperty(uic, __GO_VISIBLE__, false);
213             }
214
215             //enable
216             item = attributes.getValue("enable");
217             if (item == null || item.equals("true") || item.equals("on")) {
218                 controller.setProperty(uic, __GO_UI_ENABLE__, true);
219             } else {
220                 controller.setProperty(uic, __GO_UI_ENABLE__, false);
221             }
222
223             //backgroundcolor
224             item = attributes.getValue("background");
225             if (item != null) {
226
227                 controller.setProperty(uic, __GO_UI_BACKGROUNDCOLOR__, getColor(item));
228             }
229
230             // constraints
231
232             // get parent layout
233             LayoutType layout = LayoutType.NONE;
234             if (parent != 0) {
235                 layout = LayoutType.intToEnum((Integer) controller.getProperty(parent, __GO_LAYOUT__));
236             }
237
238             if (layout != LayoutType.NONE) {
239                 item = attributes.getValue("constraint");
240                 if (item == null && fromModel != null) {
241                     // use value from model if property is not in "declaration"
242                     item = XmlTools.getFromMap(fromModel, "constraint");
243                 }
244
245                 if (item != null) {
246                     map = CSSParser.parseLine(item);
247                 }
248
249                 switch (layout) {
250                     case BORDER: {
251                         item = XmlTools.getFromMap(map, "position", "center");
252                         controller.setProperty(uic, __GO_UI_BORDER_POSITION__, Uicontrol.BorderLayoutType.stringToEnum(item).ordinal());
253                         break;
254                     }
255                     case GRIDBAG: {
256                         Integer[] grid = new Integer[] { 0, 0, 0, 0 };
257                         grid[0] = Integer.parseInt(XmlTools.getFromMap(map, "gridx", "0"));
258                         grid[1] = Integer.parseInt(XmlTools.getFromMap(map, "gridy", "0"));
259                         grid[2] = Integer.parseInt(XmlTools.getFromMap(map, "gridwidth", "1"));
260                         grid[3] = Integer.parseInt(XmlTools.getFromMap(map, "gridheight", "1"));
261
262                         Double[] weight = new Double[] { 0.0, 0.0 };
263                         weight[0] = Double.parseDouble(XmlTools.getFromMap(map, "weightx", "1.0"));
264                         weight[1] = Double.parseDouble(XmlTools.getFromMap(map, "weighty", "1.0"));
265
266                         Integer fill = Uicontrol.FillType.stringToEnum(XmlTools.getFromMap(map, "fill", "none")).ordinal();
267                         Integer anchor = Uicontrol.AnchorType.stringToEnum(XmlTools.getFromMap(map, "anchor", "center")).ordinal();
268
269                         Integer[] padding = new Integer[] { 0, 0 };
270                         padding[0] = Integer.parseInt(XmlTools.getFromMap(map, "ipadx", "0"));
271                         padding[1] = Integer.parseInt(XmlTools.getFromMap(map, "ipady", "0"));
272
273                         Integer[] preferredsize = new Integer[] { -1, -1};
274                         item = attributes.getValue("preferred-size");
275                         if (item != null) {
276                             String[] pref = item.split(",");
277                             for (int i = 0; i < pref.length && i < 4; i++) {
278                                 preferredsize[i] = Integer.parseInt(pref[i]);
279                             }
280                         }
281                         controller.setProperty(uic, __GO_UI_GRIDBAG_GRID__, grid);
282                         controller.setProperty(uic, __GO_UI_GRIDBAG_WEIGHT__, weight);
283                         controller.setProperty(uic, __GO_UI_GRIDBAG_FILL__, fill);
284                         controller.setProperty(uic, __GO_UI_GRIDBAG_ANCHOR__, anchor);
285                         controller.setProperty(uic, __GO_UI_GRIDBAG_PADDING__, padding);
286                         controller.setProperty(uic, __GO_UI_GRIDBAG_PREFERREDSIZE__, preferredsize);
287                         break;
288                     }
289                     default:
290                         break;
291                 }
292
293                 // insets -> marging
294                 String insets = XmlTools.getFromMap(map, "insets", "0,0,0,0");
295                 Double[] margins = new Double[] { 0.0, 0.0, 0.0, 0.0 };
296                 String[] inset = insets.split(",");
297                 for (int i = 0; i < inset.length && i < 4; i++) {
298                     margins[i] = Double.parseDouble(inset[i]);
299                 }
300
301                 controller.setProperty(uic, __GO_MARGINS__, margins);
302             }
303
304             // specific attributes
305             Integer type = (Integer) controller.getProperty(uic, __GO_STYLE__);
306             switch (type) {
307                 case __GO_UI_FRAME__: {
308                     // border
309                     item = attributes.getValue("border");
310                     if (item == null && fromModel != null) {
311                         // use value from model if property is not in
312                         // "declaration"
313                         item = XmlTools.getFromMap(fromModel, "border");
314                     }
315
316                     if (item != null) {
317                         map = CSSParser.parseLine(item);
318                     }
319
320                     FrameBorderType borderType = FrameBorderType.stringToEnum(XmlTools.getFromMap(map, "name", "none"));
321                     Integer border = createBorder(controller, uic, borderType, map);
322                     controller.setProperty(uic, __GO_UI_FRAME_BORDER__, border);
323
324                     String[] text = new String[1];
325                     text[0] = attributes.getValue("tab-title");
326                     if (text[0] != null) {
327                         controller.setProperty(uic, __GO_UI_STRING__, text);
328                     }
329
330                     item = attributes.getValue("scrollable");
331                     if (item == null || item.equals("false")) {
332                         controller.setProperty(uic, __GO_UI_SCROLLABLE__, false);
333                     } else {
334                         controller.setProperty(uic, __GO_UI_SCROLLABLE__, true);
335                     }
336
337                     break;
338                 }
339
340                 case __GO_UI_TAB__: {
341                     item = attributes.getValue("ui-style");
342                     if (item != null) {
343                         map = CSSParser.parseLine(item);
344                         item = XmlTools.getFromMap(map, "bold", "false");
345                         if (item.equals("true")) {
346                             controller.setProperty(uic, __GO_UI_FONTWEIGHT__, "bold");
347                         }
348
349                         item = XmlTools.getFromMap(map, "italic", "false");
350                         if (item.equals("true")) {
351                             controller.setProperty(uic, __GO_UI_FONTANGLE__, "italic");
352                         }
353                     }
354                     break;
355                 }
356                 case __GO_UI_CHECKBOX__: {
357                     String[] text = new String[1];
358                     text[0] = attributes.getValue("text");
359                     if (text[0] != null) {
360                         controller.setProperty(uic, __GO_UI_STRING__, text);
361                     }
362
363                     //callback
364                     item = attributes.getValue("onclick");
365                     if (item != null && item.equals("") == false) {
366                         controller.setProperty(uic, __GO_CALLBACK__, item);
367                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
368                     }
369
370                     //groupname
371                     item = attributes.getValue("button-group");
372                     if (item != null && item.equals("") == false) {
373                         controller.setProperty(uic, __GO_UI_GROUP_NAME__, item);
374                     }
375
376                     break;
377                 }
378                 case __GO_UI_RADIOBUTTON__: {
379                     String[] text = new String[1];
380                     text[0] = attributes.getValue("text");
381                     if (text[0] != null) {
382                         controller.setProperty(uic, __GO_UI_STRING__, text);
383                     }
384
385                     //callback
386                     item = attributes.getValue("onclick");
387                     if (item != null && item.equals("") == false) {
388                         controller.setProperty(uic, __GO_CALLBACK__, item);
389                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
390                     }
391
392                     //groupname
393                     item = attributes.getValue("button-group");
394                     if (item != null && item.equals("") == false) {
395                         controller.setProperty(uic, __GO_UI_GROUP_NAME__, item);
396                     }
397
398                     break;
399                 }
400                 case __GO_UI_PUSHBUTTON__: {
401
402                     //string
403                     String[] text = new String[1];
404                     text[0] = attributes.getValue("text");
405                     if (text[0] != null) {
406                         controller.setProperty(uic, __GO_UI_STRING__, text);
407                     }
408
409
410                     //icon
411                     item = attributes.getValue("icon");
412                     if (item != null) {
413                         controller.setProperty(uic, __GO_UI_ICON__, item);
414                     }
415
416                     //callback
417                     item = attributes.getValue("onclick");
418                     if (item != null && item.equals("") == false) {
419                         controller.setProperty(uic, __GO_CALLBACK__, item);
420                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
421                     }
422
423                     break;
424                 }
425                 case __GO_UI_TEXT__: { //label
426                     controller.setProperty(uic, __GO_UI_HORIZONTALALIGNMENT__, "left");
427                     String[] text = new String[1];
428                     text[0] = attributes.getValue("text");
429                     if (text[0] != null) {
430                         controller.setProperty(uic, __GO_UI_STRING__, text);
431                     }
432
433                     //icon
434                     item = attributes.getValue("icon");
435                     if (item != null) {
436                         controller.setProperty(uic, __GO_UI_ICON__, item);
437                     }
438
439                     break;
440                 }
441                 case __GO_UI_EDIT__ : {
442                     //callback
443                     item = attributes.getValue("onenter");
444                     if (item != null && item.equals("") == false) {
445                         controller.setProperty(uic, __GO_CALLBACK__, item);
446                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
447                     }
448
449                     item = attributes.getValue("columns");
450                     if (item != null) {
451                         controller.setProperty(uic, __GO_UI_MAX__, Double.parseDouble(item));
452                     }
453
454                     break;
455                 }
456                 case __GO_UI_POPUPMENU__ : {
457                     //callback
458                     item = attributes.getValue("onchange");
459                     if (item != null && item.equals("") == false) {
460                         controller.setProperty(uic, __GO_CALLBACK__, item);
461                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
462                     }
463
464                     break;
465                 }
466                 case __GO_UI_LISTBOX__ : {
467                     //callback
468                     item = attributes.getValue("onclick");
469                     if (item != null && item.equals("") == false) {
470                         controller.setProperty(uic, __GO_CALLBACK__, item);
471                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
472                     }
473
474                     item = attributes.getValue("multiple");
475                     if (item != null && item.equals("true")) {
476                         controller.setProperty(uic, __GO_UI_MIN__, 0.0);
477                         controller.setProperty(uic, __GO_UI_MAX__, 2.0);
478                     }
479
480                     break;
481                 }
482             }
483
484         } catch (CSSParserException e) {
485             e.printStackTrace();
486         }
487
488         return uic;
489     }
490
491     private static void setLayoutProperty(GraphicController controller, Integer uid, String item) {
492         try {
493             Map<String, String> map = null;
494             map = CSSParser.parseLine(item);
495             item = map.get("name");
496             LayoutType layout = LayoutType.stringToEnum(item);
497             controller.setProperty(uid, __GO_LAYOUT__, layout.ordinal());
498
499             // layout_options
500             switch (layout) {
501                 case BORDER: {
502                     Integer[] pad = new Integer[] { 0, 0 };
503                     pad[0] = Integer.parseInt(XmlTools.getFromMap(map, "hgap", "0"));
504                     pad[1] = Integer.parseInt(XmlTools.getFromMap(map, "vgap", "0"));
505
506                     controller.setProperty(uid, __GO_BORDER_OPT_PADDING__, pad);
507                     break;
508                 }
509                 case GRID: {
510                     Integer[] grid = new Integer[] { 0, 0 };
511                     grid[0] = Integer.parseInt(XmlTools.getFromMap(map, "rows", "0"));
512                     grid[1] = Integer.parseInt(XmlTools.getFromMap(map, "cols", "0"));
513
514                     Integer[] pad = new Integer[] { 0, 0 };
515                     pad[0] = Integer.parseInt(XmlTools.getFromMap(map, "hgap", "0"));
516                     pad[1] = Integer.parseInt(XmlTools.getFromMap(map, "vgap", "0"));
517
518                     controller.setProperty(uid, __GO_GRID_OPT_GRID__, grid);
519                     controller.setProperty(uid, __GO_GRID_OPT_PADDING__, pad);
520                     break;
521                 }
522                 default:
523                 case GRIDBAG:
524                 case NONE:
525                     // nothing to do
526                     break;
527             }
528         } catch (CSSParserException e) {
529             e.printStackTrace();
530         }
531
532     }
533
534     private static Integer createBorder(GraphicController controller, Integer uic, FrameBorderType borderType, Map<String, String> map) {
535         Integer border = controller.askObject(GraphicObject.getTypeFromName(__GO_UI_FRAME_BORDER__));
536         controller.setProperty(border, __GO_UI_FRAME_BORDER_STYLE__, borderType.ordinal());
537
538         switch (borderType) {
539             case SOFTBEVEL:
540             case BEVEL: {
541                 BorderType etching = BorderType.stringToEnum(XmlTools.getFromMap(map, "type", "none"));
542                 String color = XmlTools.getFromMap(map, "color", "black");
543
544                 controller.setProperty(border, __GO_TYPE__, etching.ordinal());
545                 controller.setProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, color);
546                 controller.setProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_IN__, color);
547                 controller.setProperty(border, __GO_UI_FRAME_BORDER_SHADOW_OUT__, color);
548                 controller.setProperty(border, __GO_UI_FRAME_BORDER_SHADOW_IN__, color);
549                 break;
550             }
551             case COMPOUND: {
552                 FrameBorderType borderOut = FrameBorderType.stringToEnum(XmlTools.getFromMap(map, "border-out", "none"));
553                 FrameBorderType borderIn = FrameBorderType.stringToEnum(XmlTools.getFromMap(map, "border-in", "none"));
554
555                 Integer out = createBorder(controller, border, borderOut, map);
556                 Integer in = createBorder(controller, border, borderIn, map);
557
558                 controller.setProperty(border, __GO_UI_FRAME_BORDER_OUT_BORDER__, out);
559                 controller.setProperty(border, __GO_UI_FRAME_BORDER_IN_BORDER__, in);
560
561                 break;
562             }
563             case EMPTY: {
564                 Double[] position = new Double[4];
565                 position[0] = Double.parseDouble(XmlTools.getFromMap(map, "top", "0"));
566                 position[1] = Double.parseDouble(XmlTools.getFromMap(map, "left", "0"));
567                 position[2] = Double.parseDouble(XmlTools.getFromMap(map, "right", "0"));
568                 position[3] = Double.parseDouble(XmlTools.getFromMap(map, "bottom", "0"));
569
570                 controller.setProperty(border, __GO_POSITION__, position);
571                 break;
572             }
573             case ETCHED: {
574                 BorderType etching = BorderType.stringToEnum(XmlTools.getFromMap(map, "type", "none"));
575                 String color = XmlTools.getFromMap(map, "color", "black");
576
577                 controller.setProperty(border, __GO_TYPE__, etching.ordinal());
578                 controller.setProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, color);
579                 controller.setProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_IN__, color);
580                 break;
581             }
582             case LINE: {
583                 String color = XmlTools.getFromMap(map, "color", "black");
584                 Integer thickness = Integer.parseInt(XmlTools.getFromMap(map, "thickness", "1"));
585                 Boolean rounded = Boolean.parseBoolean(XmlTools.getFromMap(map, "rounded", "false"));
586
587                 controller.setProperty(border, __GO_UI_FRAME_BORDER_COLOR__, color);
588                 controller.setProperty(border, __GO_LINE_THICKNESS__, thickness);
589                 controller.setProperty(border, __GO_UI_FRAME_BORDER_ROUNDED__, rounded);
590                 break;
591             }
592             case MATTE: {
593                 Double[] position = new Double[4];
594                 position[0] = Double.parseDouble(XmlTools.getFromMap(map, "top", "0"));
595                 position[1] = Double.parseDouble(XmlTools.getFromMap(map, "left", "0"));
596                 position[2] = Double.parseDouble(XmlTools.getFromMap(map, "right", "0"));
597                 position[3] = Double.parseDouble(XmlTools.getFromMap(map, "bottom", "0"));
598                 String color = XmlTools.getFromMap(map, "color", "black");
599
600                 controller.setProperty(border, __GO_POSITION__, position);
601                 controller.setProperty(border, __GO_UI_FRAME_BORDER_COLOR__, color);
602                 break;
603             }
604             case TITLED: {
605
606                 String title = XmlTools.getFromMap(map, "title", "");
607                 FrameBorder.JustificationType justify = FrameBorder.JustificationType.stringToEnum(XmlTools.getFromMap(map, "justify", "leading"));
608                 String fontName = XmlTools.getFromMap(map, "font-name", "");
609                 String fontAngle = XmlTools.getFromMap(map, "italic", "false") == "false" ? "normal" : "italic";
610                 Integer fontSize = Integer.parseInt(XmlTools.getFromMap(map, "font-size", "0"));
611                 String fontWeight = XmlTools.getFromMap(map, "bold", "false") == "false" ? "normal" : "bold";
612
613                 FrameBorder.TitlePositionType position = FrameBorder.TitlePositionType.stringToEnum(XmlTools.getFromMap(map, "position", "leading"));
614
615                 String color = XmlTools.getFromMap(map, "color", "black");
616
617                 FrameBorderType borderOut = FrameBorderType.stringToEnum(XmlTools.getFromMap(map, "border", "none"));
618                 Integer out = createBorder(controller, border, borderOut, map);
619
620                 controller.setProperty(border, __GO_UI_FRAME_BORDER_TITLE__, out);
621                 controller.setProperty(border, __GO_TITLE__, title);
622                 controller.setProperty(border, __GO_UI_FRAME_BORDER_JUSTIFICATION__, justify.ordinal());
623                 controller.setProperty(border, __GO_UI_FONTNAME__, fontName);
624                 controller.setProperty(border, __GO_UI_FONTANGLE__, fontAngle);
625                 controller.setProperty(border, __GO_UI_FONTSIZE__, fontSize);
626                 controller.setProperty(border, __GO_UI_FONTWEIGHT__, fontWeight);
627                 controller.setProperty(border, __GO_UI_FRAME_BORDER_POSITION__, position.ordinal());
628                 controller.setProperty(border, __GO_UI_FRAME_BORDER_COLOR__, color);
629
630                 break;
631             }
632             case NONE:
633             default:
634                 break;
635         }
636
637         return border;
638     }
639
640     private static Double[] getColor(String str) {
641         try {
642             Field field = Class.forName("java.awt.Color").getField(str);
643             Color color = (Color) field.get(null);
644             return new Double[] {(double) color.getRed() / 255, (double) color.getGreen() / 255, (double) color.getBlue() / 255};
645         } catch (Exception e) {
646             return new Double[] {(double) Color.black.getRed() / 255, (double) Color.black.getGreen() / 255, (double) Color.black.getBlue() / 255};
647         }
648     }
649 }