root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / preferences / general / LanguagePage.java @ 38564
History | View | Annotate | Download (8.23 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.coreplugin.preferences.general; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.event.ActionEvent; |
45 |
import java.awt.event.ActionListener; |
46 |
import java.util.Locale; |
47 |
|
48 |
import javax.swing.*; |
49 |
|
50 |
import org.gvsig.andami.Launcher; |
51 |
import org.gvsig.andami.PluginServices; |
52 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
53 |
|
54 |
|
55 |
public class LanguagePage extends AbstractPreferencePage { |
56 |
private static LanguageItem DEFAULT_LANGUAGE; |
57 |
private ImageIcon icon; |
58 |
|
59 |
private String id; |
60 |
|
61 |
private JPanel pN = null; |
62 |
|
63 |
private JPanel pC = null; |
64 |
|
65 |
private JPanel pS = null; |
66 |
|
67 |
private JPanel jPanel = null; |
68 |
|
69 |
private JComboBox cmbIdioma = null; |
70 |
|
71 |
private JLabel label = null; |
72 |
|
73 |
private int langIndex; |
74 |
private boolean changed = false; |
75 |
|
76 |
public LanguagePage() {
|
77 |
super();
|
78 |
initialize(); |
79 |
id = this.getClass().getName();
|
80 |
setParentID(GeneralPage.class.getName()); |
81 |
} |
82 |
|
83 |
private void initialize() { |
84 |
icon=PluginServices.getIconTheme().get("edit-setup-language");
|
85 |
this.setLayout(new BorderLayout()); |
86 |
this.setSize(new java.awt.Dimension(386, 177)); |
87 |
this.add(getPN(), java.awt.BorderLayout.NORTH);
|
88 |
this.add(getPC(), java.awt.BorderLayout.CENTER);
|
89 |
this.add(getPS(), java.awt.BorderLayout.SOUTH);
|
90 |
langIndex = getJComboBox().getSelectedIndex(); |
91 |
} |
92 |
|
93 |
public String getID() { |
94 |
return id;
|
95 |
} |
96 |
|
97 |
public String getTitle() { |
98 |
return PluginServices.getText(this, "idioma"); |
99 |
} |
100 |
|
101 |
public JPanel getPanel() { |
102 |
return this; |
103 |
} |
104 |
|
105 |
public void initializeValues() { |
106 |
} |
107 |
|
108 |
private class LanguageItem { |
109 |
public Locale locale; |
110 |
|
111 |
public String description; |
112 |
|
113 |
public LanguageItem(Locale loc, String str) { |
114 |
locale = loc; |
115 |
description = str; |
116 |
} |
117 |
|
118 |
public String toString() { |
119 |
return description;
|
120 |
} |
121 |
} |
122 |
|
123 |
public void storeValues() { |
124 |
// Se escribe el idioma
|
125 |
LanguageItem sel = (LanguageItem) cmbIdioma.getSelectedItem(); |
126 |
Launcher.getAndamiConfig().setLocaleLanguage(sel.locale.getLanguage()); |
127 |
Launcher.getAndamiConfig().setLocaleCountry(sel.locale.getCountry()); |
128 |
Launcher.getAndamiConfig().setLocaleVariant(sel.locale.getVariant()); |
129 |
langIndex = getJComboBox().getSelectedIndex(); |
130 |
|
131 |
} |
132 |
|
133 |
public void initializeDefaults() { |
134 |
getJComboBox().setSelectedItem(DEFAULT_LANGUAGE); |
135 |
} |
136 |
|
137 |
public ImageIcon getIcon() { |
138 |
return icon;
|
139 |
} |
140 |
|
141 |
/**
|
142 |
* This method initializes pN
|
143 |
*
|
144 |
* @return javax.swing.JPanel
|
145 |
*/
|
146 |
private JPanel getPN() { |
147 |
if (pN == null) { |
148 |
pN = new JPanel(); |
149 |
} |
150 |
return pN;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* This method initializes pC
|
155 |
*
|
156 |
* @return javax.swing.JPanel
|
157 |
*/
|
158 |
private JPanel getPC() { |
159 |
if (pC == null) { |
160 |
pC = new JPanel(); |
161 |
pC.add(getJPanel(), null);
|
162 |
} |
163 |
return pC;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* This method initializes pS
|
168 |
*
|
169 |
* @return javax.swing.JPanel
|
170 |
*/
|
171 |
private JPanel getPS() { |
172 |
if (pS == null) { |
173 |
pS = new JPanel(); |
174 |
pS.add(getLabel(),BorderLayout.SOUTH);
|
175 |
} |
176 |
return pS;
|
177 |
} |
178 |
|
179 |
|
180 |
/**
|
181 |
* This method initializes jPanel
|
182 |
*
|
183 |
* @return javax.swing.JPanel
|
184 |
*/
|
185 |
private JPanel getJPanel() { |
186 |
if (jPanel == null) { |
187 |
jPanel = new JPanel(); |
188 |
jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
189 |
PluginServices.getText(this,"idioma"), |
190 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
191 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
|
192 |
null));
|
193 |
jPanel.add(getJComboBox(), BorderLayout.NORTH);
|
194 |
|
195 |
} |
196 |
return jPanel;
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* This method initializes Label
|
201 |
*
|
202 |
* @return javax.swing.JComboBox
|
203 |
*/
|
204 |
private JLabel getLabel() { |
205 |
if (label == null){ |
206 |
label = new JLabel(PluginServices.getText(null,"Los_cambios_efectuados_sobre_estos_valores_se_aplicaran_al_reiniciar_la_aplicacion")); |
207 |
} |
208 |
return label;
|
209 |
} |
210 |
/**
|
211 |
* This method initializes jComboBox
|
212 |
*
|
213 |
* @return javax.swing.JComboBox
|
214 |
*/
|
215 |
private JComboBox getJComboBox() { |
216 |
if (cmbIdioma == null) { |
217 |
cmbIdioma = new JComboBox(); |
218 |
cmbIdioma.setPreferredSize(new java.awt.Dimension(195, 20)); |
219 |
|
220 |
Locale esp = new Locale("es"); |
221 |
Locale eng = new Locale("en"); |
222 |
Locale fra = new Locale("fr"); |
223 |
Locale ita = new Locale("it"); |
224 |
Locale val = new Locale("ca"); |
225 |
Locale cs = new Locale("cs"); // Checo |
226 |
Locale eu = new Locale("eu"); // euskera |
227 |
Locale brasil = new Locale("pt", "BR"); |
228 |
Locale de = new Locale("de"); // Alem�n |
229 |
Locale gl = new Locale("gl", "GL"); // Gallego |
230 |
Locale zh = new Locale("zh", "ZH"); // Chino |
231 |
Locale ru = new Locale("ru", "RU"); // Ruso |
232 |
Locale el = new Locale("el", "GR"); // Griego |
233 |
Locale ro = new Locale("ro"); // Romanian |
234 |
Locale pl = new Locale("pl"); // Polish |
235 |
|
236 |
// Default language
|
237 |
|
238 |
// Parche para valenciano/catal�n valenci�/catal�
|
239 |
String strValenciano = PluginServices.getText(this, "__valenciano"); |
240 |
// Parche para euskera
|
241 |
|
242 |
Locale localeActual = Locale.getDefault(); // Se configura en la |
243 |
// clase Launcher
|
244 |
String strEuskera;
|
245 |
if (eu.getDisplayLanguage().compareTo("vascuence") == 0) |
246 |
strEuskera = "Euskera";
|
247 |
else
|
248 |
strEuskera = eu.getDisplayLanguage(); |
249 |
|
250 |
// English as default language
|
251 |
DEFAULT_LANGUAGE = new LanguageItem(eng, eng.getDisplayLanguage());
|
252 |
|
253 |
LanguageItem[] lenguajes = new LanguageItem[] { |
254 |
new LanguageItem(esp, esp.getDisplayLanguage()),
|
255 |
DEFAULT_LANGUAGE, |
256 |
new LanguageItem(fra, fra.getDisplayLanguage()),
|
257 |
new LanguageItem(ita, ita.getDisplayLanguage()),
|
258 |
new LanguageItem(val, strValenciano),
|
259 |
new LanguageItem(cs, cs.getDisplayLanguage()),
|
260 |
new LanguageItem(eu, strEuskera),
|
261 |
new LanguageItem(brasil, brasil.getDisplayLanguage()),
|
262 |
new LanguageItem(de, de.getDisplayLanguage()),
|
263 |
new LanguageItem(gl, gl.getDisplayLanguage()),
|
264 |
new LanguageItem(zh, zh.getDisplayLanguage()),
|
265 |
new LanguageItem(ru, ru.getDisplayLanguage()),
|
266 |
new LanguageItem(el, el.getDisplayLanguage()),
|
267 |
new LanguageItem(ro, ro.getDisplayLanguage()),
|
268 |
new LanguageItem(pl, pl.getDisplayLanguage())};
|
269 |
|
270 |
DefaultComboBoxModel model = new DefaultComboBoxModel(lenguajes); |
271 |
|
272 |
/*
|
273 |
* Comparamos primero con los "Locales" completos para admitir
|
274 |
* las variaciones de los paises y si no encontramos la combinacion
|
275 |
* idioma-pais entonces buscamos unicamente por el nombre del idioma,
|
276 |
* y si seguimos sin encontrarlo seleccionamos el idioma por defecto.
|
277 |
*/
|
278 |
boolean foundLanguage = false; |
279 |
for (int i = 0; i < lenguajes.length; i++) { |
280 |
if (lenguajes[i].locale.equals(Locale.getDefault())) { |
281 |
model.setSelectedItem(lenguajes[i]); |
282 |
foundLanguage = true;
|
283 |
break;
|
284 |
} |
285 |
} |
286 |
if (!foundLanguage){
|
287 |
for (int i = 0; i < lenguajes.length; i++) { |
288 |
if (lenguajes[i].locale.getISO3Language().equals(Locale.getDefault().getISO3Language())) { |
289 |
model.setSelectedItem(lenguajes[i]); |
290 |
foundLanguage = true;
|
291 |
break;
|
292 |
} |
293 |
} |
294 |
} |
295 |
if (!foundLanguage){
|
296 |
model.setSelectedItem(DEFAULT_LANGUAGE); |
297 |
} |
298 |
|
299 |
cmbIdioma.setModel(model); |
300 |
cmbIdioma.addActionListener(new ActionListener() { |
301 |
public void actionPerformed(ActionEvent e) { |
302 |
changed = true;
|
303 |
} |
304 |
}); |
305 |
} |
306 |
return cmbIdioma;
|
307 |
} |
308 |
|
309 |
public boolean isValueChanged() { |
310 |
return changed;
|
311 |
} |
312 |
|
313 |
public void setChangesApplied() { |
314 |
changed = false;
|
315 |
|
316 |
} |
317 |
} // @jve:decl-index=0:visual-constraint="10,10"
|