@@ -47,35 +47,27 @@ public class WebFrame extends JFrame {
4747
4848
4949 public WebFrame (File file , int width ) throws IOException {
50- //setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
51-
52- // String content = "Could not load " + file.getAbsolutePath();
53- // if (file != null) {
54- // String[] lines = PApplet.loadStrings(file);
55- // content = PApplet.join(lines, "\n");
56- // }
57-
5850 // Need to use the URL version so that relative paths work for images
5951 // https://github.com/processing/processing/issues/3494
6052 URL fileUrl = file .toURI ().toURL (); //.toExternalForm();
61- // int high = getContentHeight(width, content);
6253 requestContentHeight (width , fileUrl );
6354
64- // while (contentHeight == 0) {
65- // try {
66- // Thread.sleep(2);
67- // } catch (InterruptedException ie) { }
68- // }
69-
70- // int high = getContentHeight(width, content);
71- // editorPane = new JEditorPane("text/html", content);
7255 editorPane = new JEditorPane ();
56+
57+ // Title cannot be set until the page has loaded
58+ editorPane .addPropertyChangeListener ("page" , new PropertyChangeListener () {
59+ public void propertyChange (PropertyChangeEvent evt ) {
60+ Object title = editorPane .getDocument ().getProperty ("title" );
61+ if (title instanceof String ) {
62+ setTitle ((String ) title );
63+ }
64+ }
65+ });
66+
7367 editorPane .setPage (fileUrl );
7468 editorPane .setEditable (false );
7569 // set height to something generic
7670 editorPane .setPreferredSize (new Dimension (width , width ));
77- // editorPane.setPreferredSize(new Dimension(width, high));
78- // editorPane.setPreferredSize(new Dimension(width, contentHeight));
7971 getContentPane ().add (editorPane );
8072
8173 Toolkit .registerWindowCloseKeys (getRootPane (), new ActionListener () {
@@ -88,11 +80,6 @@ public void actionPerformed(ActionEvent e) {
8880 editorKit = (HTMLEditorKit ) editorPane .getEditorKit ();
8981 editorKit .setAutoFormSubmission (false );
9082
91- Object title = editorPane .getDocument ().getProperty ("title" );
92- if (title instanceof String ) {
93- setTitle ((String ) title );
94- }
95-
9683 editorPane .addHyperlinkListener (new HyperlinkListener () {
9784 @ Override
9885 public void hyperlinkUpdate (HyperlinkEvent e ) {
@@ -119,9 +106,6 @@ public void hyperlinkUpdate(HyperlinkEvent e) {
119106 }
120107 }
121108 });
122- // pack();
123- // setLocationRelativeTo(null);
124- //setVisible(true);
125109 }
126110
127111
@@ -146,7 +130,6 @@ public void run() {
146130 e .printStackTrace ();
147131 }
148132 }
149- // System.out.println("setting visible");
150133 WebFrame .super .setVisible (visible );
151134 }
152135 }).start ();
0 commit comments