001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package salomeTMF_plug.helpgui.gui;
025:
026: import java.awt.GridBagConstraints;
027: import java.awt.GridBagLayout;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030: import java.util.Enumeration;
031: import java.util.Vector;
032:
033: import javax.swing.ImageIcon;
034: import javax.swing.JButton;
035: import javax.swing.JMenu;
036: import javax.swing.JMenuBar;
037: import javax.swing.JMenuItem;
038: import javax.swing.JPanel;
039: import javax.swing.JToolBar;
040:
041: import org.objectweb.salome_tmf.api.Util;
042:
043: import salomeTMF_plug.helpgui.page.PageBookMarks;
044: import salomeTMF_plug.helpgui.parser.TocOpen;
045: import salomeTMF_plug.helpgui.util.Language;
046: import salomeTMF_plug.helpgui.util.Out;
047:
048: public class MainPanel extends JPanel implements ActionListener {
049:
050: /** Version of HelpGUI. */
051: public String version = "1.0";
052:
053: /** Buttons on the toolbar */
054: protected JButton jbPrev;
055:
056: protected JButton jbNext;
057:
058: protected JButton jbHome;
059:
060: protected JButton jbPrint;
061:
062: protected JButton jbBookmarks;
063:
064: /** Menu for bookmarks */
065: JMenu menuBookMarks;
066:
067: //The view of the data
068: protected HelpView helpView;
069:
070: /** The help path where the data are */
071: public static String helpPath = "";
072: public static String helpDir = "docs/html";
073: public static String pluginDir = "plugins";
074: public static String lang = "fr";
075: public static String defaultlang = "fr";
076:
077: /** The icons path where the icons are */
078: public static String iconsPath = "crystal";
079:
080: /** Is the help path is inclued in jar file */
081: //public static boolean isJarPath = false;
082: /** Protocol to access file */
083: //public static String protocol = "file://";
084:
085: ////////////////////////////////////////////////////////////////////
086: /** Standard Constructor. */
087: public MainPanel() {
088: //super("Help Gui");
089: initPanel(helpPath, helpDir, pluginDir, lang, iconsPath, null);
090: }
091:
092: /** Standard Constructor. */
093: public MainPanel(String helpDir) {
094: //super("Help Gui");
095: initPanel(helpPath, helpDir, pluginDir, lang, iconsPath, null);
096: }
097:
098: /** Standard Constructor. */
099: public MainPanel(String helpDir, String iconsPath, Vector pluginList) {
100: //super("Help Gui");
101: initPanel(helpPath, helpDir, pluginDir, lang, iconsPath,
102: pluginList);
103: }
104:
105: /** Standard Constructor. */
106: public MainPanel(String helpPath, String helpDir, String pluginDir,
107: String lang, String iconsPath, Vector pluginList) {
108: //super("Help Gui");
109: initPanel(helpPath, helpDir, pluginDir, lang, iconsPath,
110: pluginList);
111: }
112:
113: /** Standard Constructor. */
114: public void initPanel(String pHelpPath, String pHelpRoot,
115: String pPluginDir, String pLang, String pIconsPath,
116: Vector pluginList) {
117:
118: //Remove the last "/" character
119: /*if (pHelpPath.endsWith("/"))
120: pHelpPath = pHelpPath.substring(0, pHelpPath.length() - 1);
121: */
122: helpDir = pHelpRoot;
123: lang = pLang;
124: helpPath = pHelpPath;
125: pluginDir = pPluginDir;
126: iconsPath = pIconsPath;
127:
128: Util.log("[helpgui:MainPanel] help path : " + helpPath);
129: Util.log("[helpgui:MainPanel] help dir is : " + helpDir);
130: Util.log("[helpgui:MainPanel] plugins dir is : " + pluginDir);
131: Util.log("[helpgui:MainPanel] lang is " + lang);
132:
133: //Create the menu bar
134: JMenuBar menuBar = new JMenuBar();
135: add(menuBar);
136: //this.setJMenuBar(menuBar);
137:
138: JMenu menuFile = new JMenu(Language.getInstance().getText(
139: "file"));
140: JMenu menuAction = new JMenu(Language.getInstance().getText(
141: "action"));
142: menuBookMarks = new JMenu(Language.getInstance().getText(
143: "bookmarks"));
144:
145: menuBar.add(menuFile);
146: menuBar.add(menuAction);
147: menuBar.add(menuBookMarks);
148:
149: menuFile.add(Language.getInstance().getText("print"))
150: .addActionListener(this );
151: /*menuFile.add(Language.getInstance().getText("quit")).addActionListener(
152: this);*/
153: menuAction.add(Language.getInstance().getText("previous"))
154: .addActionListener(this );
155: menuAction.add(Language.getInstance().getText("next"))
156: .addActionListener(this );
157: menuAction.add(Language.getInstance().getText("home"))
158: .addActionListener(this );
159: menuBookMarks.add(
160: Language.getInstance().getText("addBookmarks"))
161: .addActionListener(this );
162: menuBookMarks.addSeparator();
163:
164: //Construct the buttons
165: jbPrev = new TestRolloverButton(new ImageIcon(getClass()
166: .getResource(
167: "/salomeTMF_plug/helpgui/icons/" + iconsPath
168: + "/previous.gif")));
169: jbNext = new TestRolloverButton(new ImageIcon(getClass()
170: .getResource(
171: "/salomeTMF_plug/helpgui/icons/" + iconsPath
172: + "/next.gif")));
173: jbHome = new TestRolloverButton(new ImageIcon(getClass()
174: .getResource(
175: "/salomeTMF_plug/helpgui/icons/" + iconsPath
176: + "/home.gif")));
177: jbPrint = new TestRolloverButton(new ImageIcon(getClass()
178: .getResource(
179: "/salomeTMF_plug/helpgui/icons/" + iconsPath
180: + "/print.gif")));
181: jbBookmarks = new TestRolloverButton(new ImageIcon(getClass()
182: .getResource(
183: "/salomeTMF_plug/helpgui/icons/" + iconsPath
184: + "/addbookmarks.gif")));
185:
186: jbPrev.addActionListener(this );
187: jbNext.addActionListener(this );
188: jbHome.addActionListener(this );
189: jbPrint.addActionListener(this );
190: jbBookmarks.addActionListener(this );
191:
192: //Construct a toolbar
193: JToolBar toolBar = new JToolBar();
194: toolBar.setRollover(true);
195: toolBar.setFloatable(false);
196: toolBar.setBorderPainted(true);
197:
198: //Add buttons to toolbar
199: toolBar.add(jbPrev);
200: toolBar.add(jbNext);
201: toolBar.add(jbHome);
202: toolBar.add(jbPrint);
203: toolBar.add(jbBookmarks);
204:
205: //Set ToolTipsText to the button
206: jbPrev.setToolTipText(Language.getInstance()
207: .getText("previous"));
208: jbNext.setToolTipText(Language.getInstance().getText("next"));
209: jbHome.setToolTipText(Language.getInstance().getText("home"));
210: jbPrint.setToolTipText(Language.getInstance().getText("print"));
211: jbBookmarks.setToolTipText(Language.getInstance().getText(
212: "addBookmarks"));
213:
214: //View of Data
215: helpView = new HelpView();
216:
217: //Construct gui parameters
218: GridBagLayout gbPanel = new GridBagLayout();
219: GridBagConstraints gbcPanel = new GridBagConstraints();
220: //getContentPane().setLayout( gbPanel );
221: setLayout(gbPanel);
222:
223: //Add the main tool bar
224: gbcPanel.gridx = 0;
225: gbcPanel.gridy = 0;
226: gbcPanel.gridwidth = 1;
227: gbcPanel.gridheight = 1;
228: gbcPanel.fill = GridBagConstraints.VERTICAL;
229: gbcPanel.weightx = 1;
230: gbcPanel.weighty = 0;
231: gbcPanel.anchor = GridBagConstraints.WEST;
232: gbPanel.setConstraints(toolBar, gbcPanel);
233: //getContentPane().add( toolBar );
234: add(toolBar);
235:
236: //Add the panel with data to the mainframe
237: gbcPanel.gridx = 0;
238: gbcPanel.gridy = 1;
239: gbcPanel.gridwidth = 1;
240: gbcPanel.gridheight = 1;
241: gbcPanel.fill = GridBagConstraints.BOTH;
242: gbcPanel.weightx = 1;
243: gbcPanel.weighty = 1;
244: gbcPanel.anchor = GridBagConstraints.CENTER;
245: gbPanel.setConstraints(helpView, gbcPanel);
246: //getContentPane().add( helpView );
247: add(helpView);
248:
249: //Pack the window
250: //pack();
251:
252: //setLocation(100,100);
253:
254: //Set a message
255: Out.msg("Construction of the GUI", Out.OK);
256: Util.log("[helpgui:MainPanel] : Construction of the GUI OK");
257: //Load the TOC
258: try {
259: TocOpen opener = new TocOpen(helpView);
260: Util.log("[helpgui:MainPanel] : Load main Toc");
261: try {
262: opener.load(MainPanel.helpPath + "/"
263: + MainPanel.helpDir + "/" + MainPanel.lang,
264: false, null);
265: } catch (Exception e1) {
266: Util
267: .log("[helpgui:MainPanel] : Unable to load main Toc in laguage "
268: + MainPanel.lang);
269: if (!MainPanel.defaultlang.equals(MainPanel.lang)) {
270: Util
271: .log("[helpgui:MainPanel] : Use default language "
272: + MainPanel.defaultlang);
273: opener.load(MainPanel.helpPath + "/"
274: + MainPanel.helpDir + "/"
275: + MainPanel.defaultlang, false, null);
276: }
277: }
278: if (pluginList != null || !pluginList.isEmpty()) {
279: Enumeration e = pluginList.elements();
280: while (e.hasMoreElements()) {
281: String pluginName = (String) e.nextElement();
282: Util.log("[helpgui:MainPanel] : Load plugin "
283: + pluginName + " Toc");
284: try {
285: opener.load(MainPanel.helpPath + "/"
286: + MainPanel.pluginDir + "/"
287: + pluginName + "/" + MainPanel.helpDir
288: + "/" + MainPanel.lang, true,
289: pluginName);
290: } catch (Exception eToc) {
291: try {
292: Util
293: .log("[helpgui:MainPanel] : Toc plugin "
294: + pluginName + " no found");
295: if (!MainPanel.defaultlang
296: .equals(MainPanel.lang)) {
297: Util
298: .log("[helpgui:MainPanel] : Unable to load Toc for "
299: + pluginName
300: + "in laguage "
301: + MainPanel.lang);
302: Util
303: .log("[helpgui:MainPanel] : Use default language "
304: + MainPanel.defaultlang);
305: opener.load(MainPanel.helpPath + "/"
306: + MainPanel.pluginDir + "/"
307: + pluginName + "/"
308: + MainPanel.helpDir + "/"
309: + MainPanel.defaultlang, true,
310: pluginName);
311: }
312: } catch (Exception e3) {
313:
314: }
315: }
316: }
317: }
318: Out.msg("Loading the Table of Content", Out.OK);
319: } catch (Exception e2) {
320: Out.msg("Table of Content XML parsing", Out.FAILED);
321: //System.out.println(e2);
322: }
323:
324: //Go to the home page
325: helpView.goHome();
326: //helpView.firstNodeExpand();
327: }
328:
329: /** Handles buttons events */
330: public void actionPerformed(ActionEvent e) {
331: if (e.getSource() instanceof JButton) {
332: if (e.getSource().equals(jbPrev))
333: helpView.previousPage();
334: else if (e.getSource().equals(jbNext))
335: helpView.nextPage();
336: else if (e.getSource().equals(jbHome))
337: helpView.goHome();
338: else if (e.getSource().equals(jbPrint))
339: helpView.print();
340: else if (e.getSource().equals(jbBookmarks))
341: addBookMarks();
342: } else if (e.getSource() instanceof JMenuItem) {
343: String arg = e.getActionCommand();
344: if (arg.equals(Language.getInstance().getText("previous")))
345: helpView.previousPage();
346: else if (arg.equals(Language.getInstance().getText("next")))
347: helpView.nextPage();
348: else if (arg.equals(Language.getInstance().getText("home")))
349: helpView.goHome();
350: else if (arg
351: .equals(Language.getInstance().getText("print")))
352: helpView.print();
353: else if (arg.equals(Language.getInstance().getText(
354: "addBookmarks")))
355: addBookMarks();
356: else
357: helpView.updatePage(PageBookMarks.getInstance()
358: .getBookMark((JMenuItem) e.getSource()), true);
359: }
360: }
361:
362: /** Set a bookmark to the current page */
363: public void addBookMarks() {
364: //System.out.println("Add bookmark to "+helpView.getCurrentPage());
365:
366: JMenuItem menuItem = new JMenuItem(helpView.getCurrentPage()
367: .toString());
368: menuItem.addActionListener(this);
369: menuBookMarks.add(menuItem);
370: PageBookMarks.getInstance().addBookMark(menuItem,
371: helpView.getCurrentPage());
372: }
373:
374: }
|