1 /*
2 * This file is part of NetPisteur.
3 *
4 * Copyright 2001-2002 : Olivier CORNEC, David BOUANCHEAU, Loic LOPEZ,
5 * Gaetan BOUDARD, Mael LE LANNOU, Julien ROBINEAU
6 *
7 * Copyright 2002-2003 : Olivier BRIENS, Simon DEZE, Florence FRIGOULT,
8 * Olivier JOURNEAULT, Francois MARTINIER, Damien RAUDE-MORVAN
9 *
10 * Copyright 2004-2007 : Damien RAUDE-MORVAN
11 *
12 * NetPisteur is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * NetPisteur is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with NetPisteur; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 *
26 */
27 package com.drazzib.netpisteur.ui;
28
29 import java.awt.Cursor;
30 import java.io.IOException;
31 import java.net.URL;
32
33 import javax.swing.JEditorPane;
34 import javax.swing.SwingUtilities;
35 import javax.swing.text.Document;
36
37 /**
38 * Temporary class that loads synchronously (although later than the request so
39 * that a cursor change can be done)
40 */
41 public class PageLoader implements Runnable {
42
43 private URL url;
44
45 private Cursor cursor;
46
47 private JEditorPane pane;
48
49 private MainFrame frame;
50
51 /**
52 * Construct a PageLoader Object with an URL It's also need a Cusor to
53 * revert the loading and a JEditorPane / mainWindow to update loadBar
54 */
55 public PageLoader(URL u, Cursor c, JEditorPane p, MainFrame f) {
56 this.url = u;
57 this.cursor = c;
58 this.pane = p;
59 this.frame = f;
60 }
61
62 /**
63 * Launch the Thread of PageLoader by getting the page at the URL and at
64 * later time revert the Cursor
65 */
66 public void run() {
67 if (this.url == null) {
68 // restore the original cursor
69 this.frame.setCursor(this.cursor);
70 // unset the loadBar
71 this.frame.unsetProgressBar();
72 } else {
73
74 Document doc = this.pane.getDocument();
75 try {
76 // ParserGetter kit = new ParserGetter();
77 // HTMLViewer.Parser parser = kit.getParser();
78 // HTMLViewer.ParserCallback callback = new TagInter(new
79 // OutputStreamWriter(System.out), url);
80 // parser.parse(stream, callback, true);
81 this.pane.setPage(this.url);
82 } catch (IOException ioe) {
83 this.pane.setDocument(doc);
84 // getToolkit().beep();
85 } finally {
86 // schedule the cursor to revert after
87 // the paint has happended.
88 this.url = null;
89 SwingUtilities.invokeLater(this);
90 } // fin try()
91
92 } // fin if
93
94 } // fin run
95
96 }