2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Bruno JOFRET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 package org.scilab.modules.gui.bridge.tab;
15 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AUTORESIZE__;
16 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES_SIZE__;
17 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_SIZE__;
19 import java.awt.Container;
20 import java.awt.event.ComponentEvent;
21 import java.awt.event.ComponentListener;
23 import javax.swing.JLayeredPane;
24 import javax.swing.SwingUtilities;
26 import org.scilab.modules.graphic_objects.figure.Figure;
27 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
28 import org.scilab.modules.gui.SwingViewObject;
29 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvas;
30 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
31 import org.scilab.modules.gui.events.callback.CommonCallBack;
32 import org.scilab.modules.gui.menubar.MenuBar;
33 import org.scilab.modules.gui.textbox.TextBox;
34 import org.scilab.modules.gui.toolbar.ToolBar;
35 import org.scilab.modules.gui.utils.Size;
37 public class SwingScilabStaticPanel extends SwingScilabScrollPane implements SwingScilabPanel {
40 private TextBox infoBar;
41 private MenuBar menuBar;
42 private ToolBar toolBar;
43 private String eventHandler;
44 private boolean eventHandlerEnabled;
45 private String parentWindowId;
46 private String windowIcon;
48 private JLayeredPane uiContentPane;
49 private JLayeredPane layerdPane;
51 private SwingScilabCanvas contentCanvas;
53 public SwingScilabStaticPanel(String figureTitle, Integer figureId, Figure figure) {
54 super(new JLayeredPane(), new JLayeredPane(), figure);
55 uiContentPane = (JLayeredPane) getUIComponent();
56 layerdPane = (JLayeredPane) getGlobalComponent();
59 layerdPane.setLayout(null);
60 layerdPane.setOpaque(false);
62 uiContentPane.setOpaque(true);
63 uiContentPane.setLayout(null);
64 layerdPane.add(uiContentPane, JLayeredPane.DEFAULT_LAYER + 1, 0);
66 layerdPane.setVisible(true);
67 uiContentPane.setVisible(true);
69 /* Manage figure_size property */
70 addComponentListener(new ComponentListener() {
72 public void componentShown(ComponentEvent arg0) {
75 public void componentResized(ComponentEvent arg0) {
77 /* Update the figure_size property */
78 Size parentSize = SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
79 Integer[] newSize = new Integer[] { parentSize.getWidth(), parentSize.getHeight() };
81 GraphicController.getController().setProperty(id, __GO_SIZE__, newSize);
83 Boolean autoreSize = (Boolean) GraphicController.getController().getProperty(id, __GO_AUTORESIZE__);
85 if (autoreSize != null && autoreSize) {
86 /* Update the axes_size property */
87 Integer[] newAxesSize = new Integer[] { getContentPane().getWidth(), getContentPane().getHeight() };
88 GraphicController.getController().setProperty(id, __GO_AXES_SIZE__, newAxesSize);
92 public void componentMoved(ComponentEvent arg0) {
95 public void componentHidden(ComponentEvent arg0) {
100 public void setId(Integer id) {
104 public Integer getId() {
108 public void update(int property, Object value) {
109 SwingScilabCommonPanel.update(this, property, value);
112 public TextBox getInfoBar() {
116 public void setInfoBar(TextBox infoBar) {
117 this.infoBar = infoBar;
120 public MenuBar getMenuBar() {
124 public void setMenuBar(MenuBar menuBar) {
125 this.menuBar = menuBar;
128 public ToolBar getToolBar() {
132 public void setToolBar(ToolBar toolBar) {
133 this.toolBar = toolBar;
136 public void setEventHandler(String eventHandler) {
137 this.eventHandler = eventHandler;
140 public void setEventHandlerEnabled(boolean enabled) {
141 this.eventHandlerEnabled = enabled;
144 public void setParentWindowId(String parentWindowId) {
145 this.parentWindowId = parentWindowId;
148 public void setWindowIcon(String windowIcon) {
149 this.windowIcon = windowIcon;
152 public void addMember(SwingViewObject member) {
153 if (member instanceof SwingScilabAxes) {
154 if (contentCanvas == null) {
155 contentCanvas = new SwingScilabCanvas((Figure) GraphicController.getController().getObjectFromId(((SwingScilabAxes) member).getFigureId()));
156 //contentCanvas.addEventHandlerKeyListener(editorEventHandler);
157 //contentCanvas.addEventHandlerMouseListener(editorEventHandler);
158 //contentCanvas.addEventHandlerMouseMotionListener(editorEventHandler);
159 layerdPane.add(contentCanvas, JLayeredPane.FRAME_CONTENT_LAYER);
161 setCanvas(contentCanvas);
163 //contentCanvas.addKeyListener(this);
168 SwingScilabCommonPanel.addMember(this, member);
171 public String getParentWindowId() {
172 return parentWindowId;
175 public SwingScilabWindow getParentWindow() {
176 return (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this);
179 public JLayeredPane getWidgetPane() {
180 return uiContentPane;
183 public void setCallback(CommonCallBack callback) {
184 // TODO Auto-generated method stub
188 public Container getContentPane() {
189 return this.getAsContainer();
192 public void close() {
197 // without this children canvas are not released.
198 SwingScilabWindow win = getParentWindow();
199 Container dummyContainer = new Container();
200 win.setContentPane(dummyContainer);
206 * Remove a SwingViewObject (from SwingView.java)
207 * @param member the member to remove
209 public void removeMember(SwingViewObject member) {
210 SwingScilabCommonPanel.removeMember(this, member);
213 public void setName(String name) {
215 getParentWindow().setName(name);