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