* Bug #13588 fixed - Default values of "event_handler" and "event_handler_enable...
[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 import org.scilab.modules.gui.events.callback.CommonCallBack;
28
29 public class SwingScilabStaticWindow extends SwingScilabWindow {
30
31     private SwingScilabStaticPanel panel;
32
33     public SwingScilabStaticWindow() {
34         super();
35         setLayout(new BorderLayout());
36         addWindowListener(new WindowAdapter() {
37             public void windowClosing(WindowEvent e) {
38                 String closeRequestFcn = (String) GraphicController.getController().getProperty(panel.getId(), __GO_CLOSEREQUESTFCN__);
39                 if (!closeRequestFcn.equals("")) {
40                     String closeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;" + "gcbo = getcallbackobject(" + panel.getId() + ");" + closeRequestFcn
41                                           + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
42                     InterpreterManagement.putCommandInScilabQueue(closeCommand);
43                 } else {
44                     //GraphicController.getController().deleteObject(panel.getId());
45                     CommonCallBack callback = panel.getCallback();
46                     if (callback != null) {
47                         callback.actionPerformed(null);
48                     } else {
49                         GraphicController.getController().removeRelationShipAndDelete(panel.getId());
50                     }
51                 }
52             }
53         });
54     }
55
56     /**
57      * @return number of objects (tabs) docked in this window
58      */
59     @Override
60     public int getNbDockedObjects() {
61         return 1;
62     }
63
64     /**
65      * Close the window
66      * @see org.scilab.modules.gui.window.SimpleWindow#close()
67      */
68     @Override
69     public void close() {
70         try {
71             setVisible(false);
72             dispose();
73         } catch (IllegalStateException e) {
74             enableInputMethods(false);
75         }
76         allScilabWindows.remove(windowUID);
77     }
78
79     public DockingPort getDockingPort() {
80         return null;
81     }
82
83     public void addTab(SwingScilabPanel tab) {
84         add((Component) tab, BorderLayout.CENTER);
85         this.panel = (SwingScilabStaticPanel) tab;
86     }
87
88     public void removeTabs(SwingScilabPanel[] tabs) {
89         removeAll();
90     }
91 }