2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007-2008 - INRIA - Vincent Couvert
4 * Copyright (C) 2007 - INRIA - Bruno JOFRET
5 * Copyright (C) 2007 - INRIA - Marouane BEN JELLOUL
6 * Copyright (C) 2011 - DIGITEO - Vincent Couvert
8 * This file must be used under the terms of the CeCILL.
9 * This source file is licensed as described in the file COPYING, which
10 * you should have received as part of this distribution. The terms
11 * are also available at
12 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
16 package org.scilab.modules.gui.bridge.tab;
18 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AUTORESIZE__;
19 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES_SIZE__;
20 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACK__;
21 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CHILDREN__;
22 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CLOSEREQUESTFCN__;
23 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_EVENTHANDLER_ENABLE__;
24 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_EVENTHANDLER_NAME__;
25 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_ID__;
26 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_INFO_MESSAGE__;
27 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_NAME__;
28 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
29 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_SIZE__;
30 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
31 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICHECKEDMENU__;
32 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICHILDMENU__;
33 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIMENU__;
34 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIPARENTMENU__;
36 import java.awt.Color;
37 import java.awt.Component;
38 import java.awt.Container;
39 import java.awt.Dimension;
40 import java.awt.Graphics;
41 import java.awt.Image;
42 import java.awt.event.ComponentEvent;
43 import java.awt.event.ComponentListener;
44 import java.awt.event.FocusEvent;
45 import java.awt.event.FocusListener;
46 import java.awt.event.HierarchyBoundsListener;
47 import java.awt.event.HierarchyEvent;
48 import java.lang.reflect.InvocationTargetException;
49 import java.util.Iterator;
50 import java.util.List;
51 import java.util.ListIterator;
53 import javax.swing.Action;
54 import javax.swing.ImageIcon;
55 import javax.swing.JLayeredPane;
56 import javax.swing.KeyStroke;
57 import javax.swing.SwingUtilities;
59 import org.flexdock.docking.DockingConstants;
60 import org.flexdock.docking.DockingManager;
61 import org.flexdock.docking.DockingPort;
62 import org.flexdock.docking.activation.ActiveDockableTracker;
63 import org.flexdock.docking.event.DockingEvent;
64 import org.flexdock.docking.props.PropertyChangeListenerFactory;
65 import org.flexdock.view.Titlebar;
66 import org.flexdock.view.View;
67 import org.scilab.modules.action_binding.InterpreterManagement;
68 import org.scilab.modules.graphic_objects.figure.Figure;
69 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
70 import org.scilab.modules.gui.SwingView;
71 import org.scilab.modules.gui.SwingViewObject;
72 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvas;
73 import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
74 import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
75 import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
76 import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
77 import org.scilab.modules.gui.bridge.helpbrowser.SwingScilabHelpBrowser;
78 import org.scilab.modules.gui.bridge.label.SwingScilabLabel;
79 import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
80 import org.scilab.modules.gui.bridge.popupmenu.SwingScilabPopupMenu;
81 import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
82 import org.scilab.modules.gui.bridge.radiobutton.SwingScilabRadioButton;
83 import org.scilab.modules.gui.bridge.slider.SwingScilabSlider;
84 import org.scilab.modules.gui.bridge.tree.SwingScilabTree;
85 import org.scilab.modules.gui.bridge.uidisplaytree.SwingScilabUiDisplayTree;
86 import org.scilab.modules.gui.bridge.uiimage.SwingScilabUiImage;
87 import org.scilab.modules.gui.bridge.uitable.SwingScilabUiTable;
88 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
89 import org.scilab.modules.gui.canvas.Canvas;
90 import org.scilab.modules.gui.checkbox.CheckBox;
91 import org.scilab.modules.gui.console.Console;
92 import org.scilab.modules.gui.dockable.Dockable;
93 import org.scilab.modules.gui.editbox.EditBox;
94 import org.scilab.modules.gui.events.ScilabEventListener;
95 import org.scilab.modules.gui.events.callback.CommonCallBack;
96 import org.scilab.modules.gui.events.callback.ScilabCloseCallBack;
97 import org.scilab.modules.gui.frame.Frame;
98 import org.scilab.modules.gui.helpbrowser.HelpBrowser;
99 import org.scilab.modules.gui.label.Label;
100 import org.scilab.modules.gui.listbox.ListBox;
101 import org.scilab.modules.gui.menubar.MenuBar;
102 import org.scilab.modules.gui.popupmenu.PopupMenu;
103 import org.scilab.modules.gui.pushbutton.PushButton;
104 import org.scilab.modules.gui.radiobutton.RadioButton;
105 import org.scilab.modules.gui.slider.Slider;
106 import org.scilab.modules.gui.tab.SimpleTab;
107 import org.scilab.modules.gui.textbox.TextBox;
108 import org.scilab.modules.gui.toolbar.ToolBar;
109 import org.scilab.modules.gui.tree.Tree;
110 import org.scilab.modules.gui.uidisplaytree.UiDisplayTree;
111 import org.scilab.modules.gui.uitable.UiTable;
112 import org.scilab.modules.gui.utils.BarUpdater;
113 import org.scilab.modules.gui.utils.ClosingOperationsManager;
114 import org.scilab.modules.gui.utils.Position;
115 import org.scilab.modules.gui.utils.SciClosingAction;
116 import org.scilab.modules.gui.utils.SciHelpOnComponentAction;
117 import org.scilab.modules.gui.utils.SciUndockingAction;
118 import org.scilab.modules.gui.utils.ScilabSwingUtilities;
119 import org.scilab.modules.gui.utils.Size;
120 import org.scilab.modules.gui.utils.ToolBarBuilder;
123 * Swing implementation for Scilab tabs in GUIs
124 * This implementation uses FlexDock package
125 * @author Bruno JOFRET
126 * @author Vincent COUVERT
127 * @author Marouane BEN JELLOUL
128 * @author Jean-Baptiste SILVY
130 public class SwingScilabTab extends View implements SwingViewObject, SimpleTab, FocusListener {
132 public static final String GRAPHICS_TOOLBAR_DESCRIPTOR = System.getenv("SCI") + "/modules/gui/etc/graphics_toolbar.xml";
134 private static final Image SCILAB_ICON = new ImageIcon(ScilabSwingUtilities.findIcon("scilab", "256x256")).getImage();
136 private static final long serialVersionUID = 1L;
138 private static final String UNDOCK = "undock";
139 private static final String HELP = "help";
143 private boolean eventEnabled = false;
146 PropertyChangeListenerFactory.addFactory(new BarUpdater.UpdateBarFactory());
149 private String parentWindowId;
150 private MenuBar menuBar;
151 private ToolBar toolBar;
152 private TextBox infoBar;
153 private String helpID;
155 /** Contains the canvas and widgets */
156 private SwingScilabAxes contentPane;
157 private JLayeredPane layerdPane;
159 /** Scroll the axes */
160 private SwingScilabScrollPane scrolling;
164 private Action closeAction;
166 /** The listener for event handling */
167 private ScilabEventListener eventHandler;
169 /** A reference to the canvas used for event handling management */
170 SwingScilabCanvas contentCanvas;
174 * @param name the name of the tab
175 * @param uuid an uuid to identify the tab
177 public SwingScilabTab(String name, String uuid) {
178 super(uuid, name, name);
179 //This button is "overloaded" when we add a callback
180 //this.addAction(DockingConstants.CLOSE_ACTION);
181 // Removed because make JOGL crash when "Unpin"
182 //this.addAction(DockingConstants.PIN_ACTION);
183 this.addAction(DockingConstants.ACTIVE_WINDOW);
185 // no need for an axes
189 this.setVisible(true);
191 getTitlebar().addFocusListener(this);
192 addFocusListener(this);
195 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F5"), ACTION_TOGGLE_PREVIOUS);
199 * Create a graphic tab used to display a figure with 3D graphics and/or UIcontrols
200 * @param name name of the tab
201 * @param figureId id of the displayed figure
203 public SwingScilabTab(String name, int figureId) {
204 super(name, name, name);
206 // This button is "overloaded" when we add a callback
207 //this.addAction(DockingConstants.CLOSE_ACTION);
208 // Removed because make JOGL crash when "Unpin"
209 //this.addAction(DockingConstants.PIN_ACTION);
210 this.addAction(DockingConstants.ACTIVE_WINDOW);
212 // create the panel in which all the uiobjects will lie.
213 //contentPane = new SwingScilabAxes(figureId);
215 // add it inside a JSCrollPane
216 //scrolling = new SwingScilabScrollPane(contentPane);
217 //scrolling.setBackground(1, 0, 0);
218 // put in in the back of the tab
219 //setContentPane(scrolling.getAsContainer());
221 this.setVisible(true);
223 getTitlebar().addFocusListener(this);
224 addFocusListener(this);
227 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F5"), ACTION_TOGGLE_PREVIOUS);
232 * @param name the name of the tab (used to identify it)
234 public SwingScilabTab(String name) {
239 * Set the associated help page
240 * @param helpID the xml id of the associated help page
242 public void setAssociatedXMLIDForHelp(String helpID) {
243 this.helpID = helpID;
247 * Get the associated help page
248 * @return the xml id of the associated help page
250 public String getAssociatedXMLIDForHelp() {
254 public static void removeActions(SwingScilabTab tab) {
255 tab.setActionBlocked(DockingConstants.CLOSE_ACTION, true);
256 tab.setActionBlocked(UNDOCK, true);
257 if (tab.getTitlebar() != null) {
258 tab.getTitlebar().revalidate();
262 public static void addActions(SwingScilabTab tab) {
263 tab.setActionBlocked(DockingConstants.CLOSE_ACTION, false);
264 tab.setActionBlocked(UNDOCK, false);
265 tab.getTitlebar().revalidate();
268 public SwingScilabTab(String figureTitle, int figureId, final Figure figure) {
269 this(figureTitle, figureId);
271 SwingScilabCanvas canvas = new SwingScilabCanvas(figureId, figure);
272 contentCanvas = canvas;
274 layerdPane = new JLayeredPane();
275 layerdPane.setLayout(null);
276 layerdPane.add(canvas, JLayeredPane.FRAME_CONTENT_LAYER);
278 scrolling = new SwingScilabScrollPane(layerdPane, canvas, figure);
280 setContentPane(scrolling.getAsContainer());
281 canvas.setVisible(true);
283 /* Manage figure_position property */
284 addHierarchyBoundsListener(new HierarchyBoundsListener() {
285 public void ancestorResized(HierarchyEvent arg0) {
288 public void ancestorMoved(HierarchyEvent e) {
289 if (e.getChanged() instanceof SwingScilabWindow) {
290 Position parentPosition = SwingScilabWindow.allScilabWindows.get(parentWindowId).getPosition();
291 Integer[] newPosition = new Integer[] {parentPosition.getX(), parentPosition.getY()};
292 GraphicController.getController().setProperty(id, __GO_POSITION__, newPosition);
297 /* Manage figure_size property */
298 addComponentListener(new ComponentListener() {
300 public void componentShown(ComponentEvent arg0) {
303 public void componentResized(ComponentEvent arg0) {
305 /* Update the figure_size property */
306 Size parentSize = SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
307 Integer[] newSize = new Integer[] {parentSize.getWidth(), parentSize.getHeight()};
308 GraphicController.getController().setProperty(id, __GO_SIZE__, newSize);
310 Boolean autoreSize = (Boolean) GraphicController.getController().getProperty(id, __GO_AUTORESIZE__);
312 if (autoreSize != null && autoreSize) {
313 /* Update the axes_size property */
314 Integer[] newAxesSize = new Integer[] {getContentPane().getWidth(), getContentPane().getHeight()};
315 GraphicController.getController().setProperty(id, __GO_AXES_SIZE__, newAxesSize);
319 public void componentMoved(ComponentEvent arg0) {
322 public void componentHidden(ComponentEvent arg0) {
326 /* Manage closerequestfcn */
327 ClosingOperationsManager.registerClosingOperation(SwingScilabTab.this, new ClosingOperationsManager.ClosingOperation() {
329 public int canClose() {
330 String closeRequestFcn = (String) GraphicController.getController().getProperty(getId(), __GO_CLOSEREQUESTFCN__);
331 if (!closeRequestFcn.equals("")) {
332 InterpreterManagement.requestScilabExec(closeRequestFcn + ";fire_closing_finished()");
335 closeAction.actionPerformed(null);
340 public void destroy() {
343 public String askForClosing(final List<SwingScilabTab> list) {
348 public void updateDependencies(List<SwingScilabTab> list, ListIterator<SwingScilabTab> it) {
352 ClosingOperationsManager.addDependencyWithRoot(this);
356 * @param e the FocusEvent
359 public void focusGained(FocusEvent e) {
360 //ActiveDockableTracker.requestDockableActivation(this);
361 if (contentPane != null) {
362 contentPane.requestFocus();
363 } else if (getContentPane() != null) {
364 getContentPane().requestFocus();
366 SwingScilabTab.this.requestFocusInWindow();
371 * Call when the tab restoration is ended.
373 public void endedRestoration() { }
376 * @return the window icon associated with this tab
378 public Image getWindowIcon() {
387 * @param icon the window icon associated with this tab
389 public void setWindowIcon(Image icon) {
394 * @param iconName window icon associated with this tab
396 public void setWindowIcon(String iconName) {
397 setWindowIcon(new ImageIcon(ScilabSwingUtilities.findIcon(iconName, "256x256")).getImage());
401 * @param e the FocusEvent
404 public void focusLost(FocusEvent e) { }
410 public void dockingComplete(DockingEvent evt) {
411 super.dockingComplete(evt);
412 DockingPort port = evt.getNewDockingPort();
413 Iterator iter = port.getDockables().iterator();
415 if (port.getDockables().size() > 1) {
416 while (iter.hasNext()) {
417 Object d = iter.next();
418 if (d instanceof SwingScilabTab) {
419 SwingScilabTab view = (SwingScilabTab) d;
429 * Sets the Name of a swing Scilab tab
430 * @param newTabName the Name of the tab
431 * @see org.scilab.modules.gui.tab.ScilabTab#setName(String)
434 public void setName(String newTabName) {
435 setTitle(newTabName, true);
436 getTitlePane().repaint();
437 SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this).setName(newTabName);
441 * @return the UUID of the parent window
443 public String getParentWindowUUID() {
444 return ((SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this)).getUUID();
448 * Gets the title of a swing Scilab tab
449 * @return the title of the tab
450 * @see org.scilab.modules.gui.tab.ScilabTab#getName()
453 public String getName() {
454 return this.getTitle();
458 * Paint immediately this component
460 public void paintImmediately() {
462 paintImmediately(0, 0, getWidth(), getHeight());
466 * Draws a swing Scilab tab
467 * @see org.scilab.modules.gui.uielement.UIElement#draw()
471 if (SwingUtilities.isEventDispatchThread()) {
476 SwingUtilities.invokeAndWait(new Runnable() {
483 } catch (InterruptedException e) {
485 } catch (InvocationTargetException e) {
493 * Gets the dimensions (width and height) of a swing Scilab tab
494 * @return the dimensions of the tab
495 * @see org.scilab.modules.gui.uielement.UIElement#getDims()
498 public Size getDims() {
499 return new Size(this.getSize().width, this.getSize().height);
503 * Get the size for the axes
504 * @return size of the axes in pixels
507 public Size getAxesSize() {
508 return new Size(contentPane.getWidth(), contentPane.getHeight());
512 * @param newSize new size to set for the axes
515 public void setAxesSize(Size newSize) {
516 contentPane.setSize(new Dimension(newSize.getWidth(), newSize.getHeight()));
520 * Gets the position (X-coordinate and Y-coordinate) of a swing Scilab tab
521 * @return the position of the tab
522 * @see org.scilab.modules.gui.uielement.UIElement#getPosition()
525 public Position getPosition() {
526 return new Position(this.getX(), this.getY());
530 * Sets the dimensions (width and height) of a swing Scilab tab
531 * @param newSize the dimensions we want to set to the tab
532 * @see org.scilab.modules.gui.uielement.UIElement#setDims(org.scilab.modules.gui.utils.Size)
535 public void setDims(Size newSize) {
536 this.setSize(newSize.getWidth(), newSize.getHeight());
540 * Sets the position (X-coordinate and Y-coordinate) of a swing Scilab tab
541 * @param newPosition the position we want to set to the tab
542 * @see org.scilab.modules.gui.uielement.UIElement#setPosition(org.scilab.modules.gui.utils.Position)
545 public void setPosition(Position newPosition) {
546 this.setLocation(newPosition.getX(), newPosition.getY());
550 * Add a member (dockable element) to container and returns its index
551 * @param member the member to add
552 * @return index of member in ArrayList
555 public int addMember(Canvas member) {
560 * We want to be able to remove directly a Canvas from a Tab.
561 * @param member canvas to remove
564 public void removeMember(Canvas member) {
568 * Add a SwingViewObject (from SwingView.java) to container and returns its index
569 * @param member the member to add
571 public void addMember(SwingViewObject member) {
573 * Force adding Widget at JLayeredPane.DEFAULT_LAYER + 1
574 * to draw them uppon GLJPanel (even if it is at level JLayeredPane.FRAME_CONTENT_LAYER)
576 layerdPane.add((Component) member, JLayeredPane.DEFAULT_LAYER + 1, 0);
580 * Remove a SwingViewObject (from SwingView.java)
581 * @param member the member to remove
583 public void removeMember(SwingViewObject member) {
584 layerdPane.remove((Component) member);
588 * Add a member (dockable element) to container and returns its index
589 * @param member the member to add
590 * @return index of member in ArrayList
593 public int addMember(Console member) {
594 return this.addMember((SwingScilabConsole) member.getAsSimpleConsole());
598 * Add a member (dockable element) to container and returns its index
599 * @param member the member to add
600 * @return index of member in ArrayList
602 private int addMember(SwingScilabConsole member) {
603 // replace the current content pane
604 this.setContentPane(member);
605 return this.getComponentZOrder(member);
609 * Add a member (dockable element) to container and returns its index
610 * @param member the member to add
611 * @return index of member in ArrayList
614 public int addMember(HelpBrowser member) {
615 return this.addMember((SwingScilabHelpBrowser) member.getAsSimpleHelpBrowser());
619 * Add a member (dockable element) to container and returns its index
620 * @param member the member to add
621 * @return index of member in ArrayList
623 private int addMember(SwingScilabHelpBrowser member) {
624 // replace the current content pane
625 this.setContentPane(member);
626 return this.getComponentZOrder(member);
630 * Add a member (dockable element) to container and returns its index
631 * @param member the member to add
632 * @return index of member in ArrayList
635 public int addMember(Frame member) {
636 return this.addMember((SwingScilabFrame) member.getAsSimpleFrame());
640 * Add a member (dockable element) to container and returns its index
641 * @param member the member to add
642 * @return index of member in ArrayList
644 private int addMember(SwingScilabFrame member) {
645 return contentPane.addFrame(member);
649 * Remove a Frame from its container
650 * @param member the Frame to remove
653 public void removeMember(Frame member) {
654 this.removeMember((SwingScilabFrame) member.getAsSimpleFrame());
658 * Remove a Frame from its container
659 * @param member the Frame to remove
661 private void removeMember(SwingScilabFrame member) {
662 contentPane.removeFrame(member);
666 * Add a member (dockable element) to container and returns its index
667 * @param member the member to add
668 * @return index of member in ArrayList
671 public int addMember(PushButton member) {
672 return this.addMember((SwingScilabPushButton) member.getAsSimplePushButton());
676 * Add a member (dockable element) to container and returns its index
677 * @param member the member to add
678 * @return index of member in ArrayList
680 private int addMember(SwingScilabPushButton member) {
681 int res = contentPane.addWidget(member);
687 * Remove a PushButton from its container
688 * @param member the PushButton to remove
691 public void removeMember(PushButton member) {
692 this.removeMember((SwingScilabPushButton) member.getAsSimplePushButton());
696 * Remove a PushButton from its container
697 * @param member the PushButton to remove
699 private void removeMember(SwingScilabPushButton member) {
700 contentPane.remove(member);
704 * Add a member (dockable element) to container and returns its index
705 * @param member the member to add
706 * @return index of member in ArrayList
709 public int addMember(EditBox member) {
710 return this.addMember((SwingScilabEditBox) member.getAsSimpleEditBox());
714 * Add a member (dockable element) to container and returns its index
715 * @param member the member to add
716 * @return index of member in ArrayList
718 private int addMember(SwingScilabEditBox member) {
719 return contentPane.addWidget(member);
723 * Remove an EditBox from its container
724 * @param member the EditBox to remove
727 public void removeMember(EditBox member) {
728 this.removeMember((SwingScilabEditBox) member.getAsSimpleEditBox());
732 * Remove an EditBox from its container
733 * @param member the EditBox to remove
735 private void removeMember(SwingScilabEditBox member) {
736 contentPane.removeWidget(member);
740 * Add a member (dockable element) to container and returns its index
741 * @param member the member to add
742 * @return index of member in ArrayList
745 public int addMember(Label member) {
746 return this.addMember((SwingScilabLabel) member.getAsSimpleLabel());
750 * Add a member (dockable element) to container and returns its index
751 * @param member the member to add
752 * @return index of member in ArrayList
754 private int addMember(SwingScilabLabel member) {
755 return contentPane.addWidget(member);
759 * Remove a Label from its container
760 * @param member the Label to remove
763 public void removeMember(Label member) {
764 this.removeMember((SwingScilabLabel) member.getAsSimpleLabel());
768 * Remove a Label from its container
769 * @param member the Label to remove
771 private void removeMember(SwingScilabLabel member) {
772 contentPane.removeWidget(member);
776 * Add a member (dockable element) to container and returns its index
777 * @param member the member to add
778 * @return index of member in ArrayList
781 public int addMember(CheckBox member) {
782 return this.addMember((SwingScilabCheckBox) member.getAsSimpleCheckBox());
786 * Add a member (dockable element) to container and returns its index
787 * @param member the member to add
788 * @return index of member in ArrayList
790 private int addMember(SwingScilabCheckBox member) {
791 return contentPane.addWidget(member);
795 * Remove a CheckBox from its container
796 * @param member the CheckBox to remove
799 public void removeMember(CheckBox member) {
800 this.removeMember((SwingScilabCheckBox) member.getAsSimpleCheckBox());
804 * Remove a CheckBox from its container
805 * @param member the CheckBox to remove
807 private void removeMember(SwingScilabCheckBox member) {
808 contentPane.removeWidget(member);
812 * Add a member (dockable element) to container and returns its index
813 * @param member the member to add
814 * @return index of member in ArrayList
817 public int addMember(RadioButton member) {
818 return this.addMember((SwingScilabRadioButton) member.getAsSimpleRadioButton());
822 * Add a member (dockable element) to container and returns its index
823 * @param member the member to add
824 * @return index of member in ArrayList
826 private int addMember(SwingScilabRadioButton member) {
827 return contentPane.addWidget(member);
831 * Remove a RadioButton from its container
832 * @param member the RadioButton to remove
835 public void removeMember(RadioButton member) {
836 this.removeMember((SwingScilabRadioButton) member.getAsSimpleRadioButton());
840 * Remove a RadioButton from its container
841 * @param member the RadioButton to remove
843 private void removeMember(SwingScilabRadioButton member) {
844 contentPane.removeWidget(member);
848 * Add a member (dockable element) to container and returns its index
849 * @param member the member to add
850 * @return index of member in ArrayList
852 private int addMember(SwingScilabUiImage member) {
853 return contentPane.addWidget(member);
857 * Remove a Image from its container
858 * @param member the Image to remove
860 private void removeMember(SwingScilabUiImage member) {
861 contentPane.removeWidget(member);
865 * Add a member (dockable element) to container and returns its index
866 * @param member the member to add
867 * @return index of member in ArrayList
869 public int addMember(UiDisplayTree member) {
870 return this.addMember((SwingScilabUiDisplayTree) member.getAsSimpleUiDisplayTree());
874 * Add a member (dockable element) to container and returns its index
875 * @param member the member to add
876 * @return index of member in ArrayList
878 private int addMember(SwingScilabUiDisplayTree member) {
879 return contentPane.addWidget(member);
883 * Remove a Tree from its container
884 * @param member the Tree to remove
886 public void removeMember(UiDisplayTree member) {
887 this.removeMember((SwingScilabUiDisplayTree) member.getAsSimpleUiDisplayTree());
891 * Remove a Tree from its container
892 * @param member the Tree to remove
894 private void removeMember(SwingScilabUiDisplayTree member) {
895 contentPane.removeWidget(member);
899 * Add a member (dockable element) to container and returns its index
900 * @param member the member to add
901 * @return index of member in ArrayList
903 public int addMember(UiTable member) {
904 return this.addMember((SwingScilabUiTable) member.getAsSimpleUiTable());
908 * Add a member (dockable element) to container and returns its index
909 * @param member the member to add
910 * @return index of member in ArrayList
912 private int addMember(SwingScilabUiTable member) {
913 return contentPane.addWidget(member);
917 * Remove a UiTable from its container
918 * @param member the UiTable to remove
920 public void removeMember(UiTable member) {
921 this.removeMember((SwingScilabUiTable) member.getAsSimpleUiTable());
925 * Remove a UiTable from its container
926 * @param member the UiTable to remove
928 private void removeMember(SwingScilabUiTable member) {
929 contentPane.removeWidget(member);
933 * Add a member (dockable element) to container and returns its index
934 * @param member the member to add
935 * @return index of member in ArrayList
937 public int addMember(Slider member) {
938 return this.addMember((SwingScilabSlider) member.getAsSimpleSlider());
942 * Add a member (dockable element) to container and returns its index
943 * @param member the member to add
944 * @return index of member in ArrayList
946 private int addMember(SwingScilabSlider member) {
947 return contentPane.addWidget(member);
951 * Remove a Slider from its container
952 * @param member the Slider to remove
955 public void removeMember(Slider member) {
956 this.removeMember((SwingScilabSlider) member.getAsSimpleSlider());
960 * Remove a Slider from its container
961 * @param member the Slider to remove
963 private void removeMember(SwingScilabSlider member) {
964 contentPane.removeWidget(member);
968 * Add a member (dockable element) to container and returns its index
969 * @param member the member to add
970 * @return index of member in ArrayList
973 public int addMember(ListBox member) {
974 return this.addMember((SwingScilabListBox) member.getAsSimpleListBox());
978 * Add a member (dockable element) to container and returns its index
979 * @param member the member to add
980 * @return index of member in ArrayList
982 private int addMember(SwingScilabListBox member) {
983 return contentPane.addWidget(member);
987 * Remove a ListBox from its container
988 * @param member the ListBox to remove
991 public void removeMember(ListBox member) {
992 this.removeMember((SwingScilabListBox) member.getAsSimpleListBox());
996 * Remove a ListBox from its container
997 * @param member the ListBox to remove
999 private void removeMember(SwingScilabListBox member) {
1000 contentPane.removeWidget(member);
1004 * Add a member (dockable element) to container and returns its index
1005 * @param member the member to add
1006 * @return index of member in ArrayList
1009 public int addMember(PopupMenu member) {
1010 return this.addMember((SwingScilabPopupMenu) member.getAsSimplePopupMenu());
1014 * Add a member (dockable element) to container and returns its index
1015 * @param member the member to add
1016 * @return index of member in ArrayList
1018 private int addMember(SwingScilabPopupMenu member) {
1019 return contentPane.addWidget(member);
1023 * Remove a PopupMenu from its container
1024 * @param member the PopupMenu to remove
1027 public void removeMember(PopupMenu member) {
1028 this.removeMember((SwingScilabPopupMenu) member.getAsSimplePopupMenu());
1032 * Remove a PopupMenu from its container
1033 * @param member the PopupMenu to remove
1035 private void removeMember(SwingScilabPopupMenu member) {
1036 contentPane.removeWidget(member);
1040 * Add a Tree member (dockable element) to container and returns its index
1041 * @param member the member to add
1042 * @return index of member in ArrayList
1045 public int addMember(Tree member) {
1046 return this.addMember((SwingScilabTree) member.getAsSimpleTree());
1050 * Add a Tree member (dockable element) to container and returns its index
1051 * @param member the member to add
1052 * @return index of member in ArrayList
1054 public int addMember(SwingScilabTree member) {
1055 return contentPane.addWidget(member.getAsComponent());
1059 * Add a Tree member (dockable element) to container and returns its index
1060 * @param member the member to add
1061 * @return index of member in ArrayList
1063 public int addTree(SwingScilabTree member) {
1064 this.setContentPane(member.getAsComponent());
1065 return this.getComponentZOrder(member.getAsComponent());
1069 * Remove a PopupMenu from its container
1070 * @param member the PopupMenu to remove
1073 public void removeMember(Tree member) {
1074 this.removeMember((SwingScilabTree) member.getAsSimpleTree());
1078 * Remove a PopupMenu from its container
1079 * @param member the PopupMenu to remove
1081 private void removeMember(SwingScilabTree member) {
1082 contentPane.removeTree(member);
1086 * Add a member (dockable element) to container and returns its index
1087 * @param member the member to add
1088 * @return index of member in ArrayList
1090 public int addMember(Dockable member) {
1091 // TODO Auto-generated method stub
1096 * Get the current status of the Tab in its parent
1097 * @return true is the tab is the tab currently "on top" in its parent
1100 public boolean isCurrentTab() {
1101 // TODO should not always return TRUE
1106 * Get the parent window id for this tab
1107 * @return the id of the parent window
1110 public String getParentWindowId() {
1111 return this.parentWindowId;
1116 * @return the canvas
1118 public SwingScilabCanvas getContentCanvas() {
1119 return contentCanvas;
1123 * Set the parent window id for this tab
1124 * @param id the id of the parent window
1127 public void setParentWindowId(String id) {
1128 this.parentWindowId = id;
1132 * Setter for MenuBar
1133 * @param newMenuBar : the MenuBar to set.
1134 * @see org.scilab.modules.gui.tab.SimpleTab#setMenuBar(org.scilab.modules.gui.menubar.MenuBar)
1137 public void setMenuBar(MenuBar newMenuBar) {
1138 this.menuBar = newMenuBar;
1143 * Getter for MenuBar
1144 * @return MenuBar : the MenuBar associated to the Tab.
1145 * @see org.scilab.modules.gui.tab.SimpleTab#getMenuBar()
1148 public MenuBar getMenuBar() {
1149 return this.menuBar;
1153 * Setter for ToolBar
1154 * @param newToolBar : the ToolBar to set.
1155 * @see org.scilab.modules.gui.tab.SimpleTab#setToolBar(org.scilab.modules.gui.toolbar.ToolBar)
1158 public void setToolBar(ToolBar newToolBar) {
1159 this.toolBar = newToolBar;
1163 * Getter for ToolBar
1164 * @return ToolBar : the ToolBar associated to the Tab.
1165 * @see org.scilab.modules.gui.tab.SimpleTab#getToolBar()
1168 public ToolBar getToolBar() {
1169 return this.toolBar;
1173 * Setter for InfoBar
1174 * @param newInfoBar the InfoBar to set.
1177 public void setInfoBar(TextBox newInfoBar) {
1178 this.infoBar = newInfoBar;
1182 * Getter for InfoBar
1183 * @return the InfoBar associated to the Tab.
1186 public TextBox getInfoBar() {
1187 return this.infoBar;
1191 * Set the callback of the tab
1192 * @param callback the callback to set.
1195 public void setCallback(CommonCallBack callback) {
1197 if (closeAction != null) {
1198 this.getTitlebar().removeAction(closeAction);
1201 if (callback != null) {
1202 closeAction = new SciClosingAction(this, callback);
1204 closeAction = new SciClosingAction(this);
1207 closeAction.putValue(Action.NAME, DockingConstants.CLOSE_ACTION);
1208 ((Titlebar) getTitlePane()).removeAction(DockingConstants.CLOSE_ACTION);
1209 addAction(closeAction);
1212 SciUndockingAction undockAction = new SciUndockingAction(this);
1213 undockAction.putValue(Action.NAME, UNDOCK);
1214 ((Titlebar) getTitlePane()).removeAction(UNDOCK);
1215 addAction(undockAction);
1218 SciHelpOnComponentAction helpAction = new SciHelpOnComponentAction(this);
1219 helpAction.putValue(Action.NAME, HELP);
1220 ((Titlebar) getTitlePane()).removeAction(HELP);
1221 addAction(helpAction);
1225 * Set this tab as the current tab of its parent Window
1228 public void setCurrent() {
1229 ActiveDockableTracker.requestDockableActivation(this);
1233 * Set the background color of the tab.
1234 * @param red red channel of the color
1235 * @param green green channel
1236 * @param blue blue channel
1239 public void setBackground(double red, double green, double blue) {
1240 Color newColor = new Color((float) red, (float) green, (float) blue);
1241 contentPane.setBackground(red, green, blue);
1242 scrolling.setBackground(red, green, blue);
1243 setBackground(newColor);
1247 * Get the part of the axes which is currently viewed
1248 * @return [x,y,w,h] array
1251 public int[] getViewingRegion() {
1252 return scrolling.getViewingRegion();
1256 * Specify a new viewport for the axes
1257 * For SwingScilabCanvas viewport can not be modified
1258 * since it match the parent tab size
1259 * @param posX X coordinate of upper left point of the viewport within the axes
1260 * @param posY Y coordinate of upper left point of the viewport within the axes
1261 * @param width width of the viewport
1262 * @param height height of the viewport
1265 public void setViewingRegion(int posX, int posY, int width, int height) {
1269 * Set the event handler of the Canvas
1270 * @param funName the name of the Scilab function to call
1272 public void setEventHandler(String funName) {
1273 disableEventHandler();
1274 Integer figureId = (Integer) GraphicController.getController().getProperty(getId(), __GO_ID__);
1275 eventHandler = new ScilabEventListener(funName, figureId);
1277 enableEventHandler();
1282 * Set the status of the event handler of the Canvas
1283 * @param status is true to set the event handler active
1285 public void setEventHandlerEnabled(boolean status) {
1286 if (status && eventEnabled) {
1291 enableEventHandler();
1292 eventEnabled = true;
1294 disableEventHandler();
1295 eventEnabled = false;
1300 * Specify whether the canvas should fit the parent tab size
1301 * (and consequently the scrollpane size) or not
1302 * @param onOrOff true to enable autoresize mode
1305 public void setAutoResizeMode(boolean onOrOff) {
1309 * @return whether the resize mode is on or off
1312 public boolean getAutoResizeMode() {
1317 * Close the tab and disable it.
1319 public void close() {
1330 // without this children canvas are not released.
1331 Container dummyContainer = new Container();
1332 this.setContentPane(dummyContainer);
1336 * Redefine paint children to be sure that AWT components are well painted.
1337 * @param g a Graphics
1340 public void paintChildren(Graphics g) {
1341 Component[] children = getComponents();
1342 for (int i = 0; i < children.length; i++) {
1343 // AWT children don't draw themselves automatically
1344 // so force their draw
1345 if (!children[i].isLightweight()) {
1346 children[i].paint(g);
1349 super.paintChildren(g);
1353 * Update the tab after a modification of its properties
1354 * @param property the property name
1355 * @param value the property value
1356 * @see org.scilab.modules.gui.SwingViewObject#update(java.lang.String, java.lang.Object)
1358 public void update(String property, Object value) {
1359 if (property.equals(__GO_NAME__)) {
1360 String name = ((String) value);
1361 Integer figureId = (Integer) GraphicController.getController().getProperty(getId(), __GO_ID__);
1362 updateTitle(name, figureId);
1363 } else if (property.equals(__GO_ID__)) {
1365 Integer figureId = ((Integer) value);
1366 String name = (String) GraphicController.getController().getProperty(getId(), __GO_NAME__);
1367 updateTitle(name, figureId);
1369 /** Update tool bar */
1370 setToolBar(ToolBarBuilder.buildToolBar(GRAPHICS_TOOLBAR_DESCRIPTOR, figureId));
1371 SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(getParentWindowId());
1372 parentWindow.addToolBar(getToolBar());
1374 /* Update callback */
1375 String closingCommand =
1376 "if (get_figure_handle(" + figureId + ") <> []) then"
1377 + " if (get(get_figure_handle(" + figureId + "), 'event_handler_enable') == 'on') then"
1378 + " execstr(get(get_figure_handle(" + figureId + "), 'event_handler')+'(" + figureId + ", -1, -1, -1000)', 'errcatch', 'm');"
1380 + " delete(get_figure_handle(" + figureId + "));"
1383 setCallback(ScilabCloseCallBack.create(getId(), closingCommand));
1384 /* Update menus callbacks */
1385 String[] children = (String[]) GraphicController.getController().getProperty(getId(), __GO_CHILDREN__);
1386 updateChildrenCallbacks(children, figureId);
1387 } else if (property.equals(__GO_SIZE__)) {
1388 Integer[] size = (Integer[]) value;
1389 SwingScilabWindow.allScilabWindows.get(parentWindowId).setDims(new Size(size[0], size[1]));
1390 } else if (property.equals(__GO_POSITION__)) {
1391 Integer[] position = (Integer[]) value;
1392 SwingScilabWindow.allScilabWindows.get(parentWindowId).setPosition(new Position(position[0], position[1]));
1393 } else if (property.equals(__GO_AXES_SIZE__)) {
1394 Integer[] axesSize = (Integer[]) value;
1395 Dimension oldAxesSize = getContentPane().getSize();
1397 ((oldAxesSize.getWidth() != axesSize[0]) || (oldAxesSize.getHeight() != axesSize[1]))
1398 && ((Boolean) GraphicController.getController().getProperty(getId(), __GO_AUTORESIZE__))
1400 // TODO manage tabs when there are docked (do not change the window size if more than one tab docked)
1401 int deltaX = axesSize[0] - (int) oldAxesSize.getWidth();
1402 int deltaY = axesSize[1] - (int) oldAxesSize.getHeight();
1403 Size parentWindowSize = SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
1404 SwingScilabWindow.allScilabWindows.get(parentWindowId).setDims(
1405 new Size(parentWindowSize.getWidth() + deltaX, parentWindowSize.getHeight() + deltaY));
1407 } else if (property.equals(__GO_INFO_MESSAGE__)) {
1408 getInfoBar().setText((String) value);
1409 } else if (property.equals(__GO_EVENTHANDLER_ENABLE__)) {
1410 Boolean enabled = (Boolean) GraphicController.getController().getProperty(getId(), __GO_EVENTHANDLER_ENABLE__);
1411 setEventHandlerEnabled(enabled);
1412 } else if (property.equals(__GO_EVENTHANDLER_NAME__)) {
1413 String eventHandlerName = (String) GraphicController.getController().getProperty(getId(), __GO_EVENTHANDLER_NAME__);
1414 setEventHandler(eventHandlerName);
1419 * Update the menus callbacks when they are linked to the figure ID
1420 * @param children the children UID
1421 * @param parentFigureId the figure ID
1423 private void updateChildrenCallbacks(String[] children, int parentFigureId) {
1424 for (int kChild = 0; kChild < children.length; kChild++) {
1425 String childType = (String) GraphicController.getController().getProperty(children[kChild], __GO_TYPE__);
1426 if (childType.equals(__GO_UIMENU__)
1427 || childType.equals(__GO_UIPARENTMENU__)
1428 || childType.equals(__GO_UICHILDMENU__)
1429 || childType.equals(__GO_UICHECKEDMENU__)) {
1430 String cb = (String) GraphicController.getController().getProperty(children[kChild], __GO_CALLBACK__);
1431 SwingView.getFromId(children[kChild]).update(__GO_CALLBACK__, replaceFigureID(cb, parentFigureId));
1432 String[] menuChildren = (String[]) GraphicController.getController().getProperty(children[kChild], __GO_CHILDREN__);
1433 updateChildrenCallbacks(menuChildren, parentFigureId);
1439 * Replace pattern [SCILAB_FIGURE_ID] by the figure index
1440 * @param initialString string read in XML file
1441 * @param parentFigureId the figure ID
1442 * @return callback string
1444 private String replaceFigureID(String initialString, Integer parentFigureId) {
1445 return initialString.replaceAll("\\[SCILAB_FIGURE_ID\\]", Integer.toString(parentFigureId));
1449 * Update the title of the Tab
1450 * @param figureName figure_name property
1451 * @param figureId figure_id property
1453 private void updateTitle(String figureName, Integer figureId) {
1454 if ((figureName != null) && (figureId != null)) {
1455 String figureTitle = figureName.replaceFirst("%d", figureId.toString());
1456 setName(figureTitle);
1463 * @see org.scilab.modules.gui.SwingViewObject#getId()
1465 public String getId() {
1472 * @see org.scilab.modules.gui.SwingViewObject#setId(java.lang.String)
1474 public void setId(String id) {
1479 * Turn on event handling.
1481 private void enableEventHandler() {
1482 contentCanvas.addEventHandlerKeyListener(eventHandler);
1483 contentCanvas.addEventHandlerMouseListener(eventHandler);
1484 contentCanvas.addEventHandlerMouseMotionListener(eventHandler);
1488 * Turn off event handling.
1490 private void disableEventHandler() {
1491 if (eventHandler != null) {
1492 contentCanvas.removeEventHandlerKeyListener(eventHandler);
1493 contentCanvas.removeEventHandlerMouseListener(eventHandler);
1494 contentCanvas.removeEventHandlerMouseMotionListener(eventHandler);