20 package net.sf.gridarta.gui.dialog.help;
22 import java.awt.Component;
23 import java.awt.Cursor;
25 import java.io.IOException;
26 import java.net.MalformedURLException;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import javax.swing.JEditorPane;
31 import javax.swing.JScrollPane;
32 import javax.swing.JViewport;
33 import javax.swing.SwingUtilities;
34 import javax.swing.event.HyperlinkEvent;
35 import javax.swing.event.HyperlinkListener;
36 import javax.swing.text.Document;
38 import org.jetbrains.annotations.NotNull;
39 import org.jetbrains.annotations.Nullable;
45 class HtmlPane
extends JScrollPane implements HyperlinkListener {
51 private static final Logger LOG = Logger.getLogger(
"HtmlPane.class");
56 private static final long serialVersionUID = 1L;
62 private final JEditorPane html;
69 HtmlPane(@NotNull
final String fileName) {
72 final File file =
new File(CommonConstants.HELP_DIR, fileName);
75 final String s =
"file:" + file.getAbsolutePath();
76 html =
new JEditorPane(s);
79 final URL url1 = ClassLoader.getSystemResource(CommonConstants.HELP_DIR.replace(
'\\',
'/') +
'/' + fileName);
82 html =
new JEditorPane(url1);
85 LOG.info(
"trying: HelpFiles/" + fileName);
86 final URL url2 = ClassLoader.getSystemResource(
"HelpFiles/" + fileName);
88 html =
new JEditorPane(url2);
90 LOG.info(
"Failed to open help file '" + fileName +
"'!");
91 throw new RuntimeException();
96 html.setEditable(
false);
97 html.addHyperlinkListener(
this);
98 final JViewport vp = getViewport();
105 getViewport().putClientProperty(
"EnableWindowBlit", Boolean.TRUE);
106 vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
111 setAutoscrolls(
true);
112 }
catch (
final NullPointerException e) {
114 throw new RuntimeException(e);
115 }
catch (
final MalformedURLException e) {
116 LOG.log(Level.WARNING,
"Malformed URL: %s", e);
117 throw new RuntimeException(e);
118 }
catch (
final IOException e) {
119 LOG.log(Level.WARNING,
"IOException: %s", e);
120 throw new RuntimeException(e);
130 HtmlPane(@NotNull
final String type, @NotNull
final String text) {
132 html =
new JEditorPane(type, text);
133 html.setEditable(
false);
134 html.addHyperlinkListener(
this);
135 final JViewport vp = getViewport();
142 getViewport().putClientProperty(
"EnableWindowBlit", Boolean.TRUE);
143 vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
149 setAutoscrolls(
true);
157 public void hyperlinkUpdate(@NotNull
final HyperlinkEvent e) {
158 if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
159 linkActivated(e.getURL());
172 private void linkActivated(@NotNull
final URL u) {
173 final Cursor cursor = html.getCursor();
174 final Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
175 html.setCursor(waitCursor);
176 SwingUtilities.invokeLater(
new PageLoader(u, cursor));
201 private PageLoader(@NotNull
final URL url, @NotNull
final Cursor cursor) {
210 html.setCursor(cursor);
214 final Component parent = html.getParent();
217 final Document doc = html.getDocument();
220 }
catch (
final IOException ioe) {
221 html.setDocument(doc);
228 SwingUtilities.invokeLater(
this);
Synchronous page loader, loads a page and handles the cursor.
Class with constants used in Gridarta and derivates.
PageLoader(@NotNull final URL url, @NotNull final Cursor cursor)
Create a PageLoader.
Base package of all Gridarta classes.
final Cursor cursor
Original cursor that should be restored once the document is loaded.