Debian Codegraph @

uk/ac/babraham/FastQC/Help/HelpPageDisplay.java

raw symbols SCIP
1 /**
2 * Copyright 2009-15 Simon Andrews
3 *
4 * This file is part of SeqMonk.
5 *
6 * SeqMonk is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * SeqMonk is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with SeqMonk; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 package uk.ac.babraham.FastQC.Help;
21
22 import java.awt.BorderLayout;
23 import java.awt.Graphics;
24 import java.awt.Graphics2D;
25 import java.awt.RenderingHints;
26 import java.io.IOException;
27 import java.net.MalformedURLException;
28 import java.net.URL;
29
30 import javax.swing.BorderFactory;
31 import javax.swing.JEditorPane;
32 import javax.swing.JPanel;
33 import javax.swing.JScrollPane;
34 import javax.swing.event.HyperlinkEvent;
35 import javax.swing.event.HyperlinkListener;
36
37 /**
38 * The Class HelpPageDisplay.
39 */
40 public class HelpPageDisplay extends JPanel implements HyperlinkListener {
41
42 /** The html pane. */
43 public JEditorPane htmlPane;
44
45 /**
46 * Instantiates a new help page display.
47 *
48 * @param page the page
49 */
50 public HelpPageDisplay (HelpPage page) {
51
52 if (page != null) {
53 try {
54 htmlPane = new HelpEditor(page.getFile().toURI().toURL());
55 }
56 catch (MalformedURLException e) {
57 e.printStackTrace();
58 }
59 catch (IOException e) {
60 e.printStackTrace();
61 }
62
63 htmlPane.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
64 htmlPane.setEditable(false);
65 htmlPane.addHyperlinkListener(this);
66
67 setLayout(new BorderLayout());
68 add(new JScrollPane(htmlPane),BorderLayout.CENTER);
69 }
70 }
71
72
73 /**
74 * The Class HelpEditor.
75 */
76 private class HelpEditor extends JEditorPane {
77
78 /**
79 * Instantiates a new help editor.
80 *
81 * @param u the u
82 * @throws IOException Signals that an I/O exception has occurred.
83 */
84 public HelpEditor (URL u) throws IOException {
85 super(u);
86 }
87
88 /* (non-Javadoc)
89 * @see javax.swing.JComponent#paint(java.awt.Graphics)
90 */
91 public void paint(Graphics g) {
92 if (g instanceof Graphics2D) {
93 Graphics2D g2 = (Graphics2D)g;
94 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
95 }
96 super.paint(g);
97 }
98 }
99
100 /* (non-Javadoc)
101 * @see javax.swing.event.HyperlinkListener#hyperlinkUpdate(javax.swing.event.HyperlinkEvent)
102 */
103 public void hyperlinkUpdate(HyperlinkEvent h) {
104 if (h.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
105 try {
106 htmlPane.setPage(h.getURL());
107 } catch (IOException e) {
108 e.printStackTrace();
109 }
110 }
111 }
112
113 }