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
7 * Copyright (C) 2014 - Scilab Enterprises - Bruno JOFRET
9 * This file must be used under the terms of the CeCILL.
10 * This source file is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at
13 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
17 package org.scilab.modules.gui.bridge.tab;
19 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AUTORESIZE__;
20 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES_SIZE__;
21 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CLOSEREQUESTFCN__;
22 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
23 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_SIZE__;
25 import java.awt.Color;
26 import java.awt.Component;
27 import java.awt.Container;
28 import java.awt.Dimension;
29 import java.awt.Graphics;
30 import java.awt.Image;
31 import java.awt.event.ComponentEvent;
32 import java.awt.event.ComponentListener;
33 import java.awt.event.FocusEvent;
34 import java.awt.event.FocusListener;
35 import java.awt.event.HierarchyBoundsListener;
36 import java.awt.event.HierarchyEvent;
37 import java.awt.event.KeyEvent;
38 import java.awt.event.KeyListener;
39 import java.lang.reflect.InvocationTargetException;
40 import java.util.Iterator;
41 import java.util.List;
42 import java.util.ListIterator;
44 import javax.swing.Action;
45 import javax.swing.ImageIcon;
46 import javax.swing.JLayeredPane;
47 import javax.swing.JTextPane;
48 import javax.swing.KeyStroke;
49 import javax.swing.SwingUtilities;
51 import org.flexdock.docking.DockingConstants;
52 import org.flexdock.docking.DockingManager;
53 import org.flexdock.docking.DockingPort;
54 import org.flexdock.docking.activation.ActiveDockableTracker;
55 import org.flexdock.docking.event.DockingEvent;
56 import org.flexdock.docking.props.PropertyChangeListenerFactory;
57 import org.flexdock.view.Titlebar;
58 import org.flexdock.view.View;
59 import org.scilab.modules.action_binding.InterpreterManagement;
60 import org.scilab.modules.commons.ScilabConstants;
61 import org.scilab.modules.commons.gui.FindIconHelper;
62 import org.scilab.modules.graphic_objects.figure.Figure;
63 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
64 import org.scilab.modules.gui.SwingViewObject;
65 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvas;
66 import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
67 import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
68 import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
69 import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
70 import org.scilab.modules.gui.bridge.frame.SwingScilabScrollableFrame;
71 import org.scilab.modules.gui.bridge.helpbrowser.SwingScilabHelpBrowser;
72 import org.scilab.modules.gui.bridge.label.SwingScilabLabel;
73 import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
74 import org.scilab.modules.gui.bridge.menubar.SwingScilabMenuBar;
75 import org.scilab.modules.gui.bridge.popupmenu.SwingScilabPopupMenu;
76 import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
77 import org.scilab.modules.gui.bridge.radiobutton.SwingScilabRadioButton;
78 import org.scilab.modules.gui.bridge.slider.SwingScilabScroll;
79 import org.scilab.modules.gui.bridge.tree.SwingScilabTree;
80 import org.scilab.modules.gui.bridge.uidisplaytree.SwingScilabUiDisplayTree;
81 import org.scilab.modules.gui.bridge.uiimage.SwingScilabUiImage;
82 import org.scilab.modules.gui.bridge.uitable.SwingScilabUiTable;
83 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
84 import org.scilab.modules.gui.canvas.Canvas;
85 import org.scilab.modules.gui.checkbox.CheckBox;
86 import org.scilab.modules.gui.console.Console;
87 import org.scilab.modules.gui.console.ScilabConsole;
88 import org.scilab.modules.gui.dockable.Dockable;
89 import org.scilab.modules.gui.editbox.EditBox;
90 import org.scilab.modules.gui.editor.EditorEventListener;
91 import org.scilab.modules.gui.events.GlobalEventWatcher;
92 import org.scilab.modules.gui.events.ScilabEventListener;
93 import org.scilab.modules.gui.events.callback.CommonCallBack;
94 import org.scilab.modules.gui.frame.Frame;
95 import org.scilab.modules.gui.frame.SimpleFrame;
96 import org.scilab.modules.gui.helpbrowser.HelpBrowser;
97 import org.scilab.modules.gui.label.Label;
98 import org.scilab.modules.gui.listbox.ListBox;
99 import org.scilab.modules.gui.menubar.MenuBar;
100 import org.scilab.modules.gui.popupmenu.PopupMenu;
101 import org.scilab.modules.gui.pushbutton.PushButton;
102 import org.scilab.modules.gui.radiobutton.RadioButton;
103 import org.scilab.modules.gui.slider.Slider;
104 import org.scilab.modules.gui.tab.SimpleTab;
105 import org.scilab.modules.gui.textbox.TextBox;
106 import org.scilab.modules.gui.toolbar.ToolBar;
107 import org.scilab.modules.gui.tree.Tree;
108 import org.scilab.modules.gui.uidisplaytree.UiDisplayTree;
109 import org.scilab.modules.gui.uitable.UiTable;
110 import org.scilab.modules.gui.utils.BarUpdater;
111 import org.scilab.modules.gui.utils.ClosingOperationsManager;
112 import org.scilab.modules.gui.utils.Position;
113 import org.scilab.modules.gui.utils.SciClosingAction;
114 import org.scilab.modules.gui.utils.SciHelpOnComponentAction;
115 import org.scilab.modules.gui.utils.SciUndockingAction;
116 import org.scilab.modules.gui.utils.Size;
119 * Swing implementation for Scilab tabs in GUIs
120 * This implementation uses FlexDock package
121 * @author Bruno JOFRET
122 * @author Vincent COUVERT
123 * @author Marouane BEN JELLOUL
124 * @author Jean-Baptiste SILVY
127 public class SwingScilabDockablePanel extends View implements SimpleTab, FocusListener, KeyListener, SwingScilabPanel {
131 private static final Image SCILAB_ICON = new ImageIcon(FindIconHelper.findIcon("scilab", "256x256")).getImage();
133 private static final long serialVersionUID = 1L;
135 private static final String UNDOCK = "undock";
136 private static final String HELP = "help";
140 private boolean eventEnabled = false;
143 PropertyChangeListenerFactory.addFactory(new BarUpdater.UpdateBarFactory());
146 private String parentWindowId;
147 private MenuBar menuBar;
148 private ToolBar toolBar;
149 private TextBox infoBar;
150 private String helpID;
151 private boolean paintEnable = true;
153 /** Contains the canvas and widgets */
154 private JLayeredPane uiContentPane;
155 private JLayeredPane layerdPane;
157 /** Scroll the axes */
158 private SwingScilabScrollPane scrolling;
162 private Action closeAction;
164 /** The listener for event handling */
165 private ScilabEventListener eventHandler;
166 private EditorEventListener editorEventHandler = null;
168 /** A reference to the canvas used for event handling management */
169 private SwingScilabCanvas contentCanvas = null;
173 * @param name the name of the tab
174 * @param uuid an uuid to identify the tab
176 public SwingScilabDockablePanel(String name, String uuid) {
177 super(uuid, name, name);
178 //This button is "overloaded" when we add a callback
179 //this.addAction(DockingConstants.CLOSE_ACTION);
180 // Removed because make JOGL crash when "Unpin"
181 //this.addAction(DockingConstants.PIN_ACTION);
182 this.addAction(DockingConstants.ACTIVE_WINDOW);
184 // no need for an axes
186 uiContentPane = null;
189 this.setVisible(true);
192 getTitlebar().addFocusListener(this);
193 addFocusListener(this);
196 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("shift F6"), ACTION_TOGGLE_PREVIOUS);
200 * Create a graphic tab used to display a figure with 3D graphics and/or UIcontrols
201 * @param name name of the tab
202 * @param figureId id of the displayed figure
204 public SwingScilabDockablePanel(String name, int figureId) {
205 super(name, name, name);
207 // This button is "overloaded" when we add a callback
208 //this.addAction(DockingConstants.CLOSE_ACTION);
209 // Removed because make JOGL crash when "Unpin"
210 //this.addAction(DockingConstants.PIN_ACTION);
211 this.addAction(DockingConstants.ACTIVE_WINDOW);
213 // create the panel in which all the uiobjects will lie.
214 //contentPane = new SwingScilabAxes(figureId);
216 // add it inside a JSCrollPane
217 //scrolling = new SwingScilabScrollPane(contentPane);
218 //scrolling.setBackground(1, 0, 0);
219 // put in in the back of the tab
220 //setContentPane(scrolling.getAsContainer());
222 this.setVisible(true);
225 getTitlebar().addFocusListener(this);
226 addFocusListener(this);
229 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("shift F6"), ACTION_TOGGLE_PREVIOUS);
234 * @param name the name of the tab (used to identify it)
236 public SwingScilabDockablePanel(String name) {
241 * Set the associated help page
242 * @param helpID the xml id of the associated help page
244 public void setAssociatedXMLIDForHelp(String helpID) {
245 this.helpID = helpID;
249 * Get the associated help page
250 * @return the xml id of the associated help page
252 public String getAssociatedXMLIDForHelp() {
256 public static void removeActions(SwingScilabDockablePanel tab) {
257 tab.setActionBlocked(DockingConstants.CLOSE_ACTION, true);
258 tab.setActionBlocked(UNDOCK, true);
259 if (tab.getTitlebar() != null) {
260 tab.getTitlebar().revalidate();
264 public static void addActions(SwingScilabDockablePanel tab) {
265 tab.setActionBlocked(DockingConstants.CLOSE_ACTION, false);
266 tab.setActionBlocked(UNDOCK, false);
267 tab.getTitlebar().revalidate();
270 public SwingScilabDockablePanel(String figureTitle, int figureId, final Figure figure) {
271 this(figureTitle, figureId);
273 //SwingScilabCanvas canvas = new SwingScilabCanvas(figureId, figure);
274 //contentCanvas = canvas;
276 editorEventHandler = new EditorEventListener(figure.getIdentifier());
277 //contentCanvas.addEventHandlerKeyListener(editorEventHandler);
278 //contentCanvas.addEventHandlerMouseListener(editorEventHandler);
279 //contentCanvas.addEventHandlerMouseMotionListener(editorEventHandler);
281 layerdPane = new JLayeredPane();
282 layerdPane.setLayout(null);
283 layerdPane.setBorder(null);
284 //layerdPane.add(canvas, JLayeredPane.FRAME_CONTENT_LAYER);
285 uiContentPane = new JLayeredPane();
286 uiContentPane.setOpaque(true);
287 uiContentPane.setLayout(null);
288 uiContentPane.setBorder(null);
289 layerdPane.add(uiContentPane, JLayeredPane.DEFAULT_LAYER + 1, 0);
291 scrolling = new SwingScilabScrollPane(layerdPane, uiContentPane, figure);
292 //scrolling.setCanvas(canvas);
294 //contentCanvas.addKeyListener(this);
296 setContentPane(scrolling.getAsContainer());
297 //setContentPane(uiContentPane);
298 //canvas.setVisible(true);
299 uiContentPane.setVisible(true);
301 /* Manage figure_position property */
302 addHierarchyBoundsListener(new HierarchyBoundsListener() {
303 public void ancestorResized(HierarchyEvent arg0) {
306 public void ancestorMoved(HierarchyEvent e) {
307 if (e.getChanged() instanceof SwingScilabWindow) {
308 Position parentPosition = SwingScilabWindow.allScilabWindows.get(parentWindowId).getPosition();
309 Integer[] newPosition = new Integer[] {parentPosition.getX(), parentPosition.getY()};
310 GraphicController.getController().setProperty(id, __GO_POSITION__, newPosition);
315 /* Manage figure_size property */
316 addComponentListener(new ComponentListener() {
318 public void componentShown(ComponentEvent arg0) {
321 public void componentResized(ComponentEvent arg0) {
323 /* Update the figure_size property */
324 Size parentSize = SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
325 Integer[] newSize = new Integer[] {parentSize.getWidth(), parentSize.getHeight()};
327 GraphicController.getController().setProperty(id, __GO_SIZE__, newSize);
329 Boolean autoreSize = (Boolean) GraphicController.getController().getProperty(id, __GO_AUTORESIZE__);
331 if (autoreSize != null && autoreSize) {
332 /* Update the axes_size property */
333 Integer[] newAxesSize = new Integer[] {getContentPane().getWidth(), getContentPane().getHeight()};
334 GraphicController.getController().setProperty(id, __GO_AXES_SIZE__, newAxesSize);
338 public void componentMoved(ComponentEvent arg0) {
341 public void componentHidden(ComponentEvent arg0) {
345 /* Manage closerequestfcn */
346 ClosingOperationsManager.registerClosingOperation(SwingScilabDockablePanel.this, new ClosingOperationsManager.ClosingOperation() {
348 public int canClose() {
349 String closeRequestFcn = (String) GraphicController.getController().getProperty(getId(), __GO_CLOSEREQUESTFCN__);
350 if (!closeRequestFcn.equals("")) {
351 String closeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;"
352 + "gcbo = getcallbackobject(" + getId() + ");"
353 + closeRequestFcn + ";fire_closing_finished();"
354 + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
355 InterpreterManagement.putCommandInScilabQueue(closeCommand);
358 closeAction.actionPerformed(null);
363 public void destroy() {
366 public String askForClosing(final List<SwingScilabDockablePanel> list) {
371 public void updateDependencies(List<SwingScilabDockablePanel> list, ListIterator<SwingScilabDockablePanel> it) {
375 ClosingOperationsManager.addDependencyWithRoot(this);
379 * @param e the FocusEvent
382 public void focusGained(FocusEvent e) {
383 //ActiveDockableTracker.requestDockableActivation(this);
384 if (contentPane != null) {
385 contentPane.requestFocus();
386 } else if (getContentPane() != null) {
387 getContentPane().requestFocus();
389 SwingScilabDockablePanel.this.requestFocusInWindow();
394 * Call when the tab restoration is ended.
396 public void endedRestoration() { }
399 * @return the window icon associated with this tab
401 public Image getWindowIcon() {
410 * @param icon the window icon associated with this tab
412 public void setWindowIcon(Image icon) {
417 * @param iconName window icon associated with this tab
419 public void setWindowIcon(String iconName) {
420 setWindowIcon(new ImageIcon(FindIconHelper.findIcon(iconName, "256x256")).getImage());
424 * @param e the FocusEvent
427 public void focusLost(FocusEvent e) { }
433 public void dockingComplete(DockingEvent evt) {
434 super.dockingComplete(evt);
436 DockingPort port = evt.getNewDockingPort();
437 SwingScilabWindow win = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, (Component) port);
438 Iterator iter = port.getDockables().iterator();
440 if (port.getDockables().size() > 1) {
441 while (iter.hasNext()) {
442 Object d = iter.next();
443 if (d instanceof SwingScilabDockablePanel) {
444 SwingScilabDockablePanel view = (SwingScilabDockablePanel) d;
453 setParentWindowId(win.getId());
456 SwingUtilities.invokeLater(new Runnable() {
458 if (getParentWindow() != null) {
459 setParentWindowId(getParentWindow().getId());
461 System.err.println("No window for tab:" + SwingScilabDockablePanel.this.getClass().getName() + " after docking complete");
469 * Sets the Name of a swing Scilab tab
470 * @param newTabName the Name of the tab
471 * @see org.scilab.modules.gui.tab.ScilabTab#setName(String)
474 public void setName(String newTabName) {
475 setTitle(newTabName, true);
476 getTitlePane().repaint();
477 SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this).setName(newTabName);
481 * @return the UUID of the parent window
483 public String getParentWindowUUID() {
484 return ((SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this)).getUUID();
488 * @return the UUID of the parent window
490 public SwingScilabWindow getParentWindow() {
491 return (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this);
495 * Gets the title of a swing Scilab tab
496 * @return the title of the tab
497 * @see org.scilab.modules.gui.tab.ScilabTab#getName()
500 public String getName() {
501 return this.getTitle();
505 * Paint immediately this component
507 public void paintImmediately() {
509 paintImmediately(0, 0, getWidth(), getHeight());
513 * Draws a swing Scilab tab
514 * @see org.scilab.modules.gui.uielement.UIElement#draw()
518 if (SwingUtilities.isEventDispatchThread()) {
523 SwingUtilities.invokeAndWait(new Runnable() {
530 } catch (InterruptedException e) {
532 } catch (InvocationTargetException e) {
540 * Gets the dimensions (width and height) of a swing Scilab tab
541 * @return the dimensions of the tab
542 * @see org.scilab.modules.gui.uielement.UIElement#getDims()
545 public Size getDims() {
546 return new Size(this.getSize().width, this.getSize().height);
550 * Get the size for the axes
551 * @return size of the axes in pixels
554 public Size getAxesSize() {
555 return new Size(contentPane.getWidth(), contentPane.getHeight());
559 * @param newSize new size to set for the axes
562 public void setAxesSize(Size newSize) {
563 contentPane.setSize(new Dimension(newSize.getWidth(), newSize.getHeight()));
564 uiContentPane.setSize(new Dimension(newSize.getWidth(), newSize.getHeight()));
568 * Gets the position (X-coordinate and Y-coordinate) of a swing Scilab tab
569 * @return the position of the tab
570 * @see org.scilab.modules.gui.uielement.UIElement#getPosition()
573 public Position getPosition() {
574 return new Position(this.getX(), this.getY());
578 * Sets the dimensions (width and height) of a swing Scilab tab
579 * @param newSize the dimensions we want to set to the tab
580 * @see org.scilab.modules.gui.uielement.UIElement#setDims(org.scilab.modules.gui.utils.Size)
583 public void setDims(Size newSize) {
584 this.setSize(newSize.getWidth(), newSize.getHeight());
588 * Sets the position (X-coordinate and Y-coordinate) of a swing Scilab tab
589 * @param newPosition the position we want to set to the tab
590 * @see org.scilab.modules.gui.uielement.UIElement#setPosition(org.scilab.modules.gui.utils.Position)
593 public void setPosition(Position newPosition) {
594 this.setLocation(newPosition.getX(), newPosition.getY());
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
603 public int addMember(Canvas member) {
608 * We want to be able to remove directly a Canvas from a Tab.
609 * @param member canvas to remove
612 public void removeMember(Canvas member) {
616 * Add a SwingViewObject (from SwingView.java) to container and returns its index
617 * @param member the member to add
619 public void addMember(SwingViewObject member) {
620 if (member instanceof SwingScilabAxes) {
621 if (contentCanvas == null) {
622 contentCanvas = new SwingScilabCanvas((Figure) GraphicController.getController().getObjectFromId(((SwingScilabAxes) member).getFigureId()));
623 contentCanvas.addEventHandlerKeyListener(editorEventHandler);
624 contentCanvas.addEventHandlerMouseListener(editorEventHandler);
625 contentCanvas.addEventHandlerMouseMotionListener(editorEventHandler);
627 layerdPane.add(contentCanvas, JLayeredPane.FRAME_CONTENT_LAYER);
629 scrolling.setCanvas(contentCanvas);
630 contentCanvas.addKeyListener(this);
635 SwingScilabCommonPanel.addMember(this, member);
639 * Remove a SwingViewObject (from SwingView.java)
640 * @param member the member to remove
642 public void removeMember(SwingViewObject member) {
643 SwingScilabCommonPanel.removeMember(this, 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
652 public int addMember(Console member) {
653 return this.addMember((SwingScilabConsole) member.getAsSimpleConsole());
657 * Add a member (dockable element) to container and returns its index
658 * @param member the member to add
659 * @return index of member in ArrayList
661 private int addMember(SwingScilabConsole member) {
662 // replace the current content pane
663 this.setContentPane(member);
664 return this.getComponentZOrder(member);
668 * Add a member (dockable element) to container and returns its index
669 * @param member the member to add
670 * @return index of member in ArrayList
673 public int addMember(HelpBrowser member) {
674 return this.addMember((SwingScilabHelpBrowser) member.getAsSimpleHelpBrowser());
678 * Add a member (dockable element) to container and returns its index
679 * @param member the member to add
680 * @return index of member in ArrayList
682 private int addMember(SwingScilabHelpBrowser member) {
683 // replace the current content pane
684 this.setContentPane(member);
685 return this.getComponentZOrder(member);
689 * Add a member (dockable element) to container and returns its index
690 * @param member the member to add
691 * @return index of member in ArrayList
694 public int addMember(Frame member) {
695 SimpleFrame frame = member.getAsSimpleFrame();
696 if (frame instanceof SwingScilabFrame) {
697 return this.addMember((SwingScilabFrame) member.getAsSimpleFrame());
699 return this.addMember((SwingScilabScrollableFrame) member.getAsSimpleFrame());
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
708 private int addMember(SwingScilabScrollableFrame member) {
712 private int addMember(SwingScilabFrame member) {
717 * Remove a Frame from its container
718 * @param member the Frame to remove
721 public void removeMember(Frame member) {
722 SimpleFrame frame = member.getAsSimpleFrame();
723 if (frame instanceof SwingScilabFrame) {
724 this.removeMember((SwingScilabFrame) member.getAsSimpleFrame());
726 this.removeMember((SwingScilabScrollableFrame) member.getAsSimpleFrame());
731 * Remove a Frame from its container
732 * @param member the Frame to remove
734 private void removeMember(SwingScilabScrollableFrame member) {
737 private void removeMember(SwingScilabFrame member) {
741 * Add a member (dockable element) to container and returns its index
742 * @param member the member to add
743 * @return index of member in ArrayList
746 public int addMember(PushButton member) {
747 return this.addMember((SwingScilabPushButton) member.getAsSimplePushButton());
751 * Add a member (dockable element) to container and returns its index
752 * @param member the member to add
753 * @return index of member in ArrayList
755 private int addMember(SwingScilabPushButton member) {
761 * Remove a PushButton from its container
762 * @param member the PushButton to remove
765 public void removeMember(PushButton member) {
766 this.removeMember((SwingScilabPushButton) member.getAsSimplePushButton());
770 * Remove a PushButton from its container
771 * @param member the PushButton to remove
773 private void removeMember(SwingScilabPushButton member) {
774 contentPane.remove(member);
778 * Add a member (dockable element) to container and returns its index
779 * @param member the member to add
780 * @return index of member in ArrayList
783 public int addMember(EditBox member) {
784 return this.addMember((SwingScilabEditBox) member.getAsSimpleEditBox());
788 * Add a member (dockable element) to container and returns its index
789 * @param member the member to add
790 * @return index of member in ArrayList
792 private int addMember(SwingScilabEditBox member) {
797 * Remove an EditBox from its container
798 * @param member the EditBox to remove
801 public void removeMember(EditBox member) {
802 this.removeMember((SwingScilabEditBox) member.getAsSimpleEditBox());
806 * Remove an EditBox from its container
807 * @param member the EditBox to remove
809 private void removeMember(SwingScilabEditBox member) {
813 * Add a member (dockable element) to container and returns its index
814 * @param member the member to add
815 * @return index of member in ArrayList
818 public int addMember(Label member) {
819 return this.addMember((SwingScilabLabel) member.getAsSimpleLabel());
823 * Add a member (dockable element) to container and returns its index
824 * @param member the member to add
825 * @return index of member in ArrayList
827 private int addMember(SwingScilabLabel member) {
832 * Remove a Label from its container
833 * @param member the Label to remove
836 public void removeMember(Label member) {
837 this.removeMember((SwingScilabLabel) member.getAsSimpleLabel());
841 * Remove a Label from its container
842 * @param member the Label to remove
844 private void removeMember(SwingScilabLabel 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
853 public int addMember(CheckBox member) {
854 return this.addMember((SwingScilabCheckBox) member.getAsSimpleCheckBox());
858 * Add a member (dockable element) to container and returns its index
859 * @param member the member to add
860 * @return index of member in ArrayList
862 private int addMember(SwingScilabCheckBox member) {
867 * Remove a CheckBox from its container
868 * @param member the CheckBox to remove
871 public void removeMember(CheckBox member) {
872 this.removeMember((SwingScilabCheckBox) member.getAsSimpleCheckBox());
876 * Remove a CheckBox from its container
877 * @param member the CheckBox to remove
879 private void removeMember(SwingScilabCheckBox member) {
883 * Add a member (dockable element) to container and returns its index
884 * @param member the member to add
885 * @return index of member in ArrayList
888 public int addMember(RadioButton member) {
889 return this.addMember((SwingScilabRadioButton) member.getAsSimpleRadioButton());
893 * Add a member (dockable element) to container and returns its index
894 * @param member the member to add
895 * @return index of member in ArrayList
897 private int addMember(SwingScilabRadioButton member) {
902 * Remove a RadioButton from its container
903 * @param member the RadioButton to remove
906 public void removeMember(RadioButton member) {
907 this.removeMember((SwingScilabRadioButton) member.getAsSimpleRadioButton());
911 * Remove a RadioButton from its container
912 * @param member the RadioButton to remove
914 private void removeMember(SwingScilabRadioButton member) {
918 * Add a member (dockable element) to container and returns its index
919 * @param member the member to add
920 * @return index of member in ArrayList
922 private int addMember(SwingScilabUiImage member) {
927 * Remove a Image from its container
928 * @param member the Image to remove
930 private void removeMember(SwingScilabUiImage member) {
934 * Add a member (dockable element) to container and returns its index
935 * @param member the member to add
936 * @return index of member in ArrayList
938 public int addMember(UiDisplayTree member) {
939 return this.addMember((SwingScilabUiDisplayTree) member.getAsSimpleUiDisplayTree());
943 * Add a member (dockable element) to container and returns its index
944 * @param member the member to add
945 * @return index of member in ArrayList
947 private int addMember(SwingScilabUiDisplayTree member) {
952 * Remove a Tree from its container
953 * @param member the Tree to remove
955 public void removeMember(UiDisplayTree member) {
956 this.removeMember((SwingScilabUiDisplayTree) member.getAsSimpleUiDisplayTree());
960 * Remove a Tree from its container
961 * @param member the Tree to remove
963 private void removeMember(SwingScilabUiDisplayTree member) {
967 * Add a member (dockable element) to container and returns its index
968 * @param member the member to add
969 * @return index of member in ArrayList
971 public int addMember(UiTable member) {
972 return this.addMember((SwingScilabUiTable) member.getAsSimpleUiTable());
976 * Add a member (dockable element) to container and returns its index
977 * @param member the member to add
978 * @return index of member in ArrayList
980 private int addMember(SwingScilabUiTable member) {
985 * Remove a UiTable from its container
986 * @param member the UiTable to remove
988 public void removeMember(UiTable member) {
989 this.removeMember((SwingScilabUiTable) member.getAsSimpleUiTable());
993 * Remove a UiTable from its container
994 * @param member the UiTable to remove
996 private void removeMember(SwingScilabUiTable member) {
1000 * Add a member (dockable element) to container and returns its index
1001 * @param member the member to add
1002 * @return index of member in ArrayList
1004 public int addMember(Slider member) {
1005 return this.addMember((SwingScilabScroll) member.getAsSimpleSlider());
1009 * Add a member (dockable element) to container and returns its index
1010 * @param member the member to add
1011 * @return index of member in ArrayList
1013 private int addMember(SwingScilabScroll member) {
1018 * Remove a Slider from its container
1019 * @param member the Slider to remove
1022 public void removeMember(Slider member) {
1023 this.removeMember((SwingScilabScroll) member.getAsSimpleSlider());
1027 * Remove a Slider from its container
1028 * @param member the Slider to remove
1030 private void removeMember(SwingScilabScroll member) {
1034 * Add a member (dockable element) to container and returns its index
1035 * @param member the member to add
1036 * @return index of member in ArrayList
1039 public int addMember(ListBox member) {
1040 return this.addMember((SwingScilabListBox) member.getAsSimpleListBox());
1044 * Add a member (dockable element) to container and returns its index
1045 * @param member the member to add
1046 * @return index of member in ArrayList
1048 private int addMember(SwingScilabListBox member) {
1053 * Remove a ListBox from its container
1054 * @param member the ListBox to remove
1057 public void removeMember(ListBox member) {
1058 this.removeMember((SwingScilabListBox) member.getAsSimpleListBox());
1062 * Remove a ListBox from its container
1063 * @param member the ListBox to remove
1065 private void removeMember(SwingScilabListBox member) {
1069 * Add a member (dockable element) to container and returns its index
1070 * @param member the member to add
1071 * @return index of member in ArrayList
1074 public int addMember(PopupMenu member) {
1075 return this.addMember((SwingScilabPopupMenu) member.getAsSimplePopupMenu());
1079 * Add a member (dockable element) to container and returns its index
1080 * @param member the member to add
1081 * @return index of member in ArrayList
1083 private int addMember(SwingScilabPopupMenu member) {
1088 * Remove a PopupMenu from its container
1089 * @param member the PopupMenu to remove
1092 public void removeMember(PopupMenu member) {
1093 this.removeMember((SwingScilabPopupMenu) member.getAsSimplePopupMenu());
1097 * Remove a PopupMenu from its container
1098 * @param member the PopupMenu to remove
1100 private void removeMember(SwingScilabPopupMenu member) {
1104 * Add a Tree member (dockable element) to container and returns its index
1105 * @param member the member to add
1106 * @return index of member in ArrayList
1109 public int addMember(Tree member) {
1110 return this.addMember((SwingScilabTree) member.getAsSimpleTree());
1114 * Add a Tree member (dockable element) to container and returns its index
1115 * @param member the member to add
1116 * @return index of member in ArrayList
1118 public int addMember(SwingScilabTree member) {
1123 * Add a Tree member (dockable element) to container and returns its index
1124 * @param member the member to add
1125 * @return index of member in ArrayList
1127 public int addTree(SwingScilabTree member) {
1128 this.setContentPane(member.getAsComponent());
1129 return this.getComponentZOrder(member.getAsComponent());
1133 * Remove a PopupMenu from its container
1134 * @param member the PopupMenu to remove
1137 public void removeMember(Tree member) {
1138 this.removeMember((SwingScilabTree) member.getAsSimpleTree());
1142 * Remove a PopupMenu from its container
1143 * @param member the PopupMenu to remove
1145 private void removeMember(SwingScilabTree member) {
1149 * Add a member (dockable element) to container and returns its index
1150 * @param member the member to add
1151 * @return index of member in ArrayList
1153 public int addMember(Dockable member) {
1154 // TODO Auto-generated method stub
1159 * Get the current status of the Tab in its parent
1160 * @return true is the tab is the tab currently "on top" in its parent
1163 public boolean isCurrentTab() {
1164 // TODO should not always return TRUE
1169 * Get the parent window id for this tab
1170 * @return the id of the parent window
1173 public String getParentWindowId() {
1174 return this.parentWindowId;
1179 * @return the canvas
1181 public SwingScilabCanvas getContentCanvas() {
1182 return contentCanvas;
1186 * Set the parent window id for this tab
1187 * @param id the id of the parent window
1190 public void setParentWindowId(String id) {
1191 this.parentWindowId = id;
1195 * Setter for MenuBar
1196 * @param newMenuBar : the MenuBar to set.
1197 * @see org.scilab.modules.gui.tab.SimpleTab#setMenuBar(org.scilab.modules.gui.menubar.MenuBar)
1200 public void setMenuBar(MenuBar newMenuBar) {
1201 if (this.menuBar != newMenuBar) {
1202 if (this.menuBar != null) {
1203 ((SwingScilabMenuBar) this.menuBar.getAsSimpleMenuBar()).close();
1205 this.menuBar = newMenuBar;
1210 * Getter for MenuBar
1211 * @return MenuBar : the MenuBar associated to the Tab.
1212 * @see org.scilab.modules.gui.tab.SimpleTab#getMenuBar()
1215 public MenuBar getMenuBar() {
1216 return this.menuBar;
1220 * Setter for ToolBar
1221 * @param newToolBar : the ToolBar to set.
1222 * @see org.scilab.modules.gui.tab.SimpleTab#setToolBar(org.scilab.modules.gui.toolbar.ToolBar)
1225 public void setToolBar(ToolBar newToolBar) {
1226 this.toolBar = newToolBar;
1230 * Getter for ToolBar
1231 * @return ToolBar : the ToolBar associated to the Tab.
1232 * @see org.scilab.modules.gui.tab.SimpleTab#getToolBar()
1235 public ToolBar getToolBar() {
1236 return this.toolBar;
1240 * Setter for InfoBar
1241 * @param newInfoBar the InfoBar to set.
1244 public void setInfoBar(TextBox newInfoBar) {
1245 this.infoBar = newInfoBar;
1249 * Getter for InfoBar
1250 * @return the InfoBar associated to the Tab.
1253 public TextBox getInfoBar() {
1254 return this.infoBar;
1258 * Set the callback of the tab
1259 * @param callback the callback to set.
1262 public void setCallback(CommonCallBack callback) {
1264 if (closeAction != null) {
1265 this.getTitlebar().removeAction(closeAction);
1268 if (callback != null) {
1269 closeAction = new SciClosingAction(this, callback);
1271 closeAction = new SciClosingAction(this);
1274 closeAction.putValue(Action.NAME, DockingConstants.CLOSE_ACTION);
1275 ((Titlebar) getTitlePane()).removeAction(DockingConstants.CLOSE_ACTION);
1276 addAction(closeAction);
1279 SciUndockingAction undockAction = new SciUndockingAction(this);
1280 undockAction.putValue(Action.NAME, UNDOCK);
1281 ((Titlebar) getTitlePane()).removeAction(UNDOCK);
1282 addAction(undockAction);
1285 SciHelpOnComponentAction helpAction = new SciHelpOnComponentAction(this);
1286 helpAction.putValue(Action.NAME, HELP);
1287 ((Titlebar) getTitlePane()).removeAction(HELP);
1288 addAction(helpAction);
1292 * Set this tab as the current tab of its parent Window
1295 public void setCurrent() {
1296 ActiveDockableTracker.requestDockableActivation(this);
1300 * Set the background color of the tab.
1301 * @param red red channel of the color
1302 * @param green green channel
1303 * @param blue blue channel
1306 public void setBackground(double red, double green, double blue) {
1307 Color newColor = new Color((float) red, (float) green, (float) blue);
1308 uiContentPane.setBackground(newColor);
1309 scrolling.setBackground(red, green, blue);
1310 setBackground(newColor);
1314 * Get the part of the axes which is currently viewed
1315 * @return [x,y,w,h] array
1318 public int[] getViewingRegion() {
1319 return scrolling.getViewingRegion();
1323 * Specify a new viewport for the axes
1324 * For SwingScilabCanvas viewport can not be modified
1325 * since it match the parent tab size
1326 * @param posX X coordinate of upper left point of the viewport within the axes
1327 * @param posY Y coordinate of upper left point of the viewport within the axes
1328 * @param width width of the viewport
1329 * @param height height of the viewport
1332 public void setViewingRegion(int posX, int posY, int width, int height) {
1336 * Set the event handler of the Canvas
1337 * @param funName the name of the Scilab function to call
1339 public void setEventHandler(String funName) {
1340 disableEventHandler();
1341 eventHandler = new ScilabEventListener(funName, getId());
1343 editorEventHandler.setEnable(false);
1344 enableEventHandler();
1349 * Set the status of the event handler of the Canvas
1350 * @param status is true to set the event handler active
1352 public void setEventHandlerEnabled(boolean status) {
1353 if (status && eventEnabled) {
1358 editorEventHandler.setEnable(false);
1359 enableEventHandler();
1360 eventEnabled = true;
1362 editorEventHandler.setEnable(true);
1363 disableEventHandler();
1364 eventEnabled = false;
1369 * Specify whether the canvas should fit the parent tab size
1370 * (and consequently the scrollpane size) or not
1371 * @param onOrOff true to enable autoresize mode
1374 public void setAutoResizeMode(boolean onOrOff) {
1378 * @return whether the resize mode is on or off
1381 public boolean getAutoResizeMode() {
1386 * Close the tab and disable it.
1388 public void close() {
1389 if (getTitlePane() != null) {
1390 ((Titlebar) getTitlePane()).removeAction(DockingConstants.CLOSE_ACTION);
1391 ((Titlebar) getTitlePane()).removeAction(UNDOCK);
1392 ((Titlebar) getTitlePane()).removeAction(HELP);
1395 if (closeAction != null) {
1396 getTitlebar().removeAction(closeAction);
1397 if (closeAction instanceof SciClosingAction) {
1398 ((SciClosingAction) closeAction).clean();
1412 DockingManager.unregisterDockable((Component) this);
1414 // without this children canvas are not released.
1415 Container dummyContainer = new Container();
1416 this.setContentPane(dummyContainer);
1417 if (editorEventHandler != null) {
1418 editorEventHandler.onExit();
1422 public void disablePaint() {
1423 paintEnable = false;
1427 * Redefine paint children to be sure that AWT components are well painted.
1428 * @param g a Graphics
1431 public void paintChildren(Graphics g) {
1433 Component[] children = getComponents();
1434 for (int i = 0; i < children.length; i++) {
1435 // AWT children don't draw themselves automatically
1436 // so force their draw
1437 if (!children[i].isLightweight()) {
1438 children[i].paint(g);
1441 super.paintChildren(g);
1446 * Update the tab after a modification of its properties
1447 * @param property the property name
1448 * @param value the property value
1449 * @see org.scilab.modules.gui.SwingViewObject#update(java.lang.String, java.lang.Object)
1451 public void update(int property, Object value) {
1452 SwingScilabCommonPanel.update(this, property, value);
1458 * @see org.scilab.modules.gui.SwingViewObject#getId()
1460 public Integer getId() {
1467 * @see org.scilab.modules.gui.SwingViewObject#setId(java.lang.String)
1469 public void setId(Integer id) {
1474 * Turn on event handling.
1476 private void enableEventHandler() {
1477 if (contentCanvas != null) {
1478 contentCanvas.addEventHandlerKeyListener(eventHandler);
1479 contentCanvas.addEventHandlerMouseListener(eventHandler);
1480 contentCanvas.addEventHandlerMouseMotionListener(eventHandler);
1485 * Turn off event handling.
1487 private void disableEventHandler() {
1488 if (eventHandler != null && contentCanvas != null) {
1489 contentCanvas.removeEventHandlerKeyListener(eventHandler);
1490 contentCanvas.removeEventHandlerMouseListener(eventHandler);
1491 contentCanvas.removeEventHandlerMouseMotionListener(eventHandler);
1495 public void keyPressed(KeyEvent e) {
1499 public void keyReleased(KeyEvent e) {
1502 public void keyTyped(KeyEvent e) {
1503 if (ScilabConstants.isGUI() && (eventHandler == null || !eventEnabled) && !GlobalEventWatcher.isActivated() && !editorEventHandler.isDatatipEnable() && Character.isLetterOrDigit(e.getKeyChar())) {
1504 SwingScilabConsole console = (SwingScilabConsole) ScilabConsole.getConsole().getAsSimpleConsole();
1505 JTextPane input = (JTextPane) console.getConfiguration().getInputCommandView();
1506 input.requestFocus();
1507 SwingScilabWindow win = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, console);
1509 input.dispatchEvent(new KeyEvent(input, KeyEvent.KEY_TYPED, System.currentTimeMillis(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation()));
1513 public JLayeredPane getWidgetPane() {
1514 return uiContentPane;