Revision 29533

View differences:

branches/v2_0_0_prep/extensions/extI18n/src/main/java/org/gvsig/i18n/I18nManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {New extension for installation and update of text translations}
26
 */
27
package org.gvsig.i18n;
28

  
29
import java.io.File;
30
import java.util.Locale;
31

  
32
/**
33
 * Management of I18n and Locale related activities.
34
 * 
35
 * @author <a href="mailto:dcervera@disid.com">David Cervera</a>
36
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
37
 */
38
public interface I18nManager {
39

  
40
    public static final Locale SPANISH = new Locale("es");
41

  
42
    public static final Locale ENGLISH = new Locale("en");
43

  
44
    /**
45
     * Returns the display name of a locale language.
46
     * 
47
     * @param locale
48
     *            to get the language display name
49
     * @param displayLocale
50
     *            the locale to display the name
51
     * @return the locale language display name
52
     */
53
    String getLanguageDisplayName(Locale locale, Locale displayLocale);
54

  
55
    /**
56
     * Returns the display name of a locale language.
57
     * 
58
     * @param locale
59
     *            to get the language display name
60
     * @return the locale language display name
61
     */
62
    String getLanguageDisplayName(Locale locale);
63

  
64
    /**
65
     * Returns the display name of a locale in the given locale to be displayed.
66
     * 
67
     * @param locale
68
     *            to get the display name
69
     * @param displayLocale
70
     *            the locale to display the name
71
     * @return the locale display name
72
     */
73
    String getDisplayName(Locale locale, Locale displayLocale);
74

  
75
    /**
76
     * Returns the display name of a locale.
77
     * 
78
     * @param locale
79
     *            to get the display name
80
     * @return the locale display name
81
     */
82
    String getDisplayName(Locale locale);
83

  
84
    /**
85
     * Returns the current locale.
86
     * 
87
     * @return the current locale
88
     */
89
    Locale getCurrentLocale();
90

  
91
    /**
92
     * Sets the current application locale.
93
     * 
94
     * @param locale
95
     *            the current application locale
96
     */
97
    void setCurrentLocale(Locale locale);
98
    
99
    /**
100
     * Returns the application host system default locale.
101
     * 
102
     * @return the default system locale
103
     */
104
    Locale getDefaultSystemLocale();
105

  
106
    /**
107
     * Returns the list of locales supported by the current gvSIG installation.
108
     * 
109
     * @return the list of locales supported
110
     */
111
    Locale[] getInstalledLocales();
112

  
113
    /**
114
     * Installs or a new locale (or a list) and its translation, or updates an
115
     * already existing one.
116
     * 
117
     * @param importFile
118
     *            the jar or zip file which contains the locales and the
119
     *            translations as resource bundle files
120
     * @return the list of installed or updated locales
121
     * @throws I18nException
122
     *             if the locales could'n be installed
123
     */
124
    Locale[] installLocales(File importFile) throws I18nException;
125

  
126
    /**
127
     * Uninstalls a locale and its translation.
128
     * 
129
     * @param locale
130
     *            to uninstall
131
     * @throws I18nException
132
     *             if the locale can't be uninstalled
133
     */
134
    void uninstallLocale(Locale locale) throws I18nException;
135

  
136
    /**
137
     * Exports the translations of a locale to update or complete its
138
     * translation, into a jar file. Into the file is also included the
139
     * translations of another existing locale to be used as reference for
140
     * updating the locale.
141
     * 
142
     * @param locale
143
     *            the locale to update or complete
144
     * @param referenceLocale
145
     *            the locale to be used as reference
146
     * @param exportFile
147
     *            the jar file to export to
148
     * @throws I18nException
149
     *             if the locale could not be exported for update
150
     */
151
    void exportLocaleForUpdate(Locale locale, Locale referenceLocale,
152
	    File exportFile) throws I18nException;
153

  
154
    /**
155
     * Exports the translations of a list of locales to update or complete its
156
     * translation, into a jar file. Into the file is also included the
157
     * translations of another existing locale to be used as reference for
158
     * updating the locale.
159
     * 
160
     * @param locales
161
     *            the locales to update or complete
162
     * @param referenceLocale
163
     *            the locale to be used as reference
164
     * @param exportFile
165
     *            the jar file to export to
166
     * @throws I18nException
167
     *             if the locale could not be exported for update
168
     */
169
    void exportLocalesForUpdate(Locale[] locales, Locale referenceLocale,
170
	    File exportFile) throws I18nException;
171

  
172
    /**
173
     * Exports the keys of text to translate to a new locale to a jar file. Into
174
     * the file is also included the translations of another existing locale to
175
     * be used as reference for translating to the new locale.
176
     * 
177
     * @param locale
178
     *            the new locale to translate to
179
     * @param referenceLocale
180
     *            the locale to be used as reference
181
     * @param exportFile
182
     *            the jar file to export to
183
     * @throws I18nException
184
     *             if the locale could not be exported for translation
185
     */
186
    void exportLocaleForTranslation(Locale locale, Locale referenceLocale,
187
	    File exportFile) throws I18nException;
188

  
189
    /**
190
     * Exports the keys of text to translate to a new locale to a jar file. Into
191
     * the file is also included the translations of another existing locales to
192
     * be used as reference for translating to the new locale.
193
     * 
194
     * @param locale
195
     *            the new locale to translate to
196
     * @param referenceLocales
197
     *            the locales to be used as reference
198
     * @param exportFile
199
     *            the jar file to export to
200
     * @throws I18nException
201
     *             if the locale could not be exported for translation
202
     */
203
    void exportLocaleForTranslation(Locale locale, Locale[] referenceLocales,
204
	    File exportFile) throws I18nException;
205

  
206
    /**
207
     * Returns the list of default locales to use as reference when exporting to
208
     * translate a new locale, or update or complete an existing one.
209
     * 
210
     * @return the list of default locales to export
211
     */
212
    Locale[] getReferenceLocales();
213

  
214
    /**
215
     * Sets the list of default locales to export.
216
     * 
217
     * @param referenceLocales
218
     *            the list of default locales to export
219
     */
220
    void setReferenceLocales(Locale[] referenceLocales);
221

  
222
    /**
223
     * Sets the list of default locales bundled with gvSIG. That list of locales
224
     * will be used as the list of installed ones when gvSIG is run for the
225
     * first time with the I18n extension. The following times, that list will
226
     * be taken form the extension configuration in the plugins persistence.
227
     * 
228
     * @param defaultLocales
229
     */
230
    void setDefaultLocales(Locale[] defaultLocales);
231
}
branches/v2_0_0_prep/extensions/extI18n/src/main/java/org/gvsig/i18n/extension/I18nExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {New extension for installation and update of text translations}
26
 */
27
package org.gvsig.i18n.extension;
28

  
29
import java.net.URL;
30

  
31
import org.gvsig.i18n.extension.preferences.I18nPreferencePage;
32
import org.gvsig.tools.ToolsLocator;
33

  
34
import com.iver.andami.PluginServices;
35
import com.iver.andami.plugins.Extension;
36
import com.iver.cit.gvsig.About;
37
import com.iver.cit.gvsig.gui.panels.FPanelAbout;
38

  
39
/**
40
 * Texts localization management extension.
41
 * 
42
 * @author <a href="mailto:dcervera@disid.com">David Cervera</a>
43
 */
44
public class I18nExtension extends Extension {
45

  
46
    public void execute(String actionCommand) {
47
        // Nothing to do
48
    }
49

  
50
    public void initialize() {
51
        // Replace the default locale Preferences page for the new one
52
        ToolsLocator.getExtensionPointManager()
53
                .add("AplicationPreferences", "").append("LanguagePage", "",
54
                        new I18nPreferencePage());
55
    }
56

  
57
    public void postInitialize() {
58
        // Register the about panel
59
        About about = (About) PluginServices.getExtension(About.class);
60
        FPanelAbout panelAbout = about.getAboutPanel();
61
        URL aboutURL = getClass().getResource("/about.htm");
62
        panelAbout.addAboutUrl("I18nExtension", aboutURL);
63
    }
64

  
65
    public boolean isEnabled() {
66
        return true;
67
    }
68

  
69
    public boolean isVisible() {
70
        return true;
71
    }
72
}
branches/v2_0_0_prep/extensions/extI18n/src/main/java/org/gvsig/i18n/extension/preferences/table/RadioButtonCellEditor.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {New extension for installation and update of text translations}
26
 */
27
package org.gvsig.i18n.extension.preferences.table;
28

  
29
import java.awt.Component;
30
import java.awt.event.*;
31

  
32
import javax.swing.AbstractCellEditor;
33
import javax.swing.JTable;
34
import javax.swing.table.TableCellEditor;
35

  
36
/**
37
 * Allows to edit a cell content with a Radio button.
38
 * 
39
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
40
 */
41
public class RadioButtonCellEditor extends AbstractCellEditor implements
42
	TableCellEditor, ItemListener {
43

  
44
    private static final long serialVersionUID = 1000179477526963659L;
45

  
46
    private RadioButtonCell delegate = new RadioButtonCell();
47

  
48
    /**
49
     * Constructor.
50
     */
51
    public RadioButtonCellEditor() {
52
	delegate.getRadioButton().addItemListener(this);
53
    }
54

  
55
    public Object getCellEditorValue() {
56
	return Boolean.valueOf(delegate.getRadioButton().isSelected());
57
    }
58

  
59
    public Component getTableCellEditorComponent(JTable table, Object value,
60
	    boolean isSelected, int row, int column) {
61
	return delegate.getTableCellComponent(table, value, isSelected,
62
		isSelected, row, column);
63
    }
64

  
65
    public void actionPerformed(ActionEvent e) {
66
	// Stop editing when the user clicks into the radio button,
67
	// so other cells get its rendering updated
68
	fireEditingStopped();
69
    }
70

  
71
    public void itemStateChanged(ItemEvent e) {
72
	fireEditingStopped();
73
    }
74

  
75
}
branches/v2_0_0_prep/extensions/extI18n/src/main/java/org/gvsig/i18n/extension/preferences/table/RadioButtonCellRenderer.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {New extension for installation and update of text translations}
26
 */
27
package org.gvsig.i18n.extension.preferences.table;
28

  
29
import java.awt.Component;
30

  
31
import javax.swing.JTable;
32
import javax.swing.table.TableCellRenderer;
33

  
34
/**
35
 * Renders a Radio button on a JTable cell.
36
 * 
37
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
38
 */
39
public class RadioButtonCellRenderer extends RadioButtonCell implements
40
	TableCellRenderer {
41

  
42
    private static final long serialVersionUID = 7085349383073216796L;
43

  
44
    public Component getTableCellRendererComponent(JTable table, Object value,
45
	    boolean isSelected, boolean hasFocus, int row, int column) {
46
	return getTableCellComponent(table, value, isSelected, hasFocus, row,
47
		column);
48
    }
49
}
branches/v2_0_0_prep/extensions/extI18n/src/main/java/org/gvsig/i18n/extension/preferences/table/LocaleTableModel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {New extension for installation and update of text translations}
26
 */
27
package org.gvsig.i18n.extension.preferences.table;
28

  
29
import java.util.Locale;
30

  
31
import javax.swing.table.AbstractTableModel;
32

  
33
import org.gvsig.i18n.*;
34

  
35
/**
36
 * TableModel to show the list of available Locales in gvSIG.
37
 *
38
 * @author <a href="mailto:dcervera@disid.com">David Cervera</a>
39
 */
40
public class LocaleTableModel extends AbstractTableModel {
41

  
42
    // Start from 0 to enable de locale column again
43
    public static final int COLUMN_LOCALE = -1;
44

  
45
    public static final int COLUMN_LANGUAGE = 0;
46

  
47
    public static final int COLUMN_COUNTRY = 1;
48

  
49
    public static final int COLUMN_VARIANT = 2;
50

  
51
    public static final int COLUMN_ACTIVE = 3;
52

  
53
    private static final long serialVersionUID = -3855372372788577788L;
54

  
55
    private final I18nManager manager;
56

  
57
    private Locale[] locales;
58

  
59
    private int currentLocaleIndex;
60

  
61
    private int originalLocaleIndex;
62

  
63
    /**
64
     * Creates a LocaleTableModel with a I18nManager to handle locales.
65
     */
66
    public LocaleTableModel(I18nManager manager) {
67
	this.manager = manager;
68
	loadLocales();
69
    }
70

  
71
    public int getColumnCount() {
72
	return 4;
73
    }
74

  
75
    public int getRowCount() {
76
	return locales.length;
77
    }
78

  
79
    public Object getValueAt(int rowIndex, int columnIndex) {
80
	switch (columnIndex) {
81
	case COLUMN_LOCALE:
82
	    return locales[rowIndex];
83
	case COLUMN_LANGUAGE:
84
	    return manager.getLanguageDisplayName(locales[rowIndex]);
85
	case COLUMN_COUNTRY:
86
	    return locales[rowIndex].getDisplayCountry();
87
	case COLUMN_VARIANT:
88
	    return locales[rowIndex].getDisplayVariant();
89
	case COLUMN_ACTIVE:
90
	    return rowIndex == currentLocaleIndex ? Boolean.TRUE
91
		    : Boolean.FALSE;
92
	}
93
	return null;
94
    }
95

  
96
    public String getColumnName(int columnIndex) {
97
	switch (columnIndex) {
98
	case COLUMN_LOCALE:
99
	    return Messages.getText("I18nPreferencePage.Locale_code");
100
	case COLUMN_LANGUAGE:
101
	    return Messages.getText("I18nPreferencePage.Idioma");
102
	case COLUMN_COUNTRY:
103
	    return Messages.getText("I18nPreferencePage.Pais");
104
	case COLUMN_VARIANT:
105
	    return Messages.getText("I18nPreferencePage.Variante");
106
	case COLUMN_ACTIVE:
107
	    return Messages.getText("I18nPreferencePage.Activar");
108
	}
109
	return "";
110
    }
111

  
112
    public Class getColumnClass(int columnIndex) {
113
	switch (columnIndex) {
114
	case COLUMN_LOCALE:
115
	case COLUMN_LANGUAGE:
116
	case COLUMN_COUNTRY:
117
	case COLUMN_VARIANT:
118
	    return String.class;
119
	case COLUMN_ACTIVE:
120
	    return Boolean.class;
121
	}
122
	return Object.class;
123
    }
124

  
125
    public boolean isCellEditable(int rowIndex, int columnIndex) {
126
	return columnIndex == 3;
127
    }
128

  
129
    public void setValueAt(Object value, int rowIndex, int columnIndex) {
130
	// Only edit current locale value
131
	if (columnIndex == COLUMN_ACTIVE && Boolean.TRUE.equals(value)) {
132
	    setSelectedLocale(rowIndex, columnIndex);
133
	}
134
    }
135

  
136
    /**
137
     * Returns the {@link Locale} shown in a table row.
138
     *
139
     * @param rowIndex
140
     *            the table row index
141
     * @return the {@link Locale}
142
     */
143
    public Locale getLocale(int rowIndex) {
144
    	return rowIndex >= 0 ? locales[rowIndex] : null;
145
    }
146

  
147
    /**
148
     * Removes and uninstalls a locale.
149
     *
150
     * @param locale
151
     *            to remove
152
     * @throws I18nException
153
     *             if there is an error removing a Locale
154
     */
155
    public void removeLocale(Locale locale) throws I18nException {
156
	int rowIndex = getLocaleRowIndex(locale);
157
	manager.uninstallLocale(locale);
158
	loadLocales();
159
	fireTableRowsDeleted(rowIndex, rowIndex);
160
    }
161

  
162
    /**
163
     * Reloads the list of installed locales.
164
     */
165
    public void reloadLocales() {
166
	loadLocales();
167
	fireTableDataChanged();
168
    }
169

  
170
    public void saveSelectedLocale() {
171
	manager.setCurrentLocale(getSelectedLocale());
172
	originalLocaleIndex = currentLocaleIndex;
173
    }
174

  
175
    public void selectPreviousLocale() {
176
	setSelectedLocale(originalLocaleIndex, COLUMN_ACTIVE);
177
    }
178

  
179
    /**
180
     *
181
     */
182
    public void selectDefaultLocale() {
183
	Locale defLocale = manager.getDefaultSystemLocale();
184
	int pos = getLocaleRowIndex(defLocale);
185
	// Maybe the locale has country and/or variant and is not registered
186
	// (ex: en_US). Look for the locale with only the language (ex: en).
187
	if (pos == -1) {
188
	    defLocale = new Locale(defLocale.getLanguage());
189
	    pos = getLocaleRowIndex(defLocale);
190
	}
191
	// If the locale could'nt be found, use English as default
192
	if (pos == -1) {
193
	    pos = getLocaleRowIndex(I18nManager.ENGLISH);
194
	}
195
	setSelectedLocale(pos, COLUMN_ACTIVE);
196
    }
197

  
198
    public boolean isValueChanged() {
199
	return currentLocaleIndex != originalLocaleIndex;
200
    }
201

  
202
    public void setChangesApplied() {
203
	originalLocaleIndex = currentLocaleIndex;
204
    }
205

  
206
    /**
207
     * Sets the current selected locale.
208
     */
209
    public void setSelectedLocale(Locale locale) {
210
	int localeIndex = getLocaleRowIndex(locale);
211
	setSelectedLocale(localeIndex);
212
    }
213

  
214
    /**
215
     * Returns the current selected locale.
216
     */
217
    public Locale getSelectedLocale() {
218
	Locale selected = getLocale(currentLocaleIndex);
219
	return selected == null ? manager.getCurrentLocale() : selected;
220
    }
221

  
222
    private void setSelectedLocale(int rowIndex) {
223
	setSelectedLocale(rowIndex, 0);
224
    }
225

  
226
    private void setSelectedLocale(int rowIndex, int columnIndex) {
227
	int oldCurrentLocaleIndex = currentLocaleIndex;
228
	currentLocaleIndex = rowIndex;
229
	fireTableCellUpdated(oldCurrentLocaleIndex, columnIndex);
230
	fireTableCellUpdated(rowIndex, columnIndex);
231
    }
232

  
233
    /**
234
     * Loads the locales from the I18nManager.
235
     */
236
    private void loadLocales() {
237
	locales = manager.getInstalledLocales();
238
	Locale currentLocale = manager.getCurrentLocale();
239
	currentLocaleIndex = getLocaleRowIndex(currentLocale);
240
	originalLocaleIndex = currentLocaleIndex;
241
    }
242

  
243
    /**
244
     * Returns the table row position for a Locale.
245
     */
246
    private int getLocaleRowIndex(Locale locale) {
247
	for (int i = 0; i < locales.length; i++) {
248
	    if (locale.equals(locales[i])) {
249
		return i;
250
	    }
251
	}
252
	return -1;
253
    }
254
}
branches/v2_0_0_prep/extensions/extI18n/src/main/java/org/gvsig/i18n/extension/preferences/table/RadioButtonCell.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {New extension for installation and update of text translations}
26
 */
27
package org.gvsig.i18n.extension.preferences.table;
28

  
29
import java.awt.Component;
30

  
31
import javax.swing.*;
32

  
33
/**
34
 * Renders a radio button on a table cell.
35
 * 
36
 * @author <a href="mailto:dcervera@disid.com">David Cervera</a>
37
 */
38
public class RadioButtonCell {
39

  
40
    private JRadioButton radio = new JRadioButton();
41

  
42
    /**
43
     * Constructor.
44
     */
45
    public RadioButtonCell() {
46
	radio.setHorizontalAlignment(SwingConstants.CENTER);
47
    }
48

  
49
    protected Component getTableCellComponent(JTable table, Object value,
50
	    boolean isSelected, boolean hasFocus, int row, int column) {
51

  
52
	if (isSelected) {
53
	    radio.setForeground(table.getSelectionForeground());
54
	    radio.setBackground(table.getSelectionBackground());
55
	}
56
	else {
57
	    radio.setForeground(table.getForeground());
58
	    radio.setBackground(table.getBackground());
59
	}
60

  
61
	radio.setSelected(Boolean.TRUE.equals(value));
62

  
63
	return radio;
64
    }
65

  
66
    protected JRadioButton getRadioButton() {
67
	return radio;
68
    }
69
}
branches/v2_0_0_prep/extensions/extI18n/src/main/java/org/gvsig/i18n/extension/preferences/I18nPreferencePage.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {New extension for installation and update of text translations}
26
 */
27
package org.gvsig.i18n.extension.preferences;
28

  
29
import java.awt.*;
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32
import java.io.File;
33
import java.util.*;
34
import java.util.List;
35

  
36
import javax.swing.*;
37
import javax.swing.filechooser.FileFilter;
38
import javax.swing.table.TableColumn;
39

  
40
import org.gvsig.gui.beans.swing.JButton;
41
import org.gvsig.i18n.I18nException;
42
import org.gvsig.i18n.I18nManager;
43
import org.gvsig.i18n.Messages;
44
import org.gvsig.i18n.extension.preferences.table.LocaleTableModel;
45
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellEditor;
46
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellRenderer;
47
import org.gvsig.i18n.impl.I18nManagerImpl;
48

  
49
import com.iver.andami.preferences.AbstractPreferencePage;
50
import com.iver.andami.preferences.StoreException;
51

  
52
/**
53
 * Prefence page to manage gvSIG locales.
54
 * 
55
 * @author <a href="mailto:dcervera@disid.com">David Cervera</a>
56
 */
57
public class I18nPreferencePage extends AbstractPreferencePage implements
58
	ActionListener {
59

  
60
    private static final long serialVersionUID = 7164183052397200888L;
61

  
62
    private static final String COMMAND_UNINSTALL = "UNINSTALL";
63

  
64
    private static final String COMMAND_EXPORT = "EXPORT";
65

  
66
    private static final String COMMAND_EXPORT_NEW = "EXPORT_NEW";
67

  
68
    private static final String COMMAND_INSTALL = "INSTALL";
69

  
70
    private static final String EXPORT_JAR_FILE_EXTENSION = ".jar";
71

  
72
    private static final String EXPORT_ZIP_FILE_EXTENSION = ".zip";
73

  
74
    private ImageIcon icon;
75

  
76
    private I18nManager manager = I18nManagerImpl.getInstance();
77

  
78
    private JTable localesTable;
79

  
80
    private LocaleTableModel tableModel;
81

  
82
    private JFileChooser fileChooser;
83

  
84
    /**
85
     * Creates a new I18n preferences page.
86
     */
87
    public I18nPreferencePage() {
88
	setParentID("com.iver.core.preferences.general.GeneralPage");
89
	icon = new ImageIcon(this.getClass().getClassLoader().getResource(
90
		"images/babel.png"));
91

  
92
	setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
93

  
94
	add(getLocalesPanel());
95
	add(Box.createRigidArea(new Dimension(0, 5)));
96
	add(getActiveLocaleLabel());
97
	add(Box.createRigidArea(new Dimension(0, 5)));
98
	add(getButtonsPanel());
99
	add(Box.createRigidArea(new Dimension(0, 5)));
100
	add(getCollaborationLabel());
101
    }
102

  
103
    public String getID() {
104
	return getClass().getName();
105
    }
106

  
107
    public String getTitle() {
108
	return Messages.getText("idioma");
109
    }
110

  
111
    public ImageIcon getIcon() {
112
	return icon;
113
    }
114

  
115
    public JPanel getPanel() {
116
	return this;
117
    }
118

  
119
    public void setChangesApplied() {
120
	tableModel.setChangesApplied();
121
    }
122

  
123
    public boolean isValueChanged() {
124
	return tableModel.isValueChanged();
125
    }
126

  
127
    public void storeValues() throws StoreException {
128
	tableModel.saveSelectedLocale();
129
    }
130

  
131
    public void initializeDefaults() {
132
	tableModel.selectDefaultLocale();
133
    }
134

  
135
    public void initializeValues() {
136
	tableModel.selectPreviousLocale();
137
    }
138

  
139
    public void actionPerformed(ActionEvent event) {
140
	if (COMMAND_INSTALL.equals(event.getActionCommand())) {
141
	    installLocale();
142
	}
143
	else if (COMMAND_EXPORT.equals(event.getActionCommand())) {
144
	    exportLocaleForUpdate();
145
	}
146
	else if (COMMAND_EXPORT_NEW.equals(event.getActionCommand())) {
147
	    exportLocaleForTranslation();
148
	}
149
	else if (COMMAND_UNINSTALL.equals(event.getActionCommand())) {
150
	    uninstallSelectedLocale();
151
	}
152
    }
153

  
154
    /**
155
     * Installs a new Locale translation or updates an already existing one.
156
     */
157
    private void installLocale() {
158
	JFileChooser fileChooser = getJarFileChooser();
159

  
160
	int returnVal = fileChooser.showOpenDialog(this);
161

  
162
	if (returnVal == JFileChooser.APPROVE_OPTION) {
163
	    File importFile = fileChooser.getSelectedFile();
164
	    try {
165
		Locale[] installedLocales = manager.installLocales(importFile);
166
		if (installedLocales == null || installedLocales.length == 0) {
167
		    JOptionPane
168
			    .showMessageDialog(
169
				    this,
170
				    Messages
171
					    .getText("I18nPreferencePage.idiomas_no_encontrados_para_instalar"),
172
				    Messages
173
					    .getText("I18nPreferencePage.error_instalar_idiomas"),
174
				    JOptionPane.ERROR_MESSAGE);
175
		}
176
		else {
177
		    StringBuffer msg = new StringBuffer(Messages
178
			    .getText("I18nPreferencePage.idiomas_instalados"));
179

  
180
		    for (int i = 0; i < installedLocales.length; i++) {
181
			msg.append(manager.getDisplayName(installedLocales[i]));
182
			if (i < installedLocales.length - 1) {
183
			    msg.append(", ");
184
			}
185
		    }
186
		    tableModel.reloadLocales();
187
		    JOptionPane
188
			    .showMessageDialog(
189
				    this,
190
				    msg.toString(),
191
				    Messages
192
					    .getText("I18nPreferencePage.instalar_idiomas"),
193
				    JOptionPane.INFORMATION_MESSAGE);
194
		}
195
	    } catch (I18nException ex) {
196
		ex.showError();
197
	    }
198
	}
199
    }
200

  
201
    /**
202
     * Updates the translation of a locale
203
     */
204
    private void exportLocaleForUpdate() {
205
	Locale[] locales = getSelectedLocales();
206

  
207
	if (locales == null) {
208
	    JOptionPane.showMessageDialog(this, Messages
209
		    .getText("I18nPreferencePage.seleccione_idioma"), Messages
210
		    .getText("I18nPreferencePage.error_actualizar_idioma"),
211
		    JOptionPane.ERROR_MESSAGE);
212
	}
213
	else {
214
	    // Select the reference language
215
	    LocaleItem[] items = getLocaleItemsForSelection(manager
216
		    .getInstalledLocales(), locales);
217
	    LocaleItem selected = null;
218
	    if (items != null && items.length > 0) {
219
		// Select by default the current locale, or the first one
220
		// if the current locale is one of the ones to be updated
221
		for (int i = 0; i < locales.length && selected == null; i++) {
222
		    if (locales[i].equals(manager.getCurrentLocale())) {
223
			selected = items[0];
224
		    }
225
		}
226
		if (selected == null) {
227
		    selected = new LocaleItem(manager.getCurrentLocale(),
228
			    manager);
229
		}
230
		selected = (LocaleItem) JOptionPane
231
			.showInputDialog(
232
				this,
233
				Messages
234
					.getText("I18nPreferencePage.seleccione_idioma_referencia"),
235
				Messages
236
					.getText("I18nPreferencePage.exportar_idioma"),
237
				JOptionPane.QUESTION_MESSAGE, null, items,
238
				selected);
239

  
240
		if (selected == null) {
241
		    return;
242
		}
243
	    }
244
	    // Select the file to export to
245
	    JFileChooser fileChooser = getJarFileChooser();
246
	    fileChooser.setSelectedFile(new File(
247
		    getLocaleJarFileName(locales[0])));
248

  
249
	    if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
250
		File saveFile = fileChooser.getSelectedFile();
251
		try {
252
		    Locale fileNameLocale = selected == null ? manager
253
			    .getCurrentLocale() : selected.getLocale();
254
		    manager.exportLocalesForUpdate(locales, fileNameLocale,
255
			    saveFile);
256
		    
257
		    JOptionPane
258
			    .showMessageDialog(
259
				    this,
260
				    Messages
261
					    .getText("I18nPreferencePage.exportado_textos_idioma")
262
					    + " "
263
					    + saveFile,
264
				    Messages
265
					    .getText("I18nPreferencePage.exportar_idioma"),
266
				    JOptionPane.INFORMATION_MESSAGE);
267
		} catch (I18nException ex) {
268
		    ex.showError();
269
		}
270
	    }
271
	}
272
    }
273

  
274
    /**
275
     * Prepares a locale for translation.
276
     */
277
    private void exportLocaleForTranslation() {
278
	// Get the selected locale as the ones for reference
279
	Locale[] refLocales = getSelectedLocales();
280

  
281
	if (refLocales == null) {
282
	    JOptionPane
283
		    .showMessageDialog(
284
			    this,
285
			    Messages
286
				    .getText("I18nPreferencePage.seleccione_idioma_actualizar"),
287
			    Messages
288
				    .getText("I18nPreferencePage.error_actualizar_idioma"),
289
			    JOptionPane.ERROR_MESSAGE);
290
	}
291
	else {
292

  
293
	    // Select the locale to translate
294
	    LocaleItem[] items = getLocaleItemsForSelection(Locale
295
		    .getAvailableLocales(), manager.getInstalledLocales());
296
	    LocaleItem selected = (LocaleItem) JOptionPane
297
		    .showInputDialog(
298
			    this,
299
			    Messages
300
				    .getText("I18nPreferencePage.seleccione_idioma_traducir"),
301
			    Messages
302
				    .getText("I18nPreferencePage.exportar_idioma"),
303
			    JOptionPane.QUESTION_MESSAGE, null, items, items[0]);
304

  
305
	    if (selected == null) {
306
		return;
307
	    }
308

  
309
	    // Select the file to export to
310
	    JFileChooser fileChooser = getJarFileChooser();
311
	    fileChooser.setSelectedFile(new File(getLocaleJarFileName(selected
312
		    .getLocale())));
313

  
314
	    if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
315
		File saveFile = fileChooser.getSelectedFile();
316
		try {
317
		    manager.exportLocaleForTranslation(selected.getLocale(),
318
			    refLocales, saveFile);
319

  
320
		    JOptionPane
321
			    .showMessageDialog(
322
				    this,
323
				    Messages
324
					    .getText("I18nPreferencePage.idioma_preparado_traducir")
325
					    + manager.getDisplayName(selected
326
						    .getLocale())
327
					    + Messages
328
						    .getText("I18nPreferencePage.en_archivo")
329
					    + saveFile,
330
				    Messages
331
					    .getText("I18nPreferencePage.exportar_idioma"),
332
				    JOptionPane.INFORMATION_MESSAGE);
333
		} catch (I18nException ex) {
334
		    ex.showError();
335
		}
336
	    }
337
	}
338

  
339
    }
340

  
341
    private LocaleItem[] getLocaleItemsForSelection(Locale[] locales,
342
	    Locale[] exceptions) {
343
	List items = new ArrayList();
344
	Set exceptionsSet = new HashSet(exceptions.length);
345
	for (int i = 0; i < exceptions.length; i++) {
346
	    exceptionsSet.add(exceptions[i]);
347
	}
348

  
349
	int j = 0;
350
	for (int i = 0; i < locales.length; i++) {
351
	    // Only add locales not included in the exceptions list
352
	    if (!exceptionsSet.contains(locales[i])) {
353
		items.add(new LocaleItem(locales[i], manager));
354
		j++;
355
	    }
356
	}
357
	return (LocaleItem[]) items.toArray(new LocaleItem[items.size()]);
358
    }
359

  
360
    /**
361
     * Returns a name for the jar file to export a locale.
362
     */
363
    private String getLocaleJarFileName(Locale locale) {
364
	return manager.getDisplayName(locale, I18nManager.ENGLISH).replace(' ',
365
		'_').concat(EXPORT_ZIP_FILE_EXTENSION);
366
    }
367

  
368
    /**
369
     * Creates a new JFileChooser to import or export a locale jar file.
370
     */
371
    private JFileChooser getJarFileChooser() {
372
	if (fileChooser == null) {
373
	    fileChooser = new JFileChooser();
374
	    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
375
	    fileChooser.setMultiSelectionEnabled(false);
376
	    fileChooser.setFileFilter(new FileFilter() {
377

  
378
		public boolean accept(File file) {
379
		    return (file.isDirectory()
380
			    || file.getName().endsWith(
381
				    EXPORT_JAR_FILE_EXTENSION) || file
382
			    .getName().endsWith(EXPORT_ZIP_FILE_EXTENSION));
383
		}
384

  
385
		public String getDescription() {
386
		    return Messages.getText("I18nPreferencePage.archivos_jar");
387
		}
388

  
389
	    });
390
	}
391
	return fileChooser;
392
    }
393

  
394
    /**
395
     * Removes some installed locales from gvSIG.
396
     */
397
    private void uninstallSelectedLocale() {
398
	Locale[] locales = getSelectedLocales();
399

  
400
	if (locales == null) {
401
	    JOptionPane
402
		    .showMessageDialog(
403
			    this,
404
			    Messages
405
				    .getText("I18nPreferencePage.seleccione_idioma_desinstalar"),
406
			    Messages
407
				    .getText("I18nPreferencePage.error_desinstalar_idioma"),
408
			    JOptionPane.ERROR_MESSAGE);
409
	    return;
410
	}
411
	
412
	for (int i = 0; i < locales.length; i++) {
413

  
414
	    if (locales[i].equals(manager.getCurrentLocale())) {
415
		JOptionPane
416
			.showMessageDialog(
417
				this,
418
				Messages
419
					.getText("I18nPreferencePage.idioma_actual_no_puede_desinstalar"),
420
				Messages
421
					.getText("I18nPreferencePage.error_desinstalar_idioma"),
422
				JOptionPane.ERROR_MESSAGE);
423
	    } else {
424
		int option = JOptionPane
425
			.showConfirmDialog(
426
				this,
427
				Messages
428
					.getText("I18nPreferencePage.seguro_desea_desinstalar_idioma")
429
					+ " "
430
					+ manager.getDisplayName(locales[i])
431
					+ "?",
432
				Messages
433
					.getText("I18nPreferencePage.confirmar_desinstalar_idioma"),
434
				JOptionPane.YES_NO_OPTION);
435
		if (option == JOptionPane.YES_OPTION) {
436
		    try {
437
			tableModel.removeLocale(locales[i]);
438
		    } catch (I18nException ex) {
439
			ex.showError();
440
		    }
441
		}
442
	    }
443
	}
444
    }
445

  
446
    /**
447
     * Returns the Locales selected in the table of available locales.
448
     */
449
    private Locale[] getSelectedLocales() {
450
	int[] rowIndexes = localesTable.getSelectedRows();
451
	if (rowIndexes != null && rowIndexes.length > 0) {
452
	    Locale[] locales = new Locale[rowIndexes.length];
453
	    for (int i = 0; i < locales.length; i++) {
454
		locales[i] = tableModel.getLocale(rowIndexes[i]);
455
	    }
456
	    return locales;
457
	}
458
	else {
459
	    return null;
460
	}
461
    }
462

  
463
    /**
464
     * Creates the Panel with the table of Locales.
465
     */
466
    private Component getLocalesPanel() {
467
	tableModel = new LocaleTableModel(manager);
468
	localesTable = new JTable(tableModel);
469

  
470
	TableColumn activeColumn = localesTable.getColumnModel().getColumn(
471
		LocaleTableModel.COLUMN_ACTIVE);
472
	activeColumn.setCellEditor(new RadioButtonCellEditor());
473
	activeColumn.setCellRenderer(new RadioButtonCellRenderer());
474

  
475
	localesTable
476
		.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
477
	localesTable.getSelectionModel().setSelectionInterval(0, 0);
478
	JScrollPane scrollPane = new JScrollPane(localesTable);
479

  
480
	// Container panel
481
	JPanel localesPanel = new JPanel();
482
	localesPanel.setLayout(new BoxLayout(localesPanel, BoxLayout.Y_AXIS));
483
	localesPanel.add(scrollPane);
484
	localesPanel.setAlignmentX(CENTER_ALIGNMENT);
485
	localesPanel.setPreferredSize(new Dimension(236, 230));
486
	localesPanel.setMaximumSize(new Dimension(500, 230));
487

  
488
	return localesPanel;
489
    }
490

  
491
    /**
492
     * Creates the panel with the buttons to perform the related actions.
493
     */
494
    private Component getButtonsPanel() {
495
	JPanel buttonPanel = new JPanel(new GridBagLayout());
496
	GridBagConstraints constraints = new GridBagConstraints();
497
	constraints.fill = GridBagConstraints.NONE;
498
	constraints.anchor = GridBagConstraints.LINE_START;
499
	Insets btInsets = new Insets(2, 0, 2, 4);
500
	Insets lbInsets = new Insets(2, 2, 2, 0);
501

  
502
	/* ROW 0 */
503
	constraints.gridy = 0;
504

  
505
	constraints.gridx = 0;
506
	constraints.insets = btInsets;
507
	JButton newLocaleButton = new JButton(Messages
508
		.getText("I18nPreferencePage.Instalar"));
509
	newLocaleButton.setActionCommand(COMMAND_INSTALL);
510
	newLocaleButton.addActionListener(this);
511
	newLocaleButton.setToolTipText(Messages
512
		.getText("I18nPreferencePage.Instalar_idioma_tooltip"));
513
	buttonPanel.add(newLocaleButton, constraints);
514

  
515
	constraints.gridx = 1;
516
	constraints.insets = lbInsets;
517
	buttonPanel.add(new JLabel(Messages
518
		.getText("I18nPreferencePage.Instalar_idioma_tooltip")),
519
		constraints);
520

  
521
	/* ROW 1 */
522
	constraints.gridy = 1;
523

  
524
	constraints.gridx = 0;
525
	constraints.insets = btInsets;
526
	JButton removeLocaleButton = new JButton(Messages
527
		.getText("I18nPreferencePage.Desinstalar"));
528
	removeLocaleButton.setActionCommand(COMMAND_UNINSTALL);
529
	removeLocaleButton.addActionListener(this);
530
	removeLocaleButton.setToolTipText(Messages
531
		.getText("I18nPreferencePage.Desinstalar_idioma_tooltip"));
532
	buttonPanel.add(removeLocaleButton, constraints);
533

  
534
	constraints.gridx = 1;
535
	constraints.insets = lbInsets;
536
	buttonPanel.add(new JLabel(Messages
537
		.getText("I18nPreferencePage.Desinstalar_idioma_tooltip")),
538
		constraints);
539

  
540
	/* ROW 2 */
541
	constraints.gridy = 2;
542

  
543
	constraints.gridx = 0;
544
	constraints.insets = btInsets;
545
	JButton exportLocaleButton = new JButton(Messages
546
		.getText("I18nPreferencePage.exportar_actualizar"));
547
	exportLocaleButton.setActionCommand(COMMAND_EXPORT);
548
	exportLocaleButton.addActionListener(this);
549
	exportLocaleButton.setToolTipText(Messages
550
		.getText("I18nPreferencePage.exportar_actualizar_tooltip"));
551
	buttonPanel.add(exportLocaleButton, constraints);
552

  
553
	constraints.gridx = 1;
554
	constraints.insets = lbInsets;
555
	buttonPanel.add(new JLabel(Messages
556
		.getText("I18nPreferencePage.exportar_actualizar_tooltip")),
557
		constraints);
558

  
559
	/* ROW 3 */
560
	constraints.gridy = 3;
561

  
562
	constraints.gridx = 0;
563
	constraints.insets = btInsets;
564
	JButton exportNewLocaleButton = new JButton(Messages
565
		.getText("I18nPreferencePage.exportar_traducir"));
566
	exportNewLocaleButton.setActionCommand(COMMAND_EXPORT_NEW);
567
	exportNewLocaleButton.addActionListener(this);
568
	exportNewLocaleButton.setToolTipText(Messages
569
		.getText("I18nPreferencePage.exportar_traducir_tooltip"));
570
	buttonPanel.add(exportNewLocaleButton, constraints);
571

  
572
	constraints.gridx = 1;
573
	constraints.insets = lbInsets;
574
	buttonPanel.add(new JLabel(Messages
575
		.getText("I18nPreferencePage.exportar_traducir_tooltip")),
576
		constraints);
577

  
578
	buttonPanel.setAlignmentX(CENTER_ALIGNMENT);
579
	return buttonPanel;
580
    }
581

  
582
    /**
583
     * Creates the JLabel to show information about the preference page.
584
     */
585
    private Component getActiveLocaleLabel() {
586
	JTextArea textArea = new JTextArea(Messages
587
		.getText("I18nPreferencePage.ayuda"));
588
	textArea.setEditable(false);
589
	textArea.setAutoscrolls(true);
590
	textArea.setLineWrap(true);
591
	textArea.setWrapStyleWord(true);
592
	textArea.setFont(textArea.getFont().deriveFont(Font.BOLD));
593
	return textArea;
594
    }
595

  
596
    /**
597
     * Creates the JLabel to show information about gvSIG translation
598
     * collaboration.
599
     */
600
    private Component getCollaborationLabel() {
601
	JTextArea textArea = new JTextArea(Messages
602
		.getText("I18nPreferencePage.colaboracion"));
603
	textArea.setEditable(false);
604
	textArea.setAutoscrolls(true);
605
	textArea.setLineWrap(true);
606
	textArea.setWrapStyleWord(true);
607
	return textArea;
608
    }
609

  
610
    private class LocaleItem {
611
	private final Locale locale;
612
	private final I18nManager manager;
613

  
614
	public LocaleItem(Locale locale, I18nManager manager) {
615
	    this.locale = locale;
616
	    this.manager = manager;
617
	}
618

  
619
	public Locale getLocale() {
620
	    return locale;
621
	}
622

  
623
	public String toString() {
624
	    return manager.getDisplayName(locale);
625
	}
626

  
627
	public boolean equals(Object obj) {
628
	    if (obj == null || !(obj instanceof LocaleItem)) {
629
		return false;
630
	    }
631

  
632
	    LocaleItem item = (LocaleItem) obj;
633
	    return locale.equals(item.getLocale());
634
	}
635
    }
636
}
branches/v2_0_0_prep/extensions/extI18n/src/main/java/org/gvsig/i18n/I18nException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {DiSiD Technologies}  {New extension for installation and update of text translations}
26
 */
27
package org.gvsig.i18n;
28

  
29
import com.iver.andami.messages.NotificationManager;
30

  
31
/**
32
 * Exception for errors of the I18nManager.
33
 * 
34
 * TODO: hacer que extienda BaseException cuando se pase a gvSIG trunk.
35
 * 
36
 * @author <a href="mailto:dcervera@disid.com">David Cervera</a>
37
 */
38
public class I18nException extends Exception {
39

  
40
    private static final long serialVersionUID = 2877056472517898602L;
41
    
42
    private String key;
43

  
44
    /**
45
     * Creates a new exception with an error message.
46
     * 
47
     * @param message
48
     *            the error message
49
     * @param key
50
     *            the i18n key to localize the exception message
51
     */
52
    public I18nException(String message, String key) {
53
	super(message);
54
	this.key = key;
55
    }
56

  
57
    /**
58
     * Creates a new exception with an error message and a cause exception.
59
     * 
60
     * @param message
61
     *            the error message
62
     * @param key
63
     *            the i18n key to localize the exception message
64
     * @param cause
65
     *            the error that caused the exception
66
     */
67
    public I18nException(String message, String key, Throwable cause) {
68
	super(message, cause);
69
	this.key = key;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff