Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.coreplugin.app / org.gvsig.coreplugin.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / LanguagePage.java @ 40558

History | View | Annotate | Download (7.97 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.coreplugin.preferences.general;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.util.Locale;
30

    
31
import javax.swing.*;
32

    
33
import org.gvsig.andami.Launcher;
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.preferences.AbstractPreferencePage;
36

    
37

    
38
public class LanguagePage extends AbstractPreferencePage {
39
        private static LanguageItem DEFAULT_LANGUAGE;
40
        private ImageIcon icon;
41

    
42
        private String id;
43

    
44
        private JPanel pN = null;
45

    
46
        private JPanel pC = null;
47

    
48
        private JPanel pS = null;
49

    
50
        private JPanel jPanel = null;
51

    
52
        private JComboBox cmbIdioma = null;
53

    
54
        private JLabel label = null;
55

    
56
        private int langIndex;
57
        private boolean changed = false;
58

    
59
        public LanguagePage() {
60
                super();
61
                initialize();
62
                id = this.getClass().getName();
63
                setParentID(GeneralPage.class.getName());
64
        }
65

    
66
        private void initialize() {
67
                icon=PluginServices.getIconTheme().get("edit-setup-language");
68
                this.setLayout(new BorderLayout());
69
                this.setSize(new java.awt.Dimension(386, 177));
70
                this.add(getPN(), java.awt.BorderLayout.NORTH);
71
                this.add(getPC(), java.awt.BorderLayout.CENTER);
72
                this.add(getPS(), java.awt.BorderLayout.SOUTH);
73
                langIndex = getJComboBox().getSelectedIndex();
74
        }
75

    
76
        public String getID() {
77
                return id;
78
        }
79

    
80
        public String getTitle() {
81
                return PluginServices.getText(this, "idioma");
82
        }
83

    
84
        public JPanel getPanel() {
85
                return this;
86
        }
87

    
88
        public void initializeValues() {
89
        }
90

    
91
        private class LanguageItem {
92
                public Locale locale;
93

    
94
                public String description;
95

    
96
                public LanguageItem(Locale loc, String str) {
97
                        locale = loc;
98
                        description = str;
99
                }
100

    
101
                public String toString() {
102
                        return description;
103
                }
104
        }
105

    
106
        public void storeValues() {
107
                // Se escribe el idioma
108
                LanguageItem sel = (LanguageItem) cmbIdioma.getSelectedItem();
109
                Launcher.getAndamiConfig().setLocaleLanguage(sel.locale.getLanguage());
110
                Launcher.getAndamiConfig().setLocaleCountry(sel.locale.getCountry());
111
                Launcher.getAndamiConfig().setLocaleVariant(sel.locale.getVariant());
112
                langIndex = getJComboBox().getSelectedIndex();
113

    
114
        }
115

    
116
        public void initializeDefaults() {
117
                getJComboBox().setSelectedItem(DEFAULT_LANGUAGE);
118
        }
119

    
120
        public ImageIcon getIcon() {
121
                return icon;
122
        }
123

    
124
        /**
125
         * This method initializes pN
126
         *
127
         * @return javax.swing.JPanel
128
         */
129
        private JPanel getPN() {
130
                if (pN == null) {
131
                        pN = new JPanel();
132
                }
133
                return pN;
134
        }
135

    
136
        /**
137
         * This method initializes pC
138
         *
139
         * @return javax.swing.JPanel
140
         */
141
        private JPanel getPC() {
142
                if (pC == null) {
143
                        pC = new JPanel();
144
                        pC.add(getJPanel(), null);
145
                }
146
                return pC;
147
        }
148

    
149
        /**
150
         * This method initializes pS
151
         *
152
         * @return javax.swing.JPanel
153
         */
154
        private JPanel getPS() {
155
                if (pS == null) {
156
                        pS = new JPanel();
157
                        pS.add(getLabel(),BorderLayout.SOUTH);
158
                }
159
                return pS;
160
        }
161

    
162

    
163
        /**
164
         * This method initializes jPanel
165
         *
166
         * @return javax.swing.JPanel
167
         */
168
        private JPanel getJPanel() {
169
                if (jPanel == null) {
170
                        jPanel = new JPanel();
171
                        jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
172
                                        PluginServices.getText(this,"idioma"),
173
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
174
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
175
                                        null));
176
                        jPanel.add(getJComboBox(), BorderLayout.NORTH);
177

    
178
                }
179
                return jPanel;
180
        }
181

    
182
        /**
183
         * This method initializes Label
184
         *
185
         * @return javax.swing.JComboBox
186
         */
187
        private JLabel getLabel() {
188
                if (label == null){
189
                        label = new JLabel(PluginServices.getText(null,"Los_cambios_efectuados_sobre_estos_valores_se_aplicaran_al_reiniciar_la_aplicacion"));
190
                }
191
                return label;
192
        }
193
        /**
194
         * This method initializes jComboBox
195
         *
196
         * @return javax.swing.JComboBox
197
         */
198
        private JComboBox getJComboBox() {
199
                if (cmbIdioma == null) {
200
                        cmbIdioma = new JComboBox();
201
                        cmbIdioma.setPreferredSize(new java.awt.Dimension(195, 20));
202

    
203
                        Locale esp = new Locale("es");
204
                        Locale eng = new Locale("en");
205
                        Locale fra = new Locale("fr");
206
                        Locale ita = new Locale("it");
207
                        Locale val = new Locale("ca");
208
                        Locale cs = new Locale("cs"); // Checo
209
                        Locale eu = new Locale("eu"); // euskera
210
                        Locale brasil = new Locale("pt", "BR");
211
                        Locale de = new Locale("de"); // Alem�n
212
                        Locale gl = new Locale("gl", "GL"); // Gallego
213
                        Locale zh = new Locale("zh", "ZH"); // Chino
214
            Locale ru = new Locale("ru", "RU"); // Ruso
215
            Locale el = new Locale("el", "GR"); // Griego
216
            Locale ro = new Locale("ro"); // Romanian
217
            Locale pl = new Locale("pl"); // Polish
218

    
219
                        // Default language
220

    
221
                        // Parche para valenciano/catal�n valenci�/catal�
222
                        String strValenciano = PluginServices.getText(this, "__valenciano");
223
                        // Parche para euskera
224

    
225
                        Locale localeActual = Locale.getDefault(); // Se configura en la
226
                                                                                                                // clase Launcher
227
                        String strEuskera;
228
                        if (eu.getDisplayLanguage().compareTo("vascuence") == 0)
229
                                strEuskera = "Euskera";
230
                        else
231
                                strEuskera = eu.getDisplayLanguage();
232

    
233
                        // English as default language
234
                        DEFAULT_LANGUAGE = new LanguageItem(eng, eng.getDisplayLanguage());
235

    
236
                        LanguageItem[] lenguajes = new LanguageItem[] {
237
                                        new LanguageItem(esp, esp.getDisplayLanguage()),
238
                                        DEFAULT_LANGUAGE,
239
                                        new LanguageItem(fra, fra.getDisplayLanguage()),
240
                                        new LanguageItem(ita, ita.getDisplayLanguage()),
241
                                        new LanguageItem(val, strValenciano),
242
                                        new LanguageItem(cs, cs.getDisplayLanguage()),
243
                                        new LanguageItem(eu, strEuskera),
244
                                        new LanguageItem(brasil, brasil.getDisplayLanguage()),
245
                                        new LanguageItem(de, de.getDisplayLanguage()),
246
                                        new LanguageItem(gl, gl.getDisplayLanguage()),
247
                                        new LanguageItem(zh, zh.getDisplayLanguage()),
248
                    new LanguageItem(ru, ru.getDisplayLanguage()),
249
                    new LanguageItem(el, el.getDisplayLanguage()),
250
                    new LanguageItem(ro, ro.getDisplayLanguage()),
251
                    new LanguageItem(pl, pl.getDisplayLanguage())};
252

    
253
                        DefaultComboBoxModel model = new DefaultComboBoxModel(lenguajes);
254

    
255
                        /*
256
                         * Comparamos primero con los "Locales" completos para admitir
257
                         * las variaciones de los paises y si no encontramos la combinacion
258
                         * idioma-pais entonces buscamos unicamente por el nombre del idioma,
259
                         * y si seguimos sin encontrarlo seleccionamos el idioma por defecto.
260
                         */
261
                        boolean foundLanguage = false;
262
                        for (int i = 0; i < lenguajes.length; i++) {
263
                                if (lenguajes[i].locale.equals(Locale.getDefault())) {
264
                                        model.setSelectedItem(lenguajes[i]);
265
                                        foundLanguage = true;
266
                                        break;
267
                                }
268
                        }
269
                        if (!foundLanguage){
270
                                for (int i = 0; i < lenguajes.length; i++) {
271
                                        if (lenguajes[i].locale.getISO3Language().equals(Locale.getDefault().getISO3Language())) {
272
                                                model.setSelectedItem(lenguajes[i]);
273
                                                foundLanguage = true;
274
                                                break;
275
                                        }
276
                                }
277
                        }
278
                        if (!foundLanguage){
279
                                model.setSelectedItem(DEFAULT_LANGUAGE);
280
                        }
281

    
282
                        cmbIdioma.setModel(model);
283
                        cmbIdioma.addActionListener(new ActionListener() {
284
                                public void actionPerformed(ActionEvent e) {
285
                                        changed = true;
286
                                }
287
                        });
288
                }
289
                return cmbIdioma;
290
        }
291

    
292
        public boolean isValueChanged() {
293
                return changed;
294
        }
295

    
296
        public void setChangesApplied() {
297
                changed = false;
298

    
299
        }
300
} // @jve:decl-index=0:visual-constraint="10,10"