c4be084770ab44c92c7ad670cda7e587fe91b4bf
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / bridge / window / SwingScilabStaticWindow.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2014 - Scilab Enterprises - Bruno JOFRET
4  *
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
10  *
11  */
12
13 package org.scilab.modules.gui.bridge.window;
14
15 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CLOSEREQUESTFCN__;
16
17 import java.awt.BorderLayout;
18 import java.awt.Component;
19 import java.awt.event.WindowAdapter;
20 import java.awt.event.WindowEvent;
21
22 import org.flexdock.docking.DockingPort;
23 import org.scilab.modules.action_binding.InterpreterManagement;
24 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
25 import org.scilab.modules.gui.bridge.tab.SwingScilabPanel;
26 import org.scilab.modules.gui.bridge.tab.SwingScilabStaticPanel;
27
28 public class SwingScilabStaticWindow extends SwingScilabWindow {
29
30     private SwingScilabStaticPanel panel;
31
32     public SwingScilabStaticWindow() {
33         super();
34         setLayout(new BorderLayout());
35         addWindowListener(new WindowAdapter() {
36             public void windowClosing(WindowEvent e) {
37                 String closeRequestFcn = (String) GraphicController.getController().getProperty(panel.getId(), __GO_CLOSEREQUESTFCN__);
38                 if (!closeRequestFcn.equals("")) {
39                     String closeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;" + "gcbo = getcallbackobject(" + panel.getId() + ");" + closeRequestFcn
40                                           + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
41                     InterpreterManagement.putCommandInScilabQueue(closeCommand);
42                 } else {
43                     GraphicController.getController().deleteObject(panel.getId());
44                 }
45             }
46         });
47     }
48
49     /**
50      * @return number of objects (tabs) docked in this window
51      */
52     @Override
53     public int getNbDockedObjects() {
54         return 1;
55     }
56
57     /**
58      * Close the window
59      * @see org.scilab.modules.gui.window.SimpleWindow#close()
60      */
61     @Override
62     public void close() {
63         try {
64             setVisible(false);
65             dispose();
66         } catch (IllegalStateException e) {
67             enableInputMethods(false);
68         }
69         allScilabWindows.remove(windowUID);
70     }
71
72     public DockingPort getDockingPort() {
73         return null;
74     }
75
76     public void addTab(SwingScilabPanel tab) {
77         add((Component) tab, BorderLayout.CENTER);
78         this.panel = (SwingScilabStaticPanel) tab;
79     }
80
81     public void removeTabs(SwingScilabPanel[] tabs) {
82         removeAll();
83     }
84 }