New Java Help Browser for Scilab.
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / helpbrowser / ScilabHelpBrowser.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2008 - INRIA - Vincent Couvert
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-en.txt
10  *
11  */
12
13 package org.scilab.modules.gui.helpbrowser;
14
15 import org.scilab.modules.gui.bridge.ScilabBridge;
16 import org.scilab.modules.gui.dockable.ScilabDockable;
17 import org.scilab.modules.gui.events.callback.ScilabCallBack;
18 import org.scilab.modules.gui.menu.Menu;
19 import org.scilab.modules.gui.menu.ScilabMenu;
20 import org.scilab.modules.gui.menubar.MenuBar;
21 import org.scilab.modules.gui.menubar.ScilabMenuBar;
22 import org.scilab.modules.gui.tab.ScilabTab;
23 import org.scilab.modules.gui.tab.Tab;
24 import org.scilab.modules.gui.textbox.ScilabTextBox;
25 import org.scilab.modules.gui.textbox.TextBox;
26 import org.scilab.modules.gui.utils.Position;
27 import org.scilab.modules.gui.utils.Size;
28 import org.scilab.modules.gui.window.ScilabWindow;
29 import org.scilab.modules.gui.window.Window;
30
31 /**
32  * Class for Scilab Help Browser in GUIs
33  * @author Vincent COUVERT
34  */
35 public class ScilabHelpBrowser extends ScilabDockable implements HelpBrowser {
36
37         private static HelpBrowser instance;
38         
39         private static Tab helpTab;
40         
41         private SimpleHelpBrowser component;
42
43         /**
44          * Constructor
45          */
46         protected ScilabHelpBrowser() {
47                 component = ScilabBridge.createHelpBrowser();
48         }
49
50         /**
51          * Creates a Scilab Help Browser
52          * @return the created Help Browser
53          */
54         public static HelpBrowser createHelpBrowser() {
55                 if (instance == null) {
56                         instance = new ScilabHelpBrowser();
57                         helpTab = ScilabTab.createTab("Help Browser");
58                         helpTab.addMember(instance);
59                         helpTab.setCallback(ScilabCallBack
60                                         .createCallback("org.scilab.modules.gui.bridge.CallScilabBridge.closeHelpBrowser", ScilabCallBack.JAVA));
61                         
62                         MenuBar menubar = ScilabMenuBar.createMenuBar();
63                         
64                         Menu menu = ScilabMenu.createMenu();
65                         menu.setText("File");
66                         menubar.add(menu);
67                         
68                         menu = ScilabMenu.createMenu();
69                         menu.setText("?");
70                         menubar.add(menu);
71                         
72                         helpTab.addMenuBar(menubar);
73
74                         TextBox infobar = ScilabTextBox.createTextBox();
75                         helpTab.addInfoBar(infobar);
76
77                         Window helpWindow = ScilabWindow.createWindow();
78                         helpWindow.addTab(helpTab);
79                         helpWindow.draw();
80                 }
81                 return instance;
82         }
83
84         /**
85          * Get the Scilab Help Browser
86          * @return the console
87          */
88         public static HelpBrowser getHelpBrowser() {
89                 if (instance == null) {
90                         instance = new ScilabHelpBrowser();
91                 }
92                 return instance;
93         }
94         
95         /**
96          * Display the Help Browser
97          */
98         public void display() {
99                 ScilabBridge.display(this);
100         }
101         
102         /**
103          * Display the matching items for a specified keyword
104          * @param keyword the keyword
105          * @return true if the keyword exists
106          */
107         public boolean searchKeywork(String keyword) {
108                 return ScilabBridge.searchKeywork(this, keyword);
109         }
110         
111         /**
112          * Close the HelpBrowser
113          */
114         public void close() {
115                 ScilabBridge.close(this);
116                 helpTab.close();
117                 instance = null;
118         }
119
120
121         /**
122          * Not used
123          */
124         public void draw() {
125                 throw new UnsupportedOperationException();
126         }
127
128         /**
129          * Gets this Bridge component object
130          * @return this Bridge component object
131          */
132         public SimpleHelpBrowser getAsSimpleHelpBrowser() {
133                 return component;
134         }
135
136         /**
137          * Not used
138          * @return nothing
139          */
140         public Size getDims() {
141                 throw new UnsupportedOperationException();
142         }
143
144         /**
145          * Not used
146          * @return nothing
147          */
148         public Position getPosition() {
149                 throw new UnsupportedOperationException();
150         }
151
152         /**
153          * Not used
154          * @return nothing
155          */
156         public boolean isVisible() {
157                 throw new UnsupportedOperationException();
158         }
159
160         /**
161          * Not used
162          * @param newSize not used
163          */
164         public void setDims(Size newSize) {
165                 throw new UnsupportedOperationException();
166         }
167
168         /**
169          * Not used
170          * @param newPosition not used
171          */
172         public void setPosition(Position newPosition) {
173                 throw new UnsupportedOperationException();
174         }
175
176         /**
177          * Not used
178          * @param newVisibleState not used
179          */
180         public void setVisible(boolean newVisibleState) {
181                 throw new UnsupportedOperationException();
182         }
183 }