2323
2424package processing .app ;
2525
26+ import processing .app .syntax .SyntaxStyle ;
27+ import processing .core .PApplet ;
28+ import processing .core .PConstants ;
29+
30+ import javax .swing .*;
2631import java .awt .*;
2732import java .awt .event .*;
2833import java .io .*;
2934import java .util .*;
3035
31- import javax .swing .*;
32-
33- import processing .app .syntax .*;
34- import processing .core .*;
3536import 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
0 commit comments