Skip to content

Commit 2c97736

Browse files
committed
javafx is overkill and trickier than necessary, old school method much easier/cleaner
1 parent 6c792a0 commit 2c97736

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,75 @@
2121

2222
package processing.app.ui;
2323

24+
import java.awt.EventQueue;
25+
import java.io.File;
26+
27+
import javax.swing.*;
28+
import javax.swing.event.*;
29+
import javax.swing.text.html.*;
30+
31+
import processing.app.Base;
32+
import processing.core.PApplet;
33+
import processing.data.StringDict;
34+
35+
36+
public class Welcome {
37+
38+
static public void main(String[] args) {
39+
Base.initPlatform();
40+
41+
//File indexFile = Base.getLibFile("welcome/index.html");
42+
final File indexFile = new File("../build/shared/lib/welcome/index.html");
43+
44+
EventQueue.invokeLater(new Runnable() {
45+
public void run() {
46+
JFrame frame = new JFrame("Welcome to Processing 3");
47+
frame.setSize(500, 400);
48+
frame.setLocationRelativeTo(null);
49+
50+
frame.setVisible(true);
51+
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
52+
53+
JTextPane textPane = new JTextPane();
54+
textPane.setContentType("text/html");
55+
textPane.setEditable(false);
56+
String[] lines = PApplet.loadStrings(indexFile);
57+
textPane.setText(PApplet.join(lines, "\n"));
58+
59+
//frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
60+
frame.getContentPane().add(textPane);
61+
62+
HTMLEditorKit kit = (HTMLEditorKit) textPane.getEditorKit();
63+
kit.setAutoFormSubmission(false);
64+
textPane.addHyperlinkListener(new HyperlinkListener() {
65+
66+
@Override
67+
public void hyperlinkUpdate(HyperlinkEvent e) {
68+
//System.out.println(e);
69+
if (e instanceof FormSubmitEvent) {
70+
//System.out.println("got submit event");
71+
String result = ((FormSubmitEvent) e).getData();
72+
StringDict dict = new StringDict();
73+
String[] pairs = result.split("&");
74+
for (String pair : pairs) {
75+
String[] pieces = pair.split("=");
76+
String attr = PApplet.urlDecode(pieces[0]);
77+
String valu = PApplet.urlDecode(pieces[1]);
78+
dict.set(attr, valu);
79+
}
80+
dict.print();
81+
} else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
82+
//System.out.println("clicked " + e.getURL());
83+
Base.openURL(e.getURL().toExternalForm());
84+
}
85+
}
86+
});
87+
}
88+
});
89+
}
90+
}
91+
92+
/*
2493
import javafx.application.Platform;
2594
import javafx.beans.value.ChangeListener;
2695
import javafx.beans.value.ObservableValue;
@@ -279,3 +348,4 @@ public void run() {
279348
});
280349
}
281350
}
351+
*/

build/shared/lib/welcome/index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html>
2-
<body>
3-
<form>
2+
<body>
3+
<!-- action needs to exist (even though blank), otherwise causes NPE -->
4+
<form action="">
45
<p>
56
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">Read about what&rsquo;s new in 3.0</a> &rarr;
67
</p>
@@ -14,7 +15,7 @@
1415
Since older sketches may not be compatible, we recommend creating a new sketchbook folder, so Processing 2 and 3 can happily coexist. This is a one-time process. <a href="https://github.com/processing/processing/wiki/Multiple-Sketchbooks">Read more about it.</a>
1516
</p>
1617

17-
<input type="radio" name="sketchbook" value="create_new" />
18+
<input type="radio" name="sketchbook" value="create_new" checked />
1819
Create a new sketchbook folder for use with Processing 3 sketches <i>(recommended!)</i>
1920
<br/>
2021
<input type="radio" name="sketchbook" value="use_existing" />
@@ -25,7 +26,7 @@
2526
<input type="checkbox" name="show_each_time" checked />
2627
Show this welcome message each time
2728
<br/>
28-
<input type="button" value="Get Started" />
29+
<input type="submit" value="Get Started" />
2930
</form>
3031
</body>
3132
</html>

0 commit comments

Comments
 (0)