Skip to content

Commit b56034e

Browse files
committed
Merged 1.0.4 pre-release into 1.5
2 parents 38c05d2 + ce1ccb4 commit b56034e

File tree

8 files changed

+104
-38
lines changed

8 files changed

+104
-38
lines changed

app/src/processing/app/Base.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public class Base {
113113

114114

115115
static public void main(String args[]) throws Exception {
116+
initPlatform();
117+
118+
// run static initialization that grabs all the prefs
119+
Preferences.init(null);
120+
116121
try {
117122
File versionFile = getContentFile("lib/version.txt");
118123
if (versionFile.exists()) {
@@ -151,8 +156,6 @@ static public void main(String args[]) throws Exception {
151156
}
152157
*/
153158

154-
initPlatform();
155-
156159
// // Set the look and feel before opening the window
157160
// try {
158161
// platform.setLookAndFeel();
@@ -172,12 +175,6 @@ static public void main(String args[]) throws Exception {
172175
// Make sure a full JDK is installed
173176
//initRequirements();
174177

175-
// run static initialization that grabs all the prefs
176-
Preferences.init(null);
177-
178-
// load the I18n module for internationalization
179-
I18n.init(Preferences.get("editor.languages.current"));
180-
181178
// setup the theme coloring fun
182179
Theme.init();
183180

app/src/processing/app/EditorStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ public void paintComponent(Graphics screen) {
290290

291291
protected void setup() {
292292
if (okButton == null) {
293-
cancelButton = new JButton(Preferences.PROMPT_CANCEL);
294-
okButton = new JButton(Preferences.PROMPT_OK);
293+
cancelButton = new JButton(I18n.PROMPT_CANCEL);
294+
okButton = new JButton(I18n.PROMPT_OK);
295295

296296
cancelButton.addActionListener(new ActionListener() {
297297
public void actionPerformed(ActionEvent e) {

app/src/processing/app/I18n.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,29 @@
1919

2020
public class I18n {
2121
// start using current locale but still allow using the dropdown list later
22-
private static ResourceBundle i18n = ResourceBundle.getBundle("processing.app.Resources");
23-
public static Locale locale;
22+
private static ResourceBundle i18n;
23+
24+
// prompt text stuff
25+
26+
static String PROMPT_YES;
27+
static String PROMPT_NO;
28+
static String PROMPT_CANCEL;
29+
static String PROMPT_OK;
30+
static String PROMPT_BROWSE;
2431

2532
static protected void init (String language) {
2633
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
2734
try {
28-
if (language == null || language.trim().length() == 0) locale = Locale.getDefault();
29-
else locale = new Locale(language);
30-
i18n = ResourceBundle.getBundle("processing.app.Resources", locale);
35+
if (language != null && language.trim().length() > 0) {
36+
Locale.setDefault(new Locale(language));
37+
}
38+
i18n = ResourceBundle.getBundle("processing.app.Resources", Locale.getDefault());
39+
40+
PROMPT_YES = _("Yes");
41+
PROMPT_NO = _("No");
42+
PROMPT_CANCEL = _("Cancel");
43+
PROMPT_OK = _("OK");
44+
PROMPT_BROWSE = _("Browse");
3145
} catch (java.lang.NullPointerException e) {
3246
}
3347
}

app/src/processing/app/Platform.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import com.sun.jna.Library;
3131
import com.sun.jna.Native;
32+
import processing.core.PConstants;
3233

3334

3435
/**
@@ -159,6 +160,10 @@ public int unsetenv(String variable) {
159160
return clib.unsetenv(variable);
160161
}
161162

163+
public String getName() {
164+
return PConstants.platformNames[PConstants.OTHER];
165+
}
166+
162167

163168
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
164169

app/src/processing/app/Preferences.java

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323

2424
package processing.app;
2525

26+
import processing.app.syntax.SyntaxStyle;
27+
import processing.core.PApplet;
28+
import processing.core.PConstants;
29+
30+
import javax.swing.*;
2631
import java.awt.*;
2732
import java.awt.event.*;
2833
import java.io.*;
2934
import java.util.*;
3035

31-
import javax.swing.*;
32-
3336
import processing.app.helpers.PreferencesMap;
34-
import processing.app.syntax.*;
35-
import processing.core.*;
3637
import static processing.app.I18n._;
3738

3839

@@ -71,15 +72,6 @@ public class Preferences {
7172

7273
static final String PREFS_FILE = "preferences.txt";
7374

74-
75-
// prompt text stuff
76-
77-
static final String PROMPT_YES = _("Yes");
78-
static final String PROMPT_NO = _("No");
79-
static final String PROMPT_CANCEL = _("Cancel");
80-
static final String PROMPT_OK = _("OK");
81-
static final String PROMPT_BROWSE = _("Browse");
82-
8375
String[] languages = {
8476
_("System Default"),
8577
"العربية" + " (" + _("Arabic") + ")",
@@ -228,7 +220,7 @@ static protected void init(String commandLinePrefs) {
228220
table.put("runtime.ide.version", "" + Base.REVISION);
229221

230222
// check for platform-specific properties in the defaults
231-
String platformExt = "." + PConstants.platformNames[PApplet.platform];
223+
String platformExt = "." + Base.platform.getName();
232224
int platformExtLength = platformExt.length();
233225
Enumeration e = table.keys();
234226
while (e.hasMoreElements()) {
@@ -244,9 +236,6 @@ static protected void init(String commandLinePrefs) {
244236
// clone the hash table
245237
defaults = (Hashtable) table.clone();
246238

247-
// other things that have to be set explicitly for the defaults
248-
setColor("run.window.bgcolor", SystemColor.control);
249-
250239
// Load a prefs file if specified on the command line
251240
if (commandLinePrefs != null) {
252241
try {
@@ -283,7 +272,13 @@ static protected void init(String commandLinePrefs) {
283272
), ex);
284273
}
285274
}
286-
}
275+
}
276+
277+
// load the I18n module for internationalization
278+
I18n.init(Preferences.get("editor.languages.current"));
279+
280+
// other things that have to be set explicitly for the defaults
281+
setColor("run.window.bgcolor", SystemColor.control);
287282
}
288283

289284

@@ -322,7 +317,7 @@ public Preferences() {
322317
pain.add(sketchbookLocationField);
323318
d = sketchbookLocationField.getPreferredSize();
324319

325-
button = new JButton(PROMPT_BROWSE);
320+
button = new JButton(I18n.PROMPT_BROWSE);
326321
button.addActionListener(new ActionListener() {
327322
public void actionPerformed(ActionEvent e) {
328323
File dflt = new File(sketchbookLocationField.getText());
@@ -486,7 +481,7 @@ public void mouseExited(MouseEvent e) {
486481

487482
// [ OK ] [ Cancel ] maybe these should be next to the message?
488483

489-
button = new JButton(PROMPT_OK);
484+
button = new JButton(I18n.PROMPT_OK);
490485
button.addActionListener(new ActionListener() {
491486
public void actionPerformed(ActionEvent e) {
492487
applyFrame();
@@ -501,7 +496,7 @@ public void actionPerformed(ActionEvent e) {
501496
button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
502497
h += BUTTON_WIDTH + GUI_SMALL;
503498

504-
button = new JButton(PROMPT_CANCEL);
499+
button = new JButton(I18n.PROMPT_CANCEL);
505500
button.addActionListener(new ActionListener() {
506501
public void actionPerformed(ActionEvent e) {
507502
disposeFrame();
@@ -682,8 +677,8 @@ static protected void load(InputStream input) throws IOException {
682677
load(input, table);
683678
}
684679

685-
static public void load(InputStream input, Map table) throws IOException {
686-
String[] lines = PApplet.loadStrings(input); // Reads as UTF-8
680+
static public void load(InputStream input, Map table) throws IOException {
681+
String[] lines = loadStrings(input); // Reads as UTF-8
687682
for (String line : lines) {
688683
if ((line.length() == 0) ||
689684
(line.charAt(0) == '#')) continue;
@@ -698,6 +693,41 @@ static public void load(InputStream input, Map table) throws IOException {
698693
}
699694
}
700695

696+
static public String[] loadStrings(InputStream input) {
697+
try {
698+
BufferedReader reader =
699+
new BufferedReader(new InputStreamReader(input, "UTF-8"));
700+
701+
String lines[] = new String[100];
702+
int lineCount = 0;
703+
String line = null;
704+
while ((line = reader.readLine()) != null) {
705+
if (lineCount == lines.length) {
706+
String temp[] = new String[lineCount << 1];
707+
System.arraycopy(lines, 0, temp, 0, lineCount);
708+
lines = temp;
709+
}
710+
lines[lineCount++] = line;
711+
}
712+
reader.close();
713+
714+
if (lineCount == lines.length) {
715+
return lines;
716+
}
717+
718+
// resize array to appropriate amount for these lines
719+
String output[] = new String[lineCount];
720+
System.arraycopy(lines, 0, output, 0, lineCount);
721+
return output;
722+
723+
} catch (IOException e) {
724+
e.printStackTrace();
725+
//throw new RuntimeException("Error inside loadStrings()");
726+
}
727+
return null;
728+
}
729+
730+
701731

702732
// .................................................................
703733

app/src/processing/app/linux/Platform.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.swing.UIManager;
2828

2929
import processing.app.Preferences;
30+
import processing.core.PConstants;
3031

3132

3233
/**
@@ -112,4 +113,9 @@ public void openFolder(File file) throws Exception {
112113
file.getAbsolutePath());
113114
}
114115
}
116+
117+
@Override
118+
public String getName() {
119+
return PConstants.platformNames[PConstants.LINUX];
120+
}
115121
}

app/src/processing/app/macosx/Platform.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import processing.app.Base;
3636
import processing.core.PApplet;
37+
import processing.core.PConstants;
3738

3839

3940
/**
@@ -195,4 +196,10 @@ protected String getLibraryFolder() throws FileNotFoundException {
195196
protected String getDocumentsFolder() throws FileNotFoundException {
196197
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
197198
}
199+
200+
@Override
201+
public String getName() {
202+
return PConstants.platformNames[PConstants.MACOSX];
203+
}
204+
198205
}

app/src/processing/app/windows/Platform.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import processing.app.Preferences;
3333
import processing.app.windows.Registry.REGISTRY_ROOT_KEY;
3434
import processing.core.PApplet;
35+
import processing.core.PConstants;
3536

3637

3738
// http://developer.apple.com/documentation/QuickTime/Conceptual/QT7Win_Update_Guide/Chapter03/chapter_3_section_1.html
@@ -302,4 +303,10 @@ public int unsetenv(String variable) {
302303
//return 0;
303304
return clib._putenv(variable + "=");
304305
}
306+
307+
@Override
308+
public String getName() {
309+
return PConstants.platformNames[PConstants.WINDOWS];
310+
}
311+
305312
}

0 commit comments

Comments
 (0)