Skip to content

Commit 24bef6b

Browse files
author
Federico Fissore
committed
1 parent cce70d2 commit 24bef6b

File tree

8 files changed

+104
-38
lines changed

8 files changed

+104
-38
lines changed

app/src/processing/app/Base.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public class Base {
107107

108108

109109
static public void main(String args[]) {
110+
initPlatform();
111+
112+
// run static initialization that grabs all the prefs
113+
Preferences.init(null);
114+
110115
try {
111116
File versionFile = getContentFile("lib/version.txt");
112117
if (versionFile.exists()) {
@@ -145,8 +150,6 @@ static public void main(String args[]) {
145150
}
146151
*/
147152

148-
initPlatform();
149-
150153
// // Set the look and feel before opening the window
151154
// try {
152155
// platform.setLookAndFeel();
@@ -166,12 +169,6 @@ static public void main(String args[]) {
166169
// Make sure a full JDK is installed
167170
//initRequirements();
168171

169-
// run static initialization that grabs all the prefs
170-
Preferences.init(null);
171-
172-
// load the I18n module for internationalization
173-
I18n.init(Preferences.get("editor.languages.current"));
174-
175172
// setup the theme coloring fun
176173
Theme.init();
177174

app/src/processing/app/EditorStatus.java

+2-2
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

+19-5
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

+5
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

+53-23
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
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-
33-
import processing.app.syntax.*;
34-
import processing.core.*;
3536
import static processing.app.I18n._;
3637

3738

@@ -70,15 +71,6 @@ public class Preferences {
7071

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

73-
74-
// prompt text stuff
75-
76-
static final String PROMPT_YES = _("Yes");
77-
static final String PROMPT_NO = _("No");
78-
static final String PROMPT_CANCEL = _("Cancel");
79-
static final String PROMPT_OK = _("OK");
80-
static final String PROMPT_BROWSE = _("Browse");
81-
8274
String[] languages = {
8375
_("System Default"),
8476
"العربية" + " (" + _("Arabic") + ")",
@@ -220,7 +212,7 @@ static protected void init(String commandLinePrefs) {
220212
}
221213

222214
// check for platform-specific properties in the defaults
223-
String platformExt = "." + PConstants.platformNames[PApplet.platform];
215+
String platformExt = "." + Base.platform.getName();
224216
int platformExtLength = platformExt.length();
225217
Enumeration e = table.keys();
226218
while (e.hasMoreElements()) {
@@ -236,9 +228,6 @@ static protected void init(String commandLinePrefs) {
236228
// clone the hash table
237229
defaults = (Hashtable) table.clone();
238230

239-
// other things that have to be set explicitly for the defaults
240-
setColor("run.window.bgcolor", SystemColor.control);
241-
242231
// Load a prefs file if specified on the command line
243232
if (commandLinePrefs != null) {
244233
try {
@@ -275,7 +264,13 @@ static protected void init(String commandLinePrefs) {
275264
), ex);
276265
}
277266
}
278-
}
267+
}
268+
269+
// load the I18n module for internationalization
270+
I18n.init(Preferences.get("editor.languages.current"));
271+
272+
// other things that have to be set explicitly for the defaults
273+
setColor("run.window.bgcolor", SystemColor.control);
279274
}
280275

281276

@@ -314,7 +309,7 @@ public Preferences() {
314309
pain.add(sketchbookLocationField);
315310
d = sketchbookLocationField.getPreferredSize();
316311

317-
button = new JButton(PROMPT_BROWSE);
312+
button = new JButton(I18n.PROMPT_BROWSE);
318313
button.addActionListener(new ActionListener() {
319314
public void actionPerformed(ActionEvent e) {
320315
File dflt = new File(sketchbookLocationField.getText());
@@ -478,7 +473,7 @@ public void mouseExited(MouseEvent e) {
478473

479474
// [ OK ] [ Cancel ] maybe these should be next to the message?
480475

481-
button = new JButton(PROMPT_OK);
476+
button = new JButton(I18n.PROMPT_OK);
482477
button.addActionListener(new ActionListener() {
483478
public void actionPerformed(ActionEvent e) {
484479
applyFrame();
@@ -493,7 +488,7 @@ public void actionPerformed(ActionEvent e) {
493488
button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT);
494489
h += BUTTON_WIDTH + GUI_SMALL;
495490

496-
button = new JButton(PROMPT_CANCEL);
491+
button = new JButton(I18n.PROMPT_CANCEL);
497492
button.addActionListener(new ActionListener() {
498493
public void actionPerformed(ActionEvent e) {
499494
disposeFrame();
@@ -674,8 +669,8 @@ static protected void load(InputStream input) throws IOException {
674669
load(input, table);
675670
}
676671

677-
static public void load(InputStream input, Map table) throws IOException {
678-
String[] lines = PApplet.loadStrings(input); // Reads as UTF-8
672+
static public void load(InputStream input, Map table) throws IOException {
673+
String[] lines = loadStrings(input); // Reads as UTF-8
679674
for (String line : lines) {
680675
if ((line.length() == 0) ||
681676
(line.charAt(0) == '#')) continue;
@@ -690,6 +685,41 @@ static public void load(InputStream input, Map table) throws IOException {
690685
}
691686
}
692687

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

694724
// .................................................................
695725

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

+6
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

+7
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

+7
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)