svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.i18n.app / org.gvsig.i18n.app.mainplugin / src / main / java / org / gvsig / i18n / extension / preferences / I18nPreferencePage.java @ 41730
History | View | Annotate | Download (9.31 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.i18n.extension.preferences; |
26 |
|
27 |
import java.awt.Color; |
28 |
import java.awt.Component; |
29 |
import java.awt.Dimension; |
30 |
import java.awt.Font; |
31 |
import java.awt.GridBagConstraints; |
32 |
import java.awt.GridBagLayout; |
33 |
|
34 |
import javax.swing.Box; |
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.ImageIcon; |
37 |
import javax.swing.JLabel; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JScrollPane; |
40 |
import javax.swing.JTable; |
41 |
import javax.swing.JTextArea; |
42 |
import javax.swing.ListSelectionModel; |
43 |
import javax.swing.table.TableColumn; |
44 |
|
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
47 |
import org.gvsig.andami.preferences.StoreException; |
48 |
import org.gvsig.i18n.Messages; |
49 |
import org.gvsig.i18n.extension.preferences.table.LocaleTableModel; |
50 |
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellEditor; |
51 |
import org.gvsig.i18n.extension.preferences.table.RadioButtonCellRenderer; |
52 |
import org.gvsig.i18n.impl.I18nManagerImpl; |
53 |
import org.gvsig.tools.ToolsLocator; |
54 |
|
55 |
/**
|
56 |
* Prefence page to manage gvSIG locales.
|
57 |
*
|
58 |
* @author <a href="mailto:dcervera@disid.com">David Cervera</a>
|
59 |
*/
|
60 |
public class I18nPreferencePage extends AbstractPreferencePage { |
61 |
|
62 |
private static final long serialVersionUID = 7164183052397200888L; |
63 |
|
64 |
private final ImageIcon icon; |
65 |
|
66 |
private JTable localesTable; |
67 |
|
68 |
private LocaleTableModel tableModel;
|
69 |
|
70 |
private JTextArea txtWarning = null; |
71 |
private JTextArea txtCollaboration = null; |
72 |
|
73 |
/**
|
74 |
* Creates a new I18n preferences page.
|
75 |
*/
|
76 |
public I18nPreferencePage() {
|
77 |
setParentID("org.gvsig.coreplugin.preferences.general.GeneralPage");
|
78 |
|
79 |
icon = PluginServices.getIconTheme().get("i18n-preferences");
|
80 |
|
81 |
this.initComponents();
|
82 |
} |
83 |
|
84 |
private void initComponents() { |
85 |
GridBagConstraints gridBagConstraints;
|
86 |
|
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)); |
96 |
|
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); |
101 |
|
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); |
108 |
|
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); |
115 |
|
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();
|
142 |
} |
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 |
|
160 |
public String getID() { |
161 |
return getClass().getName();
|
162 |
} |
163 |
|
164 |
public String getTitle() { |
165 |
return Messages.getText("idioma"); |
166 |
} |
167 |
|
168 |
public ImageIcon getIcon() { |
169 |
return icon;
|
170 |
} |
171 |
|
172 |
public JPanel getPanel() { |
173 |
return this; |
174 |
} |
175 |
|
176 |
public void setChangesApplied() { |
177 |
if ( tableModel == null ) { |
178 |
return;
|
179 |
} |
180 |
tableModel.setChangesApplied(); |
181 |
} |
182 |
|
183 |
public boolean isValueChanged() { |
184 |
if ( tableModel == null ) { |
185 |
return false; |
186 |
} |
187 |
return tableModel.isValueChanged();
|
188 |
} |
189 |
|
190 |
public void storeValues() throws StoreException { |
191 |
if ( tableModel == null ) { |
192 |
return;
|
193 |
} |
194 |
tableModel.saveSelectedLocale(); |
195 |
} |
196 |
|
197 |
public void initializeDefaults() { |
198 |
if ( tableModel == null ) { |
199 |
return;
|
200 |
} |
201 |
tableModel.selectDefaultLocale(); |
202 |
} |
203 |
|
204 |
public void initializeValues() { |
205 |
if ( tableModel == null ) { |
206 |
tableModel = new LocaleTableModel(I18nManagerImpl.getInstance());
|
207 |
localesTable.setModel(tableModel); |
208 |
|
209 |
TableColumn activeColumn = localesTable.getColumnModel().getColumn(
|
210 |
LocaleTableModel.COLUMN_ACTIVE); |
211 |
activeColumn.setCellEditor(new RadioButtonCellEditor());
|
212 |
activeColumn.setCellRenderer(new RadioButtonCellRenderer());
|
213 |
|
214 |
localesTable |
215 |
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
216 |
localesTable.getSelectionModel().setSelectionInterval(0, 0); |
217 |
} |
218 |
tableModel.selectPreviousLocale(); |
219 |
|
220 |
this.translate();
|
221 |
} |
222 |
|
223 |
/**
|
224 |
* Creates the Panel with the table of Locales.
|
225 |
*/
|
226 |
private Component getLocalesPanel() { |
227 |
localesTable = new JTable(); |
228 |
// Asignaremos el modelo a la tabla mas adelante para dar tiempo a que
|
229 |
// se haya inicializado todo o casi todo en gvSIG.
|
230 |
|
231 |
JScrollPane scrollPane = new JScrollPane(localesTable); |
232 |
|
233 |
// Container panel
|
234 |
JPanel localesPanel = new JPanel(); |
235 |
localesPanel.setLayout(new BoxLayout(localesPanel, BoxLayout.Y_AXIS)); |
236 |
localesPanel.add(scrollPane); |
237 |
localesPanel.setAlignmentX(CENTER_ALIGNMENT); |
238 |
localesPanel.setPreferredSize(new Dimension(236, 200)); |
239 |
localesPanel.setMaximumSize(new Dimension(500, 230)); |
240 |
|
241 |
return localesPanel;
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* Creates the JLabel to show information about the preference page.
|
246 |
*/
|
247 |
private JTextArea getActiveLocaleLabel(Color bg, Font fnt) { |
248 |
JTextArea textArea = new JTextArea(Messages |
249 |
.getText("I18nPreferencePage.ayuda"));
|
250 |
textArea.setEditable(false);
|
251 |
textArea.setAutoscrolls(true);
|
252 |
textArea.setLineWrap(true);
|
253 |
textArea.setWrapStyleWord(true);
|
254 |
textArea.setFont(fnt); |
255 |
textArea.setBackground(bg); |
256 |
return textArea;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* Creates the JLabel to show information about gvSIG translation
|
261 |
* collaboration.
|
262 |
*/
|
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 |
); |
271 |
textArea.setEditable(false);
|
272 |
textArea.setAutoscrolls(true);
|
273 |
textArea.setLineWrap(true);
|
274 |
textArea.setWrapStyleWord(true);
|
275 |
textArea.setFont(fnt); |
276 |
textArea.setBackground(bg); |
277 |
return textArea;
|
278 |
} |
279 |
|
280 |
} |