1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.panels;
17
18 import java.awt.BorderLayout;
19 import java.io.BufferedReader;
20 import java.io.FileReader;
21 import java.io.IOException;
22
23 import javax.swing.JEditorPane;
24 import javax.swing.JPanel;
25 import javax.swing.JScrollPane;
26 import javax.swing.event.HyperlinkEvent;
27 import javax.swing.event.HyperlinkListener;
28
29 import org.jamesii.SimSystem;
30
31 import p3j.misc.gui.GUI;
32
33
34
35
36
37
38
39
40
41 public class WelcomePanel extends JPanel implements HyperlinkListener {
42
43
44 private static final long serialVersionUID = -216475639669435678L;
45
46
47 protected static final String CONTENT_FILE = "doc/index.html";
48
49
50 private JEditorPane htmlPane;
51
52
53
54
55 public WelcomePanel() {
56 super();
57 setLayout(new BorderLayout());
58 htmlPane = new JEditorPane();
59 htmlPane.setContentType("text/html");
60 htmlPane.addHyperlinkListener(this);
61 htmlPane.setEditable(false);
62 String content = getContent();
63 htmlPane.setText(content);
64 this.add(new JScrollPane(htmlPane));
65 }
66
67
68
69
70
71
72
73 private String getContent() {
74
75 StringBuffer content = new StringBuffer();
76
77 BufferedReader reader = null;
78 try {
79 reader = new BufferedReader(new FileReader(CONTENT_FILE));
80 String line = reader.readLine();
81 while (line != null) {
82 content.append(line);
83 line = reader.readLine();
84 }
85 } catch (Exception ex) {
86 SimSystem.report(ex);
87 content.append("An error occurred:\n");
88 content.append(ex);
89 } finally {
90 if (reader != null) {
91 try {
92 reader.close();
93 } catch (IOException ex) {
94 SimSystem.report(ex);
95 }
96 }
97 }
98
99 return content.toString();
100 }
101
102 @Override
103 public void hyperlinkUpdate(HyperlinkEvent event) {
104 if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
105 try {
106 htmlPane.setPage(event.getURL());
107 } catch (IOException ioe) {
108 GUI.printErrorMessage(this, "Could not open link.", ioe.getMessage(),
109 ioe);
110 }
111 }
112 }
113 }