1 import javax
.swing
.JFrame
;
2 import javax
.swing
.JScrollPane
;
3 import javax
.swing
.JEditorPane
;
4 import javax
.swing
.JButton
;
6 import javax
.swing
.event
.HyperlinkListener
;
7 import javax
.swing
.event
.HyperlinkEvent
;
8 import java
.net
.MalformedURLException
;
9 import java
.io
.IOException
;
11 import java
.awt
.event
.WindowAdapter
;
12 import java
.awt
.event
.WindowEvent
;
13 import java
.awt
.GridBagLayout
;
14 import java
.awt
.GridBagConstraints
;
15 import java
.awt
.event
.ActionListener
;
16 import java
.util
.LinkedList
;
19 implements ActionListener
21 public static synchronized HelpWindow
Instance ()
23 if (maInstance
== null)
24 maInstance
= new HelpWindow();
28 public void loadFile (String sFilename
)
30 File aFile
= new File (sFilename
);
33 loadURL (aFile
.toURL());
35 catch (MalformedURLException e
)
37 e
.printStackTrace (System
.err
);
40 public void loadURL (String sURL
)
44 loadURL (new URL (sURL
));
46 catch (MalformedURLException e
)
48 e
.printStackTrace (System
.err
);
55 public void loadURL (URL aURL
)
57 maHistory
.addLast (aURL
);
58 selectHistoryPage (maHistory
.size()-1);
69 maCurrentHistoryEntry
= -1;
70 maHistory
= new LinkedList();
72 maFrame
= new JFrame ();
73 maFrame
.addWindowListener (new WindowAdapter ()
75 public void windowClosing (WindowEvent e
)
80 maContent
= createContentWidget();
82 maFrame
.getContentPane().setLayout (new GridBagLayout());
83 GridBagConstraints aConstraints
= new GridBagConstraints ();
84 aConstraints
.gridx
= 0;
85 aConstraints
.gridy
= 0;
86 aConstraints
.gridwidth
= 3;
87 aConstraints
.weightx
= 1;
88 aConstraints
.weighty
= 1;
89 aConstraints
.fill
= GridBagConstraints
.BOTH
;
90 maFrame
.getContentPane().add (new JScrollPane (maContent
), aConstraints
);
92 aConstraints
= new GridBagConstraints();
93 aConstraints
.gridx
= 0;
94 aConstraints
.gridy
= 1;
95 maPrevButton
= new JButton ("Prev");
96 maFrame
.getContentPane().add (maPrevButton
, aConstraints
);
97 maPrevButton
.addActionListener (this);
99 aConstraints
= new GridBagConstraints();
100 aConstraints
.gridx
= 1;
101 aConstraints
.gridy
= 1;
102 maNextButton
= new JButton ("Next");
103 maFrame
.getContentPane().add (maNextButton
, aConstraints
);
104 maNextButton
.addActionListener (this);
106 aConstraints
= new GridBagConstraints();
107 aConstraints
.gridx
= 2;
108 aConstraints
.gridy
= 1;
109 aConstraints
.anchor
= GridBagConstraints
.EAST
;
110 JButton aButton
= new JButton ("Close");
111 maFrame
.getContentPane().add (aButton
, aConstraints
);
112 aButton
.addActionListener (this);
114 maFrame
.setSize (600,400);
115 maFrame
.setVisible (true);
121 public void actionPerformed (java
.awt
.event
.ActionEvent e
)
123 if (e
.getActionCommand().equals("Prev"))
125 selectHistoryPage (maCurrentHistoryEntry
- 1);
127 else if (e
.getActionCommand().equals("Next"))
129 selectHistoryPage (maCurrentHistoryEntry
+ 1);
131 else if (e
.getActionCommand().equals("Close"))
138 private JEditorPane
createContentWidget ()
140 JEditorPane aContent
= new JEditorPane ();
141 aContent
.setEditable (false);
142 aContent
.addHyperlinkListener (new HyperlinkListener()
144 public void hyperlinkUpdate (HyperlinkEvent e
)
146 if (e
.getEventType() == HyperlinkEvent
.EventType
.ACTIVATED
)
147 HelpWindow
.Instance().loadURL (e
.getURL());
153 private void selectHistoryPage (int i
)
157 else if (i
>= maHistory
.size()-1)
158 i
= maHistory
.size()-1;
159 if (i
!= maCurrentHistoryEntry
)
161 URL aURL
= (URL
)maHistory
.get (i
);
164 maContent
.setPage (aURL
);
166 catch (java
.io
.IOException ex
)
168 ex
.printStackTrace(System
.err
);
171 maCurrentHistoryEntry
= i
;
174 maPrevButton
.setEnabled (maCurrentHistoryEntry
> 0);
175 maNextButton
.setEnabled (maCurrentHistoryEntry
< maHistory
.size()-1);
178 private static HelpWindow maInstance
= null;
179 private JFrame maFrame
;
180 private JEditorPane maContent
;
181 private LinkedList maHistory
;
182 private int maCurrentHistoryEntry
;
183 private JButton maPrevButton
;
184 private JButton maNextButton
;