7294c6deb8cf2c41813e10cd7613f10166e8a8f4
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / SwingViewWidget.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2011 - DIGITEO - Bruno JOFRET
4  * Copyright (C) 2011 - DIGITEO - Vincent COUVERT
5  *
6  * This file must be used under the terms of the CeCILL.
7  * This source file is licensed as described in the file COPYING, which
8  * you should have received as part of this distribution.  The terms
9  * are also available at
10  * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
11  *
12  */
13
14 package org.scilab.modules.gui;
15
16 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BORDER_OPT_PADDING__;
17 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACKTYPE__;
18 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACK__;
19 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CHILDREN__;
20 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_GRID__;
21 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_PADDING__;
22 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT__;
23 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_PARENT__;
24 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
25 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_STYLE__;
26 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TAG__;
27 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
28 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BACKGROUNDCOLOR__;
29 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
30 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTANGLE__;
31 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTNAME__;
32 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTSIZE__;
33 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTUNITS__;
34 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTWEIGHT__;
35 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FOREGROUNDCOLOR__;
36 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
37 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_GROUP_NAME__;
38 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_HORIZONTALALIGNMENT__;
39 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LISTBOXTOP__;
40 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MAX__;
41 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MIN__;
42 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_RELIEF__;
43 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SLIDERSTEP__;
44 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING_COLNB__;
45 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
46 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_TOOLTIPSTRING__;
47 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_UNITS__;
48 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VALUE__;
49 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VERTICALALIGNMENT__;
50 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_USER_DATA__;
51 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VALID__;
52 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
53 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTROL__;
54 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LAYER__;
55
56 import java.awt.BorderLayout;
57 import java.awt.Color;
58 import java.awt.Font;
59 import java.awt.GridBagLayout;
60 import java.awt.GridLayout;
61
62 import javax.swing.AbstractButton;
63 import javax.swing.border.Border;
64
65 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
66 import org.scilab.modules.graphic_objects.graphicObject.CallBack;
67 import org.scilab.modules.graphic_objects.utils.LayoutType;
68 import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
69 import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
70 import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
71 import org.scilab.modules.gui.bridge.frame.SwingScilabLayer;
72 import org.scilab.modules.gui.bridge.groupmanager.GroupManager;
73 import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
74 import org.scilab.modules.gui.bridge.popupmenu.SwingScilabPopupMenu;
75 import org.scilab.modules.gui.bridge.radiobutton.SwingScilabRadioButton;
76 import org.scilab.modules.gui.bridge.slider.SwingScilabScroll;
77 import org.scilab.modules.gui.bridge.slider.SwingScilabSlider;
78 import org.scilab.modules.gui.bridge.textbox.SwingScilabTextBox;
79 import org.scilab.modules.gui.bridge.uiimage.SwingScilabUiImage;
80 import org.scilab.modules.gui.bridge.uitable.SwingScilabUiTable;
81 import org.scilab.modules.gui.events.callback.CommonCallBack;
82 import org.scilab.modules.gui.utils.BorderConvertor;
83 import org.scilab.modules.gui.utils.Position;
84 import org.scilab.modules.gui.utils.Size;
85 import org.scilab.modules.gui.utils.UnitsConverter;
86 import org.scilab.modules.gui.utils.UnitsConverter.UicontrolUnits;
87 import org.scilab.modules.gui.widget.Widget;
88
89 /**
90  * @author Bruno JOFRET
91  * @author Vincent COUVERT
92  */
93 public final class SwingViewWidget {
94
95     private static final String OBLIQUEFONT = "oblique";
96     private static final String ITALICFONT = "italic";
97     private static final String BOLDFONT = "bold";
98     private static final int COLORS_COEFF = 255;
99     private static final int X_INDEX = 0;
100     private static final int Y_INDEX = 1;
101     private static final int WIDTH_INDEX = 2;
102     private static final int HEIGHT_INDEX = 3;
103
104     /**
105      * Constructor
106      */
107     private SwingViewWidget() {
108         throw new UnsupportedOperationException();
109     }
110
111     /**
112      * Update the component in the view
113      * @param uiControl the component
114      * @param property the property name
115      * @param value the property value
116      */
117     public static void update(Widget uiControl, int property, Object value) {
118         Integer uid = ((SwingViewObject) uiControl).getId();
119         Font font = null;
120         Double[] allColors = null;
121         double maxValue = 0;
122
123         GraphicController controller = GraphicController.getController();
124         switch (property) {
125             case __GO_UI_BACKGROUNDCOLOR__:
126                 allColors = ((Double[]) value);
127                 if (allColors[0] != -1) {
128                     if (uiControl instanceof SwingScilabListBox) {
129                         ((SwingScilabListBox)uiControl).setListBackground(new Color((int) (allColors[0] * COLORS_COEFF),
130                                 (int) (allColors[1] * COLORS_COEFF),
131                                 (int) (allColors[2] * COLORS_COEFF)));
132                     } else {
133                         uiControl.setBackground(new Color((int) (allColors[0] * COLORS_COEFF),
134                                                           (int) (allColors[1] * COLORS_COEFF),
135                                                           (int) (allColors[2] * COLORS_COEFF)));
136                     }
137                 } else {
138                     // Do not set BackgroundColor for widgets
139                     // rely on Look and Feel
140                 }
141                 break;
142             case __GO_CALLBACK__:
143                 int cbType = (Integer) controller.getProperty(uid, __GO_CALLBACKTYPE__);
144                 uiControl.setCallback(CommonCallBack.createCallback((String) value, cbType, uid));
145                 break;
146             case __GO_CALLBACKTYPE__:
147                 String cbString = (String) controller.getProperty(uid, __GO_CALLBACK__);
148                 if ((Integer) value == CallBack.UNTYPED) {
149                     /*
150                      * Deactivate
151                      * callback
152                      */
153                     uiControl.setCallback(null);
154                 } else {
155                     uiControl.setCallback(CommonCallBack.createCallback(cbString, (Integer) value, uid));
156                 }
157                 break;
158             case __GO_CHILDREN__:
159                 /* Nothing to do */
160                 break;
161             case __GO_UI_ENABLE__:
162                 uiControl.setEnabled(((Boolean) value).booleanValue());
163                 break;
164             case __GO_UI_FONTANGLE__ : {
165                 String angle = (String) value;
166                 if (angle.equals("") == false) {
167                     font = uiControl.getFont();
168                     if (font != null) {
169                         if (angle.equalsIgnoreCase(ITALICFONT) || angle.equalsIgnoreCase(OBLIQUEFONT)) {
170                             if (font.isBold()) {
171                                 font = new Font(font.getName(), Font.ITALIC + Font.BOLD, font.getSize());
172                             } else {
173                                 font = new Font(font.getName(), Font.ITALIC, font.getSize());
174                             }
175                         } else {
176                             if (font.isBold()) {
177                                 font = new Font(font.getName(), Font.BOLD, font.getSize());
178                             } else {
179                                 font = new Font(font.getName(), Font.PLAIN, font.getSize());
180                             }
181                         }
182
183                         uiControl.setFont(font);
184                     }
185                 }
186                 break;
187             }
188             case __GO_UI_FONTNAME__ : {
189                 String name = (String) value;
190                 if (name.equals("") == false) {
191                     font = uiControl.getFont();
192                     if (font != null) {
193
194                         font = new Font(name, font.getStyle(), font.getSize());
195
196                         if (uiControl instanceof SwingScilabEditBox) {
197                             ((SwingScilabEditBox)uiControl).setEditFont(font);
198                         } else {
199                             uiControl.setFont(font);
200                         }
201                     }
202                 }
203                 break;
204             }
205             case __GO_UI_FONTSIZE__ : {
206                 if ((Double)value != 0.0) {
207                     UicontrolUnits fontUnitsProperty = UnitsConverter.stringToUnitsEnum((String) controller.getProperty(uid, __GO_UI_FONTUNITS__));
208                     Double dblFontSize = UnitsConverter.convertToPoint((Double) value, fontUnitsProperty, uiControl, false);
209                     font = uiControl.getFont();
210                     if (font != null) {
211                         int size = dblFontSize.intValue();
212                         font = new Font(font.getName(), font.getStyle(), size);
213                         uiControl.setFont(font);
214                     }
215                 }
216                 break;
217             }
218             case __GO_UI_FONTUNITS__ :
219                 /* Nothing to do here, this property is used when setting position */
220                 break;
221             case __GO_UI_FONTWEIGHT__ : {
222                 String weight = (String) value;
223                 if (weight.equals("") == false) {
224                     font = uiControl.getFont();
225                     if (font != null) {
226                         if (weight.equalsIgnoreCase(BOLDFONT)) {
227                             if (font.isItalic()) {
228                                 font = new Font(font.getName(), Font.ITALIC + Font.BOLD, font.getSize());
229                             } else {
230                                 font = new Font(font.getName(), Font.BOLD, font.getSize());
231                             }
232                         } else {
233                             if (font.isItalic()) {
234                                 font = new Font(font.getName(), Font.ITALIC, font.getSize());
235                             } else {
236                                 font = new Font(font.getName(), Font.PLAIN, font.getSize());
237                             }
238                         }
239
240                         uiControl.setFont(font);
241                     }
242                 }
243                 break;
244             }
245             case __GO_UI_FOREGROUNDCOLOR__ :
246                 allColors = ((Double[]) value);
247                 uiControl.setForeground(new Color((int) (allColors[0] * COLORS_COEFF), (int) (allColors[1] * COLORS_COEFF), (int) (allColors[2] * COLORS_COEFF)));
248                 break;
249             case __GO_UI_HORIZONTALALIGNMENT__ : {
250                 String align = (String)value;
251                 if (align.equals("") == false) {
252                     uiControl.setHorizontalAlignment((String) value);
253                 }
254                 break;
255             }
256             case __GO_UI_LISTBOXTOP__ :
257                 if (uiControl instanceof SwingScilabListBox) {
258                     Integer[] listboxtopValue = ((Integer[]) value);
259                     if (listboxtopValue.length > 0) {
260                         ((SwingScilabListBox) uiControl).setListBoxTop(listboxtopValue[0]);
261                     }
262                 }
263                 break;
264             case __GO_UI_MAX__:
265                 maxValue = ((Double) value);
266                 if (uiControl instanceof SwingScilabScroll) {
267                     // Update the slider properties
268                     double minValue = (Double) controller.getProperty(uid, __GO_UI_MIN__);
269                     ((SwingScilabScroll) uiControl).setMaximumValue(maxValue);
270                     Double[] sliderStep = ((Double[]) controller.getProperty(uid, __GO_UI_SLIDERSTEP__));
271                     double minorSliderStep = sliderStep[0].doubleValue();
272                     double majorSliderStep = sliderStep[1].doubleValue();
273                     if (minValue <= maxValue) {
274                         ((SwingScilabScroll) uiControl).setMinorTickSpacing(minorSliderStep);
275                         ((SwingScilabScroll) uiControl).setMajorTickSpacing(majorSliderStep);
276                     }
277                 } else if (uiControl instanceof SwingScilabSlider) {
278                     // Update the slider properties
279                     double minValue = (Double) controller.getProperty(uid, __GO_UI_MIN__);
280                     ((SwingScilabSlider) uiControl).setMaximumValue(maxValue);
281                     Double[] sliderStep = ((Double[]) controller.getProperty(uid, __GO_UI_SLIDERSTEP__));
282                     double minorSliderStep = sliderStep[0].doubleValue();
283                     double majorSliderStep = sliderStep[1].doubleValue();
284                     if (minValue <= maxValue) {
285                         ((SwingScilabSlider) uiControl).setMinorTickSpacing(minorSliderStep);
286                         ((SwingScilabSlider) uiControl).setMajorTickSpacing(majorSliderStep);
287                     }
288                 } else if (uiControl instanceof SwingScilabListBox) {
289                     // Enable/Disable multiple selection
290                     double minValue = (Double) controller.getProperty(uid, __GO_UI_MIN__);
291                     ((SwingScilabListBox) uiControl).setMultipleSelectionEnabled(maxValue - minValue > 1);
292                 } else if (uiControl instanceof SwingScilabCheckBox) {
293                     Double[] allValues = (Double[]) controller.getProperty(uid, __GO_UI_VALUE__);
294                     if ((allValues == null) || (allValues.length == 0)) {
295                         return;
296                     }
297                     double uicontrolValue = allValues[0];
298                     // Check/Uncheck the CheckBox
299                     ((SwingScilabCheckBox) uiControl).setChecked(maxValue == uicontrolValue);
300                 } else if (uiControl instanceof SwingScilabRadioButton) {
301                     Double[] allValues = (Double[]) controller.getProperty(uid, __GO_UI_VALUE__);
302                     if ((allValues == null) || (allValues.length == 0)) {
303                         return;
304                     }
305                     double uicontrolValue = allValues[0];
306                     // Check/Uncheck the RadioButton
307                     ((SwingScilabRadioButton) uiControl).setChecked(maxValue == uicontrolValue);
308                 } else if (uiControl instanceof SwingScilabTextBox) {
309                     //System.out.println("max value be come columns for textfield");
310                     //((SwingScilabTextBox) uiControl).setColumns((int)maxValue);
311                 } else if (uiControl instanceof SwingScilabEditBox) {
312                     double min = ((Double) controller.getProperty(uid, __GO_UI_MIN__));
313                     double max = ((Double) controller.getProperty(uid, __GO_UI_MAX__));
314                     if (max - min > 1.0) {
315                         ((SwingScilabEditBox) uiControl).setMultiLineText(true);
316                     } else {
317                         ((SwingScilabEditBox) uiControl).setMultiLineText(false);
318                     }
319                     // Force String update
320                     update(uiControl, __GO_UI_STRING__, GraphicController.getController().getProperty(uid, __GO_UI_STRING__));
321                 }
322                 break;
323             case __GO_UI_MIN__:
324                 double minValue = ((Double) value);
325                 if (uiControl instanceof SwingScilabScroll) {
326                     // Update the slider properties
327                     maxValue = (Double) controller.getProperty(uid, __GO_UI_MAX__);
328                     ((SwingScilabScroll) uiControl).setMinimumValue(minValue);
329                     Double[] sliderStep = ((Double[]) controller.getProperty(uid, __GO_UI_SLIDERSTEP__));
330                     double minorSliderStep = sliderStep[0].doubleValue();
331                     double majorSliderStep = sliderStep[1].doubleValue();
332                     if (minValue <= maxValue) {
333                         ((SwingScilabScroll) uiControl).setMinorTickSpacing(minorSliderStep);
334                         ((SwingScilabScroll) uiControl).setMajorTickSpacing(majorSliderStep);
335                     }
336                 } else if (uiControl instanceof SwingScilabSlider) {
337                     // Update the slider properties
338                     maxValue = (Double) controller.getProperty(uid, __GO_UI_MAX__);
339                     ((SwingScilabSlider) uiControl).setMinimumValue(minValue);
340                     Double[] sliderStep = ((Double[]) controller.getProperty(uid, __GO_UI_SLIDERSTEP__));
341                     double minorSliderStep = sliderStep[0].doubleValue();
342                     double majorSliderStep = sliderStep[1].doubleValue();
343                     if (minValue <= maxValue) {
344                         ((SwingScilabSlider) uiControl).setMinorTickSpacing(minorSliderStep);
345                         ((SwingScilabSlider) uiControl).setMajorTickSpacing(majorSliderStep);
346                     }
347                 } else if (uiControl instanceof SwingScilabListBox) {
348                     // Enable/Disable multiple selection
349                     maxValue = (Double) controller.getProperty(uid, __GO_UI_MAX__);
350                     ((SwingScilabListBox) uiControl).setMultipleSelectionEnabled(maxValue - minValue > 1);
351                 } else if (uiControl instanceof SwingScilabEditBox) {
352                     double min = ((Double) controller.getProperty(uid, __GO_UI_MIN__));
353                     double max = ((Double) controller.getProperty(uid, __GO_UI_MAX__));
354                     if (max - min > 1.0) {
355                         ((SwingScilabEditBox) uiControl).setMultiLineText(true);
356                     } else {
357                         ((SwingScilabEditBox) uiControl).setMultiLineText(false);
358                     }
359                     // Force String update
360                     update(uiControl, __GO_UI_STRING__, GraphicController.getController().getProperty(uid, __GO_UI_STRING__));
361                 }
362                 break;
363             case __GO_POSITION__:
364
365                 /* Convert value according to units */
366                 UicontrolUnits unitsProperty = UnitsConverter.stringToUnitsEnum((String) GraphicController.getController().getProperty(uid, __GO_UI_UNITS__));
367                 Double[] dblValues = UnitsConverter.convertPositionToPixels((Double[]) value, unitsProperty, uiControl);
368                 // Set dimensions before position because position is adjusted according to size
369                 uiControl.setDims(new Size(dblValues[WIDTH_INDEX].intValue(), dblValues[HEIGHT_INDEX].intValue()));
370                 uiControl.setPosition(new Position(dblValues[X_INDEX].intValue(), dblValues[Y_INDEX].intValue()));
371                 // Manage sliders orientation
372                 if (uiControl instanceof SwingScilabScroll) {
373                     if (dblValues[WIDTH_INDEX].intValue() > dblValues[HEIGHT_INDEX].intValue()) {
374                         ((SwingScilabScroll) uiControl).setHorizontal();
375                     } else {
376                         ((SwingScilabScroll) uiControl).setVertical();
377                     }
378                 } else if (uiControl instanceof SwingScilabSlider) {
379                     if (dblValues[WIDTH_INDEX].intValue() > dblValues[HEIGHT_INDEX].intValue()) {
380                         ((SwingScilabSlider) uiControl).setHorizontal();
381                     } else {
382                         ((SwingScilabSlider) uiControl).setVertical();
383                     }
384                 }
385                 break;
386             case __GO_UI_RELIEF__:
387                 uiControl.setRelief((String) value);
388                 break;
389             case __GO_UI_SLIDERSTEP__:
390                 Double[] sliderStep = ((Double[]) value);
391                 if (uiControl instanceof SwingScilabScroll) {
392                     // Update the slider properties
393                     double minorSliderStep = sliderStep[0].doubleValue();
394                     double majorSliderStep = sliderStep[1].doubleValue();
395                     ((SwingScilabScroll) uiControl).setMinorTickSpacing(minorSliderStep);
396                     ((SwingScilabScroll) uiControl).setMajorTickSpacing(majorSliderStep);
397                 } else if (uiControl instanceof SwingScilabSlider) {
398                     // Update the slider properties
399                     double minorSliderStep = sliderStep[0].doubleValue();
400                     double majorSliderStep = sliderStep[1].doubleValue();
401                     ((SwingScilabSlider) uiControl).setMinorTickSpacing(minorSliderStep);
402                     ((SwingScilabSlider) uiControl).setMajorTickSpacing(majorSliderStep);
403                 }
404                 break;
405             case __GO_STYLE__:
406                 /* Nothing to do unless we want to change style interactively */
407                 break;
408             case __GO_UI_STRING__:
409                 if (uiControl instanceof SwingScilabUiTable) {
410                     // Update column names
411                     String[] stringValue = (String[]) value;
412                     int colNb = ((Integer) controller.getProperty(uid, __GO_UI_STRING_COLNB__));
413                     String[] colNames = new String[colNb - 1];
414                     for (int k = 1; k < colNb; k++) {
415                         colNames[k - 1] = stringValue[k * (stringValue.length / colNb)];
416                     }
417                     ((SwingScilabUiTable) uiControl).setColumnNames(colNames);
418                     // Update row names
419                     String[] rowNames = new String[stringValue.length / colNb - 1];
420                     for (int k = 1; k < stringValue.length / colNb; k++) {
421                         rowNames[k - 1] = stringValue[k];
422                     }
423                     ((SwingScilabUiTable) uiControl).setRowNames(rowNames);
424                     // Update data
425                     String[] tableData = new String[rowNames.length * colNames.length];
426                     int kData = 0;
427                     for (int kCol = 1; kCol <= colNames.length; kCol++) {
428                         for (int kRow = 1; kRow <= rowNames.length; kRow++) {
429                             tableData[kData++] = stringValue[kCol * (stringValue.length / colNb) + kRow];
430                         }
431                     }
432                     if (tableData.length != 0) {
433                         ((SwingScilabUiTable) uiControl).setData(tableData);
434                     }
435                 } else if (uiControl instanceof SwingScilabListBox) {
436                     // Listboxes manage string vectors
437                     ((SwingScilabListBox) uiControl).setText((String[]) value);
438                 } else if (uiControl instanceof SwingScilabPopupMenu) {
439                     // Popupmenus manage string vectors
440                     ((SwingScilabPopupMenu) uiControl).setText((String[]) value);
441                 } else if (uiControl instanceof SwingScilabEditBox) {
442                     double min = ((Double) controller.getProperty(uid, __GO_UI_MIN__));
443                     double max = ((Double) controller.getProperty(uid, __GO_UI_MAX__));
444                     if (max - min > 1.0) {
445                         ((SwingScilabEditBox) uiControl).setText((String[]) value);
446                         ((SwingScilabEditBox) uiControl).setMultiLineText(true);
447                     } else {
448                         uiControl.setText(((String[]) value)[0]);
449                         ((SwingScilabEditBox) uiControl).setMultiLineText(false);
450                     }
451                 } else {
452                     uiControl.setText(((String[]) value)[0]);
453                 }
454                 break;
455             case __GO_UI_TOOLTIPSTRING__:
456                 String[] tooltipString = ((String[]) value);
457                 String tooltipText = tooltipString[0];
458                 if (tooltipString.length > 1) {
459                     tooltipText = "<html>" + tooltipText;
460                     for (int kString = 1; kString < tooltipString.length; kString++) {
461                         tooltipText = tooltipText + "<br>" + tooltipString[kString];
462                     }
463                     tooltipText = tooltipText + "</html>";
464                 }
465                 if (tooltipText.equals("")) {
466                     uiControl.setToolTipText(null);
467                 } else {
468                     uiControl.setToolTipText(tooltipText);
469                 }
470                 break;
471             case __GO_UI_STRING_COLNB__:
472                 /* Nothing to do */
473             case __GO_TAG__:
474                 /* Nothing to do */
475             case __GO_USER_DATA__:
476                 /* Nothing to do here */
477             case __GO_UI_UNITS__:
478                 /*
479                  * Nothing to do here, this property is used when setting
480                  * position
481                  */
482             case __GO_VALID__:
483                 /* Nothing to do */
484                 break;
485             case __GO_UI_VALUE__:
486
487                 Double[] doubleValue = ((Double[]) value);
488                 if (doubleValue.length == 0) {
489                     return;
490                 }
491                 int[] intValue = new int[doubleValue.length];
492                 for (int k = 0; k < doubleValue.length; k++) {
493                     intValue[k] = doubleValue[k].intValue();
494                 }
495
496                 if (uiControl instanceof SwingScilabListBox) {
497                     // Update selected items in the listbox
498                     ((SwingScilabListBox) uiControl).setSelectedIndices(intValue);
499                 } else if (uiControl instanceof SwingScilabPopupMenu) {
500                     // Update selected items in the popupmenu
501                     ((SwingScilabPopupMenu) uiControl).setUserSelectedIndex(intValue[0]);
502                 } else if (uiControl instanceof SwingScilabCheckBox) {
503                     // Check the checkbox if the value is equal to MAX property
504                     maxValue = ((Double) controller.getProperty(uid, __GO_UI_MAX__)).intValue();
505                     ((SwingScilabCheckBox) uiControl).setChecked(maxValue == intValue[0]);
506                 } else if (uiControl instanceof SwingScilabRadioButton) {
507                     // Check the radiobutton if the value is equal to MAX property
508                     maxValue = ((Double) controller.getProperty(uid, __GO_UI_MAX__)).intValue();
509                     ((SwingScilabRadioButton) uiControl).setChecked(maxValue == intValue[0]);
510                 } else if (uiControl instanceof SwingScilabScroll) {
511                     // Update the slider value
512                     ((SwingScilabScroll) uiControl).setUserValue(doubleValue[0]);
513                 } else if (uiControl instanceof SwingScilabSlider) {
514                     // Update the slider value
515                     ((SwingScilabSlider) uiControl).setUserValue(doubleValue[0]);
516                 } else if (uiControl instanceof SwingScilabUiImage) {
517                     // Update the image parameters
518                     double[] imageParams = new double[5];
519                     if (doubleValue.length < 1) {
520                         imageParams[0] = 1.0;
521                     } else {
522                         imageParams[0] = doubleValue[0];
523                     }
524                     if (doubleValue.length < 2) {
525                         imageParams[1] = 1.0;
526                     } else {
527                         imageParams[1] = doubleValue[1];
528                     }
529                     if (doubleValue.length < 3) {
530                         imageParams[2] = 0.0;
531                     } else {
532                         imageParams[2] = doubleValue[2];
533                     }
534                     if (doubleValue.length < 4) {
535                         imageParams[3] = 0.0;
536                     } else {
537                         imageParams[3] = doubleValue[3];
538                     }
539                     if (doubleValue.length < 5) {
540                         imageParams[4] = 0.0;
541                     } else {
542                         imageParams[4] = doubleValue[4];
543                     }
544                     double[] scale = new double[2];
545                     scale[0] = imageParams[0];
546                     scale[1] = imageParams[1];
547                     ((SwingScilabUiImage) uiControl).setScale(scale);
548                     double[] shear = new double[2];
549                     shear[0] = imageParams[2];
550                     shear[1] = imageParams[3];
551                     ((SwingScilabUiImage) uiControl).setShear(shear);
552                     ((SwingScilabUiImage) uiControl).setRotate(imageParams[4]);
553                 } else if (uiControl instanceof SwingScilabLayer) {
554                     SwingScilabLayer layer = (SwingScilabLayer)uiControl;
555                     //if intValue[0] is out of bounds, do not update view but let "wrong" value in model
556                     layer.setActiveLayer(intValue[0]);
557                 }
558                 break;
559             case __GO_UI_VERTICALALIGNMENT__ : {
560                 String align = (String)value;
561                 if (align.equals("") == false) {
562                     uiControl.setVerticalAlignment((String) value);
563                 }
564                 break;
565             }
566             case __GO_VISIBLE__ : {
567                 boolean needUpdate = true;
568                 if (uiControl instanceof SwingScilabFrame) {
569                     SwingScilabFrame frame = (SwingScilabFrame) uiControl;
570                     Integer parent = (Integer) controller.getProperty(frame.getId(), __GO_PARENT__);
571                     if (parent != 0) {
572                         Integer type = (Integer) controller.getProperty(parent, __GO_TYPE__);
573                         if (type == __GO_UICONTROL__) {
574                             Integer style = (Integer) controller.getProperty(parent, __GO_STYLE__);
575                             if (style == __GO_UI_LAYER__) {
576                                 //no no no don't touch visible on layer children !
577                                 Boolean visible = (Boolean)value;
578                                 SwingScilabLayer layer = (SwingScilabLayer) SwingView.getFromId(parent);
579                                 Boolean isActive = layer.isLayerActive(frame);
580                                 if (isActive != visible ) {
581                                     controller.setProperty(frame.getId(), __GO_VISIBLE__, isActive);
582                                 }
583
584                                 needUpdate = false;
585                             }
586                         }
587                     }
588                 }
589
590                 if (needUpdate) {
591                     uiControl.setVisible(((Boolean) value).booleanValue());
592                 }
593                 break;
594             }
595             case __GO_PARENT__:
596                 /* Update position */
597                 SwingViewWidget.update(uiControl, __GO_POSITION__, controller.getProperty(uid, __GO_POSITION__));
598                 break;
599             case __GO_UI_GROUP_NAME__:
600                 if (uiControl instanceof SwingScilabRadioButton || uiControl instanceof SwingScilabCheckBox) {
601                     String groupName = (String) value;
602                     if (groupName == null || groupName.equals("")) {
603                         //remove rb from buttonGroup Map
604                         GroupManager.getGroupManager().removeFromGroup((AbstractButton) uiControl);
605                     } else {
606                         GroupManager.getGroupManager().addToGroup(groupName, (AbstractButton) uiControl);
607                     }
608                 }
609                 break;
610             case __GO_LAYOUT__:
611                 if (uiControl instanceof SwingScilabFrame) {
612                     SwingScilabFrame frame = (SwingScilabFrame) uiControl;
613                     LayoutType newLayout = LayoutType.intToEnum((Integer) value);
614                     switch (newLayout) {
615                         case BORDER: {
616                             Integer[] padding = (Integer[]) controller.getProperty(frame.getId(), __GO_BORDER_OPT_PADDING__);
617                             frame.setLayout(new BorderLayout(padding[0], padding[1]));
618                             break;
619                         }
620                         case GRIDBAG:
621                             frame.setLayout(new GridBagLayout());
622                             break;
623                         case GRID: {
624                             Integer[] padding = (Integer[]) controller.getProperty(frame.getId(), __GO_GRID_OPT_PADDING__);
625                             Integer[] grid = (Integer[]) controller.getProperty(frame.getId(), __GO_GRID_OPT_GRID__);
626                             if (grid[0] == 0 && grid[1] == 0) {
627                                 grid[0] = 1;
628                             }
629                             frame.setLayout(new GridLayout(grid[0], grid[1], padding[0], padding[1]));
630                             break;
631                         }
632                         case NONE:
633                         default:
634                             frame.setLayout(null);
635                             break;
636                     }
637                 } else {
638                 }
639                 break;
640             case __GO_UI_FRAME_BORDER__:
641                 if (uiControl instanceof SwingScilabFrame) {
642                     SwingScilabFrame frame = (SwingScilabFrame) uiControl;
643                     Integer borderId = (Integer) value;
644                     Border border = BorderConvertor.getBorder(borderId);
645                     frame.setBorder(border);
646                 }
647                 break;
648             default:
649                 //System.err.println("[SwingScilabWidget.update] Property not mapped: " + property);
650         }
651     }
652 }