during clone recursion on frameborder set new uid in parent ( frame or frameborder )
[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
372                     String[] text = new String[1];
373                     text[0] = xmlAttributes.get("tab-title");
374                     if (text[0] != null) {
375                         controller.setProperty(uic, __GO_UI_STRING__, text);
376                     }
377
378                     item = xmlAttributes.get("scrollable");
379                     if (item == null || item.equals("false")) {
380                         controller.setProperty(uic, __GO_UI_SCROLLABLE__, false);
381                     } else {
382                         controller.setProperty(uic, __GO_UI_SCROLLABLE__, true);
383                     }
384
385                     break;
386                 }
387
388                 case __GO_UI_TAB__: {
389                     item = xmlAttributes.get("ui-style");
390                     if (item != null) {
391                         map = CSSParser.parseLine(item);
392                         item = XmlTools.getFromMap(map, "bold", "false");
393                         if (item.equals("true")) {
394                             controller.setProperty(uic, __GO_UI_FONTWEIGHT__, "bold");
395                         }
396
397                         item = XmlTools.getFromMap(map, "italic", "false");
398                         if (item.equals("true")) {
399                             controller.setProperty(uic, __GO_UI_FONTANGLE__, "italic");
400                         }
401                     }
402                     break;
403                 }
404                 case __GO_UI_CHECKBOX__: {
405                     String[] text = new String[1];
406                     text[0] = xmlAttributes.get("text");
407                     if (text[0] != null) {
408                         controller.setProperty(uic, __GO_UI_STRING__, text);
409                     }
410
411                     //groupname
412                     item = xmlAttributes.get("button-group");
413                     if (item != null && item.equals("") == false) {
414                         controller.setProperty(uic, __GO_UI_GROUP_NAME__, item);
415                     }
416
417                     //callback
418                     item = xmlAttributes.get("onclick");
419                     if (item != null && item.equals("") == false) {
420                         controller.setProperty(uic, __GO_CALLBACK__, item);
421                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
422                     }
423
424                     break;
425                 }
426                 case __GO_UI_RADIOBUTTON__: {
427                     String[] text = new String[1];
428                     text[0] = xmlAttributes.get("text");
429                     if (text[0] != null) {
430                         controller.setProperty(uic, __GO_UI_STRING__, text);
431                     }
432
433                     //groupname
434                     item = xmlAttributes.get("button-group");
435                     if (item != null && item.equals("") == false) {
436                         controller.setProperty(uic, __GO_UI_GROUP_NAME__, item);
437                     }
438
439                     //callback
440                     item = xmlAttributes.get("onclick");
441                     if (item != null && item.equals("") == false) {
442                         controller.setProperty(uic, __GO_CALLBACK__, item);
443                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
444                     }
445
446                     break;
447                 }
448                 case __GO_UI_PUSHBUTTON__: {
449
450                     //string
451                     String[] text = new String[1];
452                     text[0] = xmlAttributes.get("text");
453                     if (text[0] != null) {
454                         controller.setProperty(uic, __GO_UI_STRING__, text);
455                     }
456
457
458                     //icon
459                     item = xmlAttributes.get("icon");
460                     if (item != null) {
461                         controller.setProperty(uic, __GO_UI_ICON__, item);
462                     }
463
464                     //callback
465                     item = xmlAttributes.get("onclick");
466                     if (item != null && item.equals("") == false) {
467                         controller.setProperty(uic, __GO_CALLBACK__, item);
468                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
469                     }
470
471                     break;
472                 }
473                 case __GO_UI_TEXT__: { //label
474                     controller.setProperty(uic, __GO_UI_HORIZONTALALIGNMENT__, "left");
475                     String[] text = new String[1];
476                     text[0] = xmlAttributes.get("text");
477                     if (text[0] != null) {
478                         String[] old = (String[])controller.getProperty(uic, __GO_UI_STRING__);
479                         if (old != null && old[0] != null && old[0].equals("$$")) {
480                             text[0] = "$" + text[0] + "$";
481                         }
482                         controller.setProperty(uic, __GO_UI_STRING__, text);
483                     }
484
485                     //icon
486                     item = xmlAttributes.get("icon");
487                     if (item != null) {
488                         controller.setProperty(uic, __GO_UI_ICON__, item);
489                     }
490
491                     break;
492                 }
493                 case __GO_UI_EDIT__ : {
494                     item = xmlAttributes.get("columns");
495                     if (item != null) {
496                         controller.setProperty(uic, __GO_UI_MAX__, Double.parseDouble(item));
497                     }
498
499                     //callback
500                     item = xmlAttributes.get("onenter");
501                     if (item != null && item.equals("") == false) {
502                         controller.setProperty(uic, __GO_CALLBACK__, item);
503                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
504                     }
505
506                     item = xmlAttributes.get("onfocusloss");
507                     if (item != null && item.equals("") == false) {
508                         controller.setProperty(uic, __GO_CALLBACK__, item);
509                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
510                     }
511
512                     break;
513                 }
514                 case __GO_UI_POPUPMENU__ : {
515                     item = xmlAttributes.get("items");
516                     if (item != null && item.equals("") == false) {
517                         controller.setProperty(uic, __GO_UI_STRING__, new String[] {item});
518                     }
519
520                     item = xmlAttributes.get("prototype-display-value");
521                     if (item != null && item.equals("") == false) {
522                         controller.setProperty(uic, __GO_UI_MAX__, new Double(item.length()));
523                     }
524
525                     //callback
526                     item = xmlAttributes.get("onchange");
527                     if (item != null && item.equals("") == false) {
528                         controller.setProperty(uic, __GO_CALLBACK__, item);
529                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
530                     }
531
532                     break;
533                 }
534                 case __GO_UI_LISTBOX__ : {
535                     item = xmlAttributes.get("items");
536                     if (item != null && item.equals("") == false) {
537                         controller.setProperty(uic, __GO_UI_STRING__, new String[] {item});
538                     }
539
540                     item = xmlAttributes.get("multiple");
541                     if (item != null && item.equals("true")) {
542                         controller.setProperty(uic, __GO_UI_MIN__, 0.0);
543                         controller.setProperty(uic, __GO_UI_MAX__, 2.0);
544                     }
545
546                     //callback
547                     item = xmlAttributes.get("onclick");
548                     if (item != null && item.equals("") == false) {
549                         controller.setProperty(uic, __GO_CALLBACK__, item);
550                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
551                     }
552
553                     break;
554                 }
555                 case __GO_UI_SPINNER__: {
556
557                 }
558             }
559
560         } catch (CSSParserException e) {
561             e.printStackTrace();
562         }
563
564         return uic;
565     }
566
567     private static void setLayoutProperty(GraphicController controller, Integer uid, String item) {
568         try {
569             Map<String, String> map = null;
570             map = CSSParser.parseLine(item);
571             item = map.get("name");
572             LayoutType layout = LayoutType.stringToEnum(item);
573
574             // layout_options
575             switch (layout) {
576                 case BORDER: {
577                     Integer[] pad = new Integer[] { 0, 0 };
578                     pad[0] = Integer.parseInt(XmlTools.getFromMap(map, "hgap", "0"));
579                     pad[1] = Integer.parseInt(XmlTools.getFromMap(map, "vgap", "0"));
580
581                     controller.setProperty(uid, __GO_BORDER_OPT_PADDING__, pad);
582                     break;
583                 }
584                 case GRID: {
585                     Integer[] grid = new Integer[] { 0, 0 };
586                     grid[0] = Integer.parseInt(XmlTools.getFromMap(map, "rows", "0"));
587                     grid[1] = Integer.parseInt(XmlTools.getFromMap(map, "cols", "0"));
588
589                     Integer[] pad = new Integer[] { 0, 0 };
590                     pad[0] = Integer.parseInt(XmlTools.getFromMap(map, "hgap", "0"));
591                     pad[1] = Integer.parseInt(XmlTools.getFromMap(map, "vgap", "0"));
592
593                     controller.setProperty(uid, __GO_GRID_OPT_GRID__, grid);
594                     controller.setProperty(uid, __GO_GRID_OPT_PADDING__, pad);
595                     break;
596                 }
597                 default:
598                 case GRIDBAG:
599                 case NONE:
600                     // nothing to do
601                     break;
602             }
603             controller.setProperty(uid, __GO_LAYOUT__, layout.ordinal());
604         } catch (CSSParserException e) {
605             e.printStackTrace();
606         }
607
608     }
609
610     public static Integer uimenuBuilder(GraphicController controller, Attributes attributes, int parent) {
611         Integer parentType = (Integer)controller.getProperty(parent, __GO_TYPE__);
612         if (parentType == __GO_FIGURE__) {
613             controller.setProperty(parent, __GO_MENUBAR_VISIBLE__, true);
614         }
615
616         Integer uim = controller.askObject(GraphicObject.getTypeFromName(__GO_UIMENU__));
617
618         String item = null;
619
620         item = attributes.getValue("id");
621         if (item != null) {
622             controller.setProperty(uim, __GO_TAG__, item);
623         }
624
625         item = attributes.getValue("text");
626         if (item != null) {
627             controller.setProperty(uim, __GO_UI_LABEL__, item);
628         }
629
630         item = attributes.getValue("onclick");
631         if (item != null) {
632             controller.setProperty(uim, __GO_CALLBACK__, item);
633             controller.setProperty(uim, __GO_CALLBACKTYPE__, 0);
634         }
635
636         item = attributes.getValue("checked");
637         if (item != null && (item.equals("true") || item.equals("on"))) {
638             controller.setProperty(uim, __GO_UI_CHECKED__, true);
639         }
640
641         item = attributes.getValue("icon");
642         if (item != null) {
643             controller.setProperty(uim, __GO_UI_ICON__, item);
644         }
645
646         return uim;
647     }
648
649     private static Integer createBorder(GraphicController controller, Integer uic, FrameBorderType borderType, Map<String, String> map) {
650         Integer border = controller.askObject(GraphicObject.getTypeFromName(__GO_UI_FRAME_BORDER__));
651         controller.setProperty(border, __GO_UI_FRAME_BORDER_STYLE__, borderType.ordinal());
652         controller.setProperty(border, __GO_HIDDEN__, true);
653
654         switch (borderType) {
655             case SOFTBEVEL:
656             case BEVEL: {
657                 BorderType etching = BorderType.stringToEnum(XmlTools.getFromMap(map, "type", "none"));
658                 String color = XmlTools.getFromMap(map, "color", "black");
659
660                 controller.setProperty(border, __GO_TYPE__, etching.ordinal());
661                 controller.setProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, color);
662                 controller.setProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_IN__, color);
663                 controller.setProperty(border, __GO_UI_FRAME_BORDER_SHADOW_OUT__, color);
664                 controller.setProperty(border, __GO_UI_FRAME_BORDER_SHADOW_IN__, color);
665                 break;
666             }
667             case COMPOUND: {
668                 FrameBorderType borderOut = FrameBorderType.stringToEnum(XmlTools.getFromMap(map, "border-out", "none"));
669                 FrameBorderType borderIn = FrameBorderType.stringToEnum(XmlTools.getFromMap(map, "border-in", "none"));
670
671                 Integer out = createBorder(controller, border, borderOut, map);
672                 Integer in = createBorder(controller, border, borderIn, map);
673
674                 controller.setProperty(border, __GO_UI_FRAME_BORDER_OUT_BORDER__, out);
675
676                 controller.setProperty(border, __GO_UI_FRAME_BORDER_IN_BORDER__, in);
677
678                 break;
679             }
680             case EMPTY: {
681                 Double[] position = new Double[4];
682                 position[0] = Double.parseDouble(XmlTools.getFromMap(map, "top", "0"));
683                 position[1] = Double.parseDouble(XmlTools.getFromMap(map, "left", "0"));
684                 position[2] = Double.parseDouble(XmlTools.getFromMap(map, "right", "0"));
685                 position[3] = Double.parseDouble(XmlTools.getFromMap(map, "bottom", "0"));
686
687                 controller.setProperty(border, __GO_POSITION__, position);
688                 break;
689             }
690             case ETCHED: {
691                 BorderType etching = BorderType.stringToEnum(XmlTools.getFromMap(map, "type", "none"));
692                 String color = XmlTools.getFromMap(map, "color", "black");
693
694                 controller.setProperty(border, __GO_TYPE__, etching.ordinal());
695                 controller.setProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, color);
696                 controller.setProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_IN__, color);
697                 break;
698             }
699             case LINE: {
700                 String color = XmlTools.getFromMap(map, "color", "black");
701                 Integer thickness = Integer.parseInt(XmlTools.getFromMap(map, "thickness", "1"));
702                 Boolean rounded = Boolean.parseBoolean(XmlTools.getFromMap(map, "rounded", "false"));
703
704                 controller.setProperty(border, __GO_UI_FRAME_BORDER_COLOR__, color);
705                 controller.setProperty(border, __GO_LINE_THICKNESS__, thickness);
706                 controller.setProperty(border, __GO_UI_FRAME_BORDER_ROUNDED__, rounded);
707                 break;
708             }
709             case MATTE: {
710                 Double[] position = new Double[4];
711                 position[0] = Double.parseDouble(XmlTools.getFromMap(map, "top", "0"));
712                 position[1] = Double.parseDouble(XmlTools.getFromMap(map, "left", "0"));
713                 position[2] = Double.parseDouble(XmlTools.getFromMap(map, "right", "0"));
714                 position[3] = Double.parseDouble(XmlTools.getFromMap(map, "bottom", "0"));
715                 String color = XmlTools.getFromMap(map, "color", "black");
716
717                 controller.setProperty(border, __GO_POSITION__, position);
718                 controller.setProperty(border, __GO_UI_FRAME_BORDER_COLOR__, color);
719                 break;
720             }
721             case TITLED: {
722
723                 String title = XmlTools.getFromMap(map, "title", "");
724                 FrameBorder.JustificationType justify = FrameBorder.JustificationType.stringToEnum(XmlTools.getFromMap(map, "justify", "leading"));
725                 String fontName = XmlTools.getFromMap(map, "font-name", "");
726                 String fontAngle = XmlTools.getFromMap(map, "italic", "false") == "false" ? "normal" : "italic";
727                 Integer fontSize = Integer.parseInt(XmlTools.getFromMap(map, "font-size", "0"));
728                 String fontWeight = XmlTools.getFromMap(map, "bold", "false") == "false" ? "normal" : "bold";
729
730                 FrameBorder.TitlePositionType position = FrameBorder.TitlePositionType.stringToEnum(XmlTools.getFromMap(map, "position", "leading"));
731
732                 String color = XmlTools.getFromMap(map, "color", "black");
733
734                 FrameBorderType borderOut = FrameBorderType.stringToEnum(XmlTools.getFromMap(map, "border", ""));
735                 if (borderOut != null) {
736                     Integer out = createBorder(controller, border, borderOut, map);
737                     controller.setProperty(border, __GO_UI_FRAME_BORDER_TITLE__, out);
738                 }
739
740                 controller.setProperty(border, __GO_TITLE__, title);
741                 controller.setProperty(border, __GO_UI_FRAME_BORDER_JUSTIFICATION__, justify.ordinal());
742                 controller.setProperty(border, __GO_UI_FONTNAME__, fontName);
743                 controller.setProperty(border, __GO_UI_FONTANGLE__, fontAngle);
744                 controller.setProperty(border, __GO_UI_FONTSIZE__, fontSize);
745                 controller.setProperty(border, __GO_UI_FONTWEIGHT__, fontWeight);
746                 controller.setProperty(border, __GO_UI_FRAME_BORDER_POSITION__, position.ordinal());
747                 controller.setProperty(border, __GO_UI_FRAME_BORDER_COLOR__, color);
748
749                 break;
750             }
751             case NONE:
752             default:
753                 break;
754         }
755
756         controller.setGraphicObjectRelationship(uic, border);
757         return border;
758     }
759
760     private static Double[] getColor(String str) {
761         try {
762             Field field = Class.forName("java.awt.Color").getField(str);
763             Color color = (Color) field.get(null);
764             return new Double[] {(double) color.getRed() / 255, (double) color.getGreen() / 255, (double) color.getBlue() / 255};
765         } catch (Exception e) {
766             return new Double[] {(double) Color.black.getRed() / 255, (double) Color.black.getGreen() / 255, (double) Color.black.getBlue() / 255};
767         }
768     }
769 }