Statistics
| Revision:

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 14808 jmvivo
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2 6102 jaume
 *
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 14808 jmvivo
 *   Av. Blasco Ib��ez, 50
24 6102 jaume
 *   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 29630 jpiera
package org.gvsig.coreplugin.preferences.general;
42 5792 caballero
43
import java.awt.BorderLayout;
44 6805 jaume
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46 5792 caballero
import java.util.Locale;
47
48 28767 cordinyana
import javax.swing.*;
49 5792 caballero
50 29630 jpiera
import org.gvsig.andami.Launcher;
51
import org.gvsig.andami.PluginServices;
52
import org.gvsig.andami.preferences.AbstractPreferencePage;
53 5792 caballero
54 29630 jpiera
55 5792 caballero
public class LanguagePage extends AbstractPreferencePage {
56 7728 jaume
        private static LanguageItem DEFAULT_LANGUAGE;
57 5792 caballero
        private ImageIcon icon;
58 5804 fjp
59 5792 caballero
        private String id;
60 5804 fjp
61 5792 caballero
        private JPanel pN = null;
62 5804 fjp
63 5792 caballero
        private JPanel pC = null;
64 5804 fjp
65 9385 jmvivo
        private JPanel pS = null;
66
67 5792 caballero
        private JPanel jPanel = null;
68 5804 fjp
69 5792 caballero
        private JComboBox cmbIdioma = null;
70 5804 fjp
71 9385 jmvivo
        private JLabel label = null;
72
73 6575 jaume
        private int langIndex;
74 6805 jaume
        private boolean changed = false;
75 6575 jaume
76 5792 caballero
        public LanguagePage() {
77
                super();
78
                initialize();
79
                id = this.getClass().getName();
80 5804 fjp
                setParentID(GeneralPage.class.getName());
81 5792 caballero
        }
82
83
        private void initialize() {
84 38564 jjdelcerro
                icon=PluginServices.getIconTheme().get("edit-setup-language");
85 5804 fjp
                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 9385 jmvivo
                this.add(getPS(), java.awt.BorderLayout.SOUTH);
90 6575 jaume
                langIndex = getJComboBox().getSelectedIndex();
91 5792 caballero
        }
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 5804 fjp
        public void initializeValues() {
106 5792 caballero
        }
107
108
        private class LanguageItem {
109
                public Locale locale;
110 5804 fjp
111 5792 caballero
                public String description;
112
113 5804 fjp
                public LanguageItem(Locale loc, String str) {
114 5792 caballero
                        locale = loc;
115
                        description = str;
116
                }
117
118 5804 fjp
                public String toString() {
119 5792 caballero
                        return description;
120
                }
121
        }
122 5804 fjp
123 6662 caballero
        public void storeValues() {
124 5804 fjp
                // Se escribe el idioma
125 5792 caballero
                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 6575 jaume
                langIndex = getJComboBox().getSelectedIndex();
130 6810 jaume
131 5792 caballero
        }
132
133
        public void initializeDefaults() {
134 7728 jaume
                getJComboBox().setSelectedItem(DEFAULT_LANGUAGE);
135 5792 caballero
        }
136
137
        public ImageIcon getIcon() {
138
                return icon;
139
        }
140
141
        /**
142
         * This method initializes pN
143 6102 jaume
         *
144 5792 caballero
         * @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 6102 jaume
         *
156 5792 caballero
         * @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 9385 jmvivo
         * 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 14808 jmvivo
180 9385 jmvivo
        /**
181 5792 caballero
         * This method initializes jPanel
182 6102 jaume
         *
183 5792 caballero
         * @return javax.swing.JPanel
184
         */
185
        private JPanel getJPanel() {
186
                if (jPanel == null) {
187
                        jPanel = new JPanel();
188 5804 fjp
                        jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
189 8248 jmvivo
                                        PluginServices.getText(this,"idioma"),
190 5804 fjp
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
191
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
192
                                        null));
193 14808 jmvivo
                        jPanel.add(getJComboBox(), BorderLayout.NORTH);
194
195 5792 caballero
                }
196
                return jPanel;
197
        }
198
199
        /**
200 9385 jmvivo
         * 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 5792 caballero
         * This method initializes jComboBox
212 6102 jaume
         *
213 5792 caballero
         * @return javax.swing.JComboBox
214
         */
215
        private JComboBox getJComboBox() {
216
                if (cmbIdioma == null) {
217
                        cmbIdioma = new JComboBox();
218 5804 fjp
                        cmbIdioma.setPreferredSize(new java.awt.Dimension(195, 20));
219 5792 caballero
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 5804 fjp
                        Locale cs = new Locale("cs"); // Checo
226
                        Locale eu = new Locale("eu"); // euskera
227
                        Locale brasil = new Locale("pt", "BR");
228 14808 jmvivo
                        Locale de = new Locale("de"); // Alem�n
229 9406 cesar
                        Locale gl = new Locale("gl", "GL"); // Gallego
230 8274 caballero
                        Locale zh = new Locale("zh", "ZH"); // Chino
231 28767 cordinyana
            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 5792 caballero
236 7728 jaume
                        // Default language
237
238 14808 jmvivo
                        // Parche para valenciano/catal�n valenci�/catal�
239 28494 jmvivo
                        String strValenciano = PluginServices.getText(this, "__valenciano");
240 5804 fjp
                        // Parche para euskera
241 5792 caballero
242 5804 fjp
                        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 5792 caballero
250 7728 jaume
                        // English as default language
251
                        DEFAULT_LANGUAGE = new LanguageItem(eng, eng.getDisplayLanguage());
252
253 5804 fjp
                        LanguageItem[] lenguajes = new LanguageItem[] {
254 5792 caballero
                                        new LanguageItem(esp, esp.getDisplayLanguage()),
255 7728 jaume
                                        DEFAULT_LANGUAGE,
256 5792 caballero
                                        new LanguageItem(fra, fra.getDisplayLanguage()),
257
                                        new LanguageItem(ita, ita.getDisplayLanguage()),
258 5804 fjp
                                        new LanguageItem(val, strValenciano),
259
                                        new LanguageItem(cs, cs.getDisplayLanguage()),
260
                                        new LanguageItem(eu, strEuskera),
261
                                        new LanguageItem(brasil, brasil.getDisplayLanguage()),
262 5792 caballero
                                        new LanguageItem(de, de.getDisplayLanguage()),
263 8274 caballero
                                        new LanguageItem(gl, gl.getDisplayLanguage()),
264 28767 cordinyana
                                        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 5792 caballero
270
                        DefaultComboBoxModel model = new DefaultComboBoxModel(lenguajes);
271
272 28945 fdiaz
                        /*
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 5792 caballero
                        for (int i = 0; i < lenguajes.length; i++) {
280 5804 fjp
                                if (lenguajes[i].locale.equals(Locale.getDefault())) {
281 5792 caballero
                                        model.setSelectedItem(lenguajes[i]);
282 28945 fdiaz
                                        foundLanguage = true;
283
                                        break;
284 5792 caballero
                                }
285
                        }
286 28945 fdiaz
                        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 5792 caballero
299
                        cmbIdioma.setModel(model);
300 6805 jaume
                        cmbIdioma.addActionListener(new ActionListener() {
301
                                public void actionPerformed(ActionEvent e) {
302
                                        changed = true;
303
                                }
304
                        });
305 5792 caballero
                }
306
                return cmbIdioma;
307
        }
308 6805 jaume
309
        public boolean isValueChanged() {
310
                return changed;
311
        }
312 6810 jaume
313
        public void setChangesApplied() {
314
                changed = false;
315
316
        }
317 5804 fjp
} // @jve:decl-index=0:visual-constraint="10,10"