/*
* Title: japlot.jaxodraw
* Description: Graphical user interface for drawing Feynman diagrams
* @author Daniele Binosi
* @author Lukas Theussl
Copyright (C) 2003-2006, Daniele Binosi and Lukas Theussl
See the file LICENSE in the source distribution home directory
for a full copy of the GPL (GNU General Public License).
This file is part of japlot.jaxodraw.
japlot.jaxodraw is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
japlot.jaxodraw 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package japlot.jaxodraw;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.WindowConstants;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
import jhplot.utils.AboutDialog;
import jhplot.utils.HelpDialog;
//import java.awt.*;
/** The help menu items. */
public class JaxoHelpMenu extends JMenu implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JaxoMainPanel thePanel;
private ResourceBundle language =
ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
private JMenuItem aboutMI, usrGuideMI, aboutJaPlotMI;
private JFrame frame;
/** Creates the help menu from the specified JaxoMainPanel.
* @param mainPanel The specified JaxoMainPanel.
*/
public JaxoHelpMenu(JaxoMainPanel mainPanel) {
super(ResourceBundle.getBundle(JaxoPrefs.getPref(
JaxoPrefs.PREF_LANGUAGE)).getString("Help"));
this.thePanel = mainPanel;
aboutMI = new JMenuItem(language.getString("About"));
this.add(aboutMI);
aboutMI.addActionListener(this);
aboutMI.setAccelerator(KeyStroke.getKeyStroke('?'));
aboutMI.setActionCommand("About");
usrGuideMI = new JMenuItem(language.getString("User_guide"));
this.add(usrGuideMI);
usrGuideMI.addActionListener(this);
usrGuideMI.setAccelerator(KeyStroke.getKeyStroke('G'));
usrGuideMI.setActionCommand("User_guide");
aboutJaPlotMI= new JMenuItem("About japlot");
this.add(aboutJaPlotMI);
aboutJaPlotMI.addActionListener(this);
// usrGuideMI.setAccelerator(KeyStroke.getKeyStroke('P'));
aboutJaPlotMI.setActionCommand("About japlot");
}
/** Executes the corresponding action when an item
* from the help menu is chosen.
* @param evt The action event to be processed.
*/
public final void actionPerformed(ActionEvent evt) {
AbstractButton source = (AbstractButton) evt.getSource();
if (source.getActionCommand().equals("About")) {
new AboutDialog(thePanel);
}if (source.getActionCommand().equals("About japlot")) {
about();
} else if (source.getActionCommand().equals("User_guide")) {
thePanel.helpEvent();
}
}
/** Pops a small dialog with some information about the current
* version of japlot.jaxodraw.
*/
public final void about() {
String s0= "japlot package. (C) S.Chekanov. Includes the JaxoDraw package \n";
String s1= "for drawing Feynman diagrams";
String s2= "(by D.Binosi and L.Theuss)";
JOptionPane.showMessageDialog(thePanel, s0+s1+s2);
}
/** Sets the text for the entries in the help menu in different languages.
* @param languageString A string specifying the language to be set.
*/
public final void setLanguage(String languageString) {
language = ResourceBundle.getBundle(languageString);
super.setText(language.getString("Help"));
aboutMI.setText(language.getString("About"));
usrGuideMI.setText(language.getString("User_guide"));
}
private void displayHTML(String page, boolean listen) {
URL url = JaxoHelpMenu.class.getClassLoader().getResource(page);
String newurl = url.toString();
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
if (listen) {
editorPane.addHyperlinkListener(new Hyperlisten());
}
try {
editorPane.setPage(newurl);
} catch (Exception e) {
JOptionPane.showMessageDialog(null,
language.getString("Cannot_not_open:") + newurl + "!");
if (JaxoPrefs.verbose()) {
System.err.println(e);
}
}
JScrollPane scroller = new JScrollPane(editorPane);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setPreferredSize(new Dimension(250, 145));
scroller.setMinimumSize(new Dimension(10, 10));
JButton closeButton = new JButton(language.getString("Close"));
closeButton.setBorder(BorderFactory.createRaisedBevelBorder());
//closeButton.setToolTipText();
closeButton.addMouseListener(new MouseAdapter() {
public final void mouseClicked(MouseEvent evt) {
frame.dispose();
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(closeButton, BorderLayout.CENTER);
frame = new JFrame();
frame.getContentPane().add(scroller, BorderLayout.CENTER);
frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setSize(1000, 800);
frame.setTitle(JaxoDraw.VERSION + " - "
+ language.getString("User_guide"));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
static class Hyperlisten implements HyperlinkListener {
public final void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == EventType.ACTIVATED) {
JEditorPane pane = (JEditorPane) e.getSource();
if (e instanceof HTMLFrameHyperlinkEvent) {
HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
HTMLDocument doc = (HTMLDocument) pane.getDocument();
doc.processHTMLFrameHyperlinkEvent(evt);
} else {
try {
pane.setPage(e.getURL());
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}
}
}
Ads help maintain this website.