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.graphic_objects.graphicObject.GraphicObjectProperties;
65 import org.scilab.modules.gui.SwingViewObject;
66 import org.scilab.modules.gui.SwingViewWidget;
67 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvas;
68 import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
69 import org.scilab.modules.gui.bridge.helpbrowser.SwingScilabHelpBrowser;
70 import org.scilab.modules.gui.bridge.menubar.SwingScilabMenuBar;
71 import org.scilab.modules.gui.bridge.tree.SwingScilabTree;
72 import org.scilab.modules.gui.bridge.uidisplaytree.SwingScilabUiDisplayTree;
73 import org.scilab.modules.gui.bridge.uitable.SwingScilabUiTable;
74 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
75 import org.scilab.modules.gui.canvas.Canvas;
76 import org.scilab.modules.gui.console.Console;
77 import org.scilab.modules.gui.console.ScilabConsole;
78 import org.scilab.modules.gui.dockable.Dockable;
79 import org.scilab.modules.gui.editor.EditorEventListener;
80 import org.scilab.modules.gui.events.GlobalEventWatcher;
81 import org.scilab.modules.gui.events.ScilabEventListener;
82 import org.scilab.modules.gui.events.callback.CommonCallBack;
83 import org.scilab.modules.gui.helpbrowser.HelpBrowser;
84 import org.scilab.modules.gui.menubar.MenuBar;
85 import org.scilab.modules.gui.tab.SimpleTab;
86 import org.scilab.modules.gui.textbox.TextBox;
87 import org.scilab.modules.gui.toolbar.ToolBar;
88 import org.scilab.modules.gui.tree.Tree;
89 import org.scilab.modules.gui.uidisplaytree.UiDisplayTree;
90 import org.scilab.modules.gui.utils.BarUpdater;
91 import org.scilab.modules.gui.utils.ClosingOperationsManager;
92 import org.scilab.modules.gui.utils.Position;
93 import org.scilab.modules.gui.utils.SciClosingAction;
94 import org.scilab.modules.gui.utils.SciHelpOnComponentAction;
95 import org.scilab.modules.gui.utils.SciUndockingAction;
96 import org.scilab.modules.gui.utils.Size;
97 import org.scilab.modules.gui.widget.Widget;
100 * Swing implementation for Scilab tabs in GUIs This implementation uses
102 * @author Bruno JOFRET
103 * @author Vincent COUVERT
104 * @author Marouane BEN JELLOUL
105 * @author Jean-Baptiste SILVY
108 public class SwingScilabDockablePanel extends View implements SimpleTab, FocusListener, KeyListener, SwingScilabPanel {
110 private static final Image SCILAB_ICON = new ImageIcon(FindIconHelper.findIcon("scilab", "256x256")).getImage();
112 private static final long serialVersionUID = 1L;
114 private static final String UNDOCK = "undock";
115 private static final String HELP = "help";
116 protected boolean hasLayout = false;
120 private boolean eventEnabled = false;
121 ComponentListener componentListener;
124 PropertyChangeListenerFactory.addFactory(new BarUpdater.UpdateBarFactory());
127 private String parentWindowId;
128 private MenuBar menuBar;
129 private ToolBar toolBar;
130 private TextBox infoBar;
131 private String helpID;
132 private boolean paintEnable = true;
134 /** Contains the canvas and widgets */
135 private JLayeredPane uiContentPane;
136 private JLayeredPane layeredPane;
138 /** Scroll the axes */
139 private SwingScilabScrollPane scrolling;
143 private Action closeAction;
145 /** The listener for event handling */
146 private ScilabEventListener eventHandler;
147 private EditorEventListener editorEventHandler = null;
149 /** A reference to the canvas used for event handling management */
150 private SwingScilabCanvas contentCanvas = null;
152 private Dimension deltaSize = null;
156 * @param name the name of the tab
157 * @param uuid an uuid to identify the tab
159 public SwingScilabDockablePanel(String name, String uuid) {
160 super(uuid, name, name);
161 //This button is "overloaded" when we add a callback
162 //this.addAction(DockingConstants.CLOSE_ACTION);
163 // Removed because make JOGL crash when "Unpin"
164 //this.addAction(DockingConstants.PIN_ACTION);
165 this.addAction(DockingConstants.ACTIVE_WINDOW);
167 // no need for an axes
169 uiContentPane = null;
172 this.setVisible(true);
174 getTitlebar().addFocusListener(this);
175 addFocusListener(this);
178 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("shift F6"), ACTION_TOGGLE_PREVIOUS);
182 * Create a graphic tab used to display a figure with 3D graphics and/or
184 * @param name name of the tab
185 * @param figureId id of the displayed figure
187 public SwingScilabDockablePanel(String name, int figureId) {
188 super(name, name, name);
190 // This button is "overloaded" when we add a callback
191 //this.addAction(DockingConstants.CLOSE_ACTION);
192 // Removed because make JOGL crash when "Unpin"
193 //this.addAction(DockingConstants.PIN_ACTION);
194 this.addAction(DockingConstants.ACTIVE_WINDOW);
196 // create the panel in which all the uiobjects will lie.
197 //contentPane = new SwingScilabAxes(figureId);
199 // add it inside a JSCrollPane
200 //scrolling = new SwingScilabScrollPane(contentPane);
201 //scrolling.setBackground(1, 0, 0);
202 // put in in the back of the tab
203 //setContentPane(scrolling.getAsContainer());
205 this.setVisible(true);
207 getTitlebar().addFocusListener(this);
208 addFocusListener(this);
211 getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("shift F6"), ACTION_TOGGLE_PREVIOUS);
216 * @param name the name of the tab (used to identify it)
218 public SwingScilabDockablePanel(String name) {
223 * Set the associated help page
224 * @param helpID the xml id of the associated help page
226 public void setAssociatedXMLIDForHelp(String helpID) {
227 this.helpID = helpID;
231 * Get the associated help page
232 * @return the xml id of the associated help page
234 public String getAssociatedXMLIDForHelp() {
238 public static void removeActions(SwingScilabDockablePanel tab) {
239 tab.setActionBlocked(DockingConstants.CLOSE_ACTION, true);
240 tab.setActionBlocked(UNDOCK, true);
241 if (tab.getTitlebar() != null) {
242 tab.getTitlebar().revalidate();
246 public static void addActions(SwingScilabDockablePanel tab) {
247 tab.setActionBlocked(DockingConstants.CLOSE_ACTION, false);
248 tab.setActionBlocked(UNDOCK, false);
249 tab.getTitlebar().revalidate();
252 public SwingScilabDockablePanel(String figureTitle, int figureId, final Figure figure) {
253 this(figureTitle, figureId);
255 //SwingScilabCanvas canvas = new SwingScilabCanvas(figureId, figure);
256 //contentCanvas = canvas;
258 editorEventHandler = new EditorEventListener(figure.getIdentifier());
260 layeredPane = new JLayeredPane();
261 layeredPane.setLayout(null);
262 layeredPane.setBorder(null);
263 layeredPane.setOpaque(true);
265 uiContentPane = new JLayeredPane();
266 uiContentPane.setOpaque(false);
267 uiContentPane.setLayout(null);
268 uiContentPane.setBorder(null);
270 layeredPane.add(uiContentPane, JLayeredPane.DEFAULT_LAYER + 1, 0);
271 scrolling = new SwingScilabScrollPane(layeredPane, uiContentPane, figure);
273 setContentPane(scrolling.getAsContainer());
275 uiContentPane.setVisible(true);
277 /* Manage figure_position property */
278 addHierarchyBoundsListener(new HierarchyBoundsListener() {
279 public void ancestorResized(HierarchyEvent arg0) {
282 public void ancestorMoved(HierarchyEvent e) {
283 if (e.getChanged() instanceof SwingScilabWindow) {
284 Position parentPosition = SwingScilabWindow.allScilabWindows.get(parentWindowId).getPosition();
285 Integer[] newPosition = new Integer[] { parentPosition.getX(), parentPosition.getY() };
286 GraphicController.getController().setProperty(id, __GO_POSITION__, newPosition);
291 /* Manage figure_size property */
292 componentListener = new ComponentListener() {
293 public void componentShown(ComponentEvent arg0) {
296 public void componentResized(ComponentEvent arg0) {
298 /* Update the figure_size property */
299 Size parentSize = SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
300 Integer[] newSize = new Integer[] { parentSize.getWidth(), parentSize.getHeight() };
302 GraphicController.getController().setProperty(id, __GO_SIZE__, newSize);
304 Boolean autoResize = (Boolean) GraphicController.getController().getProperty(id, __GO_AUTORESIZE__);
306 if (autoResize != null && autoResize) {
307 /* Update the axes_size property */
308 Integer[] newAxesSize = new Integer[] { getContentPane().getWidth(), getContentPane().getHeight() };
309 GraphicController.getController().setProperty(id, __GO_AXES_SIZE__, newAxesSize);
312 String resizeFcn = (String) GraphicController.getController().getProperty(id, GraphicObjectProperties.__GO_RESIZEFCN__);
313 if (resizeFcn != null && !resizeFcn.equals("")) {
314 String resizeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;" + "gcbo = getcallbackobject(" + id + ");" + resizeFcn
315 + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
316 InterpreterManagement.requestScilabExec(resizeCommand);
317 } else if (hasLayout == false) {
318 for (Component comp : getWidgetPane().getComponents()) {
319 if (comp instanceof Widget) {
320 Widget widget = (Widget) comp;
321 SwingViewObject obj = (SwingViewObject) comp;
322 SwingViewWidget.update(widget, __GO_POSITION__, GraphicController.getController().getProperty(obj.getId(), __GO_POSITION__));
328 public void componentMoved(ComponentEvent arg0) {
331 public void componentHidden(ComponentEvent arg0) {
335 addComponentListener(componentListener);
336 /* Manage closerequestfcn */
337 ClosingOperationsManager.registerClosingOperation(SwingScilabDockablePanel.this, new ClosingOperationsManager.ClosingOperation() {
339 public int canClose() {
340 String closeRequestFcn = (String) GraphicController.getController().getProperty(getId(), __GO_CLOSEREQUESTFCN__);
341 if (!closeRequestFcn.equals("")) {
342 String closeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;"
343 + "gcbo = getcallbackobject(" + getId() + ");"
344 + closeRequestFcn + ";fire_closing_finished();"
345 + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
346 InterpreterManagement.putCommandInScilabQueue(closeCommand);
349 closeAction.actionPerformed(null);
354 public void destroy() {
357 public String askForClosing(final List<SwingScilabDockablePanel> list) {
362 public void updateDependencies(List<SwingScilabDockablePanel> list, ListIterator<SwingScilabDockablePanel> it) {
366 ClosingOperationsManager.addDependencyWithRoot(this);
370 * @param e the FocusEvent
373 public void focusGained(FocusEvent e) {
374 //ActiveDockableTracker.requestDockableActivation(this);
375 if (contentPane != null) {
376 contentPane.requestFocus();
377 } else if (getContentPane() != null) {
378 getContentPane().requestFocus();
380 SwingScilabDockablePanel.this.requestFocusInWindow();
385 * Call when the tab restoration is ended.
387 public void endedRestoration() {
391 * @return the window icon associated with this tab
393 public Image getWindowIcon() {
402 * @param icon the window icon associated with this tab
404 public void setWindowIcon(Image icon) {
409 * @param iconName window icon associated with this tab
411 public void setWindowIcon(String iconName) {
412 setWindowIcon(new ImageIcon(FindIconHelper.findIcon(iconName, "256x256")).getImage());
416 * @param e the FocusEvent
419 public void focusLost(FocusEvent e) {
426 public void dockingComplete(DockingEvent evt) {
427 super.dockingComplete(evt);
429 DockingPort port = evt.getNewDockingPort();
430 SwingScilabWindow win = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, (Component) port);
431 Iterator iter = port.getDockables().iterator();
433 if (port.getDockables().size() > 1) {
434 while (iter.hasNext()) {
435 Object d = iter.next();
436 if (d instanceof SwingScilabDockablePanel) {
437 SwingScilabDockablePanel view = (SwingScilabDockablePanel) d;
446 setParentWindowId(win.getId());
449 SwingUtilities.invokeLater(new Runnable() {
451 if (getParentWindow() != null) {
452 setParentWindowId(getParentWindow().getId());
454 System.err.println("No window for tab:" + SwingScilabDockablePanel.this.getClass().getName() + " after docking complete");
462 * Sets the Name of a swing Scilab tab
463 * @param newTabName the Name of the tab
464 * @see org.scilab.modules.gui.tab.ScilabTab#setName(String)
467 public void setName(String newTabName) {
468 setTitle(newTabName, true);
469 getTitlePane().repaint();
470 SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this).setName(newTabName);
474 * @return the UUID of the parent window
476 public String getParentWindowUUID() {
477 return ((SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this)).getUUID();
481 * @return the UUID of the parent window
483 public SwingScilabWindow getParentWindow() {
484 return (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this);
488 * Gets the title of a swing Scilab tab
489 * @return the title of the tab
490 * @see org.scilab.modules.gui.tab.ScilabTab#getName()
493 public String getName() {
494 return this.getTitle();
498 * Paint immediately this component
500 public void paintImmediately() {
502 paintImmediately(0, 0, getWidth(), getHeight());
506 * Draws a swing Scilab tab
507 * @see org.scilab.modules.gui.uielement.UIElement#draw()
511 if (SwingUtilities.isEventDispatchThread()) {
516 SwingUtilities.invokeAndWait(new Runnable() {
523 } catch (InterruptedException e) {
525 } catch (InvocationTargetException e) {
533 * Gets the dimensions (width and height) of a swing Scilab tab
534 * @return the dimensions of the tab
535 * @see org.scilab.modules.gui.uielement.UIElement#getDims()
538 public Size getDims() {
539 return new Size(this.getSize().width, this.getSize().height);
543 * Get the size for the axes
544 * @return size of the axes in pixels
547 public Size getAxesSize() {
548 return new Size(contentPane.getWidth(), contentPane.getHeight());
552 * @param newSize new size to set for the axes
555 public void setAxesSize(Size newSize) {
556 contentPane.setSize(new Dimension(newSize.getWidth(), newSize.getHeight()));
557 uiContentPane.setSize(new Dimension(newSize.getWidth(), newSize.getHeight()));
561 * Gets the position (X-coordinate and Y-coordinate) of a swing Scilab tab
562 * @return the position of the tab
563 * @see org.scilab.modules.gui.uielement.UIElement#getPosition()
566 public Position getPosition() {
567 return new Position(this.getX(), this.getY());
571 * Sets the dimensions (width and height) of a swing Scilab tab
572 * @param newSize the dimensions we want to set to the tab
573 * @see org.scilab.modules.gui.uielement.UIElement#setDims(org.scilab.modules.gui.utils.Size)
576 public void setDims(Size newSize) {
577 this.setSize(newSize.getWidth(), newSize.getHeight());
581 * Sets the position (X-coordinate and Y-coordinate) of a swing Scilab tab
582 * @param newPosition the position we want to set to the tab
583 * @see org.scilab.modules.gui.uielement.UIElement#setPosition(org.scilab.modules.gui.utils.Position)
586 public void setPosition(Position newPosition) {
587 this.setLocation(newPosition.getX(), newPosition.getY());
591 * Add a member (dockable element) to container and returns its index
592 * @param member the member to add
593 * @return index of member in ArrayList
596 public int addMember(Canvas member) {
601 * We want to be able to remove directly a Canvas from a Tab.
602 * @param member canvas to remove
605 public void removeMember(Canvas member) {
609 * Add a SwingViewObject (from SwingView.java) to container and returns its
611 * @param member the member to add
613 public void addMember(SwingViewObject member) {
614 if (member instanceof SwingScilabAxes) {
615 if (contentCanvas == null) {
616 contentCanvas = new SwingScilabCanvas((Figure) GraphicController.getController().getObjectFromId(((SwingScilabAxes) member).getFigureId()));
617 contentCanvas.addEventHandlerKeyListener(editorEventHandler);
618 contentCanvas.addEventHandlerMouseListener(editorEventHandler);
619 contentCanvas.addEventHandlerMouseMotionListener(editorEventHandler);
621 layeredPane.add(contentCanvas, JLayeredPane.FRAME_CONTENT_LAYER);
623 scrolling.setCanvas(contentCanvas);
625 contentCanvas.addKeyListener(this);
630 SwingScilabCommonPanel.addMember(this, member);
634 * Remove a SwingViewObject (from SwingView.java)
635 * @param member the member to remove
637 public void removeMember(SwingViewObject member) {
638 SwingScilabCommonPanel.removeMember(this, member);
642 * Add a member (dockable element) to container and returns its index
643 * @param member the member to add
644 * @return index of member in ArrayList
647 public int addMember(Console member) {
648 return this.addMember((SwingScilabConsole) member.getAsSimpleConsole());
652 * Add a member (dockable element) to container and returns its index
653 * @param member the member to add
654 * @return index of member in ArrayList
656 private int addMember(SwingScilabConsole member) {
657 // replace the current content pane
658 this.setContentPane(member);
659 return this.getComponentZOrder(member);
663 * Add a member (dockable element) to container and returns its index
664 * @param member the member to add
665 * @return index of member in ArrayList
668 public int addMember(HelpBrowser member) {
669 return this.addMember((SwingScilabHelpBrowser) member.getAsSimpleHelpBrowser());
673 * Add a member (dockable element) to container and returns its index
674 * @param member the member to add
675 * @return index of member in ArrayList
677 private int addMember(SwingScilabHelpBrowser member) {
678 // replace the current content pane
679 this.setContentPane(member);
680 return this.getComponentZOrder(member);
684 * Add a member (dockable element) to container and returns its index
685 * @param member the member to add
686 * @return index of member in ArrayList
688 public int addMember(UiDisplayTree member) {
689 return this.addMember((SwingScilabUiDisplayTree) member.getAsSimpleUiDisplayTree());
693 * Add a member (dockable element) to container and returns its index
694 * @param member the member to add
695 * @return index of member in ArrayList
697 private int addMember(SwingScilabUiDisplayTree member) {
702 * Remove a Tree from its container
703 * @param member the Tree to remove
705 public void removeMember(UiDisplayTree member) {
706 this.removeMember((SwingScilabUiDisplayTree) member.getAsSimpleUiDisplayTree());
710 * Remove a Tree from its container
711 * @param member the Tree to remove
713 private void removeMember(SwingScilabUiDisplayTree member) {
717 * Add a Tree member (dockable element) to container and returns its index
718 * @param member the member to add
719 * @return index of member in ArrayList
722 public int addMember(Tree member) {
723 return this.addMember((SwingScilabTree) member.getAsSimpleTree());
727 * Add a Tree member (dockable element) to container and returns its index
728 * @param member the member to add
729 * @return index of member in ArrayList
731 public int addMember(SwingScilabTree member) {
736 * Add a Tree member (dockable element) to container and returns its index
737 * @param member the member to add
738 * @return index of member in ArrayList
740 public int addTree(SwingScilabTree member) {
741 this.setContentPane(member.getAsComponent());
742 return this.getComponentZOrder(member.getAsComponent());
746 * Remove a PopupMenu from its container
747 * @param member the PopupMenu to remove
750 public void removeMember(Tree member) {
751 this.removeMember((SwingScilabTree) member.getAsSimpleTree());
755 * Remove a PopupMenu from its container
756 * @param member the PopupMenu to remove
758 private void removeMember(SwingScilabTree member) {
762 * Add a member (dockable element) to container and returns its index
763 * @param member the member to add
764 * @return index of member in ArrayList
766 public int addMember(Dockable member) {
767 // TODO Auto-generated method stub
772 * Get the current status of the Tab in its parent
773 * @return true is the tab is the tab currently "on top" in its parent
776 public boolean isCurrentTab() {
777 // TODO should not always return TRUE
782 * Get the parent window id for this tab
783 * @return the id of the parent window
786 public String getParentWindowId() {
787 return this.parentWindowId;
794 public SwingScilabCanvas getContentCanvas() {
795 return contentCanvas;
799 * Set the parent window id for this tab
800 * @param id the id of the parent window
803 public void setParentWindowId(String id) {
804 this.parentWindowId = id;
809 * @param newMenuBar : the MenuBar to set.
810 * @see org.scilab.modules.gui.tab.SimpleTab#setMenuBar(org.scilab.modules.gui.menubar.MenuBar)
813 public void setMenuBar(MenuBar newMenuBar) {
814 if (this.menuBar != newMenuBar) {
815 if (this.menuBar != null) {
816 ((SwingScilabMenuBar) this.menuBar.getAsSimpleMenuBar()).close();
818 this.menuBar = newMenuBar;
824 * @return MenuBar : the MenuBar associated to the Tab.
825 * @see org.scilab.modules.gui.tab.SimpleTab#getMenuBar()
828 public MenuBar getMenuBar() {
834 * @param newToolBar : the ToolBar to set.
835 * @see org.scilab.modules.gui.tab.SimpleTab#setToolBar(org.scilab.modules.gui.toolbar.ToolBar)
838 public void setToolBar(ToolBar newToolBar) {
839 this.toolBar = newToolBar;
844 * @return ToolBar : the ToolBar associated to the Tab.
845 * @see org.scilab.modules.gui.tab.SimpleTab#getToolBar()
848 public ToolBar getToolBar() {
854 * @param newInfoBar the InfoBar to set.
857 public void setInfoBar(TextBox newInfoBar) {
858 this.infoBar = newInfoBar;
863 * @return the InfoBar associated to the Tab.
866 public TextBox getInfoBar() {
871 * Set the callback of the tab
872 * @param callback the callback to set.
875 public void setCallback(CommonCallBack callback) {
877 if (closeAction != null) {
878 this.getTitlebar().removeAction(closeAction);
881 if (callback != null) {
882 closeAction = new SciClosingAction(this, callback);
884 closeAction = new SciClosingAction(this);
887 closeAction.putValue(Action.NAME, DockingConstants.CLOSE_ACTION);
888 ((Titlebar) getTitlePane()).removeAction(DockingConstants.CLOSE_ACTION);
889 addAction(closeAction);
892 SciUndockingAction undockAction = new SciUndockingAction(this);
893 undockAction.putValue(Action.NAME, UNDOCK);
894 ((Titlebar) getTitlePane()).removeAction(UNDOCK);
895 addAction(undockAction);
898 SciHelpOnComponentAction helpAction = new SciHelpOnComponentAction(this);
899 helpAction.putValue(Action.NAME, HELP);
900 ((Titlebar) getTitlePane()).removeAction(HELP);
901 addAction(helpAction);
905 * Set this tab as the current tab of its parent Window
908 public void setCurrent() {
909 ActiveDockableTracker.requestDockableActivation(this);
913 * Set the background color of the tab.
914 * @param red red channel of the color
915 * @param green green channel
916 * @param blue blue channel
919 public void setBackground(double red, double green, double blue) {
920 Color newColor = new Color((float) red, (float) green, (float) blue);
921 setBackground(newColor);
925 * Get the part of the axes which is currently viewed
926 * @return [x,y,w,h] array
929 public int[] getViewingRegion() {
930 return scrolling.getViewingRegion();
934 * Specify a new viewport for the axes For SwingScilabCanvas viewport can
935 * not be modified since it match the parent tab size
936 * @param posX X coordinate of upper left point of the viewport within the
938 * @param posY Y coordinate of upper left point of the viewport within the
940 * @param width width of the viewport
941 * @param height height of the viewport
944 public void setViewingRegion(int posX, int posY, int width, int height) {
948 * Set the event handler of the Canvas
949 * @param funName the name of the Scilab function to call
951 public void setEventHandler(String funName) {
952 disableEventHandler();
953 eventHandler = new ScilabEventListener(funName, getId());
955 editorEventHandler.setEnable(false);
956 enableEventHandler();
961 * Set the status of the event handler of the Canvas
962 * @param status is true to set the event handler active
964 public void setEventHandlerEnabled(boolean status) {
965 if (status && eventEnabled) {
970 editorEventHandler.setEnable(false);
971 enableEventHandler();
974 editorEventHandler.setEnable(true);
975 disableEventHandler();
976 eventEnabled = false;
981 * Specify whether the canvas should fit the parent tab size (and
982 * consequently the scrollpane size) or not
983 * @param onOrOff true to enable autoresize mode
986 public void setAutoResizeMode(boolean onOrOff) {
990 * @return whether the resize mode is on or off
993 public boolean getAutoResizeMode() {
998 * Close the tab and disable it.
1000 public void close() {
1001 if (getTitlePane() != null) {
1002 ((Titlebar) getTitlePane()).removeAction(DockingConstants.CLOSE_ACTION);
1003 ((Titlebar) getTitlePane()).removeAction(UNDOCK);
1004 ((Titlebar) getTitlePane()).removeAction(HELP);
1007 if (closeAction != null) {
1008 getTitlebar().removeAction(closeAction);
1009 if (closeAction instanceof SciClosingAction) {
1010 ((SciClosingAction) closeAction).clean();
1024 DockingManager.unregisterDockable((Component) this);
1026 // without this children canvas are not released.
1027 Container dummyContainer = new Container();
1028 this.setContentPane(dummyContainer);
1029 if (editorEventHandler != null) {
1030 editorEventHandler.onExit();
1034 public void disablePaint() {
1035 paintEnable = false;
1038 public void setFigureBackground(Color color) {
1039 if (layeredPane != null) {
1040 layeredPane.setBackground(color);
1045 * Redefine paint children to be sure that AWT components are well painted.
1046 * @param g a Graphics
1049 public void paintChildren(Graphics g) {
1051 Component[] children = getComponents();
1052 for (int i = 0; i < children.length; i++) {
1053 // AWT children don't draw themselves automatically
1054 // so force their draw
1055 if (!children[i].isLightweight()) {
1056 children[i].paint(g);
1059 super.paintChildren(g);
1064 * Update the tab after a modification of its properties
1065 * @param property the property name
1066 * @param value the property value
1067 * @see org.scilab.modules.gui.SwingViewObject#update(java.lang.String,
1070 public void update(int property, Object value) {
1071 SwingScilabCommonPanel.update(this, property, value);
1077 * @see org.scilab.modules.gui.SwingViewObject#getId()
1079 public Integer getId() {
1086 * @see org.scilab.modules.gui.SwingViewObject#setId(java.lang.String)
1088 public void setId(Integer id) {
1093 * Turn on event handling.
1095 private void enableEventHandler() {
1096 if (contentCanvas != null) {
1097 contentCanvas.addEventHandlerKeyListener(eventHandler);
1098 contentCanvas.addEventHandlerMouseListener(eventHandler);
1099 contentCanvas.addEventHandlerMouseMotionListener(eventHandler);
1104 * Turn off event handling.
1106 private void disableEventHandler() {
1107 if (eventHandler != null && contentCanvas != null) {
1108 contentCanvas.removeEventHandlerKeyListener(eventHandler);
1109 contentCanvas.removeEventHandlerMouseListener(eventHandler);
1110 contentCanvas.removeEventHandlerMouseMotionListener(eventHandler);
1114 public void keyPressed(KeyEvent e) {
1118 public void keyReleased(KeyEvent e) {
1121 public void keyTyped(KeyEvent e) {
1122 if (ScilabConstants.isGUI() && (eventHandler == null || !eventEnabled) && !GlobalEventWatcher.isActivated() && !editorEventHandler.isDatatipEnable()
1123 && Character.isLetterOrDigit(e.getKeyChar())) {
1124 SwingScilabConsole console = (SwingScilabConsole) ScilabConsole.getConsole().getAsSimpleConsole();
1125 JTextPane input = (JTextPane) console.getConfiguration().getInputCommandView();
1126 input.requestFocus();
1127 SwingScilabWindow win = (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, console);
1129 input.dispatchEvent(new KeyEvent(input, KeyEvent.KEY_TYPED, System.currentTimeMillis(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation()));
1133 public JLayeredPane getWidgetPane() {
1134 return uiContentPane;
1137 public void setHasLayout(boolean hasLayout) {
1138 this.hasLayout = hasLayout;
1141 public void applyDeltaSize() {
1142 if (deltaSize != null) {
1143 if (deltaSize.getWidth() != 0 || deltaSize.getHeight() != 0) {
1144 //update view and update model ( from componentResize of Window )
1145 SwingScilabWindow figure = SwingScilabWindow.allScilabWindows.get(getParentWindowId());
1146 Dimension oldAxesSize = getContentPane().getSize();
1147 figure.setDims(new Size((int)(oldAxesSize.getWidth() + deltaSize.getWidth()), (int)(oldAxesSize.getHeight() + deltaSize.getHeight())));
1154 public void storeSizeDelta() {
1155 Dimension axesSize = getContentPane().getSize();
1156 SwingScilabWindow figure = SwingScilabWindow.allScilabWindows.get(getParentWindowId());
1157 Size figureSize = figure.getDims();
1158 deltaSize = new Dimension((int)(figureSize.getWidth() - axesSize.getWidth()), (int)(figureSize.getHeight() - axesSize.getHeight()));
1161 public void disableResizeEvent() {
1162 removeComponentListener(componentListener);
1165 public void enableResizeEvent() {
1166 addComponentListener(componentListener);