001: /*
002: * Copyright 2007 Madhav Pulipaka
003: *
004: * This file is part of Vela.
005:
006: * Vela is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * Vela is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with Vela; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
019: */
020: package vela.view;
021:
022: import javax.swing.*;
023: import javax.swing.event.HyperlinkEvent;
024: import javax.swing.event.HyperlinkListener;
025: import javax.swing.text.html.HTMLDocument;
026: import javax.swing.text.html.HTMLFrameHyperlinkEvent;
027:
028: import java.awt.*;
029: import java.awt.event.*;
030: import java.io.File;
031: import java.io.IOException;
032:
033: public class Help extends JDialog implements ActionListener,
034: HyperlinkListener {
035:
036: private static Help messageBox;
037: private JEditorPane taMessage;
038: private static final int WIDTH = 1000;
039: private static final int HEIGHT = 700;
040:
041: private Help(Frame frame, String title, boolean isModel) {
042: super (frame, title, isModel);
043: Container container = getContentPane();
044: JButton btnOK = new JButton("Close");
045: taMessage = new JEditorPane();
046: taMessage.setEditable(false);
047: taMessage.setEnabled(false);
048: taMessage.addHyperlinkListener(this );
049: container.add(new JScrollPane(taMessage));
050: Dimension screenSize = Toolkit.getDefaultToolkit()
051: .getScreenSize();
052: setBounds((int) (screenSize.getWidth() / 2) - (WIDTH / 2),
053: (int) (screenSize.getHeight() / 2) - (HEIGHT / 2),
054: WIDTH, HEIGHT);
055: btnOK.addActionListener(this );
056: JPanel southPanel = new JPanel(
057: new FlowLayout(FlowLayout.CENTER));
058: southPanel.add(btnOK);
059: container.add(southPanel, BorderLayout.SOUTH);
060: taMessage.setFont(new Font("Verdana", Font.BOLD, 11));
061: taMessage.setDisabledTextColor(Color.BLACK);
062: //taMessage.setBackground(Color.LIGHT_GRAY);
063: btnOK.setFont(new Font("Verdana", Font.BOLD, 12));
064: //btnOK.setBackground(new Color(0,0,100));
065: //btnOK.setForeground(Color.YELLOW);
066: }
067:
068: public static void showMessage(Frame frame, String title,
069: boolean isModel) {
070: if (messageBox == null)
071: messageBox = new Help(frame, title, isModel);
072: messageBox.setMessage();
073: messageBox.setVisible(true);
074: }
075:
076: public void setMessage() {
077: try {
078: File file = new File("./docs/Help.html");
079: taMessage.setPage(file.toURL());
080: } catch (IOException e) {
081: // TODO Auto-generated catch block
082: e.printStackTrace();
083: }
084: }
085:
086: public void actionPerformed(ActionEvent arg0) {
087: setVisible(false);
088: }
089:
090: public void hyperlinkUpdate(HyperlinkEvent e) {
091: setCursor(new Cursor(Cursor.WAIT_CURSOR));
092: try {
093: if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
094: JEditorPane pane = (JEditorPane) e.getSource();
095: if (e instanceof HTMLFrameHyperlinkEvent) {
096: HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
097: HTMLDocument doc = (HTMLDocument) pane
098: .getDocument();
099: doc.processHTMLFrameHyperlinkEvent(evt);
100: } else {
101: try {
102: pane.setPage(e.getURL());
103: } catch (Throwable t) {
104: t.printStackTrace();
105: }
106: }
107: }
108: } finally {
109: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
110: }
111: }
112:
113: }
|