Skip to content

Commit f65616a

Browse files
committed
major work on the Welcome screen (fixes processing#3911, processing#3912)
1 parent 2d00f59 commit f65616a

7 files changed

Lines changed: 167 additions & 151 deletions

File tree

app/src/processing/app/ui/WebFrame.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package processing.app.ui;
2323

24+
import java.awt.Container;
2425
import java.awt.Dimension;
2526
import java.awt.event.ActionEvent;
2627
import java.awt.event.ActionListener;
@@ -46,10 +47,10 @@ public class WebFrame extends JFrame {
4647
boolean ready;
4748

4849

49-
public WebFrame(File file, int width) throws IOException {
50+
public WebFrame(File file, int width, Container panel) throws IOException {
5051
// Need to use the URL version so that relative paths work for images
5152
// https://github.com/processing/processing/issues/3494
52-
URL fileUrl = file.toURI().toURL(); //.toExternalForm();
53+
URL fileUrl = file.toURI().toURL();
5354
requestContentHeight(width, fileUrl);
5455

5556
editorPane = new JEditorPane();
@@ -68,7 +69,14 @@ public void propertyChange(PropertyChangeEvent evt) {
6869
editorPane.setEditable(false);
6970
// set height to something generic
7071
editorPane.setPreferredSize(new Dimension(width, width));
71-
getContentPane().add(editorPane);
72+
73+
//getContentPane().add(editorPane);
74+
Container pain = getContentPane();
75+
pain.setLayout(new BoxLayout(pain, BoxLayout.Y_AXIS));
76+
pain.add(editorPane);
77+
if (panel != null) {
78+
pain.add(panel);
79+
}
7280

7381
Toolkit.registerWindowCloseKeys(getRootPane(), new ActionListener() {
7482
@Override

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

Lines changed: 95 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,114 @@
2121

2222
package processing.app.ui;
2323

24+
import java.awt.Color;
2425
import java.awt.EventQueue;
26+
import java.awt.Font;
27+
import java.awt.event.ActionEvent;
28+
import java.awt.event.ActionListener;
29+
import java.awt.event.ItemEvent;
30+
import java.awt.event.ItemListener;
2531
import java.io.File;
2632
import java.io.IOException;
2733

34+
import javax.swing.Box;
35+
import javax.swing.JButton;
36+
import javax.swing.JCheckBox;
37+
import javax.swing.JComponent;
38+
2839
import processing.app.Base;
2940
import processing.app.Language;
3041
import processing.app.Platform;
3142
import processing.app.Preferences;
3243
import processing.core.PApplet;
33-
import processing.data.StringDict;
3444

3545

36-
public class Welcome extends WebFrame {
46+
public class Welcome {
3747
Base base;
48+
WebFrame view;
3849

3950

4051
public Welcome(Base base, boolean sketchbook) throws IOException {
41-
super(getIndexFile(sketchbook), 400);
4252
this.base = base;
43-
//addStyle("#new_sketchbook { background-color: rgb(0, 255, 0); }");
44-
setVisible(true);
45-
}
4653

54+
// TODO this should live inside theme or somewhere modifiable
55+
Font dialogFont = Toolkit.getSansFont(14, Font.PLAIN);
56+
57+
JComponent panel = Box.createHorizontalBox();
58+
panel.setBackground(new Color(245, 245, 245));
59+
Toolkit.setBorder(panel, 15, 20, 15, 20);
60+
61+
//panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
62+
//panel.add(Box.createHorizontalStrut(20));
63+
JCheckBox checkbox = new JCheckBox("Show this message on startup");
64+
checkbox.setFont(dialogFont);
65+
// handles the Help menu invocation, and also the pref not existing
66+
checkbox.setSelected("true".equals(Preferences.get("welcome.show")));
67+
checkbox.addItemListener(new ItemListener() {
68+
@Override
69+
public void itemStateChanged(ItemEvent e) {
70+
if (e.getStateChange() == ItemEvent.SELECTED) {
71+
Preferences.setBoolean("welcome.show", true);
72+
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
73+
Preferences.setBoolean("welcome.show", false);
74+
}
75+
}
76+
});
77+
panel.add(checkbox);
4778

48-
public void handleSubmit(StringDict dict) {
49-
// sketchbook = "create_new" or "use_existing"
50-
// show_each_time = "on" or <not param>
51-
//dict.print();
52-
53-
String sketchbookAction = dict.get("sketchbook", null);
54-
if ("create_new".equals(sketchbookAction)) {
55-
// open file dialog
56-
// on affirmative selection, update sketchbook folder
57-
// String path = Preferences.getSketchbookPath() + "3";
58-
// File folder = new File(path);
59-
// folder.mkdirs();
60-
File folder = new File(Preferences.getSketchbookPath()).getParentFile();
61-
PApplet.selectFolder(Language.text("preferences.sketchbook_location.popup"),
62-
"sketchbookCallback", folder,
63-
this, this);
64-
}
79+
panel.add(Box.createHorizontalGlue());
6580

66-
// If un-checked, the key won't be in the dict, so null will be passed
67-
boolean keepShowing = "on".equals(dict.get("show_each_time", null));
68-
Preferences.setBoolean("welcome.show", keepShowing);
69-
Preferences.save();
81+
JButton button = new JButton("Get Started");
82+
button.setFont(Toolkit.getSansFont(14, Font.PLAIN));
83+
button.addActionListener(new ActionListener() {
84+
public void actionPerformed(ActionEvent e) {
85+
view.handleClose();
86+
}
87+
});
88+
panel.add(button);
89+
//panel.add(Box.createHorizontalGlue());
90+
91+
view = new WebFrame(getIndexFile(sketchbook), 425, panel) {
92+
/*
93+
@Override
94+
public void handleSubmit(StringDict dict) {
95+
String sketchbookAction = dict.get("sketchbook", null);
96+
if ("create_new".equals(sketchbookAction)) {
97+
File folder = new File(Preferences.getSketchbookPath()).getParentFile();
98+
PApplet.selectFolder(Language.text("preferences.sketchbook_location.popup"),
99+
"sketchbookCallback", folder,
100+
this, this);
101+
}
70102
71-
handleClose();
103+
// // If un-checked, the key won't be in the dict, so null will be passed
104+
// boolean keepShowing = "on".equals(dict.get("show_each_time", null));
105+
// Preferences.setBoolean("welcome.show", keepShowing);
106+
// Preferences.save();
107+
handleClose();
108+
}
109+
*/
110+
111+
@Override
112+
public void handleLink(String link) {
113+
// The link will already have the full URL prefix
114+
if (link.endsWith("#sketchbook")) {
115+
File folder = new File(Preferences.getSketchbookPath()).getParentFile();
116+
PApplet.selectFolder(Language.text("preferences.sketchbook_location.popup"),
117+
"sketchbookCallback", folder,
118+
this, this);
119+
} else {
120+
super.handleLink(link);
121+
}
122+
}
123+
124+
@Override
125+
public void handleClose() {
126+
Preferences.setBoolean("welcome.seen", true);
127+
Preferences.save();
128+
super.handleClose();
129+
}
130+
};
131+
view.setVisible(true);
72132
}
73133

74134

@@ -77,16 +137,17 @@ public void sketchbookCallback(File folder) {
77137
if (folder != null) {
78138
if (base != null) {
79139
base.setSketchbookFolder(folder);
80-
} else {
81-
System.out.println("user selected " + folder);
140+
// } else {
141+
// System.out.println("user selected " + folder);
82142
}
83143
}
84144
}
85145

86146

87-
public void handleClose() {
88-
dispose();
89-
}
147+
// @Override
148+
// public void handleClose() {
149+
// dispose();
150+
// }
90151

91152

92153
static private File getIndexFile(boolean sketchbook) {
@@ -120,11 +181,7 @@ static public void main(String[] args) {
120181
EventQueue.invokeLater(new Runnable() {
121182
public void run() {
122183
try {
123-
new Welcome(null, true) {
124-
public void handleClose() {
125-
System.exit(0);
126-
}
127-
};
184+
new Welcome(null, true);
128185
} catch (IOException e) {
129186
e.printStackTrace();
130187
}

build/shared/lib/welcome/generic.html

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,27 @@
55
</head>
66
<body>
77

8-
<!-- action needs to exist (even though blank), otherwise causes NPE -->
9-
<form action="">
8+
<!-- Using a table here as a layout hack, as CSS "vertical-align: middle;"
9+
is not supported by the Java HTML renderer. -->
10+
<table>
11+
<tr>
12+
<td valign="top">
13+
<img src="../icons/pde-64.png" width="64" height="64">
14+
</td>
15+
<td valign="middle">
16+
<h1>Welcome to Processing 3</h1>
17+
</td>
18+
</tr>
19+
</table>
20+
21+
<p>
22+
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">Read about what&rsquo;s new in 3.0 &rarr;</a>
23+
</p>
1024

11-
<!-- Using a table here as a layout hack, as CSS "vertical-align: middle;"
12-
is not supported by the Java HTML renderer. -->
13-
<table>
14-
<tr>
15-
<td valign="top">
16-
<img src="../icons/pde-64.png" width="64" height="64">
17-
</td>
18-
<td valign="middle">
19-
<h1>Welcome to Processing 3</h1>
20-
</td>
21-
</tr>
22-
</table>
23-
24-
<p>
25-
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">Read about what&rsquo;s new in 3.0 &rarr;</a>
26-
</p>
27-
28-
<p class="inset">
29-
Note that some sketches from Processing 2 may not be compatible.
30-
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">What has changed?</a>
31-
</p>
32-
33-
<table>
34-
<tr>
35-
<td>
36-
<input type="checkbox" name="show_each_time" checked />
37-
</td>
38-
<td>
39-
Show this welcome<br/>message each time
40-
</td>
41-
<td>
42-
<input id="startButton" type="submit" value="Get Started" />
43-
</td>
44-
</tr>
45-
</table>
46-
47-
</form>
25+
<p class="inset">
26+
Note that some sketches from Processing 2 may not be compatible.
27+
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">What has changed?</a>
28+
</p>
4829

4930
</body>
5031
</html>

build/shared/lib/welcome/sketchbook.html

Lines changed: 31 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,46 @@
55
</head>
66
<body>
77

8-
<!-- action needs to exist (even though blank), otherwise causes NPE -->
9-
<form action="">
10-
11-
<!-- Using a table here as a layout hack, as CSS "vertical-align: middle;"
12-
is not supported by the Java HTML renderer. -->
13-
<table>
14-
<tr>
15-
<td valign="top">
16-
<img src="../icons/pde-64.png" width="64" height="64">
17-
</td>
18-
<td valign="middle">
19-
<h1>Welcome to Processing 3</h1>
20-
</td>
21-
</tr>
22-
</table>
23-
8+
<!-- Using a table here as a layout hack, as CSS "vertical-align: middle;"
9+
is not supported by the Java HTML renderer. -->
10+
<table>
11+
<tr>
12+
<td valign="top">
13+
<img src="../icons/pde-64.png" width="64" height="64">
14+
</td>
15+
<td valign="middle">
16+
<h1>Welcome to Processing 3</h1>
17+
</td>
18+
</tr>
19+
</table>
20+
21+
<p>
22+
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">Read about what&rsquo;s new in 3.0 &rarr;</a>
23+
</p>
24+
25+
<p class="inset">
26+
Note that some sketches from Processing 2 may not be compatible.
27+
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">What has changed?</a>
28+
</p>
29+
30+
<div id="new_sketchbook">
2431
<p>
25-
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">Read about what&rsquo;s new in 3.0 &rarr;</a>
32+
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>
2633
</p>
2734

28-
<p class="inset">
29-
Note that some sketches from Processing 2 may not be compatible.
30-
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">What has changed?</a>
31-
</p>
32-
33-
<div id="new_sketchbook">
34-
<p>
35-
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>
36-
</p>
37-
38-
<table class="inset">
39-
<tr>
40-
<td>
41-
<input type="radio" name="sketchbook" value="create_new" checked />
42-
</td>
43-
<td>
44-
Create a new sketchbook folder for use with Processing 3 sketches <em>(recommended!)</em>
45-
</td>
46-
</tr>
47-
<tr>
48-
<td>
49-
<input type="radio" name="sketchbook" value="use_existing" />
50-
</td>
51-
<td>
52-
Use the existing sketchbook folder for both old and new sketches (may cause conflicts with installed libraries)
53-
</td>
54-
</tr>
55-
</table>
56-
57-
</div>
58-
59-
<table>
35+
<table class="inset">
6036
<tr>
6137
<td>
62-
<input type="checkbox" name="show_each_time" checked />
63-
</td>
64-
<td>
65-
Show this welcome<br/>message each time
38+
<a href="#sketchbook">Click here</a> to create a new sketchbook folder for Processing 3 <em>(recommended!)</em>
6639
</td>
40+
</tr>
41+
<tr>
6742
<td>
68-
<input id="startButton" type="submit" value="Get Started" />
43+
Otherwise, your existing sketchbook folder will be used for both old and new sketches (may cause conflicts with installed libraries)
6944
</td>
7045
</tr>
7146
</table>
72-
73-
</form>
74-
47+
</div>
48+
7549
</body>
7650
</html>

0 commit comments

Comments
 (0)