001: /*
002: *
003: * HelpGui.java - Launch HelpGui API Demo
004: * Copyright (C) 2003 Alexandre THOMAS
005: * alexthomas@free.fr
006: * http://helpgui.sourceforge.net
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package salomeTMF_plug.helpgui;
024:
025: import java.net.MalformedURLException;
026: import java.net.URL;
027: import java.util.Collection;
028: import java.util.Iterator;
029: import java.util.Locale;
030: import java.util.Properties;
031: import java.util.Vector;
032:
033: import javax.swing.JTabbedPane;
034:
035: import org.java.plugin.ExtensionPoint;
036: import org.java.plugin.Plugin;
037: import org.java.plugin.PluginDescriptor;
038: import org.java.plugin.PluginManager;
039: import org.objectweb.salome_tmf.api.Util;
040: import org.objectweb.salome_tmf.ihm.main.SalomeTMF;
041: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
042: import org.objectweb.salome_tmf.plugins.UICompCst;
043: import org.objectweb.salome_tmf.plugins.core.Common;
044:
045: import salomeTMF_plug.helpgui.gui.MainFrame;
046: import salomeTMF_plug.helpgui.gui.MainPanel;
047:
048: /**
049: * A class for Lauch the Help Viewer
050: *
051: * @author Alexandre THOMAS
052: */
053: public class HelpGui extends Plugin implements Common {
054: public static boolean debug = false;
055: String helpPath;
056: MainPanel mainPanel;
057: Properties configFile;
058: Vector pluginList = new Vector();
059:
060: //For Debug purpose
061: public static void main(String[] arg) {
062: MainFrame mainFrame = new MainFrame("/docs/help/", "crystal");
063: mainFrame.setVisible(true);
064: }
065:
066: /**
067: * @param manager
068: * @param descr
069: */
070: public HelpGui(PluginManager manager, PluginDescriptor descr) {
071: super (manager, descr);
072: Collection c = manager.getRegistry().getPluginDescriptors();
073: Iterator it_c = c.iterator();
074: while (it_c.hasNext()) {
075: PluginDescriptor pPluginDescriptor = (PluginDescriptor) it_c
076: .next();
077: pluginList.add(pPluginDescriptor.getId());
078: Util.log("[helpgui] plug id " + pPluginDescriptor.getId());
079: Util.log("[helpgui] plug location "
080: + pPluginDescriptor.getLocation());
081: Util.log("[helpgui] plug unique id "
082: + pPluginDescriptor.getUniqueId());
083: }
084: }
085:
086: /**
087: * @see org.java.plugin.Plugin()
088: */
089: protected void doStart() throws Exception {
090: // no-op
091: }
092:
093: /**
094: * @see org.java.plugin.Plugin()
095: */
096: protected void doStop() throws Exception {
097: // no-op
098: }
099:
100: public void init(Object pIhm) {
101: // Config file initialisation
102: String helpDir = null;
103: ;
104: String pluginDir = null;
105: String lang = null;
106: String helpPath;
107: //URL _urlBase = ((SalomeTMF) pIhm).getDocumentBase();
108: URL _urlBase = SalomeTMFContext.getInstance().getUrlBase();
109: helpPath = _urlBase.toString();
110: helpPath = helpPath.substring(0, helpPath.lastIndexOf("/"));
111: URL url_cfg = null;
112: try {
113: URL urlBase = new URL(helpPath);
114: url_cfg = new URL(urlBase
115: + "/plugins/helpgui/cfg/CfgHelpGui.properties");
116: } catch (MalformedURLException mue) {
117: mue.printStackTrace();
118: }
119:
120: try {
121: configFile = Util.getPropertiesFile(url_cfg);
122:
123: } catch (Exception e) {
124: try {
125: configFile = Util
126: .getPropertiesFile("/plugins/helpgui/cfg/CfgHelpGui.properties");
127: } catch (Exception e1) {
128:
129: }
130: }
131: try {
132: helpDir = configFile.getProperty("HelpRoot");
133: pluginDir = configFile.getProperty("PluginPath");
134: lang = configFile.getProperty("lang");
135: } catch (Exception e) {
136: }
137:
138: if (helpDir == null || helpDir.trim().equals("")) {
139: helpDir = "docs/html";
140: }
141: if (pluginDir == null || pluginDir.trim().equals("")) {
142: pluginDir = "plugins";
143: }
144: if (lang == null | lang.trim().equals("")) {
145: lang = Locale.getDefault().getCountry().toLowerCase();
146: }
147: Util.log("[helpgui] base protocol is : "
148: + _urlBase.getProtocol());
149: Util.log("[helpgui] help path : " + helpPath);
150: Util.log("[helpgui] help dir is : " + helpDir);
151: Util.log("[helpgui] plugins dir is : " + pluginDir);
152: Util.log("[helpgui] : lang is " + lang);
153:
154: mainPanel = new MainPanel(helpPath, helpDir, pluginDir, lang,
155: "crystal", pluginList);
156: }
157:
158: /**
159: * Returns true if the plugin has menu items for "Tools" menu for tests
160: *
161: * @return true if the plugin has menu items for "Tools" menu for tests
162: */
163: public boolean isActivableInTestToolsMenu() {
164: return false;
165: }
166:
167: /**
168: * Returns true if the plugin has menu items for "Tools" menu for campaigns
169: *
170: * @return true if the plugin has menu items for "Tools" menu for campaigns
171: */
172: public boolean isActivableInCampToolsMenu() {
173: return false;
174: }
175:
176: /**
177: * Returns true if the plugin has menu items for "Tools" menu for data
178: * management
179: *
180: * @return true if the plugin has menu items for "Tools" menu for data
181: * management
182: */
183: public boolean isActivableInDataToolsMenu() {
184: return false;
185: }
186:
187: /**
188: * Returns true if the plugin uses or is activable in other UI components
189: * than these three menus true if the plugin uses or is activable in other
190: * UI components than these
191: *
192: * @return
193: */
194: public boolean usesOtherUIComponents() {
195: return true;
196: }
197:
198: /*
199: * Getting the UI components relative constants in which the plugin is
200: * activable or which it uses different from these three menus
201: *
202: * @see org.objectweb.salome_tmf.ihm.UICompCst @return A vector containing UI components
203: * constants
204: */
205: public java.util.Vector getUsedUIComponents() {
206: Vector uiComponentsUsed = new Vector();
207: uiComponentsUsed.add(0, UICompCst.MAIN_TABBED_PANE);
208: return uiComponentsUsed;
209: }
210:
211: /*
212: * Activates the plugin in static UI component This method will be called
213: * for each static UI component in the Vector returned by the previous
214: * method ( getUsedUIComponents() ). @param UIComponents
215: */
216: public void activatePluginInStaticComponent(Integer uiCompCst) {
217: JTabbedPane salomeMainTabs = (JTabbedPane) SalomeTMFContext
218: .getInstance().getUIComponent(uiCompCst);
219: salomeMainTabs.addTab("HelpGui plugin", mainPanel);
220: }
221:
222: /*
223: * Activates the plugin in dynamic UI component This method will be called
224: * for each dynamic UI component in the Vector returned by the previous
225: * method ( getUsedUIComponents() ). @param UIComponents
226: */
227: public void activatePluginInDynamicComponent(Integer uiCompCst) {
228:
229: }
230:
231: /**
232: * Retruns true if the plugin is freezable
233: */
234: public boolean isFreezable() {
235: return false;
236: }
237:
238: /**
239: * Freezes the plugin
240: */
241: public void freeze() {
242:
243: }
244:
245: /**
246: * Unfreezes the plugin
247: */
248: public void unFreeze() {
249:
250: }
251:
252: /**
253: * true if the plugin is freezed
254: */
255: public boolean isFreezed() {
256: return false;
257: }
258:
259: public void activatePluginInCampToolsMenu(javax.swing.JMenu jMenu) {
260: }
261:
262: public void activatePluginInDataToolsMenu(javax.swing.JMenu jMenu) {
263: }
264:
265: public void activatePluginInTestToolsMenu(javax.swing.JMenu jMenu) {
266: }
267:
268: public void allPluginActived(ExtensionPoint commonExtensions,
269: ExtensionPoint testDriverExtensions,
270: ExtensionPoint scriptEngineExtensions,
271: ExtensionPoint bugTrackerExtensions) {
272:
273: }
274: }
|