Statistics
| Revision:

svn-gvsig-desktop / trunk / 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
        /**
204
         * This method initializes Label
205
         *
206
         * @return javax.swing.JComboBox
207
         */
208
        private JLabel getLabel() {
209
                if (label == null){
210
                        label = new JLabel(PluginServices.getText(null,"Los_cambios_efectuados_sobre_estos_valores_se_aplicaran_al_reiniciar_la_aplicacion"));
211
                }
212
                return label;
213
        }
214
        /**
215
         * This method initializes jComboBox
216
         *
217
         * @return javax.swing.JComboBox
218
         */
219
        private JComboBox getJComboBox() {
220
                if (cmbIdioma == null) {
221
                        cmbIdioma = new JComboBox();
222
                        cmbIdioma.setPreferredSize(new java.awt.Dimension(195, 20));
223

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

    
236
                        // Default language
237

    
238
                        // Parche para valenciano/catal?n valenci?/catal?
239
                        String strValenciano = PluginServices.getText(this, "__catalan");
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

    
266
                        DefaultComboBoxModel model = new DefaultComboBoxModel(lenguajes);
267

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

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

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

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

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