/*
* SalomeTMF is a Test Management Framework
* Copyright (C) 2005 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @author Fayal SOUGRATI, Vincent Pautret, Marche Mikael
*
* Contact: mikael.marche@rd.francetelecom.com
*/
package salomeTMF_plug.helpgui.gui;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import org.objectweb.salome_tmf.api.Util;
import salomeTMF_plug.helpgui.page.PageBookMarks;
import salomeTMF_plug.helpgui.parser.TocOpen;
import salomeTMF_plug.helpgui.util.Language;
import salomeTMF_plug.helpgui.util.Out;
public class MainPanel extends JPanel implements ActionListener {
/** Version of HelpGUI. */
public String version = "1.0";
/** Buttons on the toolbar */
protected JButton jbPrev;
protected JButton jbNext;
protected JButton jbHome;
protected JButton jbPrint;
protected JButton jbBookmarks;
/** Menu for bookmarks */
JMenu menuBookMarks;
//The view of the data
protected HelpView helpView;
/** The help path where the data are */
public static String helpPath = "";
public static String helpDir = "docs/html";
public static String pluginDir = "plugins";
public static String lang = "fr";
public static String defaultlang = "fr";
/** The icons path where the icons are */
public static String iconsPath = "crystal";
/** Is the help path is inclued in jar file */
//public static boolean isJarPath = false;
/** Protocol to access file */
//public static String protocol = "file://";
////////////////////////////////////////////////////////////////////
/** Standard Constructor. */
public MainPanel() {
//super("Help Gui");
initPanel(helpPath, helpDir, pluginDir, lang, iconsPath, null);
}
/** Standard Constructor. */
public MainPanel(String helpDir) {
//super("Help Gui");
initPanel(helpPath, helpDir, pluginDir, lang, iconsPath, null);
}
/** Standard Constructor. */
public MainPanel(String helpDir, String iconsPath, Vector pluginList) {
//super("Help Gui");
initPanel(helpPath, helpDir, pluginDir, lang, iconsPath, pluginList);
}
/** Standard Constructor. */
public MainPanel(String helpPath, String helpDir, String pluginDir, String lang, String iconsPath, Vector pluginList) {
//super("Help Gui");
initPanel(helpPath, helpDir, pluginDir, lang, iconsPath, pluginList);
}
/** Standard Constructor. */
public void initPanel(String pHelpPath, String pHelpRoot, String pPluginDir, String pLang, String pIconsPath, Vector pluginList) {
//Remove the last "/" character
/*if (pHelpPath.endsWith("/"))
pHelpPath = pHelpPath.substring(0, pHelpPath.length() - 1);
*/
helpDir = pHelpRoot;
lang = pLang;
helpPath = pHelpPath;
pluginDir = pPluginDir;
iconsPath = pIconsPath;
Util.log("[helpgui:MainPanel] help path : " + helpPath);
Util.log("[helpgui:MainPanel] help dir is : " + helpDir);
Util.log("[helpgui:MainPanel] plugins dir is : " + pluginDir);
Util.log("[helpgui:MainPanel] lang is " + lang);
//Create the menu bar
JMenuBar menuBar = new JMenuBar();
add(menuBar);
//this.setJMenuBar(menuBar);
JMenu menuFile = new JMenu(Language.getInstance().getText("file"));
JMenu menuAction = new JMenu(Language.getInstance().getText("action"));
menuBookMarks = new JMenu(Language.getInstance().getText("bookmarks"));
menuBar.add(menuFile);
menuBar.add(menuAction);
menuBar.add(menuBookMarks);
menuFile.add(Language.getInstance().getText("print"))
.addActionListener(this);
/*menuFile.add(Language.getInstance().getText("quit")).addActionListener(
this);*/
menuAction.add(Language.getInstance().getText("previous"))
.addActionListener(this);
menuAction.add(Language.getInstance().getText("next"))
.addActionListener(this);
menuAction.add(Language.getInstance().getText("home"))
.addActionListener(this);
menuBookMarks.add(Language.getInstance().getText("addBookmarks"))
.addActionListener(this);
menuBookMarks.addSeparator();
//Construct the buttons
jbPrev = new TestRolloverButton(new ImageIcon(getClass()
.getResource(
"/salomeTMF_plug/helpgui/icons/" + iconsPath
+ "/previous.gif")));
jbNext = new TestRolloverButton(new ImageIcon(getClass().getResource(
"/salomeTMF_plug/helpgui/icons/" + iconsPath + "/next.gif")));
jbHome = new TestRolloverButton(new ImageIcon(getClass().getResource(
"/salomeTMF_plug/helpgui/icons/" + iconsPath + "/home.gif")));
jbPrint = new TestRolloverButton(new ImageIcon(getClass().getResource(
"/salomeTMF_plug/helpgui/icons/" + iconsPath + "/print.gif")));
jbBookmarks = new TestRolloverButton(new ImageIcon(getClass()
.getResource(
"/salomeTMF_plug/helpgui/icons/" + iconsPath
+ "/addbookmarks.gif")));
jbPrev.addActionListener(this);
jbNext.addActionListener(this);
jbHome.addActionListener(this);
jbPrint.addActionListener(this);
jbBookmarks.addActionListener(this);
//Construct a toolbar
JToolBar toolBar = new JToolBar();
toolBar.setRollover(true);
toolBar.setFloatable(false);
toolBar.setBorderPainted(true);
//Add buttons to toolbar
toolBar.add(jbPrev);
toolBar.add(jbNext);
toolBar.add(jbHome);
toolBar.add(jbPrint);
toolBar.add(jbBookmarks);
//Set ToolTipsText to the button
jbPrev.setToolTipText(Language.getInstance().getText("previous"));
jbNext.setToolTipText(Language.getInstance().getText("next"));
jbHome.setToolTipText(Language.getInstance().getText("home"));
jbPrint.setToolTipText(Language.getInstance().getText("print"));
jbBookmarks.setToolTipText(Language.getInstance().getText(
"addBookmarks"));
//View of Data
helpView = new HelpView();
//Construct gui parameters
GridBagLayout gbPanel = new GridBagLayout();
GridBagConstraints gbcPanel = new GridBagConstraints();
//getContentPane().setLayout( gbPanel );
setLayout(gbPanel);
//Add the main tool bar
gbcPanel.gridx = 0;
gbcPanel.gridy = 0;
gbcPanel.gridwidth = 1;
gbcPanel.gridheight = 1;
gbcPanel.fill = GridBagConstraints.VERTICAL;
gbcPanel.weightx = 1;
gbcPanel.weighty = 0;
gbcPanel.anchor = GridBagConstraints.WEST;
gbPanel.setConstraints(toolBar, gbcPanel);
//getContentPane().add( toolBar );
add(toolBar);
//Add the panel with data to the mainframe
gbcPanel.gridx = 0;
gbcPanel.gridy = 1;
gbcPanel.gridwidth = 1;
gbcPanel.gridheight = 1;
gbcPanel.fill = GridBagConstraints.BOTH;
gbcPanel.weightx = 1;
gbcPanel.weighty = 1;
gbcPanel.anchor = GridBagConstraints.CENTER;
gbPanel.setConstraints(helpView, gbcPanel);
//getContentPane().add( helpView );
add(helpView);
//Pack the window
//pack();
//setLocation(100,100);
//Set a message
Out.msg("Construction of the GUI", Out.OK);
Util.log("[helpgui:MainPanel] : Construction of the GUI OK");
//Load the TOC
try {
TocOpen opener = new TocOpen(helpView);
Util.log("[helpgui:MainPanel] : Load main Toc");
try {
opener.load(MainPanel.helpPath + "/" + MainPanel.helpDir + "/" + MainPanel.lang, false, null);
} catch (Exception e1){
Util.log("[helpgui:MainPanel] : Unable to load main Toc in laguage " + MainPanel.lang);
if (!MainPanel.defaultlang.equals(MainPanel.lang)) {
Util.log("[helpgui:MainPanel] : Use default language " + MainPanel.defaultlang);
opener.load(MainPanel.helpPath + "/" + MainPanel.helpDir + "/"+ MainPanel.defaultlang , false, null);
}
}
if (pluginList != null || !pluginList.isEmpty()){
Enumeration e = pluginList.elements();
while (e.hasMoreElements()){
String pluginName = (String) e.nextElement();
Util.log("[helpgui:MainPanel] : Load plugin "+ pluginName +" Toc");
try {
opener.load(MainPanel.helpPath+ "/" + MainPanel.pluginDir+"/"+ pluginName + "/" + MainPanel.helpDir + "/" + MainPanel.lang , true, pluginName);
} catch (Exception eToc) {
try {
Util.log("[helpgui:MainPanel] : Toc plugin "+ pluginName +" no found");
if (!MainPanel.defaultlang.equals(MainPanel.lang)) {
Util.log("[helpgui:MainPanel] : Unable to load Toc for "+ pluginName + "in laguage " + MainPanel.lang);
Util.log("[helpgui:MainPanel] : Use default language " + MainPanel.defaultlang);
opener.load(MainPanel.helpPath+ "/" + MainPanel.pluginDir+"/"+ pluginName + "/" + MainPanel.helpDir + "/" + MainPanel.defaultlang , true, pluginName);
}
}catch (Exception e3) {
}
}
}
}
Out.msg("Loading the Table of Content", Out.OK);
} catch (Exception e2) {
Out.msg("Table of Content XML parsing", Out.FAILED);
//System.out.println(e2);
}
//Go to the home page
helpView.goHome();
//helpView.firstNodeExpand();
}
/** Handles buttons events */
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof JButton) {
if (e.getSource().equals(jbPrev))
helpView.previousPage();
else if (e.getSource().equals(jbNext))
helpView.nextPage();
else if (e.getSource().equals(jbHome))
helpView.goHome();
else if (e.getSource().equals(jbPrint))
helpView.print();
else if (e.getSource().equals(jbBookmarks))
addBookMarks();
} else if (e.getSource() instanceof JMenuItem) {
String arg = e.getActionCommand();
if (arg.equals(Language.getInstance().getText("previous")))
helpView.previousPage();
else if (arg.equals(Language.getInstance().getText("next")))
helpView.nextPage();
else if (arg.equals(Language.getInstance().getText("home")))
helpView.goHome();
else if (arg.equals(Language.getInstance().getText("print")))
helpView.print();
else if (arg.equals(Language.getInstance().getText("addBookmarks")))
addBookMarks();
else
helpView.updatePage(PageBookMarks.getInstance().getBookMark(
(JMenuItem) e.getSource()), true);
}
}
/** Set a bookmark to the current page */
public void addBookMarks() {
//System.out.println("Add bookmark to "+helpView.getCurrentPage());
JMenuItem menuItem = new JMenuItem(helpView.getCurrentPage().toString());
menuItem.addActionListener(this);
menuBookMarks.add(menuItem);
PageBookMarks.getInstance().addBookMark(menuItem,
helpView.getCurrentPage());
}
}
|