Revision 33829

View differences:

tags/v2_0_0_Build_2020/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 Government (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
}
tags/v2_0_0_Build_2020/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 Government (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
}
tags/v2_0_0_Build_2020/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 Government (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
}
tags/v2_0_0_Build_2020/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 Government (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
}
tags/v2_0_0_Build_2020/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 Government (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
}
tags/v2_0_0_Build_2020/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 Government (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.Component;
30
import java.awt.Dimension;
31
import java.awt.Font;
32
import java.awt.GridBagConstraints;
33
import java.awt.GridBagLayout;
34
import java.awt.Insets;
35
import java.awt.event.ActionEvent;
36
import java.awt.event.ActionListener;
37
import java.io.File;
38
import java.util.ArrayList;
39
import java.util.HashSet;
40
import java.util.List;
41
import java.util.Locale;
42
import java.util.Set;
43

  
44
import javax.swing.Box;
45
import javax.swing.BoxLayout;
46
import javax.swing.ImageIcon;
47
import javax.swing.JFileChooser;
48
import javax.swing.JLabel;
49
import javax.swing.JOptionPane;
50
import javax.swing.JPanel;
51
import javax.swing.JScrollPane;
52
import javax.swing.JTable;
53
import javax.swing.JTextArea;
54
import javax.swing.ListSelectionModel;
55
import javax.swing.filechooser.FileFilter;
56
import javax.swing.table.TableColumn;
57

  
58
import org.gvsig.andami.preferences.AbstractPreferencePage;
59
import org.gvsig.andami.preferences.StoreException;
60
import org.gvsig.gui.beans.swing.JButton;
61
import org.gvsig.i18n.I18nException;
62
import org.gvsig.i18n.I18nManager;
63
import org.gvsig.i18n.Messages;
64
import org.gvsig.i18n.extension.preferences.table.LocaleTableModel;
65
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellEditor;
66
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellRenderer;
67
import org.gvsig.i18n.impl.I18nManagerImpl;
68

  
69

  
70
/**
71
 * Prefence page to manage gvSIG locales.
72
 * 
73
 * @author <a href="mailto:dcervera@disid.com">David Cervera</a>
74
 */
75
public class I18nPreferencePage extends AbstractPreferencePage implements
76
	ActionListener {
77

  
78
    private static final long serialVersionUID = 7164183052397200888L;
79

  
80
    private static final String COMMAND_UNINSTALL = "UNINSTALL";
81

  
82
    private static final String COMMAND_EXPORT = "EXPORT";
83

  
84
    private static final String COMMAND_EXPORT_NEW = "EXPORT_NEW";
85

  
86
    private static final String COMMAND_INSTALL = "INSTALL";
87

  
88
    private static final String EXPORT_JAR_FILE_EXTENSION = ".jar";
89

  
90
    private static final String EXPORT_ZIP_FILE_EXTENSION = ".zip";
91

  
92
    private ImageIcon icon;
93

  
94
    private I18nManager manager = I18nManagerImpl.getInstance();
95

  
96
    private JTable localesTable;
97

  
98
    private LocaleTableModel tableModel;
99

  
100
    private JFileChooser fileChooser;
101

  
102
    /**
103
     * Creates a new I18n preferences page.
104
     */
105
    public I18nPreferencePage() {
106
		setParentID("org.gvsig.coreplugin.preferences.general.GeneralPage");
107
	icon = new ImageIcon(this.getClass().getClassLoader().getResource(
108
		"images/babel.png"));
109

  
110
	setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
111

  
112
	add(getLocalesPanel());
113
	add(Box.createRigidArea(new Dimension(0, 5)));
114
	add(getActiveLocaleLabel());
115
	add(Box.createRigidArea(new Dimension(0, 5)));
116
	add(getButtonsPanel());
117
	add(Box.createRigidArea(new Dimension(0, 5)));
118
	add(getCollaborationLabel());
119
    }
120

  
121
    public String getID() {
122
		return getClass().getName();
123
    }
124

  
125
    public String getTitle() {
126
	return Messages.getText("idioma");
127
    }
128

  
129
    public ImageIcon getIcon() {
130
	return icon;
131
    }
132

  
133
    public JPanel getPanel() {
134
	return this;
135
    }
136

  
137
    public void setChangesApplied() {
138
	tableModel.setChangesApplied();
139
    }
140

  
141
    public boolean isValueChanged() {
142
	return tableModel.isValueChanged();
143
    }
144

  
145
    public void storeValues() throws StoreException {
146
	tableModel.saveSelectedLocale();
147
    }
148

  
149
    public void initializeDefaults() {
150
	tableModel.selectDefaultLocale();
151
    }
152

  
153
    public void initializeValues() {
154
	tableModel.selectPreviousLocale();
155
    }
156

  
157
    public void actionPerformed(ActionEvent event) {
158
	if (COMMAND_INSTALL.equals(event.getActionCommand())) {
159
	    installLocale();
160
	}
161
	else if (COMMAND_EXPORT.equals(event.getActionCommand())) {
162
	    exportLocaleForUpdate();
163
	}
164
	else if (COMMAND_EXPORT_NEW.equals(event.getActionCommand())) {
165
	    exportLocaleForTranslation();
166
	}
167
	else if (COMMAND_UNINSTALL.equals(event.getActionCommand())) {
168
	    uninstallSelectedLocale();
169
	}
170
    }
171

  
172
    /**
173
     * Installs a new Locale translation or updates an already existing one.
174
     */
175
    private void installLocale() {
176
	JFileChooser fileChooser = getJarFileChooser();
177

  
178
	int returnVal = fileChooser.showOpenDialog(this);
179

  
180
	if (returnVal == JFileChooser.APPROVE_OPTION) {
181
	    File importFile = fileChooser.getSelectedFile();
182
	    try {
183
		Locale[] installedLocales = manager.installLocales(importFile);
184
		if (installedLocales == null || installedLocales.length == 0) {
185
		    JOptionPane
186
			    .showMessageDialog(
187
				    this,
188
				    Messages
189
					    .getText("I18nPreferencePage.idiomas_no_encontrados_para_instalar"),
190
				    Messages
191
					    .getText("I18nPreferencePage.error_instalar_idiomas"),
192
				    JOptionPane.ERROR_MESSAGE);
193
		}
194
		else {
195
		    StringBuffer msg = new StringBuffer(Messages
196
			    .getText("I18nPreferencePage.idiomas_instalados"));
197

  
198
		    for (int i = 0; i < installedLocales.length; i++) {
199
			msg.append(manager.getDisplayName(installedLocales[i]));
200
			if (i < installedLocales.length - 1) {
201
			    msg.append(", ");
202
			}
203
		    }
204
		    tableModel.reloadLocales();
205
		    JOptionPane
206
			    .showMessageDialog(
207
				    this,
208
				    msg.toString(),
209
				    Messages
210
					    .getText("I18nPreferencePage.instalar_idiomas"),
211
				    JOptionPane.INFORMATION_MESSAGE);
212
		}
213
	    } catch (I18nException ex) {
214
		ex.showError();
215
	    }
216
	}
217
    }
218

  
219
    /**
220
     * Updates the translation of a locale
221
     */
222
    private void exportLocaleForUpdate() {
223
	Locale[] locales = getSelectedLocales();
224

  
225
	if (locales == null) {
226
	    JOptionPane.showMessageDialog(this, Messages
227
		    .getText("I18nPreferencePage.seleccione_idioma"), Messages
228
		    .getText("I18nPreferencePage.error_actualizar_idioma"),
229
		    JOptionPane.ERROR_MESSAGE);
230
	}
231
	else {
232
	    // Select the reference language
233
	    LocaleItem[] items = getLocaleItemsForSelection(manager
234
		    .getInstalledLocales(), locales);
235
	    LocaleItem selected = null;
236
	    if (items != null && items.length > 0) {
237
		// Select by default the current locale, or the first one
238
		// if the current locale is one of the ones to be updated
239
		for (int i = 0; i < locales.length && selected == null; i++) {
240
		    if (locales[i].equals(manager.getCurrentLocale())) {
241
			selected = items[0];
242
		    }
243
		}
244
		if (selected == null) {
245
		    selected = new LocaleItem(manager.getCurrentLocale(),
246
			    manager);
247
		}
248
		selected = (LocaleItem) JOptionPane
249
			.showInputDialog(
250
				this,
251
				Messages
252
					.getText("I18nPreferencePage.seleccione_idioma_referencia"),
253
				Messages
254
					.getText("I18nPreferencePage.exportar_idioma"),
255
				JOptionPane.QUESTION_MESSAGE, null, items,
256
				selected);
257

  
258
		if (selected == null) {
259
		    return;
260
		}
261
	    }
262
	    // Select the file to export to
263
	    JFileChooser fileChooser = getJarFileChooser();
264
	    fileChooser.setSelectedFile(new File(
265
		    getLocaleJarFileName(locales[0])));
266

  
267
	    if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
268
		File saveFile = fileChooser.getSelectedFile();
269
		try {
270
		    Locale fileNameLocale = selected == null ? manager
271
			    .getCurrentLocale() : selected.getLocale();
272
		    manager.exportLocalesForUpdate(locales, fileNameLocale,
273
			    saveFile);
274
		    
275
		    JOptionPane
276
			    .showMessageDialog(
277
				    this,
278
				    Messages
279
					    .getText("I18nPreferencePage.exportado_textos_idioma")
280
					    + " "
281
					    + saveFile,
282
				    Messages
283
					    .getText("I18nPreferencePage.exportar_idioma"),
284
				    JOptionPane.INFORMATION_MESSAGE);
285
		} catch (I18nException ex) {
286
		    ex.showError();
287
		}
288
	    }
289
	}
290
    }
291

  
292
    /**
293
     * Prepares a locale for translation.
294
     */
295
    private void exportLocaleForTranslation() {
296
	// Get the selected locale as the ones for reference
297
	Locale[] refLocales = getSelectedLocales();
298

  
299
	if (refLocales == null) {
300
	    JOptionPane
301
		    .showMessageDialog(
302
			    this,
303
			    Messages
304
				    .getText("I18nPreferencePage.seleccione_idioma_actualizar"),
305
			    Messages
306
				    .getText("I18nPreferencePage.error_actualizar_idioma"),
307
			    JOptionPane.ERROR_MESSAGE);
308
	}
309
	else {
310

  
311
	    // Select the locale to translate
312
	    LocaleItem[] items = getLocaleItemsForSelection(Locale
313
		    .getAvailableLocales(), manager.getInstalledLocales());
314
	    LocaleItem selected = (LocaleItem) JOptionPane
315
		    .showInputDialog(
316
			    this,
317
			    Messages
318
				    .getText("I18nPreferencePage.seleccione_idioma_traducir"),
319
			    Messages
320
				    .getText("I18nPreferencePage.exportar_idioma"),
321
			    JOptionPane.QUESTION_MESSAGE, null, items, items[0]);
322

  
323
	    if (selected == null) {
324
		return;
325
	    }
326

  
327
	    // Select the file to export to
328
	    JFileChooser fileChooser = getJarFileChooser();
329
	    fileChooser.setSelectedFile(new File(getLocaleJarFileName(selected
330
		    .getLocale())));
331

  
332
	    if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
333
		File saveFile = fileChooser.getSelectedFile();
334
		try {
335
		    manager.exportLocaleForTranslation(selected.getLocale(),
336
			    refLocales, saveFile);
337

  
338
		    JOptionPane
339
			    .showMessageDialog(
340
				    this,
341
				    Messages
342
					    .getText("I18nPreferencePage.idioma_preparado_traducir")
343
					    + manager.getDisplayName(selected
344
						    .getLocale())
345
					    + Messages
346
						    .getText("I18nPreferencePage.en_archivo")
347
					    + saveFile,
348
				    Messages
349
					    .getText("I18nPreferencePage.exportar_idioma"),
350
				    JOptionPane.INFORMATION_MESSAGE);
351
		} catch (I18nException ex) {
352
		    ex.showError();
353
		}
354
	    }
355
	}
356

  
357
    }
358

  
359
    private LocaleItem[] getLocaleItemsForSelection(Locale[] locales,
360
	    Locale[] exceptions) {
361
	List items = new ArrayList();
362
	Set exceptionsSet = new HashSet(exceptions.length);
363
	for (int i = 0; i < exceptions.length; i++) {
364
	    exceptionsSet.add(exceptions[i]);
365
	}
366

  
367
	int j = 0;
368
	for (int i = 0; i < locales.length; i++) {
369
	    // Only add locales not included in the exceptions list
370
	    if (!exceptionsSet.contains(locales[i])) {
371
		items.add(new LocaleItem(locales[i], manager));
372
		j++;
373
	    }
374
	}
375
	return (LocaleItem[]) items.toArray(new LocaleItem[items.size()]);
376
    }
377

  
378
    /**
379
     * Returns a name for the jar file to export a locale.
380
     */
381
    private String getLocaleJarFileName(Locale locale) {
382
	return manager.getDisplayName(locale, I18nManager.ENGLISH).replace(' ',
383
		'_').concat(EXPORT_ZIP_FILE_EXTENSION);
384
    }
385

  
386
    /**
387
     * Creates a new JFileChooser to import or export a locale jar file.
388
     */
389
    private JFileChooser getJarFileChooser() {
390
	if (fileChooser == null) {
391
	    fileChooser = new JFileChooser();
392
	    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
393
	    fileChooser.setMultiSelectionEnabled(false);
394
	    fileChooser.setFileFilter(new FileFilter() {
395

  
396
		public boolean accept(File file) {
397
		    return (file.isDirectory()
398
			    || file.getName().endsWith(
399
				    EXPORT_JAR_FILE_EXTENSION) || file
400
			    .getName().endsWith(EXPORT_ZIP_FILE_EXTENSION));
401
		}
402

  
403
		public String getDescription() {
404
		    return Messages.getText("I18nPreferencePage.archivos_jar");
405
		}
406

  
407
	    });
408
	}
409
	return fileChooser;
410
    }
411

  
412
    /**
413
     * Removes some installed locales from gvSIG.
414
     */
415
    private void uninstallSelectedLocale() {
416
	Locale[] locales = getSelectedLocales();
417

  
418
	if (locales == null) {
419
	    JOptionPane
420
		    .showMessageDialog(
421
			    this,
422
			    Messages
423
				    .getText("I18nPreferencePage.seleccione_idioma_desinstalar"),
424
			    Messages
425
				    .getText("I18nPreferencePage.error_desinstalar_idioma"),
426
			    JOptionPane.ERROR_MESSAGE);
427
	    return;
428
	}
429
	
430
	for (int i = 0; i < locales.length; i++) {
431

  
432
	    if (locales[i].equals(manager.getCurrentLocale())) {
433
		JOptionPane
434
			.showMessageDialog(
435
				this,
436
				Messages
437
					.getText("I18nPreferencePage.idioma_actual_no_puede_desinstalar"),
438
				Messages
439
					.getText("I18nPreferencePage.error_desinstalar_idioma"),
440
				JOptionPane.ERROR_MESSAGE);
441
	    } else {
442
		int option = JOptionPane
443
			.showConfirmDialog(
444
				this,
445
				Messages
446
					.getText("I18nPreferencePage.seguro_desea_desinstalar_idioma")
447
					+ " "
448
					+ manager.getDisplayName(locales[i])
449
					+ "?",
450
				Messages
451
					.getText("I18nPreferencePage.confirmar_desinstalar_idioma"),
452
				JOptionPane.YES_NO_OPTION);
453
		if (option == JOptionPane.YES_OPTION) {
454
		    try {
455
			tableModel.removeLocale(locales[i]);
456
		    } catch (I18nException ex) {
457
			ex.showError();
458
		    }
459
		}
460
	    }
461
	}
462
    }
463

  
464
    /**
465
     * Returns the Locales selected in the table of available locales.
466
     */
467
    private Locale[] getSelectedLocales() {
468
	int[] rowIndexes = localesTable.getSelectedRows();
469
	if (rowIndexes != null && rowIndexes.length > 0) {
470
	    Locale[] locales = new Locale[rowIndexes.length];
471
	    for (int i = 0; i < locales.length; i++) {
472
		locales[i] = tableModel.getLocale(rowIndexes[i]);
473
	    }
474
	    return locales;
475
	}
476
	else {
477
	    return null;
478
	}
479
    }
480

  
481
    /**
482
     * Creates the Panel with the table of Locales.
483
     */
484
    private Component getLocalesPanel() {
485
	tableModel = new LocaleTableModel(manager);
486
	localesTable = new JTable(tableModel);
487

  
488
	TableColumn activeColumn = localesTable.getColumnModel().getColumn(
489
		LocaleTableModel.COLUMN_ACTIVE);
490
	activeColumn.setCellEditor(new RadioButtonCellEditor());
491
	activeColumn.setCellRenderer(new RadioButtonCellRenderer());
492

  
493
	localesTable
494
		.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
495
	localesTable.getSelectionModel().setSelectionInterval(0, 0);
496
	JScrollPane scrollPane = new JScrollPane(localesTable);
497

  
498
	// Container panel
499
	JPanel localesPanel = new JPanel();
500
	localesPanel.setLayout(new BoxLayout(localesPanel, BoxLayout.Y_AXIS));
501
	localesPanel.add(scrollPane);
502
	localesPanel.setAlignmentX(CENTER_ALIGNMENT);
503
	localesPanel.setPreferredSize(new Dimension(236, 230));
504
	localesPanel.setMaximumSize(new Dimension(500, 230));
505

  
506
	return localesPanel;
507
    }
508

  
509
    /**
510
     * Creates the panel with the buttons to perform the related actions.
511
     */
512
    private Component getButtonsPanel() {
513
	JPanel buttonPanel = new JPanel(new GridBagLayout());
514
	GridBagConstraints constraints = new GridBagConstraints();
515
	constraints.fill = GridBagConstraints.NONE;
516
	constraints.anchor = GridBagConstraints.LINE_START;
517
	Insets btInsets = new Insets(2, 0, 2, 4);
518
	Insets lbInsets = new Insets(2, 2, 2, 0);
519

  
520
	/* ROW 0 */
521
	constraints.gridy = 0;
522

  
523
	constraints.gridx = 0;
524
	constraints.insets = btInsets;
525
	JButton newLocaleButton = new JButton(Messages
526
		.getText("I18nPreferencePage.Instalar"));
527
	newLocaleButton.setActionCommand(COMMAND_INSTALL);
528
	newLocaleButton.addActionListener(this);
529
	newLocaleButton.setToolTipText(Messages
530
		.getText("I18nPreferencePage.Instalar_idioma_tooltip"));
531
	buttonPanel.add(newLocaleButton, constraints);
532

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

  
539
	/* ROW 1 */
540
	constraints.gridy = 1;
541

  
542
	constraints.gridx = 0;
543
	constraints.insets = btInsets;
544
	JButton removeLocaleButton = new JButton(Messages
545
		.getText("I18nPreferencePage.Desinstalar"));
546
	removeLocaleButton.setActionCommand(COMMAND_UNINSTALL);
547
	removeLocaleButton.addActionListener(this);
548
	removeLocaleButton.setToolTipText(Messages
549
		.getText("I18nPreferencePage.Desinstalar_idioma_tooltip"));
550
	buttonPanel.add(removeLocaleButton, constraints);
551

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

  
558
	/* ROW 2 */
559
	constraints.gridy = 2;
560

  
561
	constraints.gridx = 0;
562
	constraints.insets = btInsets;
563
	JButton exportLocaleButton = new JButton(Messages
564
		.getText("I18nPreferencePage.exportar_actualizar"));
565
	exportLocaleButton.setActionCommand(COMMAND_EXPORT);
566
	exportLocaleButton.addActionListener(this);
567
	exportLocaleButton.setToolTipText(Messages
568
		.getText("I18nPreferencePage.exportar_actualizar_tooltip"));
569
	buttonPanel.add(exportLocaleButton, constraints);
570

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

  
577
	/* ROW 3 */
578
	constraints.gridy = 3;
579

  
580
	constraints.gridx = 0;
581
	constraints.insets = btInsets;
582
	JButton exportNewLocaleButton = new JButton(Messages
583
		.getText("I18nPreferencePage.exportar_traducir"));
584
	exportNewLocaleButton.setActionCommand(COMMAND_EXPORT_NEW);
585
	exportNewLocaleButton.addActionListener(this);
586
	exportNewLocaleButton.setToolTipText(Messages
587
		.getText("I18nPreferencePage.exportar_traducir_tooltip"));
588
	buttonPanel.add(exportNewLocaleButton, constraints);
589

  
590
	constraints.gridx = 1;
591
	constraints.insets = lbInsets;
592
	buttonPanel.add(new JLabel(Messages
593
		.getText("I18nPreferencePage.exportar_traducir_tooltip")),
594
		constraints);
595

  
596
	buttonPanel.setAlignmentX(CENTER_ALIGNMENT);
597
	return buttonPanel;
598
    }
599

  
600
    /**
601
     * Creates the JLabel to show information about the preference page.
602
     */
603
    private Component getActiveLocaleLabel() {
604
	JTextArea textArea = new JTextArea(Messages
605
		.getText("I18nPreferencePage.ayuda"));
606
	textArea.setEditable(false);
607
	textArea.setAutoscrolls(true);
608
	textArea.setLineWrap(true);
609
	textArea.setWrapStyleWord(true);
610
	textArea.setFont(textArea.getFont().deriveFont(Font.BOLD));
611
	return textArea;
612
    }
613

  
614
    /**
615
     * Creates the JLabel to show information about gvSIG translation
616
     * collaboration.
617
     */
618
    private Component getCollaborationLabel() {
619
	JTextArea textArea = new JTextArea(Messages
620
		.getText("I18nPreferencePage.colaboracion"));
621
	textArea.setEditable(false);
622
	textArea.setAutoscrolls(true);
623
	textArea.setLineWrap(true);
624
	textArea.setWrapStyleWord(true);
625
	return textArea;
626
    }
627

  
628
    private class LocaleItem {
629
	private final Locale locale;
630
	private final I18nManager manager;
631

  
632
	public LocaleItem(Locale locale, I18nManager manager) {
633
	    this.locale = locale;
634
	    this.manager = manager;
635
	}
636

  
637
	public Locale getLocale() {
638
	    return locale;
639
	}
640

  
641
	public String toString() {
642
	    return manager.getDisplayName(locale);
643
	}
644

  
645
	public boolean equals(Object obj) {
646
	    if (obj == null || !(obj instanceof LocaleItem)) {
647
		return false;
648
	    }
649

  
650
	    LocaleItem item = (LocaleItem) obj;
651
	    return locale.equals(item.getLocale());
652
	}
653
    }
654
}
tags/v2_0_0_Build_2020/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 Government (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.andami.PluginServices;
32
import org.gvsig.andami.plugins.Extension;
33
import org.gvsig.app.extension.About;
34
import org.gvsig.app.gui.panels.FPanelAbout;
35
import org.gvsig.i18n.extension.preferences.I18nPreferencePage;
36
import org.gvsig.tools.ToolsLocator;
37

  
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
}
tags/v2_0_0_Build_2020/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 Government (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 org.gvsig.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
     */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff