-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathWelcome2.java
More file actions
362 lines (315 loc) · 11.7 KB
/
Welcome2.java
File metadata and controls
362 lines (315 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2017-19 The Processing Foundation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package processing.app.ui;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import processing.app.Base;
import processing.app.Language;
import processing.app.Platform;
import processing.app.Preferences;
import processing.core.PApplet;
/**
* The Welcome class creates a welcome window upon startup
*
* It provides links to changes Processing 3
*
* If the user is migrating from Processing 2, it provides a
* prompt asking whether to use the same sketchbook folder
* as before, or use a new one.
*/
public class Welcome2 extends JFrame {
Base base;
boolean newSketchbook;
/**
* @param Base the current Processing Base
* @param oldSketchbook true if the user has a Processing 2 sketchbook
* @throws IOException if resources cannot be found
*/
public Welcome2(Base base, boolean oldSketchbook) throws IOException {
this.base = base;
// strings used in the GUI
// should be moved to external files to make tranlsation easier
final String welcomeText = "Welcome to Processing 3";
final String whatsNewText = "Read about what's new in 3.0 \u2192";
final String compatibleText = "Note that some sketches from Processing 2 " +
"may not be compatible.";
final String whatHasChangedText = "What has changed?";
final String newSketchbookText = "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.";
final String readMoreText = "Read more about it";
final String createNewSketchbookText = "Create a new sketchbook " +
"folder for use with Processing 3 sketches (recommended!)";
final String useOldSketchbookText = "Use the existing sketchbook " +
"for both old and new sketches (may cause conflicts with installed " +
"libraries)";
final String showEachTimeText = "Show this welcome message each time";
// color used for boxes with special information
final Color insetColor = new Color(224, 253, 251);
// color used in hyperlinks
final Color linkColor = new Color(44, 123, 181);
final String whatsNewUrl = "https://github.com/processing/processing/wiki/Changes-in-3.0";
// Font processingSemibold;
// Font processingSansPro;
// load fonts
// try {
// processingSemibold = Font.createFont(Font.TRUETYPE_FONT,
// Base.getLibFile("/fonts/ProcessingSansPro-Semibold.ttf"));
// processingSansPro = Font.createFont(Font.TRUETYPE_FONT,
// Base.getLibFile("/fonts/ProcessingSansPro-Regular.ttf"));
// } catch (FontFormatException e) {
// processingSemibold = UIManager.getDefaults().getFont("Label.font");
// processingSansPro = UIManager.getDefaults().getFont("Label.font");
// }
//
// headerFont = processingSemibold.deriveFont(20f);
// bodyFont = processingSansPro.deriveFont(12f);
Font headerFont = Toolkit.getSansFont(20, Font.BOLD);
Font bodyFont = Toolkit.getSansFont(12, Font.PLAIN);
//Set welcome window title
setTitle(welcomeText);
// release frame resources on close
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
//Main content panel
JPanel panel = new JPanel(new GridBagLayout());
Toolkit.setBorder(panel, 20, 20, 20, 20);
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.LINE_START;
c.fill = GridBagConstraints.HORIZONTAL;
//int width = sketchbook ? 500 : 400;
// int width = Toolkit.zoom(400);
// int height = Toolkit.zoom(oldSketchbook ? 400 : 250);
int width = 400;
int height = oldSketchbook ? 400 : 250;
panel.setPreferredSize(Toolkit.zoom(width, height));
panel.setBackground(Color.white);
// Processing logo
JLabel logo = new JLabel(Toolkit.getLibIcon("/icons/pde-64.png"));
c.gridx = 0;
c.gridy = 0;
panel.add(logo, c);
// welcome header
JLabel header = new JLabel(welcomeText);
header.setFont(headerFont);
c.gridx = 1;
c.gridy = 0;
panel.add(header, c);
// read what's new link
JLabel readNew = new JLabel(whatsNewText);
readNew.setForeground(linkColor);
readNew.setFont(bodyFont);
readNew.setCursor(new Cursor(Cursor.HAND_CURSOR));
readNew.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Platform.openURL(whatsNewUrl);
}
});
c.gridwidth = 2;
c.gridx = 0;
c.gridy = 1;
panel.add(readNew, c);
// compatible notice inset
JPanel compatible = new JPanel(new GridBagLayout());
GridBagConstraints compc = new GridBagConstraints();
compatible.setBackground(insetColor);
Toolkit.setBorder(compatible, 10, 0, 10, 0);
compc.anchor = GridBagConstraints.FIRST_LINE_START;
compc.fill = GridBagConstraints.HORIZONTAL;
// compatible notice text
JLabel compatibleNotice = new JLabel(compatibleText);
compatibleNotice.setFont(bodyFont);
compc.gridx = 0;
compc.gridy = 0;
compatible.add(compatibleNotice, compc);
// link to what has changed
JLabel changed = new JLabel(whatHasChangedText);
changed.setFont(bodyFont);
changed.setForeground(linkColor);
changed.setCursor(new Cursor(Cursor.HAND_CURSOR));
changed.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Platform.openURL(whatsNewUrl);
}
});
compc.gridx = 0;
compc.gridy = 1;
compatible.add(changed, compc);
// add compatible notice inset into main panel
c.gridx = 0;
c.gridy = 2;
panel.add(compatible, c);
// if the user needs to choose a new sketchbook
if (oldSketchbook) {
// create new sketchbook prompt
JTextArea newSketchbookPrompt = new JTextArea(newSketchbookText);
newSketchbookPrompt.setFont(bodyFont);
newSketchbookPrompt.setEditable(false);
newSketchbookPrompt.setLineWrap(true);
newSketchbookPrompt.setWrapStyleWord(true);
c.gridx = 0;
c.gridy = 3;
panel.add(newSketchbookPrompt, c);
// read more link
JLabel readMore = new JLabel(readMoreText);
readMore.setFont(bodyFont);
c.gridx = 0;
c.gridy = 4;
panel.add(readMore, c);
// inset for choose sketchbook
JPanel chooseSketchbook = new JPanel(new GridBagLayout());
Toolkit.setBorder(chooseSketchbook, 10, 0, 10, 0);
GridBagConstraints choosec = new GridBagConstraints();
choosec.fill = GridBagConstraints.HORIZONTAL;
choosec.anchor = GridBagConstraints.LINE_START;
chooseSketchbook.setBackground(insetColor);
// sketchbookGroup contains radio buttons for selection
ButtonGroup sketchbookGroup = new ButtonGroup();
// create a new sketchbook for Processing 3 option
JRadioButton createNew = new JRadioButton(createNewSketchbookText);
sketchbookGroup.add(createNew);
createNew.setSelected(true);
createNew.setFont(bodyFont);
createNew.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
//dict.set("sketchbook", "create_new");
newSketchbook = true;
}
}
});
// set default
//dict.set("sketchbook", "create_new");
newSketchbook = true;
choosec.gridx = 0;
choosec.gridy = 0;
chooseSketchbook.add(createNew, choosec);
// share sketchbook with Processing 2 option
JRadioButton useOld = new JRadioButton("<html>" + useOldSketchbookText);
sketchbookGroup.add(useOld);
useOld.setFont(bodyFont);
useOld.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
//dict.set("sketchbook", "use_existing");
newSketchbook = false;
}
}
});
choosec.gridx = 0;
choosec.gridy = 1;
chooseSketchbook.add(useOld, choosec);
// add choose sketchbook inset into main panel
c.gridx = 0;
c.gridy = 5;
panel.add(chooseSketchbook, c);
}
// show welcome each time checkbox
// fixes https://github.com/processing/processing/issues/3912
JCheckBox showEachTime = new JCheckBox("<html>" + showEachTimeText);
// handles the Help menu invocation, and also the pref not existing
showEachTime.setSelected("true".equals(Preferences.get("welcome.show")));
showEachTime.setFont(bodyFont);
showEachTime.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
Preferences.setBoolean("welcome.show", true);
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
Preferences.setBoolean("welcome.show", false);
}
}
});
// set default
// dict.set("show_each_time", "on");
c.gridx = 0;
c.gridy = 6;
panel.add(showEachTime, c);
// get started (submit) button
JButton getStarted = new JButton("Get Started");
getStarted.setFont(bodyFont);
getStarted.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
handleClose();
}
});
c.fill = GridBagConstraints.NONE;
c.gridx = 0;
c.gridy = 7;
c.anchor = GridBagConstraints.LAST_LINE_END;
panel.add(getStarted, c);
add(panel);
pack();
Toolkit.registerWindowCloseKeys(getRootPane(), new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleClose();
}
});
// center window on the screen
setLocationRelativeTo(null);
setVisible(true);
}
/**
* Callback for the folder selector, used when user chooses
* a new sketchbook for Processing 3
* @param folder the path to the new sketcbook
*/
public void sketchbookCallback(File folder) {
if (folder != null) {
if (base != null) {
base.setSketchbookFolder(folder);
} else {
System.out.println("user selected " + folder);
}
}
}
/**
* Closes the window
*/
public void handleClose() {
Preferences.save(); // save the "show this" setting
if (newSketchbook) {
File folder = new File(Preferences.getSketchbookPath()).getParentFile();
PApplet.selectFolder(Language.text("preferences.sketchbook_location.popup"),
"sketchbookCallback", folder, this, this);
}
dispose();
}
}