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