@@ -79,6 +79,79 @@ public class Preferences {
79
79
static final String PROMPT_OK = _ ("OK" );
80
80
static final String PROMPT_BROWSE = _ ("Browse" );
81
81
82
+ // XXX: DC 20120407
83
+ // Language Combo Box
84
+ // the right way to do this would be having a string[] inside the preferences.txt
85
+ // file like follows:
86
+ //
87
+ // # list of available languages (in English so far)
88
+ // editor.languages.available.list = Catalan,English,Spanish
89
+ //
90
+ // # list of ISO names (same order as previous)
91
+ // editor.languages.ISO.list = ca,en,es
92
+ //
93
+ // --> but that will require having a method to upgrade to the latest selection of
94
+ // translation files. That could be done in multiple ways, but requires some thought
95
+ //
96
+ // the code to gather those arrays into Preferences.java goes as follows:
97
+ //
98
+ // String languagesAvailable = Preferences.get("editor.languages.available.list");
99
+ // String languagesAvailableISO = Preferences.get("editor.languages.ISO.list");
100
+ // String[] languages = languagesAvailable.split(",");
101
+ // String[] languagesISO = languagesAvailableISO.split(",");
102
+ //
103
+ // --> instead, DM and DC agree that, for the time being, the languages will be listed internally
104
+ // inside the Java code, they will have to be moved out at some point
105
+ //
106
+ // also note that right now, by default we will take English, in the future, once JRE7 is running in
107
+ // Arduino, we will use the locale, since it will behave in a similar way for all OSs. Thing is, up
108
+ // to JRE6, it was misbehaving as noted here:
109
+ // http://stackoverflow.com/questions/7107972/java-7-default-locale
110
+ //
111
+ // ALSO: for this to work, the languages/languagesISO arraylists need to be declared global, yeah!
112
+
113
+ // language related arrays, please read notes later, where the language combo box is introduced
114
+ String [] languages = {
115
+ _ ("Catalan" ),
116
+ _ ("Chinese Simplified" ),
117
+ _ ("Chinese Taiwan" ),
118
+ _ ("Danish" ),
119
+ _ ("Dutch" ),
120
+ _ ("English" ),
121
+ _ ("French" ),
122
+ _ ("Filipino" ),
123
+ _ ("Galician" ),
124
+ _ ("German" ),
125
+ _ ("Greek" ),
126
+ _ ("Hungarian" ),
127
+ _ ("Italian" ),
128
+ _ ("Japanese" ),
129
+ _ ("Latvian" ),
130
+ _ ("Persian" ),
131
+ _ ("Portuguese (Brazil)" ),
132
+ _ ("Romanian" ),
133
+ _ ("Spanish" )};
134
+ String [] languagesISO = {
135
+ "ca" ,
136
+ "zh_cn" ,
137
+ "zh_tw" ,
138
+ "da" ,
139
+ "nl" ,
140
+ "en" ,
141
+ "fr" ,
142
+ "tl" ,
143
+ "gl" ,
144
+ "de" ,
145
+ "el" ,
146
+ "hu" ,
147
+ "it" ,
148
+ "ja" ,
149
+ "lv" ,
150
+ "fa" ,
151
+ "pt_br" ,
152
+ "ro" ,
153
+ "es" };
154
+
82
155
/**
83
156
* Standardized width for buttons. Mac OS X 10.3 wants 70 as its default,
84
157
* Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper.
@@ -124,6 +197,7 @@ public class Preferences {
124
197
JTextField fontSizeField ;
125
198
JCheckBox updateExtensionBox ;
126
199
JCheckBox autoAssociateBox ;
200
+ JComboBox comboLanguage ;
127
201
128
202
129
203
// the calling editor, so updates can be applied
@@ -350,6 +424,30 @@ public void actionPerformed(ActionEvent e) {
350
424
top += d .height + GUI_BETWEEN ;
351
425
}
352
426
427
+ //Label for the language combo box
428
+ box = Box .createHorizontalBox ();
429
+ label = new JLabel (_ ("Preferred Language: " ));
430
+ box .add (label );
431
+
432
+ //Create the combo box, select the item at index 4.
433
+ comboLanguage = new JComboBox (languages );
434
+ comboLanguage .setSelectedIndex ((Arrays .asList (languagesISO )).indexOf (Preferences .get ("editor.languages.current" )));
435
+ comboLanguage .addActionListener (new ActionListener () {
436
+ public void actionPerformed (ActionEvent evt ) {
437
+ JComboBox cb = (JComboBox )evt .getSource ();
438
+ // the update to the language is done outside
439
+ }
440
+ });
441
+ box .add (comboLanguage );
442
+ label = new JLabel (_ (" (requires restart of Arduino)" ));
443
+ box .add (label );
444
+ pain .add (box );
445
+ d = box .getPreferredSize ();
446
+ box .setForeground (Color .gray );
447
+ box .setBounds (left , top , d .width , d .height );
448
+ right = Math .max (right , left + d .width );
449
+ top += d .height + GUI_BETWEEN ;
450
+
353
451
354
452
// More preferences are in the ...
355
453
@@ -539,6 +637,11 @@ protected void applyFrame() {
539
637
540
638
setBoolean ("editor.update_extension" , updateExtensionBox .isSelected ());
541
639
640
+ // adds the selected language to the preferences file
641
+ Object newItem = comboLanguage .getSelectedItem ();
642
+ int pos = (Arrays .asList (languages )).indexOf (newItem .toString ()); // position in the languages array
643
+ set ("editor.languages.current" ,(Arrays .asList (languagesISO )).get (pos ));
644
+
542
645
editor .applyPreferences ();
543
646
}
544
647
0 commit comments