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.action_binding.InterpreterManagement;
27 import org.scilab.modules.graphic_objects.figure.Figure;
28 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
29 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
30 import org.scilab.modules.gui.SwingViewObject;
31 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvas;
32 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
33 import org.scilab.modules.gui.events.callback.CommonCallBack;
34 import org.scilab.modules.gui.menubar.MenuBar;
35 import org.scilab.modules.gui.textbox.TextBox;
36 import org.scilab.modules.gui.toolbar.ToolBar;
37 import org.scilab.modules.gui.utils.Size;
39 public class SwingScilabStaticPanel extends SwingScilabScrollPane implements SwingScilabPanel {
42 private TextBox infoBar;
43 private MenuBar menuBar;
44 private ToolBar toolBar;
45 private String eventHandler;
46 private boolean eventHandlerEnabled;
47 private String parentWindowId;
48 private String windowIcon;
50 private JLayeredPane uiContentPane;
51 private JLayeredPane layerdPane;
53 private SwingScilabCanvas contentCanvas;
55 public SwingScilabStaticPanel(String figureTitle, Integer figureId, Figure figure) {
56 super(new JLayeredPane(), new JLayeredPane(), figure);
57 uiContentPane = (JLayeredPane) getUIComponent();
58 layerdPane = (JLayeredPane) getGlobalComponent();
61 layerdPane.setLayout(null);
62 layerdPane.setOpaque(false);
64 uiContentPane.setOpaque(true);
65 uiContentPane.setLayout(null);
66 layerdPane.add(uiContentPane, JLayeredPane.DEFAULT_LAYER + 1, 0);
68 layerdPane.setVisible(true);
69 uiContentPane.setVisible(true);
71 /* Manage figure_size property */
72 addComponentListener(new ComponentListener() {
74 public void componentShown(ComponentEvent arg0) {
77 public void componentResized(ComponentEvent arg0) {
79 /* Update the figure_size property */
80 Size parentSize = SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
81 Integer[] newSize = new Integer[] { parentSize.getWidth(), parentSize.getHeight() };
83 GraphicController.getController().setProperty(id, __GO_SIZE__, newSize);
85 Boolean autoreSize = (Boolean) GraphicController.getController().getProperty(id, __GO_AUTORESIZE__);
87 if (autoreSize != null && autoreSize) {
88 /* Update the axes_size property */
89 Integer[] newAxesSize = new Integer[] { getContentPane().getWidth(), getContentPane().getHeight() };
90 GraphicController.getController().setProperty(id, __GO_AXES_SIZE__, newAxesSize);
93 String resizeFcn = (String) GraphicController.getController().getProperty(id, GraphicObjectProperties.__GO_RESIZEFCN__);
94 if (resizeFcn != null && !resizeFcn.equals("")) {
95 String resizeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;"
96 + "gcbo = getcallbackobject(" + id + ");"
98 + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
99 InterpreterManagement.requestScilabExec(resizeCommand);
103 public void componentMoved(ComponentEvent arg0) {
106 public void componentHidden(ComponentEvent arg0) {
111 public void setId(Integer id) {
115 public Integer getId() {
119 public void update(int property, Object value) {
120 SwingScilabCommonPanel.update(this, property, value);
123 public TextBox getInfoBar() {
127 public void setInfoBar(TextBox infoBar) {
128 this.infoBar = infoBar;
131 public MenuBar getMenuBar() {
135 public void setMenuBar(MenuBar menuBar) {
136 this.menuBar = menuBar;
139 public ToolBar getToolBar() {
143 public void setToolBar(ToolBar toolBar) {
144 this.toolBar = toolBar;
147 public void setEventHandler(String eventHandler) {
148 this.eventHandler = eventHandler;
151 public void setEventHandlerEnabled(boolean enabled) {
152 this.eventHandlerEnabled = enabled;
155 public void setParentWindowId(String parentWindowId) {
156 this.parentWindowId = parentWindowId;
159 public void setWindowIcon(String windowIcon) {
160 this.windowIcon = windowIcon;
163 public void addMember(SwingViewObject member) {
164 if (member instanceof SwingScilabAxes) {
165 if (contentCanvas == null) {
166 contentCanvas = new SwingScilabCanvas((Figure) GraphicController.getController().getObjectFromId(((SwingScilabAxes) member).getFigureId()));
167 //contentCanvas.addEventHandlerKeyListener(editorEventHandler);
168 //contentCanvas.addEventHandlerMouseListener(editorEventHandler);
169 //contentCanvas.addEventHandlerMouseMotionListener(editorEventHandler);
170 layerdPane.add(contentCanvas, JLayeredPane.FRAME_CONTENT_LAYER);
172 setCanvas(contentCanvas);
174 //contentCanvas.addKeyListener(this);
179 SwingScilabCommonPanel.addMember(this, member);
182 public String getParentWindowId() {
183 return parentWindowId;
186 public SwingScilabWindow getParentWindow() {
187 return (SwingScilabWindow) SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, this);
190 public JLayeredPane getWidgetPane() {
191 return uiContentPane;
194 public void setCallback(CommonCallBack callback) {
195 // TODO Auto-generated method stub
199 public Container getContentPane() {
200 return this.getAsContainer();
203 public void close() {
208 // without this children canvas are not released.
209 SwingScilabWindow win = getParentWindow();
210 Container dummyContainer = new Container();
211 win.setContentPane(dummyContainer);
217 * Remove a SwingViewObject (from SwingView.java)
218 * @param member the member to remove
220 public void removeMember(SwingViewObject member) {
221 SwingScilabCommonPanel.removeMember(this, member);
224 public void setName(String name) {
226 getParentWindow().setName(name);