Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libCorePlugin / src / com / iver / core / preferences / general / LanguagePage.java @ 9406

History | View | Annotate | Download (7.19 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 com.iver.core.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.DefaultComboBoxModel;
49
import javax.swing.ImageIcon;
50
import javax.swing.JComboBox;
51
import javax.swing.JLabel;
52
import javax.swing.JPanel;
53

    
54
import com.iver.andami.Launcher;
55
import com.iver.andami.PluginServices;
56
import com.iver.andami.preferences.AbstractPreferencePage;
57

    
58
public class LanguagePage extends AbstractPreferencePage {
59
        private static LanguageItem DEFAULT_LANGUAGE;
60
        private ImageIcon icon;
61

    
62
        private String id;
63

    
64
        private JPanel pN = null;
65

    
66
        private JPanel pC = null;
67

    
68
        private JPanel pS = null;
69

    
70
        private JPanel jPanel = null;
71

    
72
        private JComboBox cmbIdioma = null;
73
        
74
        private JLabel label = null;
75

    
76
        private int langIndex;
77
        private boolean changed = false;
78

    
79
        public LanguagePage() {
80
                super();
81
                initialize();
82
                id = this.getClass().getName();
83
                setParentID(GeneralPage.class.getName());
84
        }
85

    
86
        private void initialize() {
87
                icon = new ImageIcon(this.getClass().getClassLoader().getResource(
88
                                "images/babel.png"));
89
                this.setLayout(new BorderLayout());
90
                this.setSize(new java.awt.Dimension(386, 177));
91
                this.add(getPN(), java.awt.BorderLayout.NORTH);
92
                this.add(getPC(), java.awt.BorderLayout.CENTER);
93
                this.add(getPS(), java.awt.BorderLayout.SOUTH);
94
                langIndex = getJComboBox().getSelectedIndex();
95
        }
96

    
97
        public String getID() {
98
                return id;
99
        }
100

    
101
        public String getTitle() {
102
                return PluginServices.getText(this, "idioma");
103
        }
104

    
105
        public JPanel getPanel() {
106
                return this;
107
        }
108

    
109
        public void initializeValues() {
110
        }
111

    
112
        private class LanguageItem {
113
                public Locale locale;
114

    
115
                public String description;
116

    
117
                public LanguageItem(Locale loc, String str) {
118
                        locale = loc;
119
                        description = str;
120
                }
121

    
122
                public String toString() {
123
                        return description;
124
                }
125
        }
126

    
127
        public void storeValues() {
128
                // Se escribe el idioma
129
                LanguageItem sel = (LanguageItem) cmbIdioma.getSelectedItem();
130
                Launcher.getAndamiConfig().setLocaleLanguage(sel.locale.getLanguage());
131
                Launcher.getAndamiConfig().setLocaleCountry(sel.locale.getCountry());
132
                Launcher.getAndamiConfig().setLocaleVariant(sel.locale.getVariant());
133
                langIndex = getJComboBox().getSelectedIndex();
134

    
135
        }
136

    
137
        public void initializeDefaults() {
138
                getJComboBox().setSelectedItem(DEFAULT_LANGUAGE);
139
        }
140

    
141
        public ImageIcon getIcon() {
142
                return icon;
143
        }
144

    
145
        /**
146
         * This method initializes pN
147
         *
148
         * @return javax.swing.JPanel
149
         */
150
        private JPanel getPN() {
151
                if (pN == null) {
152
                        pN = new JPanel();
153
                }
154
                return pN;
155
        }
156

    
157
        /**
158
         * This method initializes pC
159
         *
160
         * @return javax.swing.JPanel
161
         */
162
        private JPanel getPC() {
163
                if (pC == null) {
164
                        pC = new JPanel();
165
                        pC.add(getJPanel(), null);
166
                }
167
                return pC;
168
        }
169

    
170
        /**
171
         * This method initializes pS
172
         *
173
         * @return javax.swing.JPanel
174
         */
175
        private JPanel getPS() {
176
                if (pS == null) {
177
                        pS = new JPanel();
178
                        pS.add(getLabel(),BorderLayout.SOUTH);
179
                }
180
                return pS;
181
        }
182

    
183
        
184
        /**
185
         * This method initializes jPanel
186
         *
187
         * @return javax.swing.JPanel
188
         */
189
        private JPanel getJPanel() {
190
                if (jPanel == null) {
191
                        jPanel = new JPanel();
192
                        jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
193
                                        PluginServices.getText(this,"idioma"),
194
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
195
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
196
                                        null));
197
                        jPanel.add(getJComboBox(), BorderLayout.NORTH);                        
198
                        
199
                }
200
                return jPanel;
201
        }
202
        /**
203
         * This method initializes Label
204
         *
205
         * @return javax.swing.JComboBox
206
         */
207
        private JLabel getLabel() {
208
                if (label == null){
209
                        label = new JLabel(PluginServices.getText(null,"Los_cambios_efectuados_sobre_estos_valores_se_aplicaran_al_reiniciar_la_aplicacion"));
210
                }
211
                return label;
212
        }
213
        /**
214
         * This method initializes jComboBox
215
         *
216
         * @return javax.swing.JComboBox
217
         */
218
        private JComboBox getJComboBox() {
219
                if (cmbIdioma == null) {
220
                        cmbIdioma = new JComboBox();
221
                        cmbIdioma.setPreferredSize(new java.awt.Dimension(195, 20));
222

    
223
                        Locale esp = new Locale("es");
224
                        Locale eng = new Locale("en");
225
                        Locale fra = new Locale("fr");
226
                        Locale ita = new Locale("it");
227
                        Locale val = new Locale("ca");
228
                        Locale cs = new Locale("cs"); // Checo
229
                        Locale eu = new Locale("eu"); // euskera
230
                        Locale brasil = new Locale("pt", "BR");
231
                        Locale de = new Locale("de"); // Alem?n
232
                        Locale gl = new Locale("gl", "GL"); // Griego
233
                        Locale zh = new Locale("zh", "ZH"); // Chino
234

    
235
                        // Default language
236

    
237
                        // Parche para valenciano/catal?n valenci?/catal?
238
                        String strValenciano = PluginServices.getText(this, "__catalan");
239
                        // Parche para euskera
240

    
241
                        Locale localeActual = Locale.getDefault(); // Se configura en la
242
                                                                                                                // clase Launcher
243
                        String strEuskera;
244
                        if (eu.getDisplayLanguage().compareTo("vascuence") == 0)
245
                                strEuskera = "Euskera";
246
                        else
247
                                strEuskera = eu.getDisplayLanguage();
248

    
249
                        // English as default language
250
                        DEFAULT_LANGUAGE = new LanguageItem(eng, eng.getDisplayLanguage());
251

    
252
                        LanguageItem[] lenguajes = new LanguageItem[] {
253
                                        new LanguageItem(esp, esp.getDisplayLanguage()),
254
                                        DEFAULT_LANGUAGE,
255
                                        new LanguageItem(fra, fra.getDisplayLanguage()),
256
                                        new LanguageItem(ita, ita.getDisplayLanguage()),
257
                                        new LanguageItem(val, strValenciano),
258
                                        new LanguageItem(cs, cs.getDisplayLanguage()),
259
                                        new LanguageItem(eu, strEuskera),
260
                                        new LanguageItem(brasil, brasil.getDisplayLanguage()),
261
                                        new LanguageItem(de, de.getDisplayLanguage()),
262
                                        new LanguageItem(gl, gl.getDisplayLanguage()),
263
                                        new LanguageItem(zh, zh.getDisplayLanguage())};
264

    
265
                        DefaultComboBoxModel model = new DefaultComboBoxModel(lenguajes);
266

    
267
                        for (int i = 0; i < lenguajes.length; i++) {
268
                                if (lenguajes[i].locale.equals(Locale.getDefault())) {
269
                                        model.setSelectedItem(lenguajes[i]);
270
                                }
271
                        }
272

    
273
                        cmbIdioma.setModel(model);
274
                        cmbIdioma.addActionListener(new ActionListener() {
275
                                public void actionPerformed(ActionEvent e) {
276
                                        changed = true;
277
                                }
278
                        });
279
                }
280
                return cmbIdioma;
281
        }
282

    
283
        public boolean isValueChanged() {
284
                return changed;
285
        }
286

    
287
        public void setChangesApplied() {
288
                changed = false;
289

    
290
        }
291
} // @jve:decl-index=0:visual-constraint="10,10"