21 |
21 |
* For any additional information, do not hesitate to contact us
|
22 |
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
23 |
*/
|
24 |
|
/*
|
25 |
|
* AUTHORS (In addition to CIT):
|
26 |
|
* 2008 {DiSiD Technologies} {New extension for installation and update of text translations}
|
27 |
|
*/
|
|
24 |
|
28 |
25 |
package org.gvsig.i18n.extension.preferences;
|
29 |
26 |
|
30 |
27 |
import java.awt.Color;
|
... | ... | |
33 |
30 |
import java.awt.Font;
|
34 |
31 |
import java.awt.GridBagConstraints;
|
35 |
32 |
import java.awt.GridBagLayout;
|
36 |
|
import java.awt.Insets;
|
37 |
|
import java.awt.event.ActionEvent;
|
38 |
|
import java.awt.event.ActionListener;
|
39 |
|
import java.io.File;
|
40 |
|
import java.util.ArrayList;
|
41 |
|
import java.util.HashSet;
|
42 |
|
import java.util.List;
|
43 |
|
import java.util.Locale;
|
44 |
|
import java.util.Set;
|
45 |
33 |
|
46 |
34 |
import javax.swing.Box;
|
47 |
35 |
import javax.swing.BoxLayout;
|
48 |
36 |
import javax.swing.ImageIcon;
|
49 |
|
import javax.swing.JFileChooser;
|
50 |
37 |
import javax.swing.JLabel;
|
51 |
|
import javax.swing.JOptionPane;
|
52 |
38 |
import javax.swing.JPanel;
|
53 |
39 |
import javax.swing.JScrollPane;
|
54 |
40 |
import javax.swing.JTable;
|
55 |
41 |
import javax.swing.JTextArea;
|
56 |
42 |
import javax.swing.ListSelectionModel;
|
57 |
|
import javax.swing.filechooser.FileFilter;
|
58 |
43 |
import javax.swing.table.TableColumn;
|
59 |
44 |
|
60 |
45 |
import org.gvsig.andami.PluginServices;
|
61 |
46 |
import org.gvsig.andami.preferences.AbstractPreferencePage;
|
62 |
47 |
import org.gvsig.andami.preferences.StoreException;
|
63 |
|
import org.gvsig.gui.beans.swing.JButton;
|
64 |
|
import org.gvsig.i18n.I18nException;
|
65 |
|
import org.gvsig.i18n.I18nManager;
|
66 |
48 |
import org.gvsig.i18n.Messages;
|
67 |
49 |
import org.gvsig.i18n.extension.preferences.table.LocaleTableModel;
|
68 |
50 |
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellEditor;
|
69 |
51 |
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellRenderer;
|
70 |
52 |
import org.gvsig.i18n.impl.I18nManagerImpl;
|
|
53 |
import org.gvsig.tools.ToolsLocator;
|
71 |
54 |
|
72 |
55 |
/**
|
73 |
56 |
* Prefence page to manage gvSIG locales.
|
74 |
57 |
*
|
75 |
58 |
* @author <a href="mailto:dcervera@disid.com">David Cervera</a>
|
76 |
59 |
*/
|
77 |
|
public class I18nPreferencePage extends AbstractPreferencePage implements
|
78 |
|
ActionListener {
|
|
60 |
public class I18nPreferencePage extends AbstractPreferencePage {
|
79 |
61 |
|
80 |
62 |
private static final long serialVersionUID = 7164183052397200888L;
|
81 |
63 |
|
82 |
|
private static final String COMMAND_UNINSTALL = "UNINSTALL";
|
|
64 |
private final ImageIcon icon;
|
83 |
65 |
|
84 |
|
private static final String COMMAND_EXPORT = "EXPORT";
|
85 |
|
|
86 |
|
private static final String COMMAND_EXPORT_NEW = "EXPORT_NEW";
|
87 |
|
|
88 |
|
private static final String COMMAND_INSTALL = "INSTALL";
|
89 |
|
|
90 |
|
private static final String EXPORT_JAR_FILE_EXTENSION = ".jar";
|
91 |
|
|
92 |
|
private static final String EXPORT_ZIP_FILE_EXTENSION = ".zip";
|
93 |
|
|
94 |
|
private ImageIcon icon;
|
95 |
|
|
96 |
|
private I18nManager manager = I18nManagerImpl.getInstance();
|
97 |
|
|
98 |
66 |
private JTable localesTable;
|
99 |
67 |
|
100 |
68 |
private LocaleTableModel tableModel;
|
101 |
69 |
|
102 |
|
private JFileChooser fileChooser;
|
103 |
|
|
|
70 |
private JTextArea txtWarning = null;
|
|
71 |
private JTextArea txtCollaboration = null;
|
|
72 |
|
104 |
73 |
/**
|
105 |
74 |
* Creates a new I18n preferences page.
|
106 |
75 |
*/
|
... | ... | |
109 |
78 |
|
110 |
79 |
icon = PluginServices.getIconTheme().get("i18n-preferences");
|
111 |
80 |
|
112 |
|
// GridBagConstants.HORIZONTAL
|
113 |
|
Insets zero_ins = new Insets(0, 0, 0, 0);
|
|
81 |
this.initComponents();
|
|
82 |
}
|
|
83 |
|
|
84 |
private void initComponents() {
|
|
85 |
GridBagConstraints gridBagConstraints;
|
|
86 |
|
114 |
87 |
Font hints_fnt = new JLabel().getFont();
|
|
88 |
|
|
89 |
Component tablePanel = getLocalesPanel();
|
|
90 |
txtWarning = getActiveLocaleLabel(this.getBackground(), hints_fnt.deriveFont(Font.BOLD));
|
|
91 |
txtCollaboration = getCollaborationLabel(this.getBackground(), hints_fnt);
|
|
92 |
|
|
93 |
Box.Filler fillerBorder1 = new Box.Filler(new Dimension(16, 16), new Dimension(16, 16), new Dimension(16, 16));
|
|
94 |
Box.Filler fillerBorder2 = new Box.Filler(new Dimension(16, 16), new Dimension(16, 16), new Dimension(16, 16));
|
|
95 |
Box.Filler fillerBottom = new Box.Filler(new Dimension(0, 0), new Dimension(0, 0), new Dimension(32767, 32767));
|
115 |
96 |
|
116 |
|
addComponent(getLocalesPanel(),
|
117 |
|
GridBagConstraints.HORIZONTAL, zero_ins);
|
|
97 |
GridBagLayout layout = new GridBagLayout();
|
|
98 |
layout.columnWidths = new int[] {0, 4, 0, 4, 0};
|
|
99 |
layout.rowHeights = new int[] {0, 4, 0, 4, 0, 4, 0, 4, 0};
|
|
100 |
setLayout(layout);
|
118 |
101 |
|
119 |
|
addComponent(Box.createRigidArea(new Dimension(0, 5)),
|
120 |
|
GridBagConstraints.HORIZONTAL, zero_ins);
|
|
102 |
gridBagConstraints = new GridBagConstraints();
|
|
103 |
gridBagConstraints.gridx = 2;
|
|
104 |
gridBagConstraints.gridy = 6;
|
|
105 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
|
106 |
gridBagConstraints.anchor = GridBagConstraints.LINE_START;
|
|
107 |
add(txtWarning, gridBagConstraints);
|
121 |
108 |
|
122 |
|
addComponent(getActiveLocaleLabel(
|
123 |
|
this.getBackground(), hints_fnt.deriveFont(Font.BOLD)),
|
124 |
|
GridBagConstraints.HORIZONTAL, zero_ins);
|
|
109 |
gridBagConstraints = new GridBagConstraints();
|
|
110 |
gridBagConstraints.gridx = 2;
|
|
111 |
gridBagConstraints.gridy = 4;
|
|
112 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
|
113 |
gridBagConstraints.anchor = GridBagConstraints.LINE_START;
|
|
114 |
add(txtCollaboration, gridBagConstraints);
|
125 |
115 |
|
126 |
|
addComponent(Box.createRigidArea(new Dimension(0, 5)),
|
127 |
|
GridBagConstraints.HORIZONTAL, zero_ins);
|
128 |
|
|
129 |
|
addComponent(getButtonsPanel(),
|
130 |
|
GridBagConstraints.HORIZONTAL, zero_ins);
|
131 |
|
|
132 |
|
addComponent(Box.createRigidArea(new Dimension(0, 5)),
|
133 |
|
GridBagConstraints.HORIZONTAL, zero_ins);
|
134 |
|
|
135 |
|
addComponent(getCollaborationLabel(
|
136 |
|
this.getBackground(), hints_fnt),
|
137 |
|
GridBagConstraints.HORIZONTAL, zero_ins);
|
138 |
|
|
139 |
|
/*
|
140 |
|
add(getLocalesPanel());
|
141 |
|
add(Box.createRigidArea(new Dimension(0, 5)));
|
142 |
|
add(getActiveLocaleLabel());
|
143 |
|
add(Box.createRigidArea(new Dimension(0, 5)));
|
144 |
|
add(getButtonsPanel());
|
145 |
|
add(Box.createRigidArea(new Dimension(0, 5)));
|
146 |
|
add(getCollaborationLabel());
|
147 |
|
*/
|
|
116 |
gridBagConstraints = new GridBagConstraints();
|
|
117 |
gridBagConstraints.gridx = 2;
|
|
118 |
gridBagConstraints.gridy = 2;
|
|
119 |
gridBagConstraints.fill = GridBagConstraints.BOTH;
|
|
120 |
gridBagConstraints.weightx = 0.1;
|
|
121 |
gridBagConstraints.weighty = 0.3;
|
|
122 |
add(tablePanel, gridBagConstraints);
|
|
123 |
|
|
124 |
gridBagConstraints = new GridBagConstraints();
|
|
125 |
gridBagConstraints.gridx = 0;
|
|
126 |
gridBagConstraints.gridy = 0;
|
|
127 |
add(fillerBorder1, gridBagConstraints);
|
|
128 |
|
|
129 |
gridBagConstraints = new GridBagConstraints();
|
|
130 |
gridBagConstraints.gridx = 4;
|
|
131 |
gridBagConstraints.gridy = 0;
|
|
132 |
add(fillerBorder2, gridBagConstraints);
|
|
133 |
|
|
134 |
gridBagConstraints = new GridBagConstraints();
|
|
135 |
gridBagConstraints.gridx = 0;
|
|
136 |
gridBagConstraints.gridy = 8;
|
|
137 |
gridBagConstraints.fill = GridBagConstraints.VERTICAL;
|
|
138 |
gridBagConstraints.weighty = 0.1;
|
|
139 |
add(fillerBottom, gridBagConstraints);
|
|
140 |
|
|
141 |
this.translate();
|
148 |
142 |
}
|
149 |
143 |
|
|
144 |
private void translate() {
|
|
145 |
org.gvsig.tools.i18n.I18nManager i18nManager = ToolsLocator.getI18nManager();
|
|
146 |
txtCollaboration.setText(
|
|
147 |
i18nManager.getTranslation(
|
|
148 |
"I18nPreferencePage.colaboraciones",
|
|
149 |
new String[] { "translations@gvsig.org" }
|
|
150 |
)
|
|
151 |
);
|
|
152 |
txtWarning.setText(i18nManager.getTranslation("I18nPreferencePage.ayuda"));
|
|
153 |
}
|
|
154 |
|
|
155 |
@Override
|
|
156 |
public boolean isResizeable() {
|
|
157 |
return true;
|
|
158 |
}
|
|
159 |
|
150 |
160 |
public String getID() {
|
151 |
161 |
return getClass().getName();
|
152 |
162 |
}
|
... | ... | |
193 |
203 |
|
194 |
204 |
public void initializeValues() {
|
195 |
205 |
if ( tableModel == null ) {
|
196 |
|
tableModel = new LocaleTableModel(manager);
|
|
206 |
tableModel = new LocaleTableModel(I18nManagerImpl.getInstance());
|
197 |
207 |
localesTable.setModel(tableModel);
|
198 |
208 |
|
199 |
209 |
TableColumn activeColumn = localesTable.getColumnModel().getColumn(
|
... | ... | |
206 |
216 |
localesTable.getSelectionModel().setSelectionInterval(0, 0);
|
207 |
217 |
}
|
208 |
218 |
tableModel.selectPreviousLocale();
|
|
219 |
|
|
220 |
this.translate();
|
209 |
221 |
}
|
210 |
222 |
|
211 |
|
public void actionPerformed(ActionEvent event) {
|
212 |
|
if ( COMMAND_INSTALL.equals(event.getActionCommand()) ) {
|
213 |
|
installLocale();
|
214 |
|
} else if ( COMMAND_EXPORT.equals(event.getActionCommand()) ) {
|
215 |
|
exportLocaleForUpdate();
|
216 |
|
} else if ( COMMAND_EXPORT_NEW.equals(event.getActionCommand()) ) {
|
217 |
|
exportLocaleForTranslation();
|
218 |
|
} else if ( COMMAND_UNINSTALL.equals(event.getActionCommand()) ) {
|
219 |
|
uninstallSelectedLocale();
|
220 |
|
}
|
221 |
|
}
|
222 |
|
|
223 |
223 |
/**
|
224 |
|
* Installs a new Locale translation or updates an already existing one.
|
225 |
|
*/
|
226 |
|
private void installLocale() {
|
227 |
|
if ( tableModel == null ) {
|
228 |
|
return;
|
229 |
|
}
|
230 |
|
JFileChooser fileChooser = getJarFileChooser();
|
231 |
|
|
232 |
|
int returnVal = fileChooser.showOpenDialog(this);
|
233 |
|
|
234 |
|
if ( returnVal == JFileChooser.APPROVE_OPTION ) {
|
235 |
|
File importFile = fileChooser.getSelectedFile();
|
236 |
|
try {
|
237 |
|
Locale[] installedLocales = manager.installLocales(importFile);
|
238 |
|
if ( installedLocales == null || installedLocales.length == 0 ) {
|
239 |
|
JOptionPane
|
240 |
|
.showMessageDialog(
|
241 |
|
this,
|
242 |
|
Messages
|
243 |
|
.getText("I18nPreferencePage.idiomas_no_encontrados_para_instalar"),
|
244 |
|
Messages
|
245 |
|
.getText("I18nPreferencePage.error_instalar_idiomas"),
|
246 |
|
JOptionPane.ERROR_MESSAGE);
|
247 |
|
} else {
|
248 |
|
StringBuffer msg = new StringBuffer(Messages
|
249 |
|
.getText("I18nPreferencePage.idiomas_instalados"));
|
250 |
|
|
251 |
|
for ( int i = 0; i < installedLocales.length; i++ ) {
|
252 |
|
msg.append(manager.getDisplayName(installedLocales[i]));
|
253 |
|
if ( i < installedLocales.length - 1 ) {
|
254 |
|
msg.append(", ");
|
255 |
|
}
|
256 |
|
}
|
257 |
|
tableModel.reloadLocales();
|
258 |
|
JOptionPane
|
259 |
|
.showMessageDialog(
|
260 |
|
this,
|
261 |
|
msg.toString(),
|
262 |
|
Messages
|
263 |
|
.getText("I18nPreferencePage.instalar_idiomas"),
|
264 |
|
JOptionPane.INFORMATION_MESSAGE);
|
265 |
|
}
|
266 |
|
} catch (I18nException ex) {
|
267 |
|
ex.showError();
|
268 |
|
}
|
269 |
|
}
|
270 |
|
}
|
271 |
|
|
272 |
|
/**
|
273 |
|
* Updates the translation of a locale
|
274 |
|
*/
|
275 |
|
private void exportLocaleForUpdate() {
|
276 |
|
Locale[] locales = getSelectedLocales();
|
277 |
|
|
278 |
|
if ( locales == null ) {
|
279 |
|
JOptionPane.showMessageDialog(this, Messages
|
280 |
|
.getText("I18nPreferencePage.seleccione_idioma"), Messages
|
281 |
|
.getText("I18nPreferencePage.error_actualizar_idioma"),
|
282 |
|
JOptionPane.ERROR_MESSAGE);
|
283 |
|
} else {
|
284 |
|
// Select the reference language
|
285 |
|
LocaleItem[] items = getLocaleItemsForSelection(manager
|
286 |
|
.getInstalledLocales(), locales);
|
287 |
|
LocaleItem selected = null;
|
288 |
|
if ( items != null && items.length > 0 ) {
|
289 |
|
// Select by default the current locale, or the first one
|
290 |
|
// if the current locale is one of the ones to be updated
|
291 |
|
for ( int i = 0; i < locales.length && selected == null; i++ ) {
|
292 |
|
if ( locales[i].equals(manager.getCurrentLocale()) ) {
|
293 |
|
selected = items[0];
|
294 |
|
}
|
295 |
|
}
|
296 |
|
if ( selected == null ) {
|
297 |
|
selected = new LocaleItem(manager.getCurrentLocale(),
|
298 |
|
manager);
|
299 |
|
}
|
300 |
|
selected = (LocaleItem) JOptionPane
|
301 |
|
.showInputDialog(
|
302 |
|
this,
|
303 |
|
Messages
|
304 |
|
.getText("I18nPreferencePage.seleccione_idioma_referencia"),
|
305 |
|
Messages
|
306 |
|
.getText("I18nPreferencePage.exportar_idioma"),
|
307 |
|
JOptionPane.QUESTION_MESSAGE, null, items,
|
308 |
|
selected);
|
309 |
|
|
310 |
|
if ( selected == null ) {
|
311 |
|
return;
|
312 |
|
}
|
313 |
|
}
|
314 |
|
// Select the file to export to
|
315 |
|
JFileChooser fileChooser = getJarFileChooser();
|
316 |
|
fileChooser.setSelectedFile(new File(
|
317 |
|
getLocaleJarFileName(locales[0])));
|
318 |
|
|
319 |
|
if ( fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION ) {
|
320 |
|
File saveFile = fileChooser.getSelectedFile();
|
321 |
|
try {
|
322 |
|
Locale fileNameLocale = selected == null ? manager
|
323 |
|
.getCurrentLocale() : selected.getLocale();
|
324 |
|
manager.exportLocalesForUpdate(locales, fileNameLocale,
|
325 |
|
saveFile);
|
326 |
|
|
327 |
|
JOptionPane
|
328 |
|
.showMessageDialog(
|
329 |
|
this,
|
330 |
|
Messages
|
331 |
|
.getText("I18nPreferencePage.exportado_textos_idioma")
|
332 |
|
+ " "
|
333 |
|
+ saveFile,
|
334 |
|
Messages
|
335 |
|
.getText("I18nPreferencePage.exportar_idioma"),
|
336 |
|
JOptionPane.INFORMATION_MESSAGE);
|
337 |
|
} catch (I18nException ex) {
|
338 |
|
ex.showError();
|
339 |
|
}
|
340 |
|
}
|
341 |
|
}
|
342 |
|
}
|
343 |
|
|
344 |
|
/**
|
345 |
|
* Prepares a locale for translation.
|
346 |
|
*/
|
347 |
|
private void exportLocaleForTranslation() {
|
348 |
|
// Get the selected locale as the ones for reference
|
349 |
|
Locale[] refLocales = getSelectedLocales();
|
350 |
|
|
351 |
|
if ( refLocales == null ) {
|
352 |
|
JOptionPane
|
353 |
|
.showMessageDialog(
|
354 |
|
this,
|
355 |
|
Messages
|
356 |
|
.getText("I18nPreferencePage.seleccione_idioma_actualizar"),
|
357 |
|
Messages
|
358 |
|
.getText("I18nPreferencePage.error_actualizar_idioma"),
|
359 |
|
JOptionPane.ERROR_MESSAGE);
|
360 |
|
} else {
|
361 |
|
|
362 |
|
// Select the locale to translate
|
363 |
|
LocaleItem[] items = getLocaleItemsForSelection(Locale
|
364 |
|
.getAvailableLocales(), manager.getInstalledLocales());
|
365 |
|
LocaleItem selected = (LocaleItem) JOptionPane
|
366 |
|
.showInputDialog(
|
367 |
|
this,
|
368 |
|
Messages
|
369 |
|
.getText("I18nPreferencePage.seleccione_idioma_traducir"),
|
370 |
|
Messages
|
371 |
|
.getText("I18nPreferencePage.exportar_idioma"),
|
372 |
|
JOptionPane.QUESTION_MESSAGE, null, items, items[0]);
|
373 |
|
|
374 |
|
if ( selected == null ) {
|
375 |
|
return;
|
376 |
|
}
|
377 |
|
|
378 |
|
// Select the file to export to
|
379 |
|
JFileChooser fileChooser = getJarFileChooser();
|
380 |
|
fileChooser.setSelectedFile(new File(getLocaleJarFileName(selected
|
381 |
|
.getLocale())));
|
382 |
|
|
383 |
|
if ( fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION ) {
|
384 |
|
File saveFile = fileChooser.getSelectedFile();
|
385 |
|
try {
|
386 |
|
manager.exportLocaleForTranslation(selected.getLocale(),
|
387 |
|
refLocales, saveFile);
|
388 |
|
|
389 |
|
JOptionPane
|
390 |
|
.showMessageDialog(
|
391 |
|
this,
|
392 |
|
Messages
|
393 |
|
.getText("I18nPreferencePage.idioma_preparado_traducir")
|
394 |
|
+ manager.getDisplayName(selected
|
395 |
|
.getLocale())
|
396 |
|
+ Messages
|
397 |
|
.getText("I18nPreferencePage.en_archivo")
|
398 |
|
+ saveFile,
|
399 |
|
Messages
|
400 |
|
.getText("I18nPreferencePage.exportar_idioma"),
|
401 |
|
JOptionPane.INFORMATION_MESSAGE);
|
402 |
|
} catch (I18nException ex) {
|
403 |
|
ex.showError();
|
404 |
|
}
|
405 |
|
}
|
406 |
|
}
|
407 |
|
|
408 |
|
}
|
409 |
|
|
410 |
|
private LocaleItem[] getLocaleItemsForSelection(Locale[] locales,
|
411 |
|
Locale[] exceptions) {
|
412 |
|
List items = new ArrayList();
|
413 |
|
Set exceptionsSet = new HashSet(exceptions.length);
|
414 |
|
for ( int i = 0; i < exceptions.length; i++ ) {
|
415 |
|
exceptionsSet.add(exceptions[i]);
|
416 |
|
}
|
417 |
|
|
418 |
|
int j = 0;
|
419 |
|
for ( int i = 0; i < locales.length; i++ ) {
|
420 |
|
// Only add locales not included in the exceptions list
|
421 |
|
if ( !exceptionsSet.contains(locales[i]) ) {
|
422 |
|
items.add(new LocaleItem(locales[i], manager));
|
423 |
|
j++;
|
424 |
|
}
|
425 |
|
}
|
426 |
|
return (LocaleItem[]) items.toArray(new LocaleItem[items.size()]);
|
427 |
|
}
|
428 |
|
|
429 |
|
/**
|
430 |
|
* Returns a name for the jar file to export a locale.
|
431 |
|
*/
|
432 |
|
private String getLocaleJarFileName(Locale locale) {
|
433 |
|
return manager.getDisplayName(locale, I18nManager.ENGLISH).replace(' ',
|
434 |
|
'_').concat(EXPORT_ZIP_FILE_EXTENSION);
|
435 |
|
}
|
436 |
|
|
437 |
|
/**
|
438 |
|
* Creates a new JFileChooser to import or export a locale jar file.
|
439 |
|
*/
|
440 |
|
private JFileChooser getJarFileChooser() {
|
441 |
|
if ( fileChooser == null ) {
|
442 |
|
fileChooser = new JFileChooser();
|
443 |
|
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
444 |
|
fileChooser.setMultiSelectionEnabled(false);
|
445 |
|
fileChooser.setFileFilter(new FileFilter() {
|
446 |
|
|
447 |
|
public boolean accept(File file) {
|
448 |
|
return (file.isDirectory()
|
449 |
|
|| file.getName().endsWith(
|
450 |
|
EXPORT_JAR_FILE_EXTENSION) || file
|
451 |
|
.getName().endsWith(EXPORT_ZIP_FILE_EXTENSION));
|
452 |
|
}
|
453 |
|
|
454 |
|
public String getDescription() {
|
455 |
|
return Messages.getText("I18nPreferencePage.archivos_jar");
|
456 |
|
}
|
457 |
|
|
458 |
|
});
|
459 |
|
}
|
460 |
|
return fileChooser;
|
461 |
|
}
|
462 |
|
|
463 |
|
/**
|
464 |
|
* Removes some installed locales from gvSIG.
|
465 |
|
*/
|
466 |
|
private void uninstallSelectedLocale() {
|
467 |
|
if ( tableModel == null ) {
|
468 |
|
return;
|
469 |
|
}
|
470 |
|
Locale[] locales = getSelectedLocales();
|
471 |
|
|
472 |
|
if ( locales == null ) {
|
473 |
|
JOptionPane
|
474 |
|
.showMessageDialog(
|
475 |
|
this,
|
476 |
|
Messages
|
477 |
|
.getText("I18nPreferencePage.seleccione_idioma_desinstalar"),
|
478 |
|
Messages
|
479 |
|
.getText("I18nPreferencePage.error_desinstalar_idioma"),
|
480 |
|
JOptionPane.ERROR_MESSAGE);
|
481 |
|
return;
|
482 |
|
}
|
483 |
|
|
484 |
|
for ( int i = 0; i < locales.length; i++ ) {
|
485 |
|
|
486 |
|
if ( locales[i].equals(manager.getCurrentLocale()) ) {
|
487 |
|
JOptionPane
|
488 |
|
.showMessageDialog(
|
489 |
|
this,
|
490 |
|
Messages
|
491 |
|
.getText("I18nPreferencePage.idioma_actual_no_puede_desinstalar"),
|
492 |
|
Messages
|
493 |
|
.getText("I18nPreferencePage.error_desinstalar_idioma"),
|
494 |
|
JOptionPane.ERROR_MESSAGE);
|
495 |
|
} else {
|
496 |
|
int option = JOptionPane
|
497 |
|
.showConfirmDialog(
|
498 |
|
this,
|
499 |
|
Messages
|
500 |
|
.getText("I18nPreferencePage.seguro_desea_desinstalar_idioma")
|
501 |
|
+ " "
|
502 |
|
+ manager.getDisplayName(locales[i])
|
503 |
|
+ "?",
|
504 |
|
Messages
|
505 |
|
.getText("I18nPreferencePage.confirmar_desinstalar_idioma"),
|
506 |
|
JOptionPane.YES_NO_OPTION);
|
507 |
|
if ( option == JOptionPane.YES_OPTION ) {
|
508 |
|
try {
|
509 |
|
tableModel.removeLocale(locales[i]);
|
510 |
|
} catch (I18nException ex) {
|
511 |
|
ex.showError();
|
512 |
|
}
|
513 |
|
}
|
514 |
|
}
|
515 |
|
}
|
516 |
|
}
|
517 |
|
|
518 |
|
/**
|
519 |
|
* Returns the Locales selected in the table of available locales.
|
520 |
|
*/
|
521 |
|
private Locale[] getSelectedLocales() {
|
522 |
|
if ( tableModel == null ) {
|
523 |
|
return null;
|
524 |
|
}
|
525 |
|
int[] rowIndexes = localesTable.getSelectedRows();
|
526 |
|
if ( rowIndexes != null && rowIndexes.length > 0 ) {
|
527 |
|
Locale[] locales = new Locale[rowIndexes.length];
|
528 |
|
for ( int i = 0; i < locales.length; i++ ) {
|
529 |
|
locales[i] = tableModel.getLocale(rowIndexes[i]);
|
530 |
|
}
|
531 |
|
return locales;
|
532 |
|
} else {
|
533 |
|
return null;
|
534 |
|
}
|
535 |
|
}
|
536 |
|
|
537 |
|
/**
|
538 |
224 |
* Creates the Panel with the table of Locales.
|
539 |
225 |
*/
|
540 |
226 |
private Component getLocalesPanel() {
|
... | ... | |
554 |
240 |
|
555 |
241 |
return localesPanel;
|
556 |
242 |
}
|
557 |
|
|
|
243 |
|
558 |
244 |
/**
|
559 |
|
* Creates the panel with the buttons to perform the related actions.
|
560 |
|
*/
|
561 |
|
private Component getButtonsPanel() {
|
562 |
|
JPanel buttonPanel = new JPanel(new GridBagLayout());
|
563 |
|
GridBagConstraints constraints = new GridBagConstraints();
|
564 |
|
constraints.fill = GridBagConstraints.NONE;
|
565 |
|
constraints.anchor = GridBagConstraints.LINE_START;
|
566 |
|
Insets btInsets = new Insets(2, 0, 2, 4);
|
567 |
|
Insets lbInsets = new Insets(2, 2, 2, 0);
|
568 |
|
|
569 |
|
/* ROW 0 */
|
570 |
|
constraints.gridy = 0;
|
571 |
|
|
572 |
|
constraints.gridx = 0;
|
573 |
|
constraints.insets = btInsets;
|
574 |
|
JButton newLocaleButton = new JButton(Messages
|
575 |
|
.getText("I18nPreferencePage.Instalar"));
|
576 |
|
newLocaleButton.setActionCommand(COMMAND_INSTALL);
|
577 |
|
newLocaleButton.addActionListener(this);
|
578 |
|
newLocaleButton.setToolTipText(Messages
|
579 |
|
.getText("I18nPreferencePage.Instalar_idioma_tooltip"));
|
580 |
|
buttonPanel.add(newLocaleButton, constraints);
|
581 |
|
|
582 |
|
constraints.gridx = 1;
|
583 |
|
constraints.insets = lbInsets;
|
584 |
|
buttonPanel.add(new JLabel(Messages
|
585 |
|
.getText("I18nPreferencePage.Instalar_idioma_tooltip")),
|
586 |
|
constraints);
|
587 |
|
|
588 |
|
/* ROW 1 */
|
589 |
|
constraints.gridy = 1;
|
590 |
|
|
591 |
|
constraints.gridx = 0;
|
592 |
|
constraints.insets = btInsets;
|
593 |
|
JButton removeLocaleButton = new JButton(Messages
|
594 |
|
.getText("I18nPreferencePage.Desinstalar"));
|
595 |
|
removeLocaleButton.setActionCommand(COMMAND_UNINSTALL);
|
596 |
|
removeLocaleButton.addActionListener(this);
|
597 |
|
removeLocaleButton.setToolTipText(Messages
|
598 |
|
.getText("I18nPreferencePage.Desinstalar_idioma_tooltip"));
|
599 |
|
buttonPanel.add(removeLocaleButton, constraints);
|
600 |
|
|
601 |
|
constraints.gridx = 1;
|
602 |
|
constraints.insets = lbInsets;
|
603 |
|
buttonPanel.add(new JLabel(Messages
|
604 |
|
.getText("I18nPreferencePage.Desinstalar_idioma_tooltip")),
|
605 |
|
constraints);
|
606 |
|
|
607 |
|
/* ROW 2 */
|
608 |
|
constraints.gridy = 2;
|
609 |
|
|
610 |
|
constraints.gridx = 0;
|
611 |
|
constraints.insets = btInsets;
|
612 |
|
JButton exportLocaleButton = new JButton(Messages
|
613 |
|
.getText("I18nPreferencePage.exportar_actualizar"));
|
614 |
|
exportLocaleButton.setActionCommand(COMMAND_EXPORT);
|
615 |
|
exportLocaleButton.addActionListener(this);
|
616 |
|
exportLocaleButton.setToolTipText(Messages
|
617 |
|
.getText("I18nPreferencePage.exportar_actualizar_tooltip"));
|
618 |
|
buttonPanel.add(exportLocaleButton, constraints);
|
619 |
|
|
620 |
|
constraints.gridx = 1;
|
621 |
|
constraints.insets = lbInsets;
|
622 |
|
buttonPanel.add(new JLabel(Messages
|
623 |
|
.getText("I18nPreferencePage.exportar_actualizar_tooltip")),
|
624 |
|
constraints);
|
625 |
|
|
626 |
|
/* ROW 3 */
|
627 |
|
constraints.gridy = 3;
|
628 |
|
|
629 |
|
constraints.gridx = 0;
|
630 |
|
constraints.insets = btInsets;
|
631 |
|
JButton exportNewLocaleButton = new JButton(Messages
|
632 |
|
.getText("I18nPreferencePage.exportar_traducir"));
|
633 |
|
exportNewLocaleButton.setActionCommand(COMMAND_EXPORT_NEW);
|
634 |
|
exportNewLocaleButton.addActionListener(this);
|
635 |
|
exportNewLocaleButton.setToolTipText(Messages
|
636 |
|
.getText("I18nPreferencePage.exportar_traducir_tooltip"));
|
637 |
|
buttonPanel.add(exportNewLocaleButton, constraints);
|
638 |
|
|
639 |
|
constraints.gridx = 1;
|
640 |
|
constraints.insets = lbInsets;
|
641 |
|
buttonPanel.add(new JLabel(Messages
|
642 |
|
.getText("I18nPreferencePage.exportar_traducir_tooltip")),
|
643 |
|
constraints);
|
644 |
|
|
645 |
|
buttonPanel.setAlignmentX(CENTER_ALIGNMENT);
|
646 |
|
return buttonPanel;
|
647 |
|
}
|
648 |
|
|
649 |
|
/**
|
650 |
245 |
* Creates the JLabel to show information about the preference page.
|
651 |
246 |
*/
|
652 |
|
private Component getActiveLocaleLabel(Color bg, Font fnt) {
|
|
247 |
private JTextArea getActiveLocaleLabel(Color bg, Font fnt) {
|
653 |
248 |
JTextArea textArea = new JTextArea(Messages
|
654 |
249 |
.getText("I18nPreferencePage.ayuda"));
|
655 |
250 |
textArea.setEditable(false);
|
... | ... | |
665 |
260 |
* Creates the JLabel to show information about gvSIG translation
|
666 |
261 |
* collaboration.
|
667 |
262 |
*/
|
668 |
|
private Component getCollaborationLabel(Color bg, Font fnt) {
|
669 |
|
JTextArea textArea = new JTextArea(Messages
|
670 |
|
.getText("I18nPreferencePage.colaboracion"));
|
|
263 |
private JTextArea getCollaborationLabel(Color bg, Font fnt) {
|
|
264 |
org.gvsig.tools.i18n.I18nManager i18nManager = ToolsLocator.getI18nManager();
|
|
265 |
JTextArea textArea = new JTextArea(
|
|
266 |
i18nManager.getTranslation(
|
|
267 |
"I18nPreferencePage.colaboraciones",
|
|
268 |
new String[] { "translations@gvsig.org" }
|
|
269 |
)
|
|
270 |
);
|
671 |
271 |
textArea.setEditable(false);
|
672 |
272 |
textArea.setAutoscrolls(true);
|
673 |
273 |
textArea.setLineWrap(true);
|
... | ... | |
677 |
277 |
return textArea;
|
678 |
278 |
}
|
679 |
279 |
|
680 |
|
private class LocaleItem {
|
681 |
|
|
682 |
|
private final Locale locale;
|
683 |
|
private final I18nManager manager;
|
684 |
|
|
685 |
|
public LocaleItem(Locale locale, I18nManager manager) {
|
686 |
|
this.locale = locale;
|
687 |
|
this.manager = manager;
|
688 |
|
}
|
689 |
|
|
690 |
|
public Locale getLocale() {
|
691 |
|
return locale;
|
692 |
|
}
|
693 |
|
|
694 |
|
public String toString() {
|
695 |
|
return manager.getDisplayName(locale);
|
696 |
|
}
|
697 |
|
|
698 |
|
public boolean equals(Object obj) {
|
699 |
|
if ( obj == null || !(obj instanceof LocaleItem) ) {
|
700 |
|
return false;
|
701 |
|
}
|
702 |
|
|
703 |
|
LocaleItem item = (LocaleItem) obj;
|
704 |
|
return locale.equals(item.getLocale());
|
705 |
|
}
|
706 |
|
}
|
707 |
280 |
}
|