svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.normalization.extension / src / org / gvsig / normalization / gui / NormalizationPanel.java @ 32523
History | View | Annotate | Download (67.5 KB)
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 Prodevelop S.L. main development
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.normalization.gui; |
29 |
|
30 |
import java.awt.Component; |
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
import java.awt.event.FocusEvent; |
34 |
import java.awt.event.FocusListener; |
35 |
import java.awt.event.ItemEvent; |
36 |
import java.awt.event.ItemListener; |
37 |
import java.awt.event.KeyEvent; |
38 |
import java.awt.event.KeyListener; |
39 |
import java.awt.event.MouseEvent; |
40 |
import java.awt.event.MouseListener; |
41 |
import java.io.File; |
42 |
import java.text.DecimalFormatSymbols; |
43 |
import java.util.ArrayList; |
44 |
import java.util.Iterator; |
45 |
import java.util.List; |
46 |
import java.util.Locale; |
47 |
|
48 |
import javax.swing.BorderFactory; |
49 |
import javax.swing.ButtonGroup; |
50 |
import javax.swing.DefaultComboBoxModel; |
51 |
import javax.swing.DefaultListModel; |
52 |
import javax.swing.ImageIcon; |
53 |
import javax.swing.InputVerifier; |
54 |
import javax.swing.JButton; |
55 |
import javax.swing.JCheckBox; |
56 |
import javax.swing.JComboBox; |
57 |
import javax.swing.JComponent; |
58 |
import javax.swing.JFileChooser; |
59 |
import javax.swing.JLabel; |
60 |
import javax.swing.JList; |
61 |
import javax.swing.JOptionPane; |
62 |
import javax.swing.JPanel; |
63 |
import javax.swing.JRadioButton; |
64 |
import javax.swing.JScrollPane; |
65 |
import javax.swing.JTable; |
66 |
import javax.swing.JTextField; |
67 |
import javax.swing.ListModel; |
68 |
import javax.swing.event.ChangeEvent; |
69 |
import javax.swing.event.ChangeListener; |
70 |
import javax.swing.event.ListSelectionEvent; |
71 |
import javax.swing.event.ListSelectionListener; |
72 |
import javax.swing.table.DefaultTableModel; |
73 |
import javax.swing.table.TableColumn; |
74 |
import javax.swing.table.TableModel; |
75 |
|
76 |
import org.gvsig.andami.PluginServices; |
77 |
import org.gvsig.app.daltransform.gui.components.impl.FeatureTypeAttributesCombo; |
78 |
import org.gvsig.app.daltransform.gui.components.impl.FeatureTypeCombo; |
79 |
import org.gvsig.app.daltransform.gui.impl.AbstractDataTransformWizardPanel; |
80 |
import org.gvsig.fmap.dal.exception.DataException; |
81 |
import org.gvsig.fmap.dal.feature.Feature; |
82 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
83 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
84 |
import org.gvsig.normalization.algorithm.NormalizationAlgorithm; |
85 |
import org.gvsig.normalization.algorithm.impl.DefaultNormalizationAlgorithm; |
86 |
import org.gvsig.normalization.pattern.Datevalue; |
87 |
import org.gvsig.normalization.pattern.Decimalvalue; |
88 |
import org.gvsig.normalization.pattern.Element; |
89 |
import org.gvsig.normalization.pattern.Fieldseparator; |
90 |
import org.gvsig.normalization.pattern.Fieldtype; |
91 |
import org.gvsig.normalization.pattern.Infieldseparators; |
92 |
import org.gvsig.normalization.pattern.Integervalue; |
93 |
import org.gvsig.normalization.pattern.NormalizationPattern; |
94 |
import org.gvsig.normalization.pattern.Stringvalue; |
95 |
import org.gvsig.normalization.pattern.impl.DefaultDatevalue; |
96 |
import org.gvsig.normalization.pattern.impl.DefaultDecimalvalue; |
97 |
import org.gvsig.normalization.pattern.impl.DefaultElement; |
98 |
import org.gvsig.normalization.pattern.impl.DefaultFieldseparator; |
99 |
import org.gvsig.normalization.pattern.impl.DefaultFieldtype; |
100 |
import org.gvsig.normalization.pattern.impl.DefaultInfieldseparators; |
101 |
import org.gvsig.normalization.pattern.impl.DefaultIntegervalue; |
102 |
import org.gvsig.normalization.pattern.impl.DefaultNormalizationPattern; |
103 |
import org.gvsig.normalization.pattern.impl.DefaultStringvalue; |
104 |
import org.gvsig.utils.GenericFileFilter; |
105 |
import org.gvsig.utils.XMLEntity; |
106 |
import org.slf4j.Logger; |
107 |
import org.slf4j.LoggerFactory; |
108 |
|
109 |
/**
|
110 |
* Normalization main panel
|
111 |
*
|
112 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
113 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
|
114 |
*/
|
115 |
public class NormalizationPanel extends AbstractDataTransformWizardPanel |
116 |
implements ActionListener, ChangeListener, KeyListener, MouseListener, |
117 |
ListSelectionListener, ItemListener, FocusListener { |
118 |
|
119 |
// ATTRIBUTES
|
120 |
private static final long serialVersionUID = -2882235643001676017L; |
121 |
private static final Logger log = LoggerFactory |
122 |
.getLogger(NormalizationPanel.class); |
123 |
private static final int SAMPLES = 3; |
124 |
private static final int WIDTH = 700; |
125 |
private static final int HEIGHT = 620; |
126 |
|
127 |
private NormalizationPattern pattern;
|
128 |
private int contador = 1; |
129 |
private String[] samples = new String[SAMPLES]; |
130 |
private boolean dirty = false; |
131 |
private int selectedField = 0; |
132 |
|
133 |
private String preFieldName; |
134 |
|
135 |
private String oldNumRows; |
136 |
|
137 |
/* ATTRIBUTES GUI */
|
138 |
private ButtonGroup butGroupDelimiter; |
139 |
private ButtonGroup butGroupFieldType; |
140 |
private JButton jButAddField; |
141 |
private JButton jButDownField; |
142 |
private JButton jButRemoveField; |
143 |
private JButton jButUpField; |
144 |
private JButton jButLoad; |
145 |
private JButton jButSave; |
146 |
private JButton jButTest; |
147 |
private JCheckBox jCheckFirstRow; |
148 |
private JCheckBox jChkComma; |
149 |
private JCheckBox jChkDontImport; |
150 |
private JCheckBox jChkJoin; |
151 |
private JCheckBox jChkOther; |
152 |
private JCheckBox jChkSemicolon; |
153 |
private JCheckBox jChkSpace; |
154 |
private JCheckBox jChkTab; |
155 |
private JComboBox jComboDate; |
156 |
private JLabel jLabDecimal; |
157 |
private JLabel jLabFieldName; |
158 |
private JLabel jLabTextDel; |
159 |
private JLabel jLabThousand; |
160 |
private JLabel jLabelSelFields; |
161 |
private JList jListFieldList; |
162 |
private JPanel jPanApply; |
163 |
private JPanel jPanFieldList; |
164 |
private JPanel jPanFieldName; |
165 |
private JPanel jPanFieldSeparators; |
166 |
private JPanel jPanFieldSettings; |
167 |
private JPanel jPanFieldType; |
168 |
private JPanel jPanFields; |
169 |
private JPanel jPanFirstRow; |
170 |
private JPanel jPanInField; |
171 |
private JPanel jPanOutputOpt; |
172 |
private JPanel jPanSampleOutput; |
173 |
private JPanel jPanSeparators; |
174 |
private JPanel jPanSource; |
175 |
private JPanel jPanel1; |
176 |
private JRadioButton jRadioAlterTable; |
177 |
private JRadioButton jRadioCharacter; |
178 |
private JRadioButton jRadioDate; |
179 |
private JRadioButton jRadioDecimal; |
180 |
private JRadioButton jRadioFixed; |
181 |
private JRadioButton jRadioInteger; |
182 |
private JRadioButton jRadioNewTable; |
183 |
private JRadioButton jRadioString; |
184 |
private JScrollPane jScrollPane2; |
185 |
private JScrollPane jScrollPaneFieldList; |
186 |
private JScrollPane jScrollPaneSource; |
187 |
private JTable jTableTest; |
188 |
private JTable jTableSamples; |
189 |
private JTextField jTextDecimal; |
190 |
private JTextField jTextNumberRows; |
191 |
private JLabel jLabelNumberRows; |
192 |
private JTextField jTextFieldName; |
193 |
private JTextField jTextFieldWidth; |
194 |
private JTextField jTextOther; |
195 |
private JTextField jTextTextDelimiter; |
196 |
private JTextField jTextThousand; |
197 |
private FeatureTypeAttributesCombo jComboField;
|
198 |
private FeatureTypeCombo jComboFieldType;
|
199 |
private JPanel jPanField; |
200 |
private JLabel jLabelFieldType; |
201 |
private JLabel jLabelField; |
202 |
|
203 |
/**
|
204 |
* Constructor
|
205 |
*/
|
206 |
public NormalizationPanel() {
|
207 |
/* Initialize components GUI */
|
208 |
initComponents(); |
209 |
setMessages(); |
210 |
setImages(); |
211 |
// load default pattern
|
212 |
pattern = initializeDefaultPattern(); |
213 |
// update GUI
|
214 |
refreshFieldsList(); |
215 |
} |
216 |
|
217 |
/**
|
218 |
* This method creates the components of the GUI
|
219 |
*/
|
220 |
private void initComponents() { |
221 |
java.awt.GridBagConstraints gridBagConstraints; |
222 |
|
223 |
jPanField = new JPanel(); |
224 |
jLabelField = new JLabel(); |
225 |
jComboField = new FeatureTypeAttributesCombo();
|
226 |
jLabelFieldType = new JLabel(); |
227 |
jComboFieldType = new FeatureTypeCombo();
|
228 |
butGroupDelimiter = new javax.swing.ButtonGroup();
|
229 |
butGroupFieldType = new javax.swing.ButtonGroup();
|
230 |
jPanSampleOutput = new javax.swing.JPanel();
|
231 |
jScrollPane2 = new javax.swing.JScrollPane();
|
232 |
jTableTest = new javax.swing.JTable();
|
233 |
jPanSource = new javax.swing.JPanel();
|
234 |
jScrollPaneSource = new javax.swing.JScrollPane();
|
235 |
jTableSamples = new javax.swing.JTable();
|
236 |
jPanFirstRow = new javax.swing.JPanel();
|
237 |
jCheckFirstRow = new javax.swing.JCheckBox();
|
238 |
jTextNumberRows = new javax.swing.JTextField();
|
239 |
jLabelNumberRows = new javax.swing.JLabel();
|
240 |
jPanFields = new javax.swing.JPanel();
|
241 |
jPanFieldList = new javax.swing.JPanel();
|
242 |
jScrollPaneFieldList = new javax.swing.JScrollPane();
|
243 |
jListFieldList = new javax.swing.JList();
|
244 |
jButAddField = new javax.swing.JButton();
|
245 |
jButRemoveField = new javax.swing.JButton();
|
246 |
jButUpField = new javax.swing.JButton();
|
247 |
jButDownField = new javax.swing.JButton();
|
248 |
jPanFieldSettings = new javax.swing.JPanel();
|
249 |
jPanFieldType = new javax.swing.JPanel();
|
250 |
jRadioString = new javax.swing.JRadioButton();
|
251 |
jRadioInteger = new javax.swing.JRadioButton();
|
252 |
jRadioDecimal = new javax.swing.JRadioButton();
|
253 |
jRadioDate = new javax.swing.JRadioButton();
|
254 |
jComboDate = new javax.swing.JComboBox();
|
255 |
jPanSeparators = new javax.swing.JPanel();
|
256 |
jPanFieldSeparators = new javax.swing.JPanel();
|
257 |
jChkTab = new javax.swing.JCheckBox();
|
258 |
jChkSpace = new javax.swing.JCheckBox();
|
259 |
jChkComma = new javax.swing.JCheckBox();
|
260 |
jChkSemicolon = new javax.swing.JCheckBox();
|
261 |
jChkOther = new javax.swing.JCheckBox();
|
262 |
jTextOther = new javax.swing.JTextField();
|
263 |
jChkJoin = new javax.swing.JCheckBox();
|
264 |
jRadioFixed = new javax.swing.JRadioButton();
|
265 |
jRadioCharacter = new javax.swing.JRadioButton();
|
266 |
jTextFieldWidth = new javax.swing.JTextField();
|
267 |
jPanFieldName = new javax.swing.JPanel();
|
268 |
jChkDontImport = new javax.swing.JCheckBox();
|
269 |
jLabFieldName = new javax.swing.JLabel();
|
270 |
jTextFieldName = new javax.swing.JTextField();
|
271 |
jPanel1 = new javax.swing.JPanel();
|
272 |
jPanApply = new javax.swing.JPanel();
|
273 |
jButTest = new javax.swing.JButton();
|
274 |
jPanInField = new javax.swing.JPanel();
|
275 |
jLabDecimal = new javax.swing.JLabel();
|
276 |
jTextDecimal = new javax.swing.JTextField();
|
277 |
jLabThousand = new javax.swing.JLabel();
|
278 |
jTextThousand = new javax.swing.JTextField();
|
279 |
jLabTextDel = new javax.swing.JLabel();
|
280 |
jTextTextDelimiter = new javax.swing.JTextField();
|
281 |
jPanOutputOpt = new javax.swing.JPanel();
|
282 |
jRadioAlterTable = new javax.swing.JRadioButton();
|
283 |
jRadioNewTable = new javax.swing.JRadioButton();
|
284 |
jLabelSelFields = new javax.swing.JLabel();
|
285 |
jButLoad = new javax.swing.JButton();
|
286 |
jButSave = new javax.swing.JButton();
|
287 |
|
288 |
setMinimumSize(new java.awt.Dimension(WIDTH, HEIGHT));
|
289 |
setPreferredSize(new java.awt.Dimension(WIDTH, HEIGHT));
|
290 |
|
291 |
addFocusListener(this);
|
292 |
setLayout(new java.awt.GridBagLayout());
|
293 |
|
294 |
jPanSampleOutput.setBorder(javax.swing.BorderFactory |
295 |
.createTitledBorder("Sample output"));
|
296 |
jPanSampleOutput.setLayout(new java.awt.GridBagLayout());
|
297 |
|
298 |
jScrollPane2 |
299 |
.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); |
300 |
jScrollPane2.setAutoscrolls(true);
|
301 |
jScrollPane2.setMinimumSize(new java.awt.Dimension(100, 90)); |
302 |
jScrollPane2.setPreferredSize(new java.awt.Dimension(100, 90)); |
303 |
|
304 |
jTableTest.setFont(new java.awt.Font("Courier New", 0, 11)); |
305 |
jTableTest.setModel(new javax.swing.table.DefaultTableModel(
|
306 |
new Object[][] { {}, {}, {} }, new String[] { |
307 |
|
308 |
})); |
309 |
jTableTest.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); |
310 |
jTableTest.setEnabled(false);
|
311 |
jTableTest.setRowSelectionAllowed(false);
|
312 |
jScrollPane2.setViewportView(jTableTest); |
313 |
|
314 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
315 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
316 |
gridBagConstraints.weightx = 1.0;
|
317 |
gridBagConstraints.weighty = 1.0;
|
318 |
jPanSampleOutput.add(jScrollPane2, gridBagConstraints); |
319 |
|
320 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
321 |
gridBagConstraints.gridx = 0;
|
322 |
gridBagConstraints.gridy = 2;
|
323 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
324 |
gridBagConstraints.weightx = 1.0;
|
325 |
gridBagConstraints.insets = new java.awt.Insets(0, 3, 4, 3); |
326 |
add(jPanSampleOutput, gridBagConstraints); |
327 |
|
328 |
jPanSource.setBorder(javax.swing.BorderFactory |
329 |
.createTitledBorder("Source"));
|
330 |
jPanSource.setMinimumSize(new java.awt.Dimension(36, 125)); |
331 |
jPanSource.setLayout(new java.awt.GridBagLayout());
|
332 |
|
333 |
jScrollPaneSource.setMinimumSize(new java.awt.Dimension(100, 90)); |
334 |
jScrollPaneSource.setPreferredSize(new java.awt.Dimension(100, 90)); |
335 |
|
336 |
jPanField.setLayout(new java.awt.GridBagLayout());
|
337 |
|
338 |
jLabelFieldType.setText("selectFieldType");
|
339 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
340 |
gridBagConstraints.gridx = 0;
|
341 |
gridBagConstraints.gridy = 0;
|
342 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6); |
343 |
jPanField.add(jLabelFieldType, gridBagConstraints); |
344 |
|
345 |
jComboFieldType.setMinimumSize(new java.awt.Dimension(100, 20)); |
346 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
347 |
gridBagConstraints.gridx = 1;
|
348 |
gridBagConstraints.gridy = 0;
|
349 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
350 |
gridBagConstraints.weightx = 1.0;
|
351 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0); |
352 |
jPanField.add(jComboFieldType, gridBagConstraints); |
353 |
|
354 |
jLabelField.setText("selectField");
|
355 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
356 |
gridBagConstraints.gridx = 0;
|
357 |
gridBagConstraints.gridy = 1;
|
358 |
gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 6); |
359 |
jPanField.add(jLabelField, gridBagConstraints); |
360 |
|
361 |
jComboField.setMinimumSize(new java.awt.Dimension(100, 20)); |
362 |
jComboField.addActionListener(this);
|
363 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
364 |
gridBagConstraints.gridx = 1;
|
365 |
gridBagConstraints.gridy = 1;
|
366 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
367 |
gridBagConstraints.weightx = 1.0;
|
368 |
gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0); |
369 |
jPanField.add(jComboField, gridBagConstraints); |
370 |
|
371 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
372 |
gridBagConstraints.gridx = 0;
|
373 |
gridBagConstraints.gridy = 0;
|
374 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
375 |
gridBagConstraints.weightx = 1.0;
|
376 |
gridBagConstraints.insets = new java.awt.Insets(1, 15, 4, 25); |
377 |
jPanSource.add(jPanField, gridBagConstraints); |
378 |
|
379 |
jTableSamples.setFont(new java.awt.Font("Courier New", 0, 11)); |
380 |
jTableSamples.setModel(new DefaultTableModel()); |
381 |
jTableSamples.getTableHeader().setReorderingAllowed(false);
|
382 |
jTableSamples.setRowSelectionAllowed(false);
|
383 |
jScrollPaneSource.setViewportView(jTableSamples); |
384 |
|
385 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
386 |
gridBagConstraints.gridx = 0;
|
387 |
gridBagConstraints.gridy = 1;
|
388 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
389 |
gridBagConstraints.weightx = 1.0;
|
390 |
gridBagConstraints.weighty = 1.0;
|
391 |
jPanSource.add(jScrollPaneSource, gridBagConstraints); |
392 |
|
393 |
jPanFirstRow.setLayout(new java.awt.GridBagLayout());
|
394 |
|
395 |
jCheckFirstRow.setText("Don't normalize the first row");
|
396 |
jCheckFirstRow.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
397 |
jCheckFirstRow.setSelected(false);
|
398 |
jCheckFirstRow.addActionListener(this);
|
399 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
400 |
gridBagConstraints.gridx = 0;
|
401 |
gridBagConstraints.gridy = 0;
|
402 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
403 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
404 |
gridBagConstraints.insets = new java.awt.Insets(3, 10, 0, 0); |
405 |
jPanFirstRow.add(jCheckFirstRow, gridBagConstraints); |
406 |
|
407 |
jTextNumberRows.setText("0");
|
408 |
jTextNumberRows.setEditable(false);
|
409 |
jTextNumberRows.setInputVerifier(new IntVerifier());
|
410 |
jTextNumberRows.setMaximumSize(new java.awt.Dimension(30, 18)); |
411 |
jTextNumberRows.setMinimumSize(new java.awt.Dimension(30, 18)); |
412 |
jTextNumberRows.setPreferredSize(new java.awt.Dimension(30, 18)); |
413 |
jTextNumberRows.addKeyListener(this);
|
414 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
415 |
gridBagConstraints.gridx = 1;
|
416 |
gridBagConstraints.gridy = 0;
|
417 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
418 |
gridBagConstraints.insets = new java.awt.Insets(2, 3, 0, 5); |
419 |
jPanFirstRow.add(jTextNumberRows, gridBagConstraints); |
420 |
|
421 |
jLabelNumberRows.setText("rows");
|
422 |
jLabelNumberRows.setEnabled(false);
|
423 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
424 |
gridBagConstraints.gridx = 2;
|
425 |
gridBagConstraints.gridy = 0;
|
426 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
427 |
gridBagConstraints.weightx = 1.0;
|
428 |
gridBagConstraints.insets = new java.awt.Insets(3, 0, 0, 0); |
429 |
jPanFirstRow.add(jLabelNumberRows, gridBagConstraints); |
430 |
|
431 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
432 |
gridBagConstraints.gridx = 0;
|
433 |
gridBagConstraints.gridy = 2;
|
434 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
435 |
gridBagConstraints.weightx = 1.0;
|
436 |
jPanSource.add(jPanFirstRow, gridBagConstraints); |
437 |
|
438 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
439 |
gridBagConstraints.gridx = 0;
|
440 |
gridBagConstraints.gridy = 0;
|
441 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
442 |
gridBagConstraints.weightx = 1.0;
|
443 |
gridBagConstraints.weighty = 1.0;
|
444 |
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); |
445 |
add(jPanSource, gridBagConstraints); |
446 |
|
447 |
jPanFields.setLayout(new java.awt.GridBagLayout());
|
448 |
|
449 |
jPanFieldList.setBorder(javax.swing.BorderFactory |
450 |
.createTitledBorder("Fields"));
|
451 |
jPanFieldList.setLayout(new java.awt.GridBagLayout());
|
452 |
|
453 |
jScrollPaneFieldList.setPreferredSize(new java.awt.Dimension(100, 150)); |
454 |
|
455 |
jListFieldList |
456 |
.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
457 |
jListFieldList.addMouseListener(this);
|
458 |
jListFieldList.addListSelectionListener(this);
|
459 |
jScrollPaneFieldList.setViewportView(jListFieldList); |
460 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
461 |
gridBagConstraints.gridx = 0;
|
462 |
gridBagConstraints.gridy = 0;
|
463 |
gridBagConstraints.gridheight = 4;
|
464 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
465 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; |
466 |
gridBagConstraints.weightx = 1.0;
|
467 |
gridBagConstraints.weighty = 1.0;
|
468 |
jPanFieldList.add(jScrollPaneFieldList, gridBagConstraints); |
469 |
|
470 |
jButAddField.setBorderPainted(false);
|
471 |
jButAddField.setMargin(new java.awt.Insets(5, 5, 5, 5)); |
472 |
jButAddField.setMaximumSize(new java.awt.Dimension(30, 30)); |
473 |
jButAddField.setMinimumSize(new java.awt.Dimension(30, 30)); |
474 |
jButAddField.addActionListener(this);
|
475 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
476 |
gridBagConstraints.gridx = 1;
|
477 |
gridBagConstraints.gridy = 2;
|
478 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; |
479 |
gridBagConstraints.weighty = 1.0;
|
480 |
gridBagConstraints.insets = new java.awt.Insets(0, 2, 5, 2); |
481 |
jPanFieldList.add(jButAddField, gridBagConstraints); |
482 |
|
483 |
jButRemoveField.setBorderPainted(false);
|
484 |
jButRemoveField.setMargin(new java.awt.Insets(5, 5, 5, 5)); |
485 |
jButRemoveField.setMaximumSize(new java.awt.Dimension(30, 30)); |
486 |
jButRemoveField.addActionListener(this);
|
487 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
488 |
gridBagConstraints.gridx = 1;
|
489 |
gridBagConstraints.gridy = 3;
|
490 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
491 |
gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2); |
492 |
jPanFieldList.add(jButRemoveField, gridBagConstraints); |
493 |
|
494 |
jButUpField.setForeground(java.awt.SystemColor.activeCaptionBorder); |
495 |
jButUpField.setBorderPainted(false);
|
496 |
jButUpField.setMargin(new java.awt.Insets(5, 5, 5, 5)); |
497 |
jButUpField.setMaximumSize(new java.awt.Dimension(30, 30)); |
498 |
jButUpField.addActionListener(this);
|
499 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
500 |
gridBagConstraints.gridx = 1;
|
501 |
gridBagConstraints.gridy = 0;
|
502 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; |
503 |
gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2); |
504 |
jPanFieldList.add(jButUpField, gridBagConstraints); |
505 |
|
506 |
jButDownField.setBorderPainted(false);
|
507 |
jButDownField.setMargin(new java.awt.Insets(5, 5, 5, 5)); |
508 |
jButDownField.setMaximumSize(new java.awt.Dimension(30, 30)); |
509 |
jButDownField.setMinimumSize(new java.awt.Dimension(30, 30)); |
510 |
jButDownField.addActionListener(this);
|
511 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
512 |
gridBagConstraints.gridx = 1;
|
513 |
gridBagConstraints.gridy = 1;
|
514 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
515 |
gridBagConstraints.weighty = 1.0;
|
516 |
gridBagConstraints.insets = new java.awt.Insets(5, 2, 0, 2); |
517 |
jPanFieldList.add(jButDownField, gridBagConstraints); |
518 |
|
519 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
520 |
gridBagConstraints.gridx = 0;
|
521 |
gridBagConstraints.gridy = 1;
|
522 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
523 |
gridBagConstraints.weightx = 1.0;
|
524 |
jPanFields.add(jPanFieldList, gridBagConstraints); |
525 |
|
526 |
jPanFieldSettings.setBorder(javax.swing.BorderFactory |
527 |
.createTitledBorder("Field settings"));
|
528 |
jPanFieldSettings.setLayout(new java.awt.GridBagLayout());
|
529 |
|
530 |
jPanFieldType.setBorder(javax.swing.BorderFactory |
531 |
.createTitledBorder("Select field type"));
|
532 |
jPanFieldType.setLayout(new java.awt.GridBagLayout());
|
533 |
|
534 |
butGroupFieldType.add(jRadioString); |
535 |
jRadioString.setSelected(true);
|
536 |
jRadioString.setText("String");
|
537 |
jRadioString.setAlignmentY(1.0F);
|
538 |
jRadioString.addActionListener(this);
|
539 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
540 |
gridBagConstraints.gridx = 0;
|
541 |
gridBagConstraints.gridy = 0;
|
542 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; |
543 |
gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3); |
544 |
jPanFieldType.add(jRadioString, gridBagConstraints); |
545 |
|
546 |
butGroupFieldType.add(jRadioInteger); |
547 |
jRadioInteger.setText("Integer");
|
548 |
jRadioInteger.addActionListener(this);
|
549 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
550 |
gridBagConstraints.gridx = 0;
|
551 |
gridBagConstraints.gridy = 1;
|
552 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
553 |
gridBagConstraints.weighty = 1.0;
|
554 |
gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3); |
555 |
jPanFieldType.add(jRadioInteger, gridBagConstraints); |
556 |
|
557 |
butGroupFieldType.add(jRadioDecimal); |
558 |
jRadioDecimal.setText("Decimal");
|
559 |
jRadioDecimal.addActionListener(this);
|
560 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
561 |
gridBagConstraints.gridx = 0;
|
562 |
gridBagConstraints.gridy = 2;
|
563 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
564 |
gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3); |
565 |
jPanFieldType.add(jRadioDecimal, gridBagConstraints); |
566 |
|
567 |
butGroupFieldType.add(jRadioDate); |
568 |
jRadioDate.setText("Date");
|
569 |
jRadioDate.addItemListener(this);
|
570 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
571 |
gridBagConstraints.gridx = 0;
|
572 |
gridBagConstraints.gridy = 3;
|
573 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
574 |
gridBagConstraints.weighty = 1.0;
|
575 |
gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3); |
576 |
jPanFieldType.add(jRadioDate, gridBagConstraints); |
577 |
|
578 |
jComboDate.setEditable(true);
|
579 |
jComboDate.setModel(new javax.swing.DefaultComboBoxModel(new String[] { |
580 |
"dd/MM/yy", "dd/MM/yyyy", "MM/dd/yyyy", "yyyy/MM/dd", |
581 |
"yy/MM/dd" }));
|
582 |
jComboDate.setEnabled(false);
|
583 |
jComboDate.addActionListener(this);
|
584 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
585 |
gridBagConstraints.gridx = 0;
|
586 |
gridBagConstraints.gridy = 4;
|
587 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
588 |
gridBagConstraints.weightx = 1.0;
|
589 |
gridBagConstraints.weighty = 1.0;
|
590 |
gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3); |
591 |
jPanFieldType.add(jComboDate, gridBagConstraints); |
592 |
|
593 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
594 |
gridBagConstraints.gridx = 0;
|
595 |
gridBagConstraints.gridy = 1;
|
596 |
gridBagConstraints.gridheight = 2;
|
597 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
598 |
jPanFieldSettings.add(jPanFieldType, gridBagConstraints); |
599 |
|
600 |
jPanSeparators.setBorder(javax.swing.BorderFactory |
601 |
.createTitledBorder("Set how field delimites with next one"));
|
602 |
jPanSeparators.setRequestFocusEnabled(false);
|
603 |
jPanSeparators.setLayout(new java.awt.GridBagLayout());
|
604 |
|
605 |
jPanFieldSeparators.setBorder(javax.swing.BorderFactory |
606 |
.createTitledBorder("Select field separators"));
|
607 |
jPanFieldSeparators.setEnabled(false);
|
608 |
jPanFieldSeparators.setLayout(new java.awt.GridBagLayout());
|
609 |
|
610 |
jChkTab.setText("Tab");
|
611 |
jChkTab.addActionListener(this);
|
612 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
613 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
614 |
jPanFieldSeparators.add(jChkTab, gridBagConstraints); |
615 |
|
616 |
jChkSpace.setText("Space");
|
617 |
jChkSpace.addActionListener(this);
|
618 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
619 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
620 |
jPanFieldSeparators.add(jChkSpace, gridBagConstraints); |
621 |
|
622 |
jChkComma.setText("Comma");
|
623 |
jChkComma.addActionListener(this);
|
624 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
625 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
626 |
jPanFieldSeparators.add(jChkComma, gridBagConstraints); |
627 |
|
628 |
jChkSemicolon.setText("Semicolon");
|
629 |
jChkSemicolon.addActionListener(this);
|
630 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
631 |
gridBagConstraints.gridy = 1;
|
632 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
633 |
jPanFieldSeparators.add(jChkSemicolon, gridBagConstraints); |
634 |
|
635 |
jChkOther.setText("Other");
|
636 |
jChkOther.addActionListener(this);
|
637 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
638 |
gridBagConstraints.gridy = 1;
|
639 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
640 |
jPanFieldSeparators.add(jChkOther, gridBagConstraints); |
641 |
|
642 |
jTextOther.setEditable(false);
|
643 |
jTextOther.setMinimumSize(new java.awt.Dimension(30, 20)); |
644 |
jTextOther.setPreferredSize(new java.awt.Dimension(30, 20)); |
645 |
jTextOther.addActionListener(this);
|
646 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
647 |
gridBagConstraints.gridy = 1;
|
648 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
649 |
jPanFieldSeparators.add(jTextOther, gridBagConstraints); |
650 |
|
651 |
jChkJoin.setText("Join consecutive delimiters ");
|
652 |
jChkJoin.addActionListener(this);
|
653 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
654 |
gridBagConstraints.gridx = 0;
|
655 |
gridBagConstraints.gridy = 3;
|
656 |
gridBagConstraints.gridwidth = 3;
|
657 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
658 |
gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0); |
659 |
jPanFieldSeparators.add(jChkJoin, gridBagConstraints); |
660 |
|
661 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
662 |
gridBagConstraints.gridx = 0;
|
663 |
gridBagConstraints.gridy = 1;
|
664 |
gridBagConstraints.gridwidth = 3;
|
665 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
666 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
667 |
gridBagConstraints.weighty = 1.0;
|
668 |
jPanSeparators.add(jPanFieldSeparators, gridBagConstraints); |
669 |
|
670 |
butGroupDelimiter.add(jRadioFixed); |
671 |
jRadioFixed.setText("Fixed width");
|
672 |
jRadioFixed.addActionListener(this);
|
673 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
674 |
gridBagConstraints.gridx = 1;
|
675 |
gridBagConstraints.gridy = 0;
|
676 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
677 |
jPanSeparators.add(jRadioFixed, gridBagConstraints); |
678 |
|
679 |
butGroupDelimiter.add(jRadioCharacter); |
680 |
jRadioCharacter.setSelected(true);
|
681 |
jRadioCharacter.setText("Character");
|
682 |
jRadioCharacter.addActionListener(this);
|
683 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
684 |
gridBagConstraints.gridx = 0;
|
685 |
gridBagConstraints.gridy = 0;
|
686 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
687 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); |
688 |
jPanSeparators.add(jRadioCharacter, gridBagConstraints); |
689 |
|
690 |
jTextFieldWidth.setEditable(false);
|
691 |
jTextFieldWidth.setInputVerifier(new IntVerifier());
|
692 |
jTextFieldWidth.setMinimumSize(new java.awt.Dimension(40, 20)); |
693 |
jTextFieldWidth.setPreferredSize(new java.awt.Dimension(40, 20)); |
694 |
jTextFieldWidth.addKeyListener(this);
|
695 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
696 |
gridBagConstraints.gridx = 2;
|
697 |
gridBagConstraints.gridy = 0;
|
698 |
gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5); |
699 |
jPanSeparators.add(jTextFieldWidth, gridBagConstraints); |
700 |
|
701 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
702 |
gridBagConstraints.gridx = 1;
|
703 |
gridBagConstraints.gridy = 1;
|
704 |
gridBagConstraints.gridheight = 2;
|
705 |
gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; |
706 |
jPanFieldSettings.add(jPanSeparators, gridBagConstraints); |
707 |
|
708 |
jPanFieldName.setLayout(new java.awt.GridBagLayout());
|
709 |
|
710 |
jChkDontImport.setText("Don't import");
|
711 |
jChkDontImport.addActionListener(this);
|
712 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
713 |
gridBagConstraints.gridx = 3;
|
714 |
gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5); |
715 |
jPanFieldName.add(jChkDontImport, gridBagConstraints); |
716 |
|
717 |
jLabFieldName.setText("Field name:");
|
718 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
719 |
gridBagConstraints.gridx = 0;
|
720 |
gridBagConstraints.gridy = 0;
|
721 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); |
722 |
jPanFieldName.add(jLabFieldName, gridBagConstraints); |
723 |
|
724 |
jTextFieldName.setText("Field1");
|
725 |
jTextFieldName.setMinimumSize(new java.awt.Dimension(100, 20)); |
726 |
jTextFieldName.setPreferredSize(new java.awt.Dimension(100, 20)); |
727 |
jTextFieldName.addKeyListener(this);
|
728 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
729 |
gridBagConstraints.gridx = 1;
|
730 |
gridBagConstraints.gridy = 0;
|
731 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
732 |
gridBagConstraints.weightx = 1.0;
|
733 |
gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5); |
734 |
jPanFieldName.add(jTextFieldName, gridBagConstraints); |
735 |
|
736 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
737 |
gridBagConstraints.gridx = 0;
|
738 |
gridBagConstraints.gridy = 0;
|
739 |
gridBagConstraints.gridwidth = 3;
|
740 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
741 |
gridBagConstraints.weightx = 1.0;
|
742 |
jPanFieldSettings.add(jPanFieldName, gridBagConstraints); |
743 |
|
744 |
jPanel1.setLayout(new java.awt.GridBagLayout());
|
745 |
|
746 |
jPanApply.setLayout(new java.awt.GridBagLayout());
|
747 |
|
748 |
jButSave.setText("Save");
|
749 |
jButSave.setEnabled(false);
|
750 |
jButSave.addActionListener(this);
|
751 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
752 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
753 |
gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3); |
754 |
gridBagConstraints.gridx = 0;
|
755 |
gridBagConstraints.gridy = 0;
|
756 |
jPanApply.add(jButSave, gridBagConstraints); |
757 |
|
758 |
jButLoad.setText("Load");
|
759 |
jButLoad.setEnabled(false);
|
760 |
jButLoad.addActionListener(this);
|
761 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
762 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
763 |
gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3); |
764 |
gridBagConstraints.gridx = 0;
|
765 |
gridBagConstraints.gridy = 1;
|
766 |
jPanApply.add(jButLoad, gridBagConstraints); |
767 |
|
768 |
jButTest.setText("Test");
|
769 |
jButTest.addActionListener(this);
|
770 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
771 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
772 |
gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3); |
773 |
gridBagConstraints.gridx = 0;
|
774 |
gridBagConstraints.gridy = 2;
|
775 |
jPanApply.add(jButTest, gridBagConstraints); |
776 |
|
777 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
778 |
gridBagConstraints.gridx = 2;
|
779 |
gridBagConstraints.gridy = 2;
|
780 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
781 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
782 |
jPanel1.add(jPanApply, gridBagConstraints); |
783 |
|
784 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
785 |
gridBagConstraints.gridx = 2;
|
786 |
gridBagConstraints.gridy = 2;
|
787 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
788 |
jPanFieldSettings.add(jPanel1, gridBagConstraints); |
789 |
|
790 |
jPanInField.setBorder(javax.swing.BorderFactory |
791 |
.createTitledBorder("Set separators"));
|
792 |
jPanInField.setLayout(new java.awt.GridBagLayout());
|
793 |
|
794 |
jLabDecimal.setText("Decimal");
|
795 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
796 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
797 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
798 |
gridBagConstraints.insets = new java.awt.Insets(5, 3, 0, 10); |
799 |
jPanInField.add(jLabDecimal, gridBagConstraints); |
800 |
|
801 |
jTextDecimal.setText(".");
|
802 |
jTextDecimal.setInputVerifier(new CharVerifier());
|
803 |
jTextDecimal.setMinimumSize(new java.awt.Dimension(30, 20)); |
804 |
jTextDecimal.setPreferredSize(new java.awt.Dimension(30, 20)); |
805 |
jTextDecimal.addFocusListener(this);
|
806 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
807 |
gridBagConstraints.gridx = 1;
|
808 |
gridBagConstraints.gridy = 0;
|
809 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
810 |
gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 3); |
811 |
jPanInField.add(jTextDecimal, gridBagConstraints); |
812 |
|
813 |
jLabThousand.setText("Thousand");
|
814 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
815 |
gridBagConstraints.gridx = 0;
|
816 |
gridBagConstraints.gridy = 1;
|
817 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
818 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
819 |
gridBagConstraints.insets = new java.awt.Insets(5, 3, 0, 10); |
820 |
jPanInField.add(jLabThousand, gridBagConstraints); |
821 |
|
822 |
jTextThousand.setText(null);
|
823 |
jTextThousand.setPreferredSize(new java.awt.Dimension(30, 20)); |
824 |
jTextThousand.addFocusListener(this);
|
825 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
826 |
gridBagConstraints.gridx = 1;
|
827 |
gridBagConstraints.gridy = 1;
|
828 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
829 |
gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 3); |
830 |
jPanInField.add(jTextThousand, gridBagConstraints); |
831 |
|
832 |
jLabTextDel.setText("Text:");
|
833 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
834 |
gridBagConstraints.gridx = 0;
|
835 |
gridBagConstraints.gridy = 2;
|
836 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
837 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
838 |
gridBagConstraints.insets = new java.awt.Insets(5, 3, 0, 10); |
839 |
jPanInField.add(jLabTextDel, gridBagConstraints); |
840 |
|
841 |
jTextTextDelimiter.setHorizontalAlignment(javax.swing.JTextField.RIGHT); |
842 |
jTextTextDelimiter.setText("\"");
|
843 |
jTextTextDelimiter.setPreferredSize(new java.awt.Dimension(30, 20)); |
844 |
jTextTextDelimiter.addFocusListener(this);
|
845 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
846 |
gridBagConstraints.gridx = 1;
|
847 |
gridBagConstraints.gridy = 2;
|
848 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
849 |
gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 3); |
850 |
jPanInField.add(jTextTextDelimiter, gridBagConstraints); |
851 |
|
852 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
853 |
gridBagConstraints.gridx = 2;
|
854 |
gridBagConstraints.gridy = 1;
|
855 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
856 |
jPanFieldSettings.add(jPanInField, gridBagConstraints); |
857 |
|
858 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
859 |
gridBagConstraints.gridx = 1;
|
860 |
gridBagConstraints.gridy = 1;
|
861 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
862 |
jPanFields.add(jPanFieldSettings, gridBagConstraints); |
863 |
|
864 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
865 |
gridBagConstraints.gridx = 0;
|
866 |
gridBagConstraints.gridy = 1;
|
867 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
868 |
gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3); |
869 |
add(jPanFields, gridBagConstraints); |
870 |
} |
871 |
|
872 |
/**
|
873 |
* This method updates panel labels (Internationalization)
|
874 |
*/
|
875 |
private void setMessages() { |
876 |
|
877 |
PluginServices ps = PluginServices.getPluginServices(this);
|
878 |
|
879 |
this.setName(ps.getText("normtitle")); |
880 |
jPanSource.setBorder(BorderFactory.createTitledBorder(ps
|
881 |
.getText("normsource")));
|
882 |
jLabelField.setText(ps.getText("selfield"));
|
883 |
jLabelFieldType.setText(ps.getText("normselectFieldType"));
|
884 |
jCheckFirstRow.setText(ps.getText("normfirstrows"));
|
885 |
jLabelNumberRows.setText(ps.getText("normfirstnumberrows"));
|
886 |
|
887 |
jPanFieldList.setBorder(BorderFactory.createTitledBorder(ps
|
888 |
.getText("normfields")));
|
889 |
|
890 |
jPanFieldSettings.setBorder(BorderFactory.createTitledBorder(ps
|
891 |
.getText("normfieldsettings")));
|
892 |
jLabFieldName.setText(ps.getText("normfieldname"));
|
893 |
jChkDontImport.setText(ps.getText("normdontimport"));
|
894 |
|
895 |
jPanFieldType.setBorder(BorderFactory.createTitledBorder(ps
|
896 |
.getText("normfieldtype")));
|
897 |
jRadioString.setText(ps.getText("normfieldstring"));
|
898 |
jRadioInteger.setText(ps.getText("normfieldinteger"));
|
899 |
jRadioDecimal.setText(ps.getText("normfielddecimal"));
|
900 |
jRadioDate.setText(ps.getText("normfielddate"));
|
901 |
|
902 |
jPanSeparators.setBorder(BorderFactory.createTitledBorder(ps
|
903 |
.getText("normdelimetersnext")));
|
904 |
jRadioCharacter.setText(ps.getText("normcharacter"));
|
905 |
jRadioFixed.setText(ps.getText("normfixedwidth"));
|
906 |
|
907 |
jPanFieldSeparators.setBorder(BorderFactory.createTitledBorder(ps
|
908 |
.getText("normfieldseparators")));
|
909 |
jChkTab.setText(ps.getText("normtab"));
|
910 |
jChkSpace.setText(ps.getText("normspace"));
|
911 |
jChkComma.setText(ps.getText("normcolon"));
|
912 |
jChkSemicolon.setText(ps.getText("normsemicolon"));
|
913 |
jChkOther.setText(ps.getText("normother"));
|
914 |
jChkJoin.setText(ps.getText("normjoin"));
|
915 |
|
916 |
jPanInField.setBorder(BorderFactory.createTitledBorder(ps
|
917 |
.getText("norminfieldseparators")));
|
918 |
jLabDecimal.setText(ps.getText("normdecimal"));
|
919 |
jLabThousand.setText(ps.getText("normthousand"));
|
920 |
jLabTextDel.setText(ps.getText("normtextdelimiter"));
|
921 |
|
922 |
jButTest.setText(ps.getText("normtest"));
|
923 |
|
924 |
jPanSampleOutput.setBorder(BorderFactory.createTitledBorder(ps
|
925 |
.getText("normsampleout")));
|
926 |
|
927 |
jPanOutputOpt.setBorder(BorderFactory.createTitledBorder(ps
|
928 |
.getText("normoutputopt")));
|
929 |
jRadioAlterTable.setText(ps.getText("normaltertable"));
|
930 |
jRadioNewTable.setText(ps.getText("normnewtable"));
|
931 |
jLabelSelFields.setText(ps.getText("normjoinfield"));
|
932 |
|
933 |
jButLoad.setText(ps.getText("normload"));
|
934 |
jButSave.setText(ps.getText("normsave"));
|
935 |
} |
936 |
|
937 |
/**
|
938 |
* This method updates the images (Icons)
|
939 |
*/
|
940 |
private void setImages() { |
941 |
|
942 |
PluginServices ps = PluginServices.getPluginServices(this);
|
943 |
|
944 |
String bDir = ps.getClassLoader().getBaseDir();
|
945 |
|
946 |
jButUpField.setIcon(new ImageIcon(bDir + File.separator + "images" |
947 |
+ File.separator + "icons16" + File.separator + "go-up.png")); |
948 |
jButDownField.setIcon(new ImageIcon(bDir + File.separator + "images" |
949 |
+ File.separator + "icons16" + File.separator + "go-down.png")); |
950 |
jButAddField |
951 |
.setIcon(new ImageIcon(bDir + File.separator + "images" |
952 |
+ File.separator + "icons16" + File.separator |
953 |
+ "list-add.png"));
|
954 |
jButRemoveField.setIcon(new ImageIcon(bDir + File.separator + "images" |
955 |
+ File.separator + "icons16" + File.separator |
956 |
+ "list-remove.png"));
|
957 |
} |
958 |
|
959 |
/**
|
960 |
* This method saves a Normalization pattern to XML file *
|
961 |
*/
|
962 |
private void savePatternXML() { |
963 |
|
964 |
JFileChooser jfc = new JFileChooser(); |
965 |
jfc.setDialogTitle(PluginServices.getText(this, "save_norm_pattern")); |
966 |
String[] extensions = { "xml" }; |
967 |
jfc.setCurrentDirectory(new File(getFolderPattern())); |
968 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
|
969 |
PluginServices.getText(this, "pattern_norm_file"))); |
970 |
int returnval = jfc.showSaveDialog((Component) PluginServices |
971 |
.getMainFrame()); |
972 |
|
973 |
if (returnval == JFileChooser.APPROVE_OPTION) { |
974 |
File thefile = jfc.getSelectedFile();
|
975 |
// Check if the file has extension .xml
|
976 |
if (!(thefile.getPath().toLowerCase().endsWith(".xml"))) { |
977 |
thefile = new File(thefile.getPath() + ".xml"); |
978 |
} |
979 |
try {
|
980 |
// the file exists
|
981 |
if (thefile.exists()) {
|
982 |
|
983 |
int n = JOptionPane.showConfirmDialog(null, PluginServices |
984 |
.getText(null, "file_exists"), PluginServices |
985 |
.getText(null, "save_norm_pattern"), |
986 |
JOptionPane.YES_NO_OPTION);
|
987 |
if (n == JOptionPane.YES_OPTION) { |
988 |
pattern.setPatternname(thefile.getName()); |
989 |
((DefaultNormalizationPattern) pattern) |
990 |
.loadFromXML(thefile); |
991 |
} |
992 |
} |
993 |
// the file not exists
|
994 |
else {
|
995 |
pattern.setPatternname(thefile.getName()); |
996 |
((DefaultNormalizationPattern) pattern) |
997 |
.loadFromXML(thefile); |
998 |
} |
999 |
} catch (Exception e) { |
1000 |
log.error("Error saving the pattern", e);
|
1001 |
} |
1002 |
} |
1003 |
} |
1004 |
|
1005 |
/**
|
1006 |
* Method to update GUI values with the selected column
|
1007 |
*
|
1008 |
* @param id
|
1009 |
* column number
|
1010 |
*/
|
1011 |
private void updateFieldToGUI(int id) { |
1012 |
|
1013 |
Element elem = this.getElement(id); |
1014 |
|
1015 |
/* name */
|
1016 |
this.jTextFieldName.setText(elem.getFieldname());
|
1017 |
|
1018 |
/* don't import */
|
1019 |
this.jChkDontImport.setSelected(!elem.getImportfield());
|
1020 |
|
1021 |
/* Update type */
|
1022 |
Fieldtype type = elem.getFieldtype(); |
1023 |
|
1024 |
if (type == null) { |
1025 |
type = new DefaultFieldtype();
|
1026 |
type.setStringvalue(new DefaultStringvalue());
|
1027 |
elem.setFieldtype(type); |
1028 |
} |
1029 |
|
1030 |
boolean flag = false; |
1031 |
if (type.getDatevalue() != null) { |
1032 |
jRadioDate.setSelected(true);
|
1033 |
String formato = type.getDatevalue().getDatevalueformat();
|
1034 |
DefaultComboBoxModel model = (DefaultComboBoxModel) jComboDate |
1035 |
.getModel(); |
1036 |
for (int i = 0; i < model.getSize(); i++) { |
1037 |
String nameformato = (String) model.getElementAt(i); |
1038 |
if (formato.compareToIgnoreCase(nameformato) == 0) { |
1039 |
jComboDate.setSelectedIndex(i); |
1040 |
flag = true;
|
1041 |
} |
1042 |
} |
1043 |
if (!flag) {
|
1044 |
model.addElement(formato); |
1045 |
jComboDate.setModel(model); |
1046 |
jComboDate.setSelectedItem(formato); |
1047 |
} |
1048 |
} else if (type.getStringvalue() != null) { |
1049 |
jRadioString.setSelected(true);
|
1050 |
} else if (type.getIntegervalue() != null) { |
1051 |
jRadioInteger.setSelected(true);
|
1052 |
} else if (type.getDecimalvalue() != null) { |
1053 |
jRadioDecimal.setSelected(true);
|
1054 |
} |
1055 |
|
1056 |
/* Update field separator */
|
1057 |
Fieldseparator seps = elem.getFieldseparator(); |
1058 |
if (seps == null) { |
1059 |
seps = this.getDefaultFieldseparators();
|
1060 |
} |
1061 |
|
1062 |
this.jTextFieldWidth.setText(Integer.toString(elem.getFieldwidth())); |
1063 |
boolean isFixedWidth = elem.getFieldwidth() > 0; |
1064 |
|
1065 |
this.jRadioFixed.setSelected(isFixedWidth);
|
1066 |
this.jRadioCharacter.setSelected(!isFixedWidth);
|
1067 |
|
1068 |
if (isFixedWidth) {
|
1069 |
this.jTextFieldWidth.setEditable(true); |
1070 |
Component[] comps = this.jPanFieldSeparators.getComponents(); |
1071 |
for (int i = 0; i < comps.length; i++) { |
1072 |
comps[i].setEnabled(false);
|
1073 |
} |
1074 |
this.jTextFieldWidth.requestFocus();
|
1075 |
dirty = true;
|
1076 |
} else {
|
1077 |
this.jTextFieldWidth.setEditable(false); |
1078 |
Component[] comps = this.jPanFieldSeparators.getComponents(); |
1079 |
for (int i = 0; i < comps.length; i++) { |
1080 |
comps[i].setEnabled(true);
|
1081 |
} |
1082 |
dirty = true;
|
1083 |
} |
1084 |
|
1085 |
this.jChkJoin.setSelected(seps.getJoinsep());
|
1086 |
|
1087 |
this.jChkTab.setSelected(seps.getTabsep());
|
1088 |
|
1089 |
this.jChkSpace.setSelected(seps.getSpacesep());
|
1090 |
|
1091 |
this.jChkComma.setSelected(seps.getColonsep());
|
1092 |
|
1093 |
this.jChkSemicolon.setSelected(seps.getSemicolonsep());
|
1094 |
|
1095 |
boolean other = seps.getOthersep() != null; |
1096 |
this.jChkOther.setSelected(other);
|
1097 |
|
1098 |
if (other) {
|
1099 |
this.jTextOther.setText(seps.getOthersep());
|
1100 |
} else {
|
1101 |
this.jTextOther.setEditable(false); |
1102 |
this.jTextOther.setText(null); |
1103 |
} |
1104 |
|
1105 |
/* Update field separator */
|
1106 |
|
1107 |
Infieldseparators insep = elem.getInfieldseparators(); |
1108 |
this.jTextDecimal.setText(insep.getDecimalseparator().trim());
|
1109 |
this.jTextThousand.setText(insep.getThousandseparator().trim());
|
1110 |
this.jTextTextDelimiter.setText(insep.getTextseparator().trim());
|
1111 |
|
1112 |
updateSelectors(); |
1113 |
|
1114 |
dirty = false;
|
1115 |
} |
1116 |
|
1117 |
/**
|
1118 |
* Update the field values in the model
|
1119 |
*
|
1120 |
* @param pos
|
1121 |
*/
|
1122 |
private void updateFieldToModel(int pos) { |
1123 |
|
1124 |
Element elem = this.getElement(pos); |
1125 |
|
1126 |
/* name */
|
1127 |
elem.setFieldname(this.jTextFieldName.getText());
|
1128 |
|
1129 |
/* don't import */
|
1130 |
elem.setImportfield(!this.jChkDontImport.isSelected());
|
1131 |
|
1132 |
/* Update type */
|
1133 |
Fieldtype type = new DefaultFieldtype();
|
1134 |
|
1135 |
if (jRadioString.isSelected()) {
|
1136 |
Stringvalue strval = new DefaultStringvalue();
|
1137 |
strval.setStringvaluewidth(50);
|
1138 |
type.setStringvalue(strval); |
1139 |
} else if (jRadioInteger.isSelected()) { |
1140 |
Integervalue intval = new DefaultIntegervalue();
|
1141 |
intval.setIntegervaluewidth(25);
|
1142 |
type.setIntegervalue(intval); |
1143 |
} else if (jRadioDecimal.isSelected()) { |
1144 |
Decimalvalue dec = new DefaultDecimalvalue();
|
1145 |
/* DECIMALES = 10 */
|
1146 |
dec.setDecimalvaluedec(10);
|
1147 |
dec.setDecimalvalueint(25);
|
1148 |
type.setDecimalvalue(dec); |
1149 |
} else {
|
1150 |
Datevalue date = new DefaultDatevalue();
|
1151 |
String form = jComboDate.getSelectedItem().toString();
|
1152 |
date.setDatevalueformat(form); |
1153 |
type.setDatevalue(date); |
1154 |
} |
1155 |
elem.setFieldtype(type); |
1156 |
|
1157 |
/* Update field separator */
|
1158 |
Fieldseparator seps = elem.getFieldseparator(); |
1159 |
|
1160 |
if (elem.getFieldseparator() == null) { |
1161 |
seps = new DefaultFieldseparator();
|
1162 |
} |
1163 |
|
1164 |
boolean isFixedWidth = this.jRadioFixed.isSelected(); |
1165 |
int val;
|
1166 |
if (isFixedWidth) {
|
1167 |
try {
|
1168 |
val = Integer.parseInt(jTextFieldWidth.getText());
|
1169 |
elem.setFieldwidth(val); |
1170 |
} catch (Exception e) { |
1171 |
jTextFieldWidth.requestFocus(); |
1172 |
} |
1173 |
|
1174 |
} else {
|
1175 |
elem.setFieldwidth(0);
|
1176 |
} |
1177 |
|
1178 |
seps.setJoinsep(this.jChkJoin.isSelected());
|
1179 |
seps.setSpacesep(this.jChkSpace.isSelected());
|
1180 |
seps.setColonsep(this.jChkComma.isSelected());
|
1181 |
seps.setSemicolonsep(this.jChkSemicolon.isSelected());
|
1182 |
seps.setTabsep(this.jChkTab.isSelected());
|
1183 |
|
1184 |
if (jChkOther.isSelected() && jTextOther.getText().length() == 1) { |
1185 |
seps.setOthersep(jTextOther.getText().trim()); |
1186 |
} else {
|
1187 |
seps.setOthersep(null);
|
1188 |
} |
1189 |
|
1190 |
/* Update In-field separator */
|
1191 |
Infieldseparators inseps = elem.getInfieldseparators(); |
1192 |
|
1193 |
if (elem.getInfieldseparators() == null) { |
1194 |
inseps = new DefaultInfieldseparators();
|
1195 |
} |
1196 |
|
1197 |
inseps.setThousandseparator(this.jTextThousand.getText().trim());
|
1198 |
inseps.setDecimalseparator(this.jTextDecimal.getText().trim());
|
1199 |
inseps.setTextseparator(this.jTextTextDelimiter.getText().trim());
|
1200 |
} |
1201 |
|
1202 |
/**
|
1203 |
* Update fields list
|
1204 |
*/
|
1205 |
private void refreshFieldsList() { |
1206 |
/* Fields List */
|
1207 |
jListFieldList.setModel(this.updateFieldsListModel());
|
1208 |
jListFieldList.setSelectedIndex(0);
|
1209 |
} |
1210 |
|
1211 |
/**
|
1212 |
* Update the in-separators
|
1213 |
*/
|
1214 |
private void updateSelectors() { |
1215 |
boolean isDecimal = false; |
1216 |
boolean isThousand = false; |
1217 |
boolean isText = false; |
1218 |
if (this.jRadioString.isSelected()) { |
1219 |
isText = true;
|
1220 |
} else if (this.jRadioInteger.isSelected()) { |
1221 |
isThousand = true;
|
1222 |
} else if (this.jRadioDecimal.isSelected()) { |
1223 |
isThousand = true;
|
1224 |
isDecimal = true;
|
1225 |
} else if (this.jRadioDate.isSelected()) { |
1226 |
|
1227 |
} |
1228 |
this.jTextDecimal.setEditable(isDecimal);
|
1229 |
this.jTextThousand.setEditable(isThousand);
|
1230 |
this.jTextTextDelimiter.setEditable(isText);
|
1231 |
} |
1232 |
|
1233 |
/**
|
1234 |
* This method creates the model of the names FieldList
|
1235 |
*
|
1236 |
* @return list model
|
1237 |
*/
|
1238 |
private ListModel updateFieldsListModel() { |
1239 |
ListModel dlmodel = new DefaultListModel(); |
1240 |
Element[] adr = pattern.getArrayElements(); |
1241 |
String name = ""; |
1242 |
for (int i = 0; i < adr.length; i++) { |
1243 |
name = adr[i].getFieldname(); |
1244 |
((DefaultListModel) dlmodel).add(i, name);
|
1245 |
} |
1246 |
return dlmodel;
|
1247 |
} |
1248 |
|
1249 |
/**
|
1250 |
* Build model of the table of samples
|
1251 |
*
|
1252 |
* @return table model
|
1253 |
* @throws DataException
|
1254 |
*/
|
1255 |
@SuppressWarnings("unchecked") |
1256 |
private TableModel getSamplesDataStore(FeatureStore store, int field, |
1257 |
int noRows) throws DataException { |
1258 |
|
1259 |
FeatureSet features = store.getFeatureSet(); |
1260 |
Iterator<Feature> it = features.iterator(noRows);
|
1261 |
int contador = 0; |
1262 |
while (it.hasNext()) {
|
1263 |
Feature feature = (Feature) it.next(); |
1264 |
if (contador < SAMPLES) {
|
1265 |
String sample = feature.get(field).toString();
|
1266 |
samples[contador] = sample; |
1267 |
contador++; |
1268 |
} |
1269 |
} |
1270 |
// String samples
|
1271 |
Object[][] data = new Object[samples.length][1]; |
1272 |
for (int i = 0; i < samples.length; i++) { |
1273 |
data[i][0] = samples[i];
|
1274 |
} |
1275 |
// table field name
|
1276 |
String fieldname = getFeatureStore().getDefaultFeatureType()
|
1277 |
.getAttributeDescriptor(field).getName(); |
1278 |
String[] names = { fieldname }; |
1279 |
TableModel tablemodel = new DefaultTableModel(data, names) { |
1280 |
|
1281 |
private static final long serialVersionUID = -7429493540158414622L; |
1282 |
|
1283 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
1284 |
return false; |
1285 |
} |
1286 |
}; |
1287 |
return tablemodel;
|
1288 |
} |
1289 |
|
1290 |
/**
|
1291 |
* This method up the selected element one position in the list of Elements
|
1292 |
*
|
1293 |
* @param pos
|
1294 |
*/
|
1295 |
private void fieldUp(int pos) { |
1296 |
int nu = pattern.getElements().size();
|
1297 |
if (pos > 0 && nu > 1) { |
1298 |
int newpos = pos - 1; |
1299 |
Element[] ad = pattern.getArrayElements(); |
1300 |
Element ele21 = ad[pos];
|
1301 |
Element ele12 = ad[newpos];
|
1302 |
ad[newpos] = ele21; |
1303 |
ad[pos] = ele12; |
1304 |
List<Element> elems = new ArrayList<Element>(); |
1305 |
for (int i = 0; i < ad.length; i++) { |
1306 |
elems.add(ad[i]); |
1307 |
} |
1308 |
pattern.setElements(elems); |
1309 |
} |
1310 |
} |
1311 |
|
1312 |
/**
|
1313 |
* This method adds a new element to the pattern
|
1314 |
*/
|
1315 |
private void addField() { |
1316 |
contador++; |
1317 |
int tam = pattern.getElements().size();
|
1318 |
Element eleme = new DefaultElement(); |
1319 |
Fieldseparator fsep = new DefaultFieldseparator();
|
1320 |
fsep.setSemicolonsep(true);
|
1321 |
fsep.setJoinsep(false);
|
1322 |
fsep.setColonsep(false);
|
1323 |
fsep.setSpacesep(false);
|
1324 |
fsep.setTabsep(false);
|
1325 |
String nam = ""; |
1326 |
boolean isOkName = true; |
1327 |
do {
|
1328 |
isOkName = true;
|
1329 |
nam = "NewField" + contador;
|
1330 |
for (int i = 0; i < tam; i++) { |
1331 |
String napat = ((Element) pattern.getElements().get(i)) |
1332 |
.getFieldname(); |
1333 |
if (napat.compareToIgnoreCase(nam) == 0) { |
1334 |
isOkName = false;
|
1335 |
break;
|
1336 |
} |
1337 |
} |
1338 |
if (!isOkName) {
|
1339 |
contador++; |
1340 |
} |
1341 |
} while (!isOkName);
|
1342 |
// validate the new field name
|
1343 |
String vname = validateFieldName(nam);
|
1344 |
eleme.setFieldname(vname); |
1345 |
eleme.setFieldseparator(fsep); |
1346 |
eleme.setInfieldseparators(getDefaultInfieldseparators()); |
1347 |
eleme.setFieldtype(getDefaultNewFieldType()); |
1348 |
eleme.setFieldwidth(0);
|
1349 |
eleme.setImportfield(true);
|
1350 |
List<Element> elems = pattern.getElements(); |
1351 |
elems.add(tam, eleme); |
1352 |
} |
1353 |
|
1354 |
/**
|
1355 |
* This method loads a Normalization pattern from a XML file and return the
|
1356 |
* pattern and the String info
|
1357 |
*
|
1358 |
* @return pattern
|
1359 |
*/
|
1360 |
private NormalizationPattern loadPatternXML() {
|
1361 |
|
1362 |
NormalizationPattern pat = new DefaultNormalizationPattern();
|
1363 |
File thefile = null; |
1364 |
// Show the FileChooser to select a pattern
|
1365 |
JFileChooser jfc = new JFileChooser(); |
1366 |
jfc.setCurrentDirectory(new File(getFolderPattern())); |
1367 |
jfc.setDialogTitle(PluginServices.getText(this, "load_norm_pattern")); |
1368 |
String[] extensions = { "xml" }; |
1369 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
|
1370 |
PluginServices.getText(this, "pattern_norm_file"))); |
1371 |
|
1372 |
int returnval = jfc.showOpenDialog((Component) PluginServices |
1373 |
.getMainFrame()); |
1374 |
|
1375 |
if (returnval == JFileChooser.APPROVE_OPTION) { |
1376 |
thefile = jfc.getSelectedFile(); |
1377 |
} else {
|
1378 |
return null; |
1379 |
} |
1380 |
try {
|
1381 |
((DefaultNormalizationPattern) pat).loadFromXML(thefile); |
1382 |
} catch (Exception e) { |
1383 |
log.error("Error loading the pattern", e);
|
1384 |
return null; |
1385 |
} |
1386 |
return pat;
|
1387 |
} |
1388 |
|
1389 |
/**
|
1390 |
* This method down the selected element one position in the list of
|
1391 |
* Elements
|
1392 |
*
|
1393 |
* @param pos
|
1394 |
*/
|
1395 |
private void fieldDown(int pos) { |
1396 |
int nu = pattern.getElements().size();
|
1397 |
if (pos != (nu - 1) && nu > 1) { |
1398 |
int newpos = pos + 1; |
1399 |
Element[] ad = pattern.getArrayElements(); |
1400 |
Element ele21 = ad[pos];
|
1401 |
Element ele12 = ad[newpos];
|
1402 |
ad[newpos] = ele21; |
1403 |
ad[pos] = ele12; |
1404 |
List<Element> elems = new ArrayList<Element>(); |
1405 |
for (int i = 0; i < ad.length; i++) { |
1406 |
elems.add(ad[i]); |
1407 |
} |
1408 |
pattern.setElements(elems); |
1409 |
} |
1410 |
} |
1411 |
|
1412 |
/**
|
1413 |
* This method validates the name of a new field
|
1414 |
*
|
1415 |
* @param text
|
1416 |
* @return field name formatted
|
1417 |
*/
|
1418 |
private String validateFieldName(String text) { |
1419 |
text = text.replaceAll("[????]", "e"); |
1420 |
text = text.replaceAll("[??]", "u"); |
1421 |
text = text.replaceAll("[??]", "i"); |
1422 |
text = text.replaceAll("[??]", "a"); |
1423 |
text = text.replaceAll("?", "o"); |
1424 |
|
1425 |
text = text.replaceAll("[????]", "E"); |
1426 |
text = text.replaceAll("[??]", "U"); |
1427 |
text = text.replaceAll("[??]", "I"); |
1428 |
text = text.replaceAll("[??]", "A"); |
1429 |
text = text.replaceAll("?", "O"); |
1430 |
|
1431 |
text = text.replaceAll("[^\\p{ASCII}]", ""); |
1432 |
text = text.replaceAll("[\\s]+", "_"); |
1433 |
text = text.toUpperCase(); |
1434 |
return text;
|
1435 |
} |
1436 |
|
1437 |
/**
|
1438 |
* This method return the folder where gvSIG stores the patterns
|
1439 |
*
|
1440 |
* @return
|
1441 |
*/
|
1442 |
private String getFolderPattern() { |
1443 |
XMLEntity xml = PluginServices.getPluginServices(this)
|
1444 |
.getPersistentXML(); |
1445 |
String pathFolder = String.valueOf(xml |
1446 |
.getStringProperty("Normalization_pattern_folder"));
|
1447 |
return pathFolder;
|
1448 |
} |
1449 |
|
1450 |
/**
|
1451 |
* This method generates and returns in field separators
|
1452 |
*
|
1453 |
* @return special characters within one string
|
1454 |
*/
|
1455 |
private Infieldseparators getDefaultInfieldseparators() {
|
1456 |
/* create the default in-field separators */
|
1457 |
Locale loc = Locale.getDefault(); |
1458 |
DecimalFormatSymbols dfs = new DecimalFormatSymbols(loc); |
1459 |
Infieldseparators infilsep = new DefaultInfieldseparators();
|
1460 |
infilsep.setThousandseparator(Character.toString(dfs
|
1461 |
.getGroupingSeparator())); |
1462 |
infilsep.setDecimalseparator(Character.toString(dfs
|
1463 |
.getDecimalSeparator())); |
1464 |
infilsep.setTextseparator("\"");
|
1465 |
return infilsep;
|
1466 |
} |
1467 |
|
1468 |
/**
|
1469 |
* This method generates and returns a new field type of type Stringvalue
|
1470 |
*
|
1471 |
* @return field type
|
1472 |
*/
|
1473 |
private Fieldtype getDefaultNewFieldType() {
|
1474 |
Fieldtype newtype = new DefaultFieldtype();
|
1475 |
Stringvalue strval = new DefaultStringvalue();
|
1476 |
strval.setStringvaluewidth(50);
|
1477 |
newtype.setStringvalue(strval); |
1478 |
return newtype;
|
1479 |
} |
1480 |
|
1481 |
/**
|
1482 |
* This method returns a Element of one position
|
1483 |
*
|
1484 |
* @param index
|
1485 |
* @return
|
1486 |
*/
|
1487 |
private Element getElement(int index) { |
1488 |
Element[] adrs = pattern.getArrayElements(); |
1489 |
return adrs[index];
|
1490 |
} |
1491 |
|
1492 |
/**
|
1493 |
* This method generates and returns field separators
|
1494 |
*
|
1495 |
* @return default separators between fields
|
1496 |
*/
|
1497 |
private Fieldseparator getDefaultFieldseparators() {
|
1498 |
Fieldseparator filsep = new DefaultFieldseparator();
|
1499 |
filsep.setSemicolonsep(true);
|
1500 |
filsep.setJoinsep(false);
|
1501 |
filsep.setColonsep(false);
|
1502 |
filsep.setSpacesep(false);
|
1503 |
filsep.setTabsep(false);
|
1504 |
return filsep;
|
1505 |
} |
1506 |
|
1507 |
/**
|
1508 |
* This method creates the default Normalization pattern
|
1509 |
*
|
1510 |
* @return pattern
|
1511 |
*/
|
1512 |
private NormalizationPattern initializeDefaultPattern() {
|
1513 |
NormalizationPattern pat = new DefaultNormalizationPattern();
|
1514 |
pat.setPatternname("defaultPattern");
|
1515 |
pat.setNofirstrows(0);
|
1516 |
/* Create the first Address Element */
|
1517 |
Element elem = new DefaultElement(); |
1518 |
elem.setFieldname("NewField");
|
1519 |
elem.setFieldseparator(getDefaultFieldseparators()); |
1520 |
elem.setInfieldseparators(getDefaultInfieldseparators()); |
1521 |
elem.setFieldtype(getDefaultNewFieldType()); |
1522 |
elem.setFieldwidth(0);
|
1523 |
elem.setImportfield(true);
|
1524 |
List<Element> elems = new ArrayList<Element>(); |
1525 |
elems.add(elem); |
1526 |
pat.setElements(elems); |
1527 |
return pat;
|
1528 |
} |
1529 |
|
1530 |
/**
|
1531 |
* @return the pattern
|
1532 |
*/
|
1533 |
protected NormalizationPattern getPattern() {
|
1534 |
return pattern;
|
1535 |
} |
1536 |
|
1537 |
/**
|
1538 |
* This method is called when the panel is displayed
|
1539 |
*/
|
1540 |
public void updatePanel() { |
1541 |
FeatureStore store = getFeatureStore(); |
1542 |
jComboFieldType.addFeatureStore(store); |
1543 |
try {
|
1544 |
if (store.getFeatureTypes().size() == 1) { |
1545 |
jComboFieldType.setEnabled(false);
|
1546 |
} |
1547 |
} catch (DataException e1) {
|
1548 |
e1.printStackTrace(); |
1549 |
} |
1550 |
|
1551 |
Object obj = jComboFieldType.getSelectedItem();
|
1552 |
if (obj != null) { |
1553 |
jComboField.addFeatureAttributes(jComboFieldType |
1554 |
.getSelectedFeatureType()); |
1555 |
} |
1556 |
|
1557 |
Object obj1 = jComboField.getSelectedItem();
|
1558 |
if (obj1 != null) { |
1559 |
TableModel model = null; |
1560 |
try {
|
1561 |
model = getSamplesDataStore(store, 0, 0); |
1562 |
} catch (DataException e) {
|
1563 |
log.error("Error reading data store", e);
|
1564 |
model = new DefaultTableModel(); |
1565 |
} |
1566 |
jTableSamples.setModel(model); |
1567 |
} |
1568 |
} |
1569 |
|
1570 |
/**
|
1571 |
* State Changed
|
1572 |
*/
|
1573 |
public void stateChanged(ChangeEvent ev) { |
1574 |
|
1575 |
} |
1576 |
|
1577 |
/**
|
1578 |
* Key pressed
|
1579 |
*/
|
1580 |
public void keyPressed(KeyEvent ev) { |
1581 |
if (ev.getSource() == jTextNumberRows) {
|
1582 |
oldNumRows = jTextNumberRows.getText().trim(); |
1583 |
} |
1584 |
} |
1585 |
|
1586 |
/**
|
1587 |
* Key released
|
1588 |
*/
|
1589 |
public void keyReleased(KeyEvent ev) { |
1590 |
|
1591 |
FeatureStore store = getFeatureStore(); |
1592 |
// Change number no rows (jTextNumberRows)
|
1593 |
if (ev.getSource() == jTextNumberRows) {
|
1594 |
int selfield = jComboField.getSelectedIndex();
|
1595 |
try {
|
1596 |
int norows = (new Integer(jTextNumberRows.getText())) |
1597 |
.intValue(); |
1598 |
TableModel model = getSamplesDataStore(store, selfield, norows);
|
1599 |
jTableSamples.setModel(model); |
1600 |
jTableSamples.validate(); |
1601 |
} catch (Exception e) { |
1602 |
jTextNumberRows.setText(oldNumRows); |
1603 |
jTextNumberRows.requestFocus(); |
1604 |
} |
1605 |
} |
1606 |
// (jTextFieldWidth)
|
1607 |
if (ev.getSource() == jTextFieldWidth) {
|
1608 |
boolean vali = new IntVerifier().verify(jTextFieldWidth); |
1609 |
if (vali) {
|
1610 |
dirty = true;
|
1611 |
} else {
|
1612 |
jTextFieldWidth.setText("1");
|
1613 |
dirty = true;
|
1614 |
} |
1615 |
} |
1616 |
// (jTextFieldName)
|
1617 |
if ((ev.getSource() == jTextFieldName)) {
|
1618 |
|
1619 |
String tx = jTextFieldName.getText();
|
1620 |
if (tx.length() < 1) { |
1621 |
jTextFieldName.setText(preFieldName); |
1622 |
} else {
|
1623 |
|
1624 |
boolean pass = true; |
1625 |
String[] values = { "!", "\"", "#", "$", "%", "&", "\'", "(", |
1626 |
")", "*", "+", ",", "-", "/", ";", "<", "=", ">", "?", |
1627 |
"@", "[", "]", "^", "?", "`", "}", "{", "~" }; |
1628 |
|
1629 |
char c = ev.getKeyChar();
|
1630 |
String s = c + ""; |
1631 |
|
1632 |
for (int j = 0; j < values.length; j++) { |
1633 |
String val = values[j];
|
1634 |
if (s.contains(val)) {
|
1635 |
pass = false;
|
1636 |
} |
1637 |
} |
1638 |
if (pass) {
|
1639 |
int pos = this.selectedField; |
1640 |
updateFieldToModel(pos); |
1641 |
refreshFieldsList(); |
1642 |
dirty = false;
|
1643 |
} else {
|
1644 |
jTextFieldName.setText(preFieldName); |
1645 |
} |
1646 |
} |
1647 |
|
1648 |
} |
1649 |
|
1650 |
} |
1651 |
|
1652 |
/**
|
1653 |
*
|
1654 |
*/
|
1655 |
public void keyTyped(KeyEvent ev) { |
1656 |
preFieldName = jTextFieldName.getName(); |
1657 |
} |
1658 |
|
1659 |
/**
|
1660 |
*
|
1661 |
*/
|
1662 |
public void mouseClicked(MouseEvent ev) { |
1663 |
|
1664 |
} |
1665 |
|
1666 |
/**
|
1667 |
*
|
1668 |
*/
|
1669 |
public void mouseEntered(MouseEvent ev) { |
1670 |
|
1671 |
} |
1672 |
|
1673 |
/**
|
1674 |
*
|
1675 |
*/
|
1676 |
public void mouseExited(MouseEvent ev) { |
1677 |
|
1678 |
} |
1679 |
|
1680 |
/**
|
1681 |
*
|
1682 |
*/
|
1683 |
public void mousePressed(MouseEvent ev) { |
1684 |
// (jListFieldList)
|
1685 |
if (ev.getSource() == jListFieldList) {
|
1686 |
selectedField = jListFieldList.getSelectedIndex(); |
1687 |
} |
1688 |
} |
1689 |
|
1690 |
/**
|
1691 |
*
|
1692 |
*/
|
1693 |
public void mouseReleased(MouseEvent ev) { |
1694 |
|
1695 |
} |
1696 |
|
1697 |
/**
|
1698 |
*
|
1699 |
*/
|
1700 |
public void valueChanged(ListSelectionEvent ev) { |
1701 |
// (jListFieldList)
|
1702 |
if (ev.getSource() == jListFieldList) {
|
1703 |
/* Save the parameters in the model */
|
1704 |
boolean sucio = dirty;
|
1705 |
if (sucio) {
|
1706 |
updateFieldToModel(this.selectedField);
|
1707 |
} |
1708 |
if (!ev.getValueIsAdjusting()) {
|
1709 |
int pos = this.selectedField; |
1710 |
updateFieldToGUI(pos); |
1711 |
jListFieldList.setSelectedIndex(pos); |
1712 |
} |
1713 |
dirty = false;
|
1714 |
} |
1715 |
} |
1716 |
|
1717 |
/**
|
1718 |
*
|
1719 |
*/
|
1720 |
public void itemStateChanged(ItemEvent ev) { |
1721 |
// (jRadioDate)
|
1722 |
if (ev.getSource() == jRadioDate) {
|
1723 |
updateSelectors(); |
1724 |
boolean enable = this.jRadioDate.isSelected(); |
1725 |
this.jComboDate.setEnabled(enable);
|
1726 |
if (enable) {
|
1727 |
this.jComboDate.requestFocus();
|
1728 |
} |
1729 |
dirty = true;
|
1730 |
} |
1731 |
|
1732 |
} |
1733 |
|
1734 |
/**
|
1735 |
*
|
1736 |
*/
|
1737 |
public void actionPerformed(ActionEvent ev) { |
1738 |
|
1739 |
if (ev.getSource() == jComboField) {
|
1740 |
FeatureStore store = getFeatureStore(); |
1741 |
if (store != null) { |
1742 |
Object obj1 = jComboField.getSelectedItem();
|
1743 |
if (obj1 != null) { |
1744 |
TableModel model = null; |
1745 |
try {
|
1746 |
int item = jComboField.getSelectedIndex();
|
1747 |
if (jCheckFirstRow.isSelected()) {
|
1748 |
int norows = (new Integer(jTextNumberRows.getText())) |
1749 |
.intValue(); |
1750 |
model = getSamplesDataStore(store, item, norows); |
1751 |
jLabelNumberRows.setEnabled(true);
|
1752 |
jCheckFirstRow.setSelected(false);
|
1753 |
jTextNumberRows.setText("0");
|
1754 |
jTextNumberRows.setEnabled(false);
|
1755 |
jLabelNumberRows.setEnabled(false);
|
1756 |
} else {
|
1757 |
model = getSamplesDataStore(store, item, 0);
|
1758 |
jLabelNumberRows.setEnabled(false);
|
1759 |
} |
1760 |
|
1761 |
} catch (DataException e) {
|
1762 |
log.error("Error reading data store", e);
|
1763 |
model = new DefaultTableModel(); |
1764 |
} |
1765 |
jTableSamples.setModel(model); |
1766 |
} |
1767 |
} |
1768 |
} |
1769 |
|
1770 |
if (ev.getSource() == jCheckFirstRow) {
|
1771 |
FeatureStore store = getFeatureStore(); |
1772 |
/* DON'T Normalize the first rows */
|
1773 |
if (jCheckFirstRow.isSelected()) {
|
1774 |
jTextNumberRows.setText("1");
|
1775 |
jTextNumberRows.setEditable(true);
|
1776 |
this.jTextNumberRows.requestFocus();
|
1777 |
|
1778 |
Object obj1 = jComboField.getSelectedItem();
|
1779 |
if (obj1 != null) { |
1780 |
TableModel model = null; |
1781 |
try {
|
1782 |
int item = jComboField.getSelectedIndex();
|
1783 |
model = getSamplesDataStore(store, item, 1);
|
1784 |
jLabelNumberRows.setEnabled(true);
|
1785 |
jTextNumberRows.setEnabled(true);
|
1786 |
} catch (DataException e) {
|
1787 |
log.error("Error reading data store", e);
|
1788 |
model = new DefaultTableModel(); |
1789 |
jLabelNumberRows.setEnabled(false);
|
1790 |
jTextNumberRows.setEnabled(false);
|
1791 |
} |
1792 |
jTableSamples.setModel(model); |
1793 |
} |
1794 |
} |
1795 |
/* Normalize all rows */
|
1796 |
else {
|
1797 |
jTextNumberRows.setText("0");
|
1798 |
jTextNumberRows.setEditable(false);
|
1799 |
Object obj2 = jComboField.getSelectedItem();
|
1800 |
if (obj2 != null) { |
1801 |
TableModel model = null; |
1802 |
try {
|
1803 |
int item = jComboField.getSelectedIndex();
|
1804 |
model = getSamplesDataStore(store, item, 0);
|
1805 |
} catch (DataException e) {
|
1806 |
log.error("Error reading data store", e);
|
1807 |
model = new DefaultTableModel(); |
1808 |
} |
1809 |
jTableSamples.setModel(model); |
1810 |
jLabelNumberRows.setEnabled(false);
|
1811 |
} |
1812 |
} |
1813 |
|
1814 |
} |
1815 |
|
1816 |
if (ev.getSource() == jButAddField) {
|
1817 |
int pos = this.selectedField; |
1818 |
updateFieldToModel(pos); |
1819 |
dirty = false;
|
1820 |
|
1821 |
this.addField();
|
1822 |
ListModel dlm = this.updateFieldsListModel(); |
1823 |
int siz = ((DefaultListModel) dlm).size(); |
1824 |
this.selectedField = siz - 1; |
1825 |
jListFieldList.setModel(dlm); |
1826 |
jListFieldList.setSelectedIndex(siz - 1);
|
1827 |
jTextOther.setEditable(false);
|
1828 |
} |
1829 |
|
1830 |
if (ev.getSource() == jButRemoveField) {
|
1831 |
int siz = jListFieldList.getModel().getSize();
|
1832 |
int pos = this.selectedField; |
1833 |
if (siz > 0) { |
1834 |
updateFieldToModel(pos); |
1835 |
dirty = false;
|
1836 |
this.deleteField(pos);
|
1837 |
ListModel dlm = this.updateFieldsListModel(); |
1838 |
if (pos > 0) { |
1839 |
this.selectedField = pos - 1; |
1840 |
jListFieldList.setModel(dlm); |
1841 |
jListFieldList.setSelectedIndex(pos - 1);
|
1842 |
} else {
|
1843 |
this.selectedField = pos;
|
1844 |
jListFieldList.setModel(dlm); |
1845 |
jListFieldList.setSelectedIndex(pos); |
1846 |
} |
1847 |
} |
1848 |
} |
1849 |
|
1850 |
if (ev.getSource() == jButUpField) {
|
1851 |
int pos = this.selectedField; |
1852 |
updateFieldToModel(pos); |
1853 |
dirty = false;
|
1854 |
|
1855 |
this.fieldUp(pos);
|
1856 |
ListModel dlm = this.updateFieldsListModel(); |
1857 |
jListFieldList.setModel(dlm); |
1858 |
if (pos > 0 && dlm.getSize() > 1) { |
1859 |
this.selectedField = pos - 1; |
1860 |
jListFieldList.setSelectedIndex(pos - 1);
|
1861 |
} else {
|
1862 |
this.selectedField = pos;
|
1863 |
jListFieldList.setSelectedIndex(pos); |
1864 |
} |
1865 |
} |
1866 |
|
1867 |
if (ev.getSource() == jButDownField) {
|
1868 |
int pos = this.selectedField; |
1869 |
updateFieldToModel(pos); |
1870 |
dirty = false;
|
1871 |
|
1872 |
this.fieldDown(pos);
|
1873 |
ListModel dlm = this.updateFieldsListModel(); |
1874 |
jListFieldList.removeAll(); |
1875 |
jListFieldList.setModel(dlm); |
1876 |
int can = dlm.getSize();
|
1877 |
if (pos < can - 1 && can > 1) { |
1878 |
this.selectedField = pos + 1; |
1879 |
jListFieldList.setSelectedIndex(pos + 1);
|
1880 |
} else {
|
1881 |
jListFieldList.setSelectedIndex(pos); |
1882 |
} |
1883 |
} |
1884 |
|
1885 |
if (ev.getSource() == jChkComma) {
|
1886 |
dirty = true;
|
1887 |
} |
1888 |
|
1889 |
if (ev.getSource() == jChkDontImport) {
|
1890 |
dirty = true;
|
1891 |
} |
1892 |
|
1893 |
if (ev.getSource() == jChkJoin) {
|
1894 |
dirty = true;
|
1895 |
} |
1896 |
|
1897 |
if (ev.getSource() == jListFieldList) {
|
1898 |
dirty = true;
|
1899 |
} |
1900 |
// (jChkSemicolon)
|
1901 |
if (ev.getSource() == jChkSemicolon) {
|
1902 |
dirty = true;
|
1903 |
} |
1904 |
// (jChkSpace)
|
1905 |
if (ev.getSource() == jChkSpace) {
|
1906 |
dirty = true;
|
1907 |
} |
1908 |
// (jChkTab)
|
1909 |
if (ev.getSource() == jChkTab) {
|
1910 |
dirty = true;
|
1911 |
} |
1912 |
// (jTextFieldWidth)
|
1913 |
if (ev.getSource() == jTextFieldWidth) {
|
1914 |
boolean vali = new IntVerifier().verify(jTextFieldWidth); |
1915 |
if (vali) {
|
1916 |
dirty = true;
|
1917 |
} else {
|
1918 |
jTextFieldWidth.setText("1");
|
1919 |
dirty = true;
|
1920 |
} |
1921 |
} |
1922 |
// (jChkOther)
|
1923 |
if (ev.getSource() == jChkOther) {
|
1924 |
this.jTextOther.setEditable(this.jChkOther.isSelected()); |
1925 |
if (this.jChkOther.isSelected()) { |
1926 |
jTextOther.requestFocus(); |
1927 |
} |
1928 |
dirty = true;
|
1929 |
} |
1930 |
// (jTextOther)
|
1931 |
if (ev.getSource() == jTextOther) {
|
1932 |
dirty = true;
|
1933 |
} |
1934 |
// (jRadioString)
|
1935 |
if (ev.getSource() == jRadioString) {
|
1936 |
updateSelectors(); |
1937 |
dirty = true;
|
1938 |
} |
1939 |
// (jRadioDate)
|
1940 |
if (ev.getSource() == jRadioDate) {
|
1941 |
updateSelectors(); |
1942 |
boolean enable = this.jRadioDate.isSelected(); |
1943 |
this.jComboDate.setEnabled(enable);
|
1944 |
if (enable) {
|
1945 |
this.jComboDate.requestFocus();
|
1946 |
} |
1947 |
dirty = true;
|
1948 |
} |
1949 |
// (jRadioInteger)
|
1950 |
if (ev.getSource() == jRadioInteger) {
|
1951 |
updateSelectors(); |
1952 |
dirty = true;
|
1953 |
} |
1954 |
// (jRadioDecimal)
|
1955 |
if (ev.getSource() == jRadioDecimal) {
|
1956 |
updateSelectors(); |
1957 |
dirty = true;
|
1958 |
} |
1959 |
// (jButsave) Button Save pattern
|
1960 |
if (ev.getSource() == jButSave) {
|
1961 |
|
1962 |
int pos = this.selectedField; |
1963 |
updateFieldToModel(pos); |
1964 |
dirty = false;
|
1965 |
/* save the pattern */
|
1966 |
this.savePatternXML();
|
1967 |
} |
1968 |
// (jButLoad) Button Load pattern
|
1969 |
if (ev.getSource() == jButLoad) {
|
1970 |
/* update the model from the view */
|
1971 |
updateFieldToModel(this.selectedField);
|
1972 |
dirty = false;
|
1973 |
|
1974 |
/* load the model from xml file */
|
1975 |
NormalizationPattern pat = this.loadPatternXML();
|
1976 |
|
1977 |
/* update the panel */
|
1978 |
if (pat != null) { |
1979 |
/* save pattern in the model */
|
1980 |
this.setPattern(pat);
|
1981 |
|
1982 |
ListModel dlm = this.updateFieldsListModel(); |
1983 |
jListFieldList.setModel(dlm); |
1984 |
jListFieldList.setSelectedIndex(0);
|
1985 |
jCheckFirstRow.setSelected(pattern.getNofirstrows() != 0);
|
1986 |
if (jCheckFirstRow.isSelected()) {
|
1987 |
jTextNumberRows.setEditable(true);
|
1988 |
jTextNumberRows.setText(pattern.getNofirstrows() + "");
|
1989 |
// jTableSamples.setModel(getSourceData());
|
1990 |
} |
1991 |
dirty = false;
|
1992 |
} |
1993 |
} |
1994 |
// (jButTest) Button testing normalization
|
1995 |
if (ev.getSource() == jButTest) {
|
1996 |
/* Save elements */
|
1997 |
if (dirty == true) { |
1998 |
updateFieldToModel(jListFieldList.getSelectedIndex()); |
1999 |
} |
2000 |
/* Normalize */
|
2001 |
Object[][] data = this.normalizeSamples(); |
2002 |
String[] nam = this.getNewFieldNames(); |
2003 |
jTableTest.setModel(new DefaultTableModel(data, nam)); |
2004 |
jTableTest.getTableHeader().setReorderingAllowed(false);
|
2005 |
for (int i = 0; i < nam.length; i++) { |
2006 |
TableColumn column = jTableTest.getColumnModel().getColumn(i);
|
2007 |
column.setMinWidth(70);
|
2008 |
column.setPreferredWidth(120);
|
2009 |
} |
2010 |
} |
2011 |
// (jRadioFixed, fixed field width)
|
2012 |
if (ev.getSource() == jRadioFixed) {
|
2013 |
this.jTextFieldWidth.setEditable(true); |
2014 |
Component[] comps = this.jPanFieldSeparators.getComponents(); |
2015 |
for (int i = 0; i < comps.length; i++) { |
2016 |
comps[i].setEnabled(false);
|
2017 |
} |
2018 |
this.jTextFieldWidth.requestFocus();
|
2019 |
dirty = true;
|
2020 |
} |
2021 |
// (jRadioCharacter)
|
2022 |
if (ev.getSource() == jRadioCharacter) {
|
2023 |
this.jTextFieldWidth.setEditable(false); |
2024 |
Component[] comps = this.jPanFieldSeparators.getComponents(); |
2025 |
for (int i = 0; i < comps.length; i++) { |
2026 |
comps[i].setEnabled(true);
|
2027 |
} |
2028 |
dirty = true;
|
2029 |
} |
2030 |
} |
2031 |
|
2032 |
/**
|
2033 |
* Focus gained
|
2034 |
*/
|
2035 |
public void focusGained(FocusEvent ev) { |
2036 |
// nothing to do
|
2037 |
} |
2038 |
|
2039 |
/**
|
2040 |
* Focus lost
|
2041 |
*/
|
2042 |
public void focusLost(FocusEvent ev) { |
2043 |
// (jTextDecimal)
|
2044 |
if (ev.getSource() == jTextDecimal) {
|
2045 |
dirty = true;
|
2046 |
} |
2047 |
// (jTextTextDelimiter)
|
2048 |
if (ev.getSource() == jTextTextDelimiter) {
|
2049 |
dirty = true;
|
2050 |
} |
2051 |
// (jTextThousand)
|
2052 |
if (ev.getSource() == jTextThousand) {
|
2053 |
dirty = true;
|
2054 |
} |
2055 |
} |
2056 |
|
2057 |
/**
|
2058 |
*
|
2059 |
* @author jsanz
|
2060 |
*
|
2061 |
*/
|
2062 |
class IntVerifier extends InputVerifier { |
2063 |
|
2064 |
public boolean verify(JComponent input) { |
2065 |
try {
|
2066 |
Integer.parseInt(((JTextField) input).getText()); |
2067 |
return true; |
2068 |
} catch (NumberFormatException e) { |
2069 |
log.error("Parsing the value");
|
2070 |
return false; |
2071 |
} |
2072 |
} |
2073 |
} |
2074 |
|
2075 |
/**
|
2076 |
*
|
2077 |
* @author jsanz
|
2078 |
*
|
2079 |
*/
|
2080 |
class CharVerifier extends InputVerifier { |
2081 |
|
2082 |
public boolean verify(JComponent input) { |
2083 |
String text = ((JTextField) input).getText(); |
2084 |
if (text != null && text.length() == 1) { |
2085 |
return true; |
2086 |
} else {
|
2087 |
return false; |
2088 |
} |
2089 |
} |
2090 |
} |
2091 |
|
2092 |
/**
|
2093 |
* Set pattern
|
2094 |
*
|
2095 |
* @param pattern
|
2096 |
*/
|
2097 |
private void setPattern(NormalizationPattern pattern) { |
2098 |
this.pattern = pattern;
|
2099 |
} |
2100 |
|
2101 |
/**
|
2102 |
* This method erases a selected element to the list
|
2103 |
*
|
2104 |
* @param pos
|
2105 |
* position
|
2106 |
*/
|
2107 |
private void deleteField(int pos) { |
2108 |
int conta = pattern.getElements().size();
|
2109 |
if (conta > 1) { |
2110 |
pattern.getElements().remove(pos); |
2111 |
} |
2112 |
} |
2113 |
|
2114 |
/**
|
2115 |
* This method returns the names of the fields from the pattern
|
2116 |
*
|
2117 |
* @return new fields names
|
2118 |
*/
|
2119 |
private String[] getNewFieldNames() { |
2120 |
|
2121 |
int numFields = pattern.getElements().size();
|
2122 |
String[] res = new String[numFields]; |
2123 |
|
2124 |
for (int i = 0; i < numFields; i++) { |
2125 |
res[i] = ((Element) pattern.getElements().get(i)).getFieldname();
|
2126 |
} |
2127 |
return res;
|
2128 |
} |
2129 |
|
2130 |
/**
|
2131 |
* This method fills the GUI sample table with the samples
|
2132 |
*
|
2133 |
* @return Object[][]
|
2134 |
*/
|
2135 |
private Object[][] normalizeSamples() { |
2136 |
|
2137 |
int numFields = pattern.getElements().size();
|
2138 |
Object[][] results = new Object[NormalizationPanel.SAMPLES][numFields]; |
2139 |
|
2140 |
NormalizationAlgorithm na = new DefaultNormalizationAlgorithm(
|
2141 |
this.pattern);
|
2142 |
List<String> chains = null; |
2143 |
for (int i = 0; i < NormalizationPanel.SAMPLES; i++) { |
2144 |
chains = na.splitChain(samples[i]); |
2145 |
numFields = chains.size(); |
2146 |
for (int j = 0; j < numFields; j++) { |
2147 |
results[i][j] = chains.get(j); |
2148 |
} |
2149 |
} |
2150 |
return results;
|
2151 |
} |
2152 |
|
2153 |
/**
|
2154 |
* Get selected field
|
2155 |
*
|
2156 |
* @return
|
2157 |
*/
|
2158 |
public int getSelectedField() { |
2159 |
int sel = jComboField.getSelectedIndex();
|
2160 |
return sel;
|
2161 |
} |
2162 |
|
2163 |
// public java.awt.Dimension getMinimunPanelDimension() {
|
2164 |
// return new java.awt.Dimension(WIDTH, HEIGHT);
|
2165 |
// }
|
2166 |
} |