23
23
24
24
package processing .app ;
25
25
26
+ import processing .app .syntax .SyntaxStyle ;
27
+ import processing .core .PApplet ;
28
+ import processing .core .PConstants ;
29
+
30
+ import javax .swing .*;
26
31
import java .awt .*;
27
32
import java .awt .event .*;
28
33
import java .io .*;
29
34
import java .util .*;
30
35
31
- import javax .swing .*;
32
-
33
- import processing .app .syntax .*;
34
- import processing .core .*;
35
36
import static processing .app .I18n ._ ;
36
37
37
38
@@ -70,15 +71,6 @@ public class Preferences {
70
71
71
72
static final String PREFS_FILE = "preferences.txt" ;
72
73
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
-
82
74
String [] languages = {
83
75
_ ("System Default" ),
84
76
"العربية" + " (" + _ ("Arabic" ) + ")" ,
@@ -220,7 +212,7 @@ static protected void init(String commandLinePrefs) {
220
212
}
221
213
222
214
// check for platform-specific properties in the defaults
223
- String platformExt = "." + PConstants . platformNames [ PApplet . platform ] ;
215
+ String platformExt = "." + Base . platform . getName () ;
224
216
int platformExtLength = platformExt .length ();
225
217
Enumeration e = table .keys ();
226
218
while (e .hasMoreElements ()) {
@@ -236,9 +228,6 @@ static protected void init(String commandLinePrefs) {
236
228
// clone the hash table
237
229
defaults = (Hashtable ) table .clone ();
238
230
239
- // other things that have to be set explicitly for the defaults
240
- setColor ("run.window.bgcolor" , SystemColor .control );
241
-
242
231
// Load a prefs file if specified on the command line
243
232
if (commandLinePrefs != null ) {
244
233
try {
@@ -275,7 +264,13 @@ static protected void init(String commandLinePrefs) {
275
264
), ex );
276
265
}
277
266
}
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 );
279
274
}
280
275
281
276
@@ -314,7 +309,7 @@ public Preferences() {
314
309
pain .add (sketchbookLocationField );
315
310
d = sketchbookLocationField .getPreferredSize ();
316
311
317
- button = new JButton (PROMPT_BROWSE );
312
+ button = new JButton (I18n . PROMPT_BROWSE );
318
313
button .addActionListener (new ActionListener () {
319
314
public void actionPerformed (ActionEvent e ) {
320
315
File dflt = new File (sketchbookLocationField .getText ());
@@ -478,7 +473,7 @@ public void mouseExited(MouseEvent e) {
478
473
479
474
// [ OK ] [ Cancel ] maybe these should be next to the message?
480
475
481
- button = new JButton (PROMPT_OK );
476
+ button = new JButton (I18n . PROMPT_OK );
482
477
button .addActionListener (new ActionListener () {
483
478
public void actionPerformed (ActionEvent e ) {
484
479
applyFrame ();
@@ -493,7 +488,7 @@ public void actionPerformed(ActionEvent e) {
493
488
button .setBounds (h , top , BUTTON_WIDTH , BUTTON_HEIGHT );
494
489
h += BUTTON_WIDTH + GUI_SMALL ;
495
490
496
- button = new JButton (PROMPT_CANCEL );
491
+ button = new JButton (I18n . PROMPT_CANCEL );
497
492
button .addActionListener (new ActionListener () {
498
493
public void actionPerformed (ActionEvent e ) {
499
494
disposeFrame ();
@@ -674,8 +669,8 @@ static protected void load(InputStream input) throws IOException {
674
669
load (input , table );
675
670
}
676
671
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
679
674
for (String line : lines ) {
680
675
if ((line .length () == 0 ) ||
681
676
(line .charAt (0 ) == '#' )) continue ;
@@ -690,6 +685,41 @@ static public void load(InputStream input, Map table) throws IOException {
690
685
}
691
686
}
692
687
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
+
693
723
694
724
// .................................................................
695
725
0 commit comments