Skip to content

Commit e9f56c1

Browse files
committed
incremental progress on web ui
1 parent 1970ed1 commit e9f56c1

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

app/src/processing/app/ui/Welcome.java

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import javafx.application.Platform;
2525
import javafx.beans.value.ChangeListener;
2626
import javafx.beans.value.ObservableValue;
27+
import javafx.concurrent.Worker;
28+
import javafx.concurrent.Worker.State;
2729
import javafx.embed.swing.JFXPanel;
2830
import javafx.event.EventHandler;
2931
import javafx.scene.Scene;
@@ -33,7 +35,19 @@
3335

3436
import javax.swing.*;
3537

36-
import java.awt.*;
38+
import org.w3c.dom.Document;
39+
import org.w3c.dom.Element;
40+
import org.w3c.dom.NodeList;
41+
import org.w3c.dom.events.Event;
42+
import org.w3c.dom.events.EventListener;
43+
import org.w3c.dom.events.EventTarget;
44+
45+
import processing.app.Base;
46+
47+
import java.awt.BorderLayout;
48+
import java.awt.Dimension;
49+
import java.awt.EventQueue;
50+
//import java.awt.*;
3751
import java.awt.event.*;
3852
import java.io.File;
3953
import java.io.IOException;
@@ -93,9 +107,10 @@ public void actionPerformed(ActionEvent e) {
93107

94108
getContentPane().add(panel);
95109

96-
setPreferredSize(new Dimension(1024, 600));
110+
setPreferredSize(new Dimension(500, 500));
97111
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
98112
pack();
113+
setLocationRelativeTo(null);
99114
}
100115

101116

@@ -162,19 +177,51 @@ public void changed(ObservableValue<? extends Throwable> o, Throwable old, final
162177
SwingUtilities.invokeLater(new Runnable() {
163178
@Override
164179
public void run() {
165-
JOptionPane.showMessageDialog(
166-
panel,
167-
(value != null)
168-
? engine.getLocation() + "\n" + value.getMessage()
169-
: engine.getLocation() + "\nUnexpected error.",
170-
"Loading error...",
171-
JOptionPane.ERROR_MESSAGE);
180+
JOptionPane.showMessageDialog(panel,
181+
(value != null) ?
182+
engine.getLocation() + "\n" + value.getMessage() :
183+
engine.getLocation() + "\nUnexpected error.",
184+
"Loading error...",
185+
JOptionPane.ERROR_MESSAGE);
172186
}
173187
});
174188
}
175189
}
176190
});
177191

192+
final String EVENT_TYPE_CLICK = "click";
193+
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
194+
@Override
195+
public void changed(ObservableValue ov, State oldState, State newState) {
196+
if (newState == Worker.State.SUCCEEDED) {
197+
EventListener listener = new EventListener() {
198+
@Override
199+
public void handleEvent(final Event ev) {
200+
String domEventType = ev.getType();
201+
//System.err.println("EventType: " + domEventType);
202+
if (domEventType.equals(EVENT_TYPE_CLICK)) {
203+
//System.out.println("href is " + href);
204+
EventQueue.invokeLater(new Runnable() {
205+
public void run() {
206+
String href = ((Element)ev.getTarget()).getAttribute("href");
207+
Base.openURL(href);
208+
}
209+
});
210+
}
211+
}
212+
};
213+
214+
Document doc = engine.getDocument();
215+
NodeList nodeList = doc.getElementsByTagName("a");
216+
for (int i = 0; i < nodeList.getLength(); i++) {
217+
((EventTarget) nodeList.item(i)).addEventListener(EVENT_TYPE_CLICK, listener, false);
218+
//((EventTarget) nodeList.item(i)).addEventListener(EVENT_TYPE_MOUSEOVER, listener, false);
219+
//((EventTarget) nodeList.item(i)).addEventListener(EVENT_TYPE_MOUSEOVER, listener, false);
220+
}
221+
}
222+
}
223+
});
224+
178225
jfxPanel.setScene(new Scene(view));
179226
}
180227
});
@@ -218,6 +265,8 @@ public void run() {
218265
Welcome browser = new Welcome();
219266
browser.setVisible(true);
220267

268+
Base.initPlatform();
269+
221270
try {
222271
//System.out.println(System.getProperty("user.dir"));
223272
//File indexFile = Base.getLibFile("welcome/index.html");

build/shared/lib/welcome/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</p>
77
<p>
88
Note that some sketches from Processing 2 may not be compatible.
9-
<a href="">What has changed?</a>
9+
<a href="https://github.com/processing/processing/wiki/Changes">What has changed?</a>
1010
</p>
1111

1212
<div id="new_sketchbook">

0 commit comments

Comments
 (0)