Statistics
| Revision:

root / trunk / libraries / libCorePlugin / src / com / iver / core / preferences / general / LanguagePage.java @ 8248

History | View | Annotate | Download (6.55 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.JPanel;
52

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

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

    
61
        private String id;
62

    
63
        private JPanel pN = null;
64

    
65
        private JPanel pC = null;
66

    
67
        private JPanel jPanel = null;
68

    
69
        private JComboBox cmbIdioma = null;
70

    
71
        private int langIndex;
72
        private boolean changed = false;
73

    
74
        public LanguagePage() {
75
                super();
76
                initialize();
77
                id = this.getClass().getName();
78
                setParentID(GeneralPage.class.getName());
79
        }
80

    
81
        private void initialize() {
82
                icon = new ImageIcon(this.getClass().getClassLoader().getResource(
83
                                "images/babel.png"));
84
                this.setLayout(new BorderLayout());
85
                this.setSize(new java.awt.Dimension(386, 177));
86
                this.add(getPN(), java.awt.BorderLayout.NORTH);
87
                this.add(getPC(), java.awt.BorderLayout.CENTER);
88
                langIndex = getJComboBox().getSelectedIndex();
89
        }
90

    
91
        public String getID() {
92
                return id;
93
        }
94

    
95
        public String getTitle() {
96
                return PluginServices.getText(this, "idioma");
97
        }
98

    
99
        public JPanel getPanel() {
100
                return this;
101
        }
102

    
103
        public void initializeValues() {
104
        }
105

    
106
        private class LanguageItem {
107
                public Locale locale;
108

    
109
                public String description;
110

    
111
                public LanguageItem(Locale loc, String str) {
112
                        locale = loc;
113
                        description = str;
114
                }
115

    
116
                public String toString() {
117
                        return description;
118
                }
119
        }
120

    
121
        public void storeValues() {
122
                // Se escribe el idioma
123
                LanguageItem sel = (LanguageItem) cmbIdioma.getSelectedItem();
124
                Launcher.getAndamiConfig().setLocaleLanguage(sel.locale.getLanguage());
125
                Launcher.getAndamiConfig().setLocaleCountry(sel.locale.getCountry());
126
                Launcher.getAndamiConfig().setLocaleVariant(sel.locale.getVariant());
127
                langIndex = getJComboBox().getSelectedIndex();
128

    
129
        }
130

    
131
        public void initializeDefaults() {
132
                getJComboBox().setSelectedItem(DEFAULT_LANGUAGE);
133
        }
134

    
135
        public ImageIcon getIcon() {
136
                return icon;
137
        }
138

    
139
        /**
140
         * This method initializes pN
141
         *
142
         * @return javax.swing.JPanel
143
         */
144
        private JPanel getPN() {
145
                if (pN == null) {
146
                        pN = new JPanel();
147
                }
148
                return pN;
149
        }
150

    
151
        /**
152
         * This method initializes pC
153
         *
154
         * @return javax.swing.JPanel
155
         */
156
        private JPanel getPC() {
157
                if (pC == null) {
158
                        pC = new JPanel();
159
                        pC.add(getJPanel(), null);
160
                }
161
                return pC;
162
        }
163

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

    
182
        /**
183
         * This method initializes jComboBox
184
         *
185
         * @return javax.swing.JComboBox
186
         */
187
        private JComboBox getJComboBox() {
188
                if (cmbIdioma == null) {
189
                        cmbIdioma = new JComboBox();
190
                        cmbIdioma.setPreferredSize(new java.awt.Dimension(195, 20));
191

    
192
                        Locale esp = new Locale("es");
193
                        Locale eng = new Locale("en");
194
                        Locale fra = new Locale("fr");
195
                        Locale ita = new Locale("it");
196
                        Locale val = new Locale("ca");
197
                        Locale cs = new Locale("cs"); // Checo
198
                        Locale eu = new Locale("eu"); // euskera
199
                        Locale brasil = new Locale("pt", "BR");
200
                        Locale de = new Locale("de"); // Alem?n
201
                        Locale gr = new Locale("el", "GR"); // Griego
202
                        Locale gl = new Locale("gl", "GL"); // Griego
203

    
204
                        // Default language
205

    
206
                        // Parche para valenciano/catal?n valenci?/catal?
207
                        String strValenciano = PluginServices.getText(this, "__catalan");
208
                        // Parche para euskera
209

    
210
                        Locale localeActual = Locale.getDefault(); // Se configura en la
211
                                                                                                                // clase Launcher
212
                        String strEuskera;
213
                        if (eu.getDisplayLanguage().compareTo("vascuence") == 0)
214
                                strEuskera = "Euskera";
215
                        else
216
                                strEuskera = eu.getDisplayLanguage();
217

    
218
                        // English as default language
219
                        DEFAULT_LANGUAGE = new LanguageItem(eng, eng.getDisplayLanguage());
220

    
221
                        LanguageItem[] lenguajes = new LanguageItem[] {
222
                                        new LanguageItem(esp, esp.getDisplayLanguage()),
223
                                        DEFAULT_LANGUAGE,
224
                                        new LanguageItem(fra, fra.getDisplayLanguage()),
225
                                        new LanguageItem(ita, ita.getDisplayLanguage()),
226
                                        new LanguageItem(val, strValenciano),
227
                                        new LanguageItem(cs, cs.getDisplayLanguage()),
228
                                        new LanguageItem(eu, strEuskera),
229
                                        new LanguageItem(brasil, brasil.getDisplayLanguage()),
230
                                        new LanguageItem(de, de.getDisplayLanguage()),
231
                                        new LanguageItem(gr, gr.getDisplayLanguage()),
232
                                        new LanguageItem(gl, gl.getDisplayLanguage()) };
233

    
234
                        DefaultComboBoxModel model = new DefaultComboBoxModel(lenguajes);
235

    
236
                        for (int i = 0; i < lenguajes.length; i++) {
237
                                if (lenguajes[i].locale.equals(Locale.getDefault())) {
238
                                        model.setSelectedItem(lenguajes[i]);
239
                                }
240
                        }
241

    
242
                        cmbIdioma.setModel(model);
243
                        cmbIdioma.addActionListener(new ActionListener() {
244
                                public void actionPerformed(ActionEvent e) {
245
                                        changed = true;
246
                                }
247
                        });
248
                }
249
                return cmbIdioma;
250
        }
251

    
252
        public boolean isValueChanged() {
253
                return changed;
254
        }
255

    
256
        public void setChangesApplied() {
257
                changed = false;
258

    
259
        }
260
} // @jve:decl-index=0:visual-constraint="10,10"