2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA - Vincent Couvert
4 * Copyright (C) 2007 - INRIA - Marouane BEN JELLOUL
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
14 package org.scilab.modules.gui.bridge.frame;
17 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ICON__;
18 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTROL__;
19 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CHILDREN__;
20 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
21 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BORDER_OPT_PADDING__;
22 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_GRID__;
23 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_PADDING__;
24 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT__;
25 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
26 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TAG__;
27 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
28 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
29 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
30 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VALUE__;
31 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
33 import java.awt.BorderLayout;
34 import java.awt.Color;
35 import java.awt.Component;
36 import java.awt.Container;
37 import java.awt.Dimension;
38 import java.awt.GridBagConstraints;
39 import java.awt.GridBagLayout;
40 import java.awt.GridLayout;
41 import java.awt.Insets;
42 import java.awt.event.ComponentEvent;
43 import java.awt.event.ComponentListener;
45 import javax.swing.JPanel;
46 import javax.swing.UIManager;
47 import javax.swing.border.Border;
49 import org.scilab.modules.graphic_objects.axes.AxesContainer;
50 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
51 import org.scilab.modules.graphic_objects.graphicModel.GraphicModel;
52 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
53 import org.scilab.modules.graphic_objects.uicontrol.Uicontrol;
54 import org.scilab.modules.graphic_objects.utils.LayoutType;
55 import org.scilab.modules.gui.SwingView;
56 import org.scilab.modules.gui.SwingViewObject;
57 import org.scilab.modules.gui.SwingViewWidget;
58 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvas;
59 import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
60 import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
61 import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
62 import org.scilab.modules.gui.bridge.label.SwingScilabLabel;
63 import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
64 import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
65 import org.scilab.modules.gui.bridge.radiobutton.SwingScilabRadioButton;
66 import org.scilab.modules.gui.bridge.slider.SwingScilabScroll;
67 import org.scilab.modules.gui.bridge.tab.SwingScilabAxes;
68 import org.scilab.modules.gui.bridge.tab.SwingScilabDockablePanel;
69 import org.scilab.modules.gui.bridge.tab.SwingScilabTabGroup;
70 import org.scilab.modules.gui.bridge.textbox.SwingScilabTextBox;
71 import org.scilab.modules.gui.canvas.Canvas;
72 import org.scilab.modules.gui.checkbox.CheckBox;
73 import org.scilab.modules.gui.console.Console;
74 import org.scilab.modules.gui.dockable.Dockable;
75 import org.scilab.modules.gui.editbox.EditBox;
76 import org.scilab.modules.gui.events.callback.CommonCallBack;
77 import org.scilab.modules.gui.frame.Frame;
78 import org.scilab.modules.gui.frame.SimpleFrame;
79 import org.scilab.modules.gui.label.Label;
80 import org.scilab.modules.gui.listbox.ListBox;
81 import org.scilab.modules.gui.menubar.MenuBar;
82 import org.scilab.modules.gui.pushbutton.PushButton;
83 import org.scilab.modules.gui.radiobutton.RadioButton;
84 import org.scilab.modules.gui.slider.Slider;
85 import org.scilab.modules.gui.tab.Tab;
86 import org.scilab.modules.gui.textbox.TextBox;
87 import org.scilab.modules.gui.toolbar.ToolBar;
88 import org.scilab.modules.gui.utils.BorderConvertor;
89 import org.scilab.modules.gui.utils.Position;
90 import org.scilab.modules.gui.utils.PositionConverter;
91 import org.scilab.modules.gui.utils.ScilabRelief;
92 import org.scilab.modules.gui.utils.Size;
93 import org.scilab.modules.gui.utils.UnitsConverter;
94 import org.scilab.modules.gui.utils.UnitsConverter.UicontrolUnits;
95 import org.scilab.modules.gui.widget.Widget;
98 * Swing implementation for Scilab frames in GUI
99 * @author Vincent COUVERT
100 * @author Marouane BEN JELLOUL
102 public class SwingScilabFrame extends JPanel implements SwingViewObject, SimpleFrame {
104 private static final long serialVersionUID = -7401084975837285447L;
106 private Integer uid = -1;
108 protected boolean hasLayout = false;
109 private Border defaultBorder = null;
114 public SwingScilabFrame() {
116 // the Default layout is null so we have to set a Position and a Size of every Dockable we add to it
117 super.setLayout(null);
119 addComponentListener(new ComponentListener() {
120 public void componentShown(ComponentEvent e) { }
122 public void componentResized(ComponentEvent e) {
123 if (getId() != -1 && getParent() != null) {
125 Double[] newPosition = new Double[4];
126 Double[] positions = (Double[]) GraphicController.getController().getProperty(getId(), GraphicObjectProperties.__GO_POSITION__);
127 if (positions == null) {
128 // Position property not yet set
132 UicontrolUnits unitsProperty = UnitsConverter.stringToUnitsEnum((String) GraphicController.getController().getProperty(uid, GraphicObjectProperties.__GO_UI_UNITS__));
134 //normalized values are always good
135 if (unitsProperty != UicontrolUnits.NORMALIZED) {
136 newPosition[0] = UnitsConverter.convertFromPixel(getPosition().getX(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
137 newPosition[1] = UnitsConverter.convertFromPixel(getPosition().getY(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
138 newPosition[2] = UnitsConverter.convertFromPixel(getWidth(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
139 newPosition[3] = UnitsConverter.convertFromPixel(getHeight(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
140 positions[2] = newPosition[2];
141 positions[3] = newPosition[3];
142 if (getParent() != null && getParent().getLayout() == null) {
143 GraphicController.getController().setProperty(getId(), GraphicObjectProperties.__GO_POSITION__, newPosition);
145 GraphicController.getController().setProperty(getId(), GraphicObjectProperties.__GO_POSITION__, positions);
150 if (hasLayout == false) {
151 for (Component comp : getComponents()) {
152 if (comp instanceof Widget) {
153 SwingViewObject obj = (SwingViewObject) comp;
154 obj.update(__GO_POSITION__, GraphicController.getController().getProperty(obj.getId(), __GO_POSITION__));
160 public void componentMoved(ComponentEvent e) { }
162 public void componentHidden(ComponentEvent e) { }
167 * Draws a Swing Scilab frame
168 * @see org.scilab.modules.gui.UIElement#draw()
171 this.setVisible(true);
176 * Gets the dimensions (width and height) of a swing Scilab frame
177 * @return the dimension of the frame
178 * @see org.scilab.modules.gui.UIElement#getDims()
180 public Size getDims() {
181 return new Size(this.getSize().width, this.getSize().height);
185 * Gets the position (X-coordinate and Y-coordinate) of a swing Scilab frame
186 * @return the position of the frame
187 * @see org.scilab.modules.gui.UIElement#getPosition()
189 public Position getPosition() {
190 return PositionConverter.javaToScilab(getLocation(), getSize(), getParent());
194 * Sets the dimensions (width and height) of a swing Scilab frame
195 * @param newSize the size we want to set to the frame
196 * @see org.scilab.modules.gui.UIElement#setDims(org.scilab.modules.gui.utils.Size)
198 public void setDims(Size newSize) {
199 this.setSize(newSize.getWidth(), newSize.getHeight());
203 * Sets the position (X-coordinate and Y-coordinate) of a swing Scilab frame
204 * @param newPosition the position we want to set to the frame
205 * @see org.scilab.modules.gui.UIElement#setPosition(org.scilab.modules.gui.utils.Position)
207 public void setPosition(Position newPosition) {
208 Position javaPosition = PositionConverter.scilabToJava(newPosition, getDims(), getParent());
209 setLocation(javaPosition.getX(), javaPosition.getY());
213 * Add a SwingViewObject (from SwingView.java) to container and returns its index
214 * @param member the member to add
216 public void addMember(SwingViewObject member) {
217 //forward disable status
218 if (isEnabled() == false) {
219 ((Component) member).setEnabled(false);
222 if (member instanceof SwingScilabAxes) {
223 AxesContainer frame = (AxesContainer) GraphicModel.getModel().getObjectFromId(getId());
224 SwingScilabCanvas canvas = new SwingScilabCanvas(frame);
225 setLayout(new BorderLayout());
227 add(canvas, BorderLayout.CENTER);
231 Uicontrol uicontrol = (Uicontrol) GraphicModel.getModel().getObjectFromId(member.getId());
232 if (getLayout() instanceof BorderLayout) {
233 switch (uicontrol.getBorderPositionAsEnum()) {
235 add((Component) member, BorderLayout.SOUTH);
238 add((Component) member, BorderLayout.NORTH);
241 add((Component) member, BorderLayout.WEST);
244 add((Component) member, BorderLayout.EAST);
247 add((Component) member, BorderLayout.CENTER);
253 Integer[] preferredSize = uicontrol.getBorderPreferredSize();
254 if (preferredSize[0].equals(-1) == false && preferredSize[1].equals(-1) == false) {
255 ((Component) member).setPreferredSize(new Dimension(preferredSize[0], preferredSize[1]));
257 } else if (getLayout() instanceof GridBagLayout) {
258 GridBagConstraints constraints = new GridBagConstraints();
261 Integer[] grid = uicontrol.getGridBagGrid();
262 constraints.gridx = grid[0];
263 constraints.gridy = grid[1];
264 constraints.gridwidth = grid[2];
265 constraints.gridheight = grid[3];
268 Double[] weight = uicontrol.getGridBagWeight();
269 constraints.weightx = weight[0];
270 constraints.weighty = weight[1];
273 switch (uicontrol.getGridBagAnchorAsEnum()) {
275 constraints.anchor = GridBagConstraints.WEST;
278 constraints.anchor = GridBagConstraints.NORTH;
281 constraints.anchor = GridBagConstraints.SOUTH;
284 constraints.anchor = GridBagConstraints.SOUTHWEST;
287 constraints.anchor = GridBagConstraints.SOUTHEAST;
290 constraints.anchor = GridBagConstraints.EAST;
293 constraints.anchor = GridBagConstraints.NORTHWEST;
296 constraints.anchor = GridBagConstraints.NORTHEAST;
300 constraints.anchor = GridBagConstraints.CENTER;
305 switch (uicontrol.getGridBagFillAsEnum()) {
307 constraints.fill = GridBagConstraints.BOTH;
310 constraints.fill = GridBagConstraints.HORIZONTAL;
313 constraints.fill = GridBagConstraints.VERTICAL;
317 constraints.fill = GridBagConstraints.NONE;
322 Double[] margins = uicontrol.getMargins();
323 constraints.insets = new Insets(
324 margins[0].intValue(), margins[1].intValue(),
325 margins[2].intValue(), margins[3].intValue());
328 Integer[] padding = uicontrol.getGridBagPadding();
329 constraints.ipadx = padding[0];
330 constraints.ipady = padding[1];
332 Integer[] preferredSize = uicontrol.getGridBagPreferredSize();
333 if (preferredSize[0].equals(-1) == false && preferredSize[1].equals(-1) == false) {
334 ((Component) member).setPreferredSize(new Dimension(preferredSize[0], preferredSize[1]));
337 add((Component) member, constraints);
339 } else if (getLayout() instanceof GridLayout) {
340 this.add((Component) member, 0);
342 this.add((Component) member);
345 //force update position
346 member.update(__GO_POSITION__, GraphicController.getController().getProperty(member.getId(), __GO_POSITION__));
350 * Add a member (dockable element) to container and returns its index
351 * @param member the member to add
352 * @return index of member in ArrayList
354 public int addMember(Console member) {
355 return this.addMember((SwingScilabConsole) member.getAsSimpleConsole());
359 * Add a member (dockable element) to container and returns its index
360 * @param member the member to add
361 * @return index of member in ArrayList
363 private int addMember(SwingScilabConsole member) {
365 return this.getComponentZOrder(member);
369 * Add a member (dockable element) to container and returns its index
370 * @param member the member to add
371 * @return index of member in ArrayList
373 public int addMember(EditBox member) {
374 return this.addMember((SwingScilabEditBox) member.getAsSimpleEditBox());
378 * Add a member (dockable element) to container and returns its index
379 * @param member the member to add
380 * @return index of member in ArrayList
382 private int addMember(SwingScilabEditBox member) {
384 return this.getComponentZOrder(member);
388 * Add a member (dockable element) to container and returns its index
389 * @param member the member to add
390 * @return index of member in ArrayList
392 public int addMember(Label member) {
393 // FIXME replace member with member.getAsSimpleLabel() when ready
394 return this.addMember((SwingScilabLabel) member);
398 * Add a member (dockable element) to container and returns its index
399 * @param member the member to add
400 * @return index of member in ArrayList
402 private int addMember(SwingScilabLabel member) {
404 return this.getComponentZOrder(member);
408 * Add a member (dockable element) to container and returns its index
409 * @param member the member to add
410 * @return index of member in ArrayList
412 public int addMember(Frame member) {
413 return this.addMember((SwingScilabFrame) member.getAsSimpleFrame());
417 * Add a member (dockable element) to container and returns its index
418 * @param member the member to add
419 * @return index of member in ArrayList
421 private int addMember(SwingScilabFrame member) {
423 return this.getComponentZOrder(member);
427 * Add a Frame in a Frame with a BorderLayout.
428 * @param member the member to add
429 * @param borderLayout the BorderLayout to use
430 * @return the position of the Frame in the member list.
432 public int addMember(Frame member, String borderLayout) {
433 return this.addMember((SwingScilabFrame) member.getAsSimpleFrame(), borderLayout);
437 * Add a member (dockable element) to container and returns its index
438 * @param member the member to add
439 * @param borderLayout the BorderLayout to use
440 * @return index of member in ArrayList
442 private int addMember(SwingScilabFrame member, String borderLayout) {
443 this.add(member, borderLayout);
444 return this.getComponentZOrder(member);
448 * Add a Frame in a Frame with a layout.
449 * @param member the member to add
450 * @param layoutPosition the Layout position to use
451 * @return the position of the Frame in the member list.
453 public int addMember(Frame member, int layoutPosition) {
454 return this.addMember((SwingScilabFrame) member.getAsSimpleFrame(), layoutPosition);
458 * Add a member (dockable element) to container and returns its index
459 * @param member the member to add
460 * @param layoutPosition the Layout position to use
461 * @return index of member in ArrayList
463 private int addMember(SwingScilabFrame member, int layoutPosition) {
464 this.add(member, layoutPosition);
465 return this.getComponentZOrder(member);
469 * Add a member (dockable element) to container and returns its index
470 * @param member the member to add
471 * @return index of member in ArrayList
473 public int addMember(Canvas member) {
474 return this.addMember((SwingScilabCanvas) member.getAsSimpleCanvas());
478 * Add a member (dockable element) to container and returns its index
479 * @param member the member to add
480 * @return index of member in ArrayList
482 private int addMember(SwingScilabCanvas member) {
487 * Add a member (dockable element) to container and returns its index
488 * @param member the member to add
489 * @return index of member in ArrayList
491 public int addMember(CheckBox member) {
492 // FIXME replace member with member.getAsSimpleCheckBox() when ready
493 return this.addMember((SwingScilabCheckBox) member);
497 * Add a member (dockable element) to container and returns its index
498 * @param member the member to add
499 * @return index of member in ArrayList
501 private int addMember(SwingScilabCheckBox member) {
503 return this.getComponentZOrder(member);
507 * Add a member (dockable element) to container and returns its index
508 * @param member the member to add
509 * @return index of member in ArrayList
511 public int addMember(ListBox member) {
512 return this.addMember((SwingScilabListBox) member.getAsSimpleListBox());
516 * Add a member (dockable element) to container and returns its index
517 * @param member the member to add
518 * @return index of member in ArrayList
520 private int addMember(SwingScilabListBox member) {
522 return this.getComponentZOrder(member);
526 * Add a member (dockable element) to container and returns its index
527 * @param member the member to add
528 * @return index of member in ArrayList
530 public int addMember(PushButton member) {
531 return this.addMember((SwingScilabPushButton) member.getAsSimplePushButton());
535 * Add a member (dockable element) to container and returns its index
536 * @param member the member to add
537 * @return index of member in ArrayList
539 private int addMember(SwingScilabPushButton member) {
541 return this.getComponentZOrder(member);
545 * Add a member (dockable element) to container and returns its index
546 * @param member the member to add
547 * @return index of member in ArrayList
549 public int addMember(RadioButton member) {
550 // FIXME replace member with member.getAsSimpleRadioButton() when ready
551 return this.addMember((SwingScilabRadioButton) member);
555 * Add a member (dockable element) to container and returns its index
556 * @param member the member to add
557 * @return index of member in ArrayList
559 private int addMember(SwingScilabRadioButton member) {
561 return this.getComponentZOrder(member);
565 * Add a member (dockable element) to container and returns its index
566 * @param member the member to add
567 * @return index of member in ArrayList
569 public int addMember(Slider member) {
570 // FIXME replace member with member.getAsSimpleSlider() when ready
571 return this.addMember((SwingScilabScroll) member);
575 * Add a member (dockable element) to container and returns its index
576 * @param member the member to add
577 * @return index of member in ArrayList
579 private int addMember(SwingScilabScroll member) {
581 return this.getComponentZOrder(member);
585 * Add a PushButton in a Frame with a BorderLayout.
586 * @param member the PushButton to add
587 * @param borderLayout the BorderLayout to use
588 * @return the position of the PushButton in the member list.
590 public int addMember(PushButton member, String borderLayout) {
591 return this.addMember((SwingScilabPushButton) member.getAsSimplePushButton(), borderLayout);
595 * Add a PushButton (dockable element) to Frame and returns its index
596 * @param member the PushButton to add
597 * @param layoutPosition the layout Position to use
598 * @return index of member in ArrayList
600 private int addMember(SwingScilabPushButton member, int layoutPosition) {
601 this.add(member, layoutPosition);
602 return this.getComponentZOrder(member);
606 * Add a PushButton in a Frame with a layout.
607 * @param member the PushButton to add
608 * @param layoutPosition the layout Position to use
609 * @return the position of the PushButton in the member list.
611 public int addMember(PushButton member, int layoutPosition) {
612 return this.addMember((SwingScilabPushButton) member.getAsSimplePushButton(), layoutPosition);
616 * Add a PushButton (dockable element) to Frame and returns its index
617 * @param member the PushButton to add
618 * @param borderLayout the BorderLayout to use
619 * @return index of member in ArrayList
621 private int addMember(SwingScilabPushButton member, String borderLayout) {
622 this.add(member, borderLayout);
623 return this.getComponentZOrder(member);
626 // TODO : Check if it should be possible to add a Tab to a frame and how it should behave
628 * Add a member (dockable element) to container and returns its index
629 * @param member the member to add
630 * @return index of member in ArrayList
632 public int addMember(Tab member) {
633 return this.addMember((SwingScilabDockablePanel) member.getAsSimpleTab());
635 // TODO : Check if it should be possible to add a Tab to a frame and how it should behave
637 * Add a member (dockable element) to container and returns its index
638 * @param member the member to add
639 * @return index of member in ArrayList
641 private int addMember(SwingScilabDockablePanel member) {
643 return this.getComponentZOrder(member);
647 * Add a member (dockable element) to container and returns its index
648 * @param member the member to add
649 * @return index of member in ArrayList
651 public int addMember(TextBox member) {
652 return this.addMember((SwingScilabTextBox) member.getAsSimpleTextBox());
656 * Add a member (dockable element) to container and returns its index
657 * @param member the member to add
658 * @return index of member in ArrayList
660 private int addMember(SwingScilabTextBox member) {
662 return this.getComponentZOrder(member);
666 * Add a callback to the Frame
667 * @param callback the callback to set.
669 public void setCallback(CommonCallBack callback) {
675 * @param menuBarToAdd the MenuBar associated to the Frame.
677 public void addMenuBar(MenuBar menuBarToAdd) {
678 /* Unimplemented for Frames */
679 throw new UnsupportedOperationException();
684 * @param toolBarToAdd the ToolBar associated to the Frame.
686 public void addToolBar(ToolBar toolBarToAdd) {
687 /* Unimplemented for Frames */
688 throw new UnsupportedOperationException();
693 * @return MenuBar: the MenuBar associated to the Frame.
695 public MenuBar getMenuBar() {
696 /* Unimplemented for Frames */
697 throw new UnsupportedOperationException();
702 * @return ToolBar: the ToolBar associated to the Frame.
704 public ToolBar getToolBar() {
705 /* Unimplemented for Frames */
706 throw new UnsupportedOperationException();
710 * Get the text of the Frame
711 * @return the text of the frame
712 * @see org.scilab.modules.gui.frame.SimpleFrame#getText()
714 public String getText() {
715 return this.getName();
719 * Set the text of the Frame
720 * @param text the text to set to the frame
721 * @see org.scilab.modules.gui.frame.SimpleFrame#setText()
723 public void setText(String text) {
728 * Add a dockable element in the Frame (Not available for the moment)
729 * @param member the object we want to add to the Frame
730 * @return the index of the member in the Frame
731 * @see org.scilab.modules.gui.container.Container#addMember(org.scilab.modules.gui.dockable.Dockable)
733 public int addMember(Dockable member) {
734 /* Unimplemented for Frames */
735 throw new UnsupportedOperationException();
739 * Set the Relief of the Frame
740 * @param reliefType the type of the relief to set (See ScilabRelief.java)
742 public void setRelief(String reliefType) {
743 if (defaultBorder == null) {
744 defaultBorder = getBorder();
746 setBorder(ScilabRelief.getBorderFromRelief(reliefType, defaultBorder));
752 public void destroy() {
753 getParent().remove(this);
754 this.setVisible(false);
759 * @param infoBarToAdd the InfoBar associated to the Frame.
761 public void addInfoBar(TextBox infoBarToAdd) {
762 /* Unimplemented for Frames */
763 throw new UnsupportedOperationException();
768 * @return the InfoBar associated to the Frame.
770 public TextBox getInfoBar() {
771 /* Unimplemented for Frames */
772 throw new UnsupportedOperationException();
776 * Set the horizontal alignment for the Slider text
777 * @param alignment the value for the alignment (See ScilabAlignment.java)
779 public void setHorizontalAlignment(String alignment) {
780 // Nothing to do here
784 * Set the vertical alignment for the Slider text
785 * @param alignment the value for the alignment (See ScilabAlignment.java)
787 public void setVerticalAlignment(String alignment) {
788 // Nothing to do here
795 public void setId(Integer id) {
803 public Integer getId() {
808 * Generic update method
809 * @param property property name
810 * @param value property value
812 public void update(int property, Object value) {
813 GraphicController controller = GraphicController.getController();
816 case __GO_UI_VALUE__: {
817 if (this instanceof SwingScilabLayer) {
818 SwingScilabLayer layer = (SwingScilabLayer) this;
819 Double[] doubleValue = ((Double[]) value);
820 if (doubleValue.length == 0) {
824 Integer val = doubleValue[0].intValue();
826 //if intValue[0] is out of bounds, do not update view but let "wrong" value in model
827 layer.setActiveLayer(val);
831 case __GO_UI_STRING__: {
833 Container parent = getParent();
834 if (parent instanceof SwingScilabTabGroup) {
835 SwingScilabTabGroup tab = (SwingScilabTabGroup) parent;
836 int index = tab.indexOfComponent(this);
838 tab.setTitleAt(index, ((String[]) value)[0]);
842 if (this instanceof SwingScilabLayer) {
843 SwingScilabLayer layer = (SwingScilabLayer) this;
844 //if intValue[0] is out of bounds, do not update view but let "wrong" value in model
845 layer.setActiveLayerFromName(((String[]) value)[0]);
849 case __GO_UI_ICON__: {
850 // Update tab icon title
851 Container parent = getParent();
852 if (parent instanceof SwingScilabTabGroup) {
853 SwingScilabTabGroup tab = (SwingScilabTabGroup) parent;
854 int index = tab.indexOfComponent(this);
856 tab.setIconAt(index, (String) value);
862 case __GO_POSITION__: {
863 SwingViewWidget.updatePosition(this, uid, value);
868 case __GO_UI_FRAME_BORDER__: {
869 Integer borderId = (Integer) value;
870 Border border = BorderConvertor.getBorder(borderId);
874 case __GO_LAYOUT__: {
876 LayoutType newLayout = LayoutType.intToEnum((Integer) value);
879 Integer[] padding = (Integer[]) controller.getProperty(getId(), __GO_BORDER_OPT_PADDING__);
880 setLayout(new BorderLayout(padding[0], padding[1]));
885 setLayout(new GridBagLayout());
889 Integer[] padding = (Integer[]) controller.getProperty(getId(), __GO_GRID_OPT_PADDING__);
890 Integer[] grid = (Integer[]) controller.getProperty(getId(), __GO_GRID_OPT_GRID__);
891 if (grid[0] == 0 && grid[1] == 0) {
895 setLayout(new GridLayout(grid[0], grid[1], padding[0], padding[1]));
908 case __GO_VISIBLE__: {
909 boolean needUpdate = true;
910 Component parent = getParent();
911 if (parent instanceof SwingScilabLayer) {
912 //no no no don't touch visible on layer children !
913 Boolean visible = (Boolean) value;
914 SwingScilabLayer layer = (SwingScilabLayer) parent;
915 Boolean isActive = layer.isLayerActive(this);
916 if (isActive != visible) {
917 controller.setProperty(uid, __GO_VISIBLE__, isActive);
921 } else if (parent instanceof SwingScilabTabGroup) {
922 //no no no don't touch visible on layer children !
923 Boolean visible = (Boolean) value;
924 SwingScilabTabGroup layer = (SwingScilabTabGroup) parent;
925 Boolean isActive = layer.isTabActive(this);
926 if (isActive != visible) {
927 controller.setProperty(uid, __GO_VISIBLE__, isActive);
934 setVisible(((Boolean) value).booleanValue());
940 Component parent = getParent();
941 if (parent instanceof SwingScilabLayer) {
942 SwingScilabLayer layer = (SwingScilabLayer)parent;
943 layer.updateModelProperties(null, layer.getActiveLayer());
944 } else if (parent instanceof SwingScilabTabGroup) {
945 ((SwingScilabTabGroup)parent).updateModelProperties();
950 SwingViewWidget.update(this, property, value);
956 * Set the enable status of the frame and its children
957 * @param status the status to set
959 public void setEnabled(boolean status) {
962 super.setEnabled(status);
963 // Enable its children according to their __GO_UI_ENABLE__ property
964 Integer[] children = (Integer[]) GraphicController.getController().getProperty(uid, __GO_CHILDREN__);
965 for (int kChild = 0; kChild < children.length; kChild++) {
966 Integer type = (Integer)GraphicController.getController().getProperty(children[kChild], __GO_TYPE__);
967 if (type == __GO_UICONTROL__) {
968 Boolean childStatus = (Boolean) GraphicController.getController().getProperty(children[kChild], __GO_UI_ENABLE__);
969 SwingView.getFromId(children[kChild]).update(__GO_UI_ENABLE__, childStatus);
974 super.setEnabled(status);
975 // Disable its children
976 Component[] components = getComponents();
977 for (int compIndex = 0; compIndex < components.length; compIndex++) {
978 components[compIndex].setEnabled(false);
982 //if parent is a tab enable/disable children tab
983 Component parent = getParent();
984 if (parent instanceof SwingScilabTabGroup) {
985 SwingScilabTabGroup tab = (SwingScilabTabGroup)parent;
986 Integer index = tab.getIndex(this);
988 tab.setEnabledAt(index, status);
993 // public void setForeground(Color color) {
994 // System.out.println((Color)UIManager.getLookAndFeelDefaults().get("Panel.foreground"));
995 // super.setForeground((Color)UIManager.getLookAndFeelDefaults().get("Panel.foreground"));
998 public void resetBackground() {
999 Color color = (Color)UIManager.getLookAndFeelDefaults().get("Panel.background");
1000 if (color != null) {
1001 setBackground(color);
1005 public void resetForeground() {
1006 Color color = (Color)UIManager.getLookAndFeelDefaults().get("Panel.foreground");
1007 if (color != null) {
1008 setForeground(color);
1012 public void removeAxes() {
1013 getComponent(0).setEnabled(false);
1014 getComponent(0).removeNotify();