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