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