Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extNormalization / src / org / gvsig / normalization / gui / NormalizationPanel.java @ 29351

History | View | Annotate | Download (67.2 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.io.FileReader;
43
import java.io.FileWriter;
44
import java.io.IOException;
45
import java.io.Writer;
46
import java.text.DecimalFormatSymbols;
47
import java.util.ArrayList;
48
import java.util.Iterator;
49
import java.util.List;
50
import java.util.Locale;
51

    
52
import javax.swing.BorderFactory;
53
import javax.swing.ButtonGroup;
54
import javax.swing.DefaultComboBoxModel;
55
import javax.swing.DefaultListModel;
56
import javax.swing.ImageIcon;
57
import javax.swing.InputVerifier;
58
import javax.swing.JButton;
59
import javax.swing.JCheckBox;
60
import javax.swing.JComboBox;
61
import javax.swing.JComponent;
62
import javax.swing.JFileChooser;
63
import javax.swing.JLabel;
64
import javax.swing.JList;
65
import javax.swing.JOptionPane;
66
import javax.swing.JPanel;
67
import javax.swing.JRadioButton;
68
import javax.swing.JScrollPane;
69
import javax.swing.JTable;
70
import javax.swing.JTextField;
71
import javax.swing.ListModel;
72
import javax.swing.event.ChangeEvent;
73
import javax.swing.event.ChangeListener;
74
import javax.swing.event.ListSelectionEvent;
75
import javax.swing.event.ListSelectionListener;
76
import javax.swing.table.DefaultTableModel;
77
import javax.swing.table.TableColumn;
78
import javax.swing.table.TableModel;
79

    
80
import org.gvsig.app.daltransform.gui.components.impl.FeatureTypeAttributesCombo;
81
import org.gvsig.app.daltransform.gui.components.impl.FeatureTypeCombo;
82
import org.gvsig.app.daltransform.gui.impl.AbstractDataTransformWizardPanel;
83
import org.gvsig.fmap.dal.exception.DataException;
84
import org.gvsig.fmap.dal.feature.Feature;
85
import org.gvsig.fmap.dal.feature.FeatureSet;
86
import org.gvsig.fmap.dal.feature.FeatureStore;
87
import org.gvsig.normalization.algorithm.NormalizationAlgorithm;
88
import org.gvsig.normalization.algorithm.impl.DefaultNormalizationAlgorithm;
89
import org.gvsig.normalization.pattern.Datevalue;
90
import org.gvsig.normalization.pattern.Decimalvalue;
91
import org.gvsig.normalization.pattern.Element;
92
import org.gvsig.normalization.pattern.Fieldseparator;
93
import org.gvsig.normalization.pattern.Fieldtype;
94
import org.gvsig.normalization.pattern.Infieldseparators;
95
import org.gvsig.normalization.pattern.Integervalue;
96
import org.gvsig.normalization.pattern.Patternnormalization;
97
import org.gvsig.normalization.pattern.Stringvalue;
98
import org.gvsig.normalization.pattern.impl.DefaultDatevalue;
99
import org.gvsig.normalization.pattern.impl.DefaultDecimalvalue;
100
import org.gvsig.normalization.pattern.impl.DefaultElement;
101
import org.gvsig.normalization.pattern.impl.DefaultFieldseparator;
102
import org.gvsig.normalization.pattern.impl.DefaultFieldtype;
103
import org.gvsig.normalization.pattern.impl.DefaultInfieldseparators;
104
import org.gvsig.normalization.pattern.impl.DefaultIntegervalue;
105
import org.gvsig.normalization.pattern.impl.DefaultPatternnormalization;
106
import org.gvsig.normalization.pattern.impl.DefaultStringvalue;
107
import org.gvsig.tools.ToolsLocator;
108
import org.gvsig.tools.persistence.PersistenceException;
109
import org.gvsig.tools.persistence.PersistenceManager;
110
import org.gvsig.tools.persistence.PersistentState;
111
import org.slf4j.Logger;
112
import org.slf4j.LoggerFactory;
113

    
114
import sun.text.Normalizer;
115

    
116
import com.iver.andami.PluginServices;
117
import com.iver.utiles.GenericFileFilter;
118
import com.iver.utiles.XMLEntity;
119

    
120
/**
121
 * Normalization main panel
122
 * 
123
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
124
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
125
 */
126
public class NormalizationPanel extends AbstractDataTransformWizardPanel
127
                implements ActionListener, ChangeListener, KeyListener, MouseListener,
128
                ListSelectionListener, ItemListener, FocusListener {
129

    
130
        // ATTRIBUTES
131
        private static final long serialVersionUID = -2882235643001676017L;
132
        private static final Logger log = LoggerFactory
133
                        .getLogger(NormalizationPanel.class);
134
        private static final int SAMPLES = 3;
135
        private static final int WIDHT = 620;
136
        private static final int HEIGHT = 600;
137

    
138
        private Patternnormalization pattern;
139
        private int contador = 1;
140
        private String[] samples = new String[SAMPLES];
141
        private boolean dirty = false;
142
        private int selectedField = 0;
143
        private String oldNumRows;
144

    
145
        /* ATTRIBUTES GUI */
146
        private ButtonGroup butGroupDelimiter;
147
        private ButtonGroup butGroupFieldType;
148
        private JButton jButAddField;
149
        private JButton jButDownField;
150
        private JButton jButRemoveField;
151
        private JButton jButUpField;
152
        private JButton jButLoad;
153
        private JButton jButSave;
154
        private JButton jButTest;
155
        private JCheckBox jCheckFirstRow;
156
        private JCheckBox jChkComma;
157
        private JCheckBox jChkDontImport;
158
        private JCheckBox jChkJoin;
159
        private JCheckBox jChkOther;
160
        private JCheckBox jChkSemicolon;
161
        private JCheckBox jChkSpace;
162
        private JCheckBox jChkTab;
163
        private JComboBox jComboDate;
164
        private JLabel jLabDecimal;
165
        private JLabel jLabFieldName;
166
        private JLabel jLabTextDel;
167
        private JLabel jLabThousand;
168
        private JLabel jLabelSelFields;
169
        private JList jListFieldList;
170
        private JPanel jPanApply;
171
        private JPanel jPanFieldList;
172
        private JPanel jPanFieldName;
173
        private JPanel jPanFieldSeparators;
174
        private JPanel jPanFieldSettings;
175
        private JPanel jPanFieldType;
176
        private JPanel jPanFields;
177
        private JPanel jPanFirstRow;
178
        private JPanel jPanInField;
179
        private JPanel jPanOutputOpt;
180
        private JPanel jPanSampleOutput;
181
        private JPanel jPanSeparators;
182
        private JPanel jPanSource;
183
        private JPanel jPanel1;
184
        private JRadioButton jRadioAlterTable;
185
        private JRadioButton jRadioCharacter;
186
        private JRadioButton jRadioDate;
187
        private JRadioButton jRadioDecimal;
188
        private JRadioButton jRadioFixed;
189
        private JRadioButton jRadioInteger;
190
        private JRadioButton jRadioNewTable;
191
        private JRadioButton jRadioString;
192
        private JScrollPane jScrollPane2;
193
        private JScrollPane jScrollPaneFieldList;
194
        private JScrollPane jScrollPaneSource;
195
        private JTable jTableTest;
196
        private JTable jTableSamples;
197
        private JTextField jTextDecimal;
198
        private JTextField jTextNumberRows;
199
        private JLabel jLabelNumberRows;
200
        private JTextField jTextFieldName;
201
        private JTextField jTextFieldWidth;
202
        private JTextField jTextOther;
203
        private JTextField jTextTextDelimiter;
204
        private JTextField jTextThousand;
205
        private FeatureTypeAttributesCombo jComboField;
206
        private FeatureTypeCombo jComboFieldType;
207
        private JPanel jPanField;
208
        private JLabel jLabelFieldType;
209
        private JLabel jLabelField;
210

    
211
        /**
212
         * Constructor
213
         */
214
        public NormalizationPanel() {
215
                /* Initialize components GUI */
216
                initComponents();
217
                setMessages();
218
                setImages();
219
                // load default pattern
220
                pattern = initializeDefaultPattern();
221
                // update GUI
222
                refreshFieldsList();
223
        }
224

    
225
        /**
226
         * This method creates the components of the GUI
227
         */
228
        private void initComponents() {
229
                java.awt.GridBagConstraints gridBagConstraints;
230

    
231
                jPanField = new JPanel();
232
                jLabelField = new JLabel();
233
                jComboField = new FeatureTypeAttributesCombo();
234
                jLabelFieldType = new JLabel();
235
                jComboFieldType = new FeatureTypeCombo();
236
                butGroupDelimiter = new javax.swing.ButtonGroup();
237
                butGroupFieldType = new javax.swing.ButtonGroup();
238
                jPanSampleOutput = new javax.swing.JPanel();
239
                jScrollPane2 = new javax.swing.JScrollPane();
240
                jTableTest = new javax.swing.JTable();
241
                jPanSource = new javax.swing.JPanel();
242
                jScrollPaneSource = new javax.swing.JScrollPane();
243
                jTableSamples = new javax.swing.JTable();
244
                jPanFirstRow = new javax.swing.JPanel();
245
                jCheckFirstRow = new javax.swing.JCheckBox();
246
                jTextNumberRows = new javax.swing.JTextField();
247
                jLabelNumberRows = new javax.swing.JLabel();
248
                jPanFields = new javax.swing.JPanel();
249
                jPanFieldList = new javax.swing.JPanel();
250
                jScrollPaneFieldList = new javax.swing.JScrollPane();
251
                jListFieldList = new javax.swing.JList();
252
                jButAddField = new javax.swing.JButton();
253
                jButRemoveField = new javax.swing.JButton();
254
                jButUpField = new javax.swing.JButton();
255
                jButDownField = new javax.swing.JButton();
256
                jPanFieldSettings = new javax.swing.JPanel();
257
                jPanFieldType = new javax.swing.JPanel();
258
                jRadioString = new javax.swing.JRadioButton();
259
                jRadioInteger = new javax.swing.JRadioButton();
260
                jRadioDecimal = new javax.swing.JRadioButton();
261
                jRadioDate = new javax.swing.JRadioButton();
262
                jComboDate = new javax.swing.JComboBox();
263
                jPanSeparators = new javax.swing.JPanel();
264
                jPanFieldSeparators = new javax.swing.JPanel();
265
                jChkTab = new javax.swing.JCheckBox();
266
                jChkSpace = new javax.swing.JCheckBox();
267
                jChkComma = new javax.swing.JCheckBox();
268
                jChkSemicolon = new javax.swing.JCheckBox();
269
                jChkOther = new javax.swing.JCheckBox();
270
                jTextOther = new javax.swing.JTextField();
271
                jChkJoin = new javax.swing.JCheckBox();
272
                jRadioFixed = new javax.swing.JRadioButton();
273
                jRadioCharacter = new javax.swing.JRadioButton();
274
                jTextFieldWidth = new javax.swing.JTextField();
275
                jPanFieldName = new javax.swing.JPanel();
276
                jChkDontImport = new javax.swing.JCheckBox();
277
                jLabFieldName = new javax.swing.JLabel();
278
                jTextFieldName = new javax.swing.JTextField();
279
                jPanel1 = new javax.swing.JPanel();
280
                jPanApply = new javax.swing.JPanel();
281
                jButTest = new javax.swing.JButton();
282
                jPanInField = new javax.swing.JPanel();
283
                jLabDecimal = new javax.swing.JLabel();
284
                jTextDecimal = new javax.swing.JTextField();
285
                jLabThousand = new javax.swing.JLabel();
286
                jTextThousand = new javax.swing.JTextField();
287
                jLabTextDel = new javax.swing.JLabel();
288
                jTextTextDelimiter = new javax.swing.JTextField();
289
                jPanOutputOpt = new javax.swing.JPanel();
290
                jRadioAlterTable = new javax.swing.JRadioButton();
291
                jRadioNewTable = new javax.swing.JRadioButton();
292
                jLabelSelFields = new javax.swing.JLabel();
293
                jButLoad = new javax.swing.JButton();
294
                jButSave = new javax.swing.JButton();
295

    
296
                setMinimumSize(new java.awt.Dimension(WIDHT, HEIGHT));
297
                setPreferredSize(new java.awt.Dimension(WIDHT, HEIGHT));
298
                addFocusListener(this);
299
                setLayout(new java.awt.GridBagLayout());
300

    
301
                jPanSampleOutput.setBorder(javax.swing.BorderFactory
302
                                .createTitledBorder("Sample output"));
303
                jPanSampleOutput.setLayout(new java.awt.GridBagLayout());
304

    
305
                jScrollPane2
306
                                .setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
307
                jScrollPane2.setAutoscrolls(true);
308
                jScrollPane2.setMinimumSize(new java.awt.Dimension(100, 90));
309
                jScrollPane2.setPreferredSize(new java.awt.Dimension(100, 90));
310

    
311
                jTableTest.setFont(new java.awt.Font("Courier New", 0, 11));
312
                jTableTest.setModel(new javax.swing.table.DefaultTableModel(
313
                                new Object[][] { {}, {}, {} }, new String[] {
314

    
315
                                }));
316
                jTableTest.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
317
                jTableTest.setEnabled(false);
318
                jTableTest.setRowSelectionAllowed(false);
319
                jScrollPane2.setViewportView(jTableTest);
320

    
321
                gridBagConstraints = new java.awt.GridBagConstraints();
322
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
323
                gridBagConstraints.weightx = 1.0;
324
                gridBagConstraints.weighty = 1.0;
325
                jPanSampleOutput.add(jScrollPane2, gridBagConstraints);
326

    
327
                gridBagConstraints = new java.awt.GridBagConstraints();
328
                gridBagConstraints.gridx = 0;
329
                gridBagConstraints.gridy = 2;
330
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
331
                gridBagConstraints.weightx = 1.0;
332
                gridBagConstraints.insets = new java.awt.Insets(0, 3, 4, 3);
333
                add(jPanSampleOutput, gridBagConstraints);
334

    
335
                jPanSource.setBorder(javax.swing.BorderFactory
336
                                .createTitledBorder("Source"));
337
                jPanSource.setMinimumSize(new java.awt.Dimension(36, 125));
338
                jPanSource.setLayout(new java.awt.GridBagLayout());
339

    
340
                jScrollPaneSource.setMinimumSize(new java.awt.Dimension(100, 90));
341
                jScrollPaneSource.setPreferredSize(new java.awt.Dimension(100, 90));
342

    
343
                jPanField.setLayout(new java.awt.GridBagLayout());
344

    
345
                jLabelFieldType.setText("selectFieldType");
346
                gridBagConstraints = new java.awt.GridBagConstraints();
347
                gridBagConstraints.gridx = 0;
348
                gridBagConstraints.gridy = 0;
349
                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
350
                jPanField.add(jLabelFieldType, gridBagConstraints);
351

    
352
                jComboFieldType.setMinimumSize(new java.awt.Dimension(100, 20));
353
                gridBagConstraints = new java.awt.GridBagConstraints();
354
                gridBagConstraints.gridx = 1;
355
                gridBagConstraints.gridy = 0;
356
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
357
                gridBagConstraints.weightx = 1.0;
358
                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0);
359
                jPanField.add(jComboFieldType, gridBagConstraints);
360

    
361
                jLabelField.setText("selectField");
362
                gridBagConstraints = new java.awt.GridBagConstraints();
363
                gridBagConstraints.gridx = 0;
364
                gridBagConstraints.gridy = 1;
365
                gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 6);
366
                jPanField.add(jLabelField, gridBagConstraints);
367

    
368
                jComboField.setMinimumSize(new java.awt.Dimension(100, 20));
369
                jComboField.addActionListener(this);
370
                gridBagConstraints = new java.awt.GridBagConstraints();
371
                gridBagConstraints.gridx = 1;
372
                gridBagConstraints.gridy = 1;
373
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
374
                gridBagConstraints.weightx = 1.0;
375
                gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
376
                jPanField.add(jComboField, gridBagConstraints);
377

    
378
                gridBagConstraints = new java.awt.GridBagConstraints();
379
                gridBagConstraints.gridx = 0;
380
                gridBagConstraints.gridy = 0;
381
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
382
                gridBagConstraints.weightx = 1.0;
383
                gridBagConstraints.insets = new java.awt.Insets(1, 15, 4, 25);
384
                jPanSource.add(jPanField, gridBagConstraints);
385

    
386
                jTableSamples.setFont(new java.awt.Font("Courier New", 0, 11));
387
                jTableSamples.setModel(new DefaultTableModel());
388
                jTableSamples.getTableHeader().setReorderingAllowed(false);
389
                jTableSamples.setRowSelectionAllowed(false);
390
                jScrollPaneSource.setViewportView(jTableSamples);
391

    
392
                gridBagConstraints = new java.awt.GridBagConstraints();
393
                gridBagConstraints.gridx = 0;
394
                gridBagConstraints.gridy = 1;
395
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
396
                gridBagConstraints.weightx = 1.0;
397
                gridBagConstraints.weighty = 1.0;
398
                jPanSource.add(jScrollPaneSource, gridBagConstraints);
399

    
400
                jPanFirstRow.setLayout(new java.awt.GridBagLayout());
401

    
402
                jCheckFirstRow.setText("Don't normalize the first row");
403
                jCheckFirstRow.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
404
                jCheckFirstRow.setSelected(false);
405
                jCheckFirstRow.addActionListener(this);
406
                gridBagConstraints = new java.awt.GridBagConstraints();
407
                gridBagConstraints.gridx = 0;
408
                gridBagConstraints.gridy = 0;
409
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
410
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
411
                gridBagConstraints.insets = new java.awt.Insets(3, 10, 0, 0);
412
                jPanFirstRow.add(jCheckFirstRow, gridBagConstraints);
413

    
414
                jTextNumberRows.setText("0");
415
                jTextNumberRows.setEditable(false);
416
                jTextNumberRows.setInputVerifier(new IntVerifier());
417
                jTextNumberRows.setMaximumSize(new java.awt.Dimension(30, 18));
418
                jTextNumberRows.setMinimumSize(new java.awt.Dimension(30, 18));
419
                jTextNumberRows.setPreferredSize(new java.awt.Dimension(30, 18));
420
                jTextNumberRows.addKeyListener(this);
421
                gridBagConstraints = new java.awt.GridBagConstraints();
422
                gridBagConstraints.gridx = 1;
423
                gridBagConstraints.gridy = 0;
424
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
425
                gridBagConstraints.insets = new java.awt.Insets(2, 3, 0, 5);
426
                jPanFirstRow.add(jTextNumberRows, gridBagConstraints);
427

    
428
                jLabelNumberRows.setText("rows");
429
                jLabelNumberRows.setEnabled(false);
430
                gridBagConstraints = new java.awt.GridBagConstraints();
431
                gridBagConstraints.gridx = 2;
432
                gridBagConstraints.gridy = 0;
433
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
434
                gridBagConstraints.weightx = 1.0;
435
                gridBagConstraints.insets = new java.awt.Insets(3, 0, 0, 0);
436
                jPanFirstRow.add(jLabelNumberRows, gridBagConstraints);
437

    
438
                gridBagConstraints = new java.awt.GridBagConstraints();
439
                gridBagConstraints.gridx = 0;
440
                gridBagConstraints.gridy = 2;
441
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
442
                gridBagConstraints.weightx = 1.0;
443
                jPanSource.add(jPanFirstRow, gridBagConstraints);
444

    
445
                gridBagConstraints = new java.awt.GridBagConstraints();
446
                gridBagConstraints.gridx = 0;
447
                gridBagConstraints.gridy = 0;
448
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
449
                gridBagConstraints.weightx = 1.0;
450
                gridBagConstraints.weighty = 1.0;
451
                gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
452
                add(jPanSource, gridBagConstraints);
453

    
454
                jPanFields.setLayout(new java.awt.GridBagLayout());
455

    
456
                jPanFieldList.setBorder(javax.swing.BorderFactory
457
                                .createTitledBorder("Fields"));
458
                jPanFieldList.setLayout(new java.awt.GridBagLayout());
459

    
460
                jScrollPaneFieldList.setPreferredSize(new java.awt.Dimension(100, 150));
461

    
462
                jListFieldList
463
                                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
464
                jListFieldList.addMouseListener(this);
465
                jListFieldList.addListSelectionListener(this);
466
                jScrollPaneFieldList.setViewportView(jListFieldList);
467
                gridBagConstraints = new java.awt.GridBagConstraints();
468
                gridBagConstraints.gridx = 0;
469
                gridBagConstraints.gridy = 0;
470
                gridBagConstraints.gridheight = 4;
471
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
472
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
473
                gridBagConstraints.weightx = 1.0;
474
                gridBagConstraints.weighty = 1.0;
475
                jPanFieldList.add(jScrollPaneFieldList, gridBagConstraints);
476

    
477
                jButAddField.setBorderPainted(false);
478
                jButAddField.setMargin(new java.awt.Insets(5, 5, 5, 5));
479
                jButAddField.setMaximumSize(new java.awt.Dimension(30, 30));
480
                jButAddField.setMinimumSize(new java.awt.Dimension(30, 30));
481
                jButAddField.addActionListener(this);
482
                gridBagConstraints = new java.awt.GridBagConstraints();
483
                gridBagConstraints.gridx = 1;
484
                gridBagConstraints.gridy = 2;
485
                gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
486
                gridBagConstraints.weighty = 1.0;
487
                gridBagConstraints.insets = new java.awt.Insets(0, 2, 5, 2);
488
                jPanFieldList.add(jButAddField, gridBagConstraints);
489

    
490
                jButRemoveField.setBorderPainted(false);
491
                jButRemoveField.setMargin(new java.awt.Insets(5, 5, 5, 5));
492
                jButRemoveField.setMaximumSize(new java.awt.Dimension(30, 30));
493
                jButRemoveField.addActionListener(this);
494
                gridBagConstraints = new java.awt.GridBagConstraints();
495
                gridBagConstraints.gridx = 1;
496
                gridBagConstraints.gridy = 3;
497
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
498
                gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
499
                jPanFieldList.add(jButRemoveField, gridBagConstraints);
500

    
501
                jButUpField.setForeground(java.awt.SystemColor.activeCaptionBorder);
502
                jButUpField.setBorderPainted(false);
503
                jButUpField.setMargin(new java.awt.Insets(5, 5, 5, 5));
504
                jButUpField.setMaximumSize(new java.awt.Dimension(30, 30));
505
                jButUpField.addActionListener(this);
506
                gridBagConstraints = new java.awt.GridBagConstraints();
507
                gridBagConstraints.gridx = 1;
508
                gridBagConstraints.gridy = 0;
509
                gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
510
                gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
511
                jPanFieldList.add(jButUpField, gridBagConstraints);
512

    
513
                jButDownField.setBorderPainted(false);
514
                jButDownField.setMargin(new java.awt.Insets(5, 5, 5, 5));
515
                jButDownField.setMaximumSize(new java.awt.Dimension(30, 30));
516
                jButDownField.setMinimumSize(new java.awt.Dimension(30, 30));
517
                jButDownField.addActionListener(this);
518
                gridBagConstraints = new java.awt.GridBagConstraints();
519
                gridBagConstraints.gridx = 1;
520
                gridBagConstraints.gridy = 1;
521
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
522
                gridBagConstraints.weighty = 1.0;
523
                gridBagConstraints.insets = new java.awt.Insets(5, 2, 0, 2);
524
                jPanFieldList.add(jButDownField, gridBagConstraints);
525

    
526
                gridBagConstraints = new java.awt.GridBagConstraints();
527
                gridBagConstraints.gridx = 0;
528
                gridBagConstraints.gridy = 1;
529
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
530
                gridBagConstraints.weightx = 1.0;
531
                jPanFields.add(jPanFieldList, gridBagConstraints);
532

    
533
                jPanFieldSettings.setBorder(javax.swing.BorderFactory
534
                                .createTitledBorder("Field settings"));
535
                jPanFieldSettings.setLayout(new java.awt.GridBagLayout());
536

    
537
                jPanFieldType.setBorder(javax.swing.BorderFactory
538
                                .createTitledBorder("Select field type"));
539
                jPanFieldType.setLayout(new java.awt.GridBagLayout());
540

    
541
                butGroupFieldType.add(jRadioString);
542
                jRadioString.setSelected(true);
543
                jRadioString.setText("String");
544
                jRadioString.setAlignmentY(1.0F);
545
                jRadioString.addActionListener(this);
546
                gridBagConstraints = new java.awt.GridBagConstraints();
547
                gridBagConstraints.gridx = 0;
548
                gridBagConstraints.gridy = 0;
549
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
550
                gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3);
551
                jPanFieldType.add(jRadioString, gridBagConstraints);
552

    
553
                butGroupFieldType.add(jRadioInteger);
554
                jRadioInteger.setText("Integer");
555
                jRadioInteger.addActionListener(this);
556
                gridBagConstraints = new java.awt.GridBagConstraints();
557
                gridBagConstraints.gridx = 0;
558
                gridBagConstraints.gridy = 1;
559
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
560
                gridBagConstraints.weighty = 1.0;
561
                gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3);
562
                jPanFieldType.add(jRadioInteger, gridBagConstraints);
563

    
564
                butGroupFieldType.add(jRadioDecimal);
565
                jRadioDecimal.setText("Decimal");
566
                jRadioDecimal.addActionListener(this);
567
                gridBagConstraints = new java.awt.GridBagConstraints();
568
                gridBagConstraints.gridx = 0;
569
                gridBagConstraints.gridy = 2;
570
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
571
                gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3);
572
                jPanFieldType.add(jRadioDecimal, gridBagConstraints);
573

    
574
                butGroupFieldType.add(jRadioDate);
575
                jRadioDate.setText("Date");
576
                jRadioDate.addItemListener(this);
577
                gridBagConstraints = new java.awt.GridBagConstraints();
578
                gridBagConstraints.gridx = 0;
579
                gridBagConstraints.gridy = 3;
580
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
581
                gridBagConstraints.weighty = 1.0;
582
                gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3);
583
                jPanFieldType.add(jRadioDate, gridBagConstraints);
584

    
585
                jComboDate.setEditable(true);
586
                jComboDate.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
587
                                "dd/MM/yy", "dd/MM/yyyy", "MM/dd/yyyy", "yyyy/MM/dd",
588
                                "yy/MM/dd" }));
589
                jComboDate.setEnabled(false);
590
                jComboDate.addActionListener(this);
591
                gridBagConstraints = new java.awt.GridBagConstraints();
592
                gridBagConstraints.gridx = 0;
593
                gridBagConstraints.gridy = 4;
594
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
595
                gridBagConstraints.weightx = 1.0;
596
                gridBagConstraints.weighty = 1.0;
597
                gridBagConstraints.insets = new java.awt.Insets(0, 3, 5, 3);
598
                jPanFieldType.add(jComboDate, gridBagConstraints);
599

    
600
                gridBagConstraints = new java.awt.GridBagConstraints();
601
                gridBagConstraints.gridx = 0;
602
                gridBagConstraints.gridy = 1;
603
                gridBagConstraints.gridheight = 2;
604
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
605
                jPanFieldSettings.add(jPanFieldType, gridBagConstraints);
606

    
607
                jPanSeparators.setBorder(javax.swing.BorderFactory
608
                                .createTitledBorder("Set how field delimites with next one"));
609
                jPanSeparators.setRequestFocusEnabled(false);
610
                jPanSeparators.setLayout(new java.awt.GridBagLayout());
611

    
612
                jPanFieldSeparators.setBorder(javax.swing.BorderFactory
613
                                .createTitledBorder("Select field separators"));
614
                jPanFieldSeparators.setEnabled(false);
615
                jPanFieldSeparators.setLayout(new java.awt.GridBagLayout());
616

    
617
                jChkTab.setText("Tab");
618
                jChkTab.addActionListener(this);
619
                gridBagConstraints = new java.awt.GridBagConstraints();
620
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
621
                jPanFieldSeparators.add(jChkTab, gridBagConstraints);
622

    
623
                jChkSpace.setText("Space");
624
                jChkSpace.addActionListener(this);
625
                gridBagConstraints = new java.awt.GridBagConstraints();
626
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
627
                jPanFieldSeparators.add(jChkSpace, gridBagConstraints);
628

    
629
                jChkComma.setText("Comma");
630
                jChkComma.addActionListener(this);
631
                gridBagConstraints = new java.awt.GridBagConstraints();
632
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
633
                jPanFieldSeparators.add(jChkComma, gridBagConstraints);
634

    
635
                jChkSemicolon.setText("Semicolon");
636
                jChkSemicolon.addActionListener(this);
637
                gridBagConstraints = new java.awt.GridBagConstraints();
638
                gridBagConstraints.gridy = 1;
639
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
640
                jPanFieldSeparators.add(jChkSemicolon, gridBagConstraints);
641

    
642
                jChkOther.setText("Other");
643
                jChkOther.addActionListener(this);
644
                gridBagConstraints = new java.awt.GridBagConstraints();
645
                gridBagConstraints.gridy = 1;
646
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
647
                jPanFieldSeparators.add(jChkOther, gridBagConstraints);
648

    
649
                jTextOther.setEditable(false);
650
                jTextOther.setMinimumSize(new java.awt.Dimension(30, 20));
651
                jTextOther.setPreferredSize(new java.awt.Dimension(30, 20));
652
                jTextOther.addActionListener(this);
653
                gridBagConstraints = new java.awt.GridBagConstraints();
654
                gridBagConstraints.gridy = 1;
655
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
656
                jPanFieldSeparators.add(jTextOther, gridBagConstraints);
657

    
658
                jChkJoin.setText("Join consecutive delimiters ");
659
                jChkJoin.addActionListener(this);
660
                gridBagConstraints = new java.awt.GridBagConstraints();
661
                gridBagConstraints.gridx = 0;
662
                gridBagConstraints.gridy = 3;
663
                gridBagConstraints.gridwidth = 3;
664
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
665
                gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
666
                jPanFieldSeparators.add(jChkJoin, gridBagConstraints);
667

    
668
                gridBagConstraints = new java.awt.GridBagConstraints();
669
                gridBagConstraints.gridx = 0;
670
                gridBagConstraints.gridy = 1;
671
                gridBagConstraints.gridwidth = 3;
672
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
673
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
674
                gridBagConstraints.weighty = 1.0;
675
                jPanSeparators.add(jPanFieldSeparators, gridBagConstraints);
676

    
677
                butGroupDelimiter.add(jRadioFixed);
678
                jRadioFixed.setText("Fixed width");
679
                jRadioFixed.addActionListener(this);
680
                gridBagConstraints = new java.awt.GridBagConstraints();
681
                gridBagConstraints.gridx = 1;
682
                gridBagConstraints.gridy = 0;
683
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
684
                jPanSeparators.add(jRadioFixed, gridBagConstraints);
685

    
686
                butGroupDelimiter.add(jRadioCharacter);
687
                jRadioCharacter.setSelected(true);
688
                jRadioCharacter.setText("Character");
689
                jRadioCharacter.addActionListener(this);
690
                gridBagConstraints = new java.awt.GridBagConstraints();
691
                gridBagConstraints.gridx = 0;
692
                gridBagConstraints.gridy = 0;
693
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
694
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
695
                jPanSeparators.add(jRadioCharacter, gridBagConstraints);
696

    
697
                jTextFieldWidth.setEditable(false);
698
                jTextFieldWidth.setInputVerifier(new IntVerifier());
699
                jTextFieldWidth.setMinimumSize(new java.awt.Dimension(40, 20));
700
                jTextFieldWidth.setPreferredSize(new java.awt.Dimension(40, 20));
701
                jTextFieldWidth.addKeyListener(this);
702
                gridBagConstraints = new java.awt.GridBagConstraints();
703
                gridBagConstraints.gridx = 2;
704
                gridBagConstraints.gridy = 0;
705
                gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
706
                jPanSeparators.add(jTextFieldWidth, gridBagConstraints);
707

    
708
                gridBagConstraints = new java.awt.GridBagConstraints();
709
                gridBagConstraints.gridx = 1;
710
                gridBagConstraints.gridy = 1;
711
                gridBagConstraints.gridheight = 2;
712
                gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
713
                jPanFieldSettings.add(jPanSeparators, gridBagConstraints);
714

    
715
                jPanFieldName.setLayout(new java.awt.GridBagLayout());
716

    
717
                jChkDontImport.setText("Don't import");
718
                jChkDontImport.addActionListener(this);
719
                gridBagConstraints = new java.awt.GridBagConstraints();
720
                gridBagConstraints.gridx = 3;
721
                gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5);
722
                jPanFieldName.add(jChkDontImport, gridBagConstraints);
723

    
724
                jLabFieldName.setText("Field name:");
725
                gridBagConstraints = new java.awt.GridBagConstraints();
726
                gridBagConstraints.gridx = 0;
727
                gridBagConstraints.gridy = 0;
728
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
729
                jPanFieldName.add(jLabFieldName, gridBagConstraints);
730

    
731
                jTextFieldName.setText("Field1");
732
                jTextFieldName.setMinimumSize(new java.awt.Dimension(100, 20));
733
                jTextFieldName.setPreferredSize(new java.awt.Dimension(100, 20));
734
                jTextFieldName.addKeyListener(this);
735
                gridBagConstraints = new java.awt.GridBagConstraints();
736
                gridBagConstraints.gridx = 1;
737
                gridBagConstraints.gridy = 0;
738
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
739
                gridBagConstraints.weightx = 1.0;
740
                gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5);
741
                jPanFieldName.add(jTextFieldName, gridBagConstraints);
742

    
743
                gridBagConstraints = new java.awt.GridBagConstraints();
744
                gridBagConstraints.gridx = 0;
745
                gridBagConstraints.gridy = 0;
746
                gridBagConstraints.gridwidth = 3;
747
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
748
                gridBagConstraints.weightx = 1.0;
749
                jPanFieldSettings.add(jPanFieldName, gridBagConstraints);
750

    
751
                jPanel1.setLayout(new java.awt.GridBagLayout());
752

    
753
                jPanApply.setLayout(new java.awt.GridBagLayout());
754

    
755
                jButSave.setText("Save");
756
                jButSave.setEnabled(false);
757
                jButSave.addActionListener(this);
758
                gridBagConstraints = new java.awt.GridBagConstraints();
759
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
760
                gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
761
                gridBagConstraints.gridx = 0;
762
                gridBagConstraints.gridy = 0;
763
                jPanApply.add(jButSave, gridBagConstraints);
764

    
765
                jButLoad.setText("Load");
766
                jButLoad.setEnabled(false);
767
                jButLoad.addActionListener(this);
768
                gridBagConstraints = new java.awt.GridBagConstraints();
769
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
770
                gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
771
                gridBagConstraints.gridx = 0;
772
                gridBagConstraints.gridy = 1;
773
                jPanApply.add(jButLoad, gridBagConstraints);
774

    
775
                jButTest.setText("Test");
776
                jButTest.addActionListener(this);
777
                gridBagConstraints = new java.awt.GridBagConstraints();
778
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
779
                gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
780
                gridBagConstraints.gridx = 0;
781
                gridBagConstraints.gridy = 2;
782
                jPanApply.add(jButTest, gridBagConstraints);
783

    
784
                gridBagConstraints = new java.awt.GridBagConstraints();
785
                gridBagConstraints.gridx = 2;
786
                gridBagConstraints.gridy = 2;
787
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
788
                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
789
                jPanel1.add(jPanApply, gridBagConstraints);
790

    
791
                gridBagConstraints = new java.awt.GridBagConstraints();
792
                gridBagConstraints.gridx = 2;
793
                gridBagConstraints.gridy = 2;
794
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
795
                jPanFieldSettings.add(jPanel1, gridBagConstraints);
796

    
797
                jPanInField.setBorder(javax.swing.BorderFactory
798
                                .createTitledBorder("Set separators"));
799
                jPanInField.setLayout(new java.awt.GridBagLayout());
800

    
801
                jLabDecimal.setText("Decimal");
802
                gridBagConstraints = new java.awt.GridBagConstraints();
803
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
804
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
805
                gridBagConstraints.insets = new java.awt.Insets(5, 3, 0, 10);
806
                jPanInField.add(jLabDecimal, gridBagConstraints);
807

    
808
                jTextDecimal.setText(".");
809
                jTextDecimal.setInputVerifier(new CharVerifier());
810
                jTextDecimal.setMinimumSize(new java.awt.Dimension(30, 20));
811
                jTextDecimal.setPreferredSize(new java.awt.Dimension(30, 20));
812
                jTextDecimal.addFocusListener(this);
813
                gridBagConstraints = new java.awt.GridBagConstraints();
814
                gridBagConstraints.gridx = 1;
815
                gridBagConstraints.gridy = 0;
816
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
817
                gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 3);
818
                jPanInField.add(jTextDecimal, gridBagConstraints);
819

    
820
                jLabThousand.setText("Thousand");
821
                gridBagConstraints = new java.awt.GridBagConstraints();
822
                gridBagConstraints.gridx = 0;
823
                gridBagConstraints.gridy = 1;
824
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
825
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
826
                gridBagConstraints.insets = new java.awt.Insets(5, 3, 0, 10);
827
                jPanInField.add(jLabThousand, gridBagConstraints);
828

    
829
                jTextThousand.setText(null);
830
                jTextThousand.setPreferredSize(new java.awt.Dimension(30, 20));
831
                jTextThousand.addFocusListener(this);
832
                gridBagConstraints = new java.awt.GridBagConstraints();
833
                gridBagConstraints.gridx = 1;
834
                gridBagConstraints.gridy = 1;
835
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
836
                gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 3);
837
                jPanInField.add(jTextThousand, gridBagConstraints);
838

    
839
                jLabTextDel.setText("Text:");
840
                gridBagConstraints = new java.awt.GridBagConstraints();
841
                gridBagConstraints.gridx = 0;
842
                gridBagConstraints.gridy = 2;
843
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
844
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
845
                gridBagConstraints.insets = new java.awt.Insets(5, 3, 0, 10);
846
                jPanInField.add(jLabTextDel, gridBagConstraints);
847

    
848
                jTextTextDelimiter.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
849
                jTextTextDelimiter.setText("\"");
850
                jTextTextDelimiter.setPreferredSize(new java.awt.Dimension(30, 20));
851
                jTextTextDelimiter.addFocusListener(this);
852
                gridBagConstraints = new java.awt.GridBagConstraints();
853
                gridBagConstraints.gridx = 1;
854
                gridBagConstraints.gridy = 2;
855
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
856
                gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 3);
857
                jPanInField.add(jTextTextDelimiter, gridBagConstraints);
858

    
859
                gridBagConstraints = new java.awt.GridBagConstraints();
860
                gridBagConstraints.gridx = 2;
861
                gridBagConstraints.gridy = 1;
862
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
863
                jPanFieldSettings.add(jPanInField, gridBagConstraints);
864

    
865
                gridBagConstraints = new java.awt.GridBagConstraints();
866
                gridBagConstraints.gridx = 1;
867
                gridBagConstraints.gridy = 1;
868
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
869
                jPanFields.add(jPanFieldSettings, gridBagConstraints);
870

    
871
                gridBagConstraints = new java.awt.GridBagConstraints();
872
                gridBagConstraints.gridx = 0;
873
                gridBagConstraints.gridy = 1;
874
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
875
                gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
876
                add(jPanFields, gridBagConstraints);
877
        }
878

    
879
        /**
880
         * This method updates panel labels (Internationalization)
881
         */
882
        private void setMessages() {
883

    
884
                PluginServices ps = PluginServices.getPluginServices(this);
885

    
886
                this.setName(ps.getText("normtitle"));
887
                jPanSource.setBorder(BorderFactory.createTitledBorder(ps
888
                                .getText("normsource")));
889
                jLabelField.setText(ps.getText("selfield"));
890
                jLabelFieldType.setText(ps.getText("normselectFieldType"));
891
                jCheckFirstRow.setText(ps.getText("normfirstrows"));
892
                jLabelNumberRows.setText(ps.getText("normfirstnumberrows"));
893

    
894
                jPanFieldList.setBorder(BorderFactory.createTitledBorder(ps
895
                                .getText("normfields")));
896

    
897
                jPanFieldSettings.setBorder(BorderFactory.createTitledBorder(ps
898
                                .getText("normfieldsettings")));
899
                jLabFieldName.setText(ps.getText("normfieldname"));
900
                jChkDontImport.setText(ps.getText("normdontimport"));
901

    
902
                jPanFieldType.setBorder(BorderFactory.createTitledBorder(ps
903
                                .getText("normfieldtype")));
904
                jRadioString.setText(ps.getText("normfieldstring"));
905
                jRadioInteger.setText(ps.getText("normfieldinteger"));
906
                jRadioDecimal.setText(ps.getText("normfielddecimal"));
907
                jRadioDate.setText(ps.getText("normfielddate"));
908

    
909
                jPanSeparators.setBorder(BorderFactory.createTitledBorder(ps
910
                                .getText("normdelimetersnext")));
911
                jRadioCharacter.setText(ps.getText("normcharacter"));
912
                jRadioFixed.setText(ps.getText("normfixedwidth"));
913

    
914
                jPanFieldSeparators.setBorder(BorderFactory.createTitledBorder(ps
915
                                .getText("normfieldseparators")));
916
                jChkTab.setText(ps.getText("normtab"));
917
                jChkSpace.setText(ps.getText("normspace"));
918
                jChkComma.setText(ps.getText("normcolon"));
919
                jChkSemicolon.setText(ps.getText("normsemicolon"));
920
                jChkOther.setText(ps.getText("normother"));
921
                jChkJoin.setText(ps.getText("normjoin"));
922

    
923
                jPanInField.setBorder(BorderFactory.createTitledBorder(ps
924
                                .getText("norminfieldseparators")));
925
                jLabDecimal.setText(ps.getText("normdecimal"));
926
                jLabThousand.setText(ps.getText("normthousand"));
927
                jLabTextDel.setText(ps.getText("normtextdelimiter"));
928

    
929
                jButTest.setText(ps.getText("normtest"));
930

    
931
                jPanSampleOutput.setBorder(BorderFactory.createTitledBorder(ps
932
                                .getText("normsampleout")));
933

    
934
                jPanOutputOpt.setBorder(BorderFactory.createTitledBorder(ps
935
                                .getText("normoutputopt")));
936
                jRadioAlterTable.setText(ps.getText("normaltertable"));
937
                jRadioNewTable.setText(ps.getText("normnewtable"));
938
                jLabelSelFields.setText(ps.getText("normjoinfield"));
939

    
940
                jButLoad.setText(ps.getText("normload"));
941
                jButSave.setText(ps.getText("normsave"));
942
        }
943

    
944
        /**
945
         * This method updates the images (Icons)
946
         */
947
        private void setImages() {
948

    
949
                PluginServices ps = PluginServices.getPluginServices(this);
950

    
951
                String bDir = ps.getClassLoader().getBaseDir();
952

    
953
                jButUpField.setIcon(new ImageIcon(bDir + File.separator + "images"
954
                                + File.separator + "icons16" + File.separator + "go-up.png"));
955
                jButDownField.setIcon(new ImageIcon(bDir + File.separator + "images"
956
                                + File.separator + "icons16" + File.separator + "go-down.png"));
957
                jButAddField
958
                                .setIcon(new ImageIcon(bDir + File.separator + "images"
959
                                                + File.separator + "icons16" + File.separator
960
                                                + "list-add.png"));
961
                jButRemoveField.setIcon(new ImageIcon(bDir + File.separator + "images"
962
                                + File.separator + "icons16" + File.separator
963
                                + "list-remove.png"));
964
        }
965

    
966
        /**
967
         * This method saves a Normalization pattern to XML file *
968
         */
969
        private void savePatternXML() {
970

    
971
                JFileChooser jfc = new JFileChooser();
972
                jfc.setDialogTitle(PluginServices.getText(this, "save_norm_pattern"));
973
                String[] extensions = { "xml" };
974
                jfc.setCurrentDirectory(new File(getFolderPattern()));
975
                jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
976
                                PluginServices.getText(this, "pattern_norm_file")));
977
                int returnval = jfc.showSaveDialog((Component) PluginServices
978
                                .getMainFrame());
979

    
980
                if (returnval == JFileChooser.APPROVE_OPTION) {
981
                        File thefile = jfc.getSelectedFile();
982
                        // Check if the file has extension .xml
983
                        if (!(thefile.getPath().toLowerCase().endsWith(".xml"))) {
984
                                thefile = new File(thefile.getPath() + ".xml");
985
                        }
986
                        try {
987
                                // the file exists
988
                                if (thefile.exists()) {
989

    
990
                                        int n = JOptionPane.showConfirmDialog(null, PluginServices
991
                                                        .getText(null, "file_exists"), PluginServices
992
                                                        .getText(null, "save_norm_pattern"),
993
                                                        JOptionPane.YES_NO_OPTION);
994
                                        if (n == JOptionPane.YES_OPTION) {
995
                                                writeSaveFile(thefile);
996
                                        }
997
                                }
998
                                // the file not exists
999
                                else {
1000
                                        writeSaveFile(thefile);
1001
                                }
1002
                        } catch (Exception e) {
1003
                                log.error("Error saving the pattern", e);
1004
                        }
1005
                }
1006
        }
1007

    
1008
        /**
1009
         * Method to update GUI values with the selected column
1010
         * 
1011
         * @param id
1012
         *            column number
1013
         */
1014
        private void updateFieldToGUI(int id) {
1015

    
1016
                Element elem = this.getElement(id);
1017

    
1018
                /* name */
1019
                this.jTextFieldName.setText(elem.getFieldname());
1020

    
1021
                /* don't import */
1022
                this.jChkDontImport.setSelected(!elem.getImportfield());
1023

    
1024
                /* Update type */
1025
                Fieldtype type = elem.getFieldtype();
1026

    
1027
                if (type == null) {
1028
                        type = new DefaultFieldtype();
1029
                        type.setStringvalue(new DefaultStringvalue());
1030
                        elem.setFieldtype(type);
1031
                }
1032

    
1033
                boolean flag = false;
1034
                if (type.getDatevalue() != null) {
1035
                        jRadioDate.setSelected(true);
1036
                        String formato = type.getDatevalue().getDatevalueformat();
1037
                        DefaultComboBoxModel model = (DefaultComboBoxModel) jComboDate
1038
                                        .getModel();
1039
                        for (int i = 0; i < model.getSize(); i++) {
1040
                                String nameformato = (String) model.getElementAt(i);
1041
                                if (formato.compareToIgnoreCase(nameformato) == 0) {
1042
                                        jComboDate.setSelectedIndex(i);
1043
                                        flag = true;
1044
                                }
1045
                        }
1046
                        if (!flag) {
1047
                                model.addElement(formato);
1048
                                jComboDate.setModel(model);
1049
                                jComboDate.setSelectedItem(formato);
1050
                        }
1051
                } else if (type.getStringvalue() != null) {
1052
                        jRadioString.setSelected(true);
1053
                } else if (type.getIntegervalue() != null) {
1054
                        jRadioInteger.setSelected(true);
1055
                } else if (type.getDecimalvalue() != null) {
1056
                        jRadioDecimal.setSelected(true);
1057
                }
1058

    
1059
                /* Update field separator */
1060
                Fieldseparator seps = elem.getFieldseparator();
1061
                if (seps == null) {
1062
                        seps = this.getDefaultFieldseparators();
1063
                }
1064

    
1065
                this.jTextFieldWidth.setText(Integer.toString(elem.getFieldwidth()));
1066
                boolean isFixedWidth = elem.getFieldwidth() > 0;
1067

    
1068
                this.jRadioFixed.setSelected(isFixedWidth);
1069
                this.jRadioCharacter.setSelected(!isFixedWidth);
1070

    
1071
                if (isFixedWidth) {
1072
                        this.jTextFieldWidth.setEditable(true);
1073
                        Component[] comps = this.jPanFieldSeparators.getComponents();
1074
                        for (int i = 0; i < comps.length; i++) {
1075
                                comps[i].setEnabled(false);
1076
                        }
1077
                        this.jTextFieldWidth.requestFocus();
1078
                        dirty = true;
1079
                } else {
1080
                        this.jTextFieldWidth.setEditable(false);
1081
                        Component[] comps = this.jPanFieldSeparators.getComponents();
1082
                        for (int i = 0; i < comps.length; i++) {
1083
                                comps[i].setEnabled(true);
1084
                        }
1085
                        dirty = true;
1086
                }
1087

    
1088
                this.jChkJoin.setSelected(seps.getJoinsep());
1089

    
1090
                this.jChkTab.setSelected(seps.getTabsep());
1091

    
1092
                this.jChkSpace.setSelected(seps.getSpacesep());
1093

    
1094
                this.jChkComma.setSelected(seps.getColonsep());
1095

    
1096
                this.jChkSemicolon.setSelected(seps.getSemicolonsep());
1097

    
1098
                boolean other = seps.getOthersep() != null;
1099
                this.jChkOther.setSelected(other);
1100

    
1101
                if (other) {
1102
                        this.jTextOther.setText(seps.getOthersep());
1103
                } else {
1104
                        this.jTextOther.setEditable(false);
1105
                        this.jTextOther.setText(null);
1106
                }
1107

    
1108
                /* Update field separator */
1109

    
1110
                Infieldseparators insep = elem.getInfieldseparators();
1111
                this.jTextDecimal.setText(insep.getDecimalseparator().trim());
1112
                this.jTextThousand.setText(insep.getThousandseparator().trim());
1113
                this.jTextTextDelimiter.setText(insep.getTextseparator().trim());
1114

    
1115
                updateSelectors();
1116

    
1117
                dirty = false;
1118
        }
1119

    
1120
        /**
1121
         * Update the field values in the model
1122
         * 
1123
         * @param pos
1124
         */
1125
        private void updateFieldToModel(int pos) {
1126

    
1127
                Element elem = this.getElement(pos);
1128

    
1129
                /* name */
1130
                elem.setFieldname(this.jTextFieldName.getText());
1131

    
1132
                /* don't import */
1133
                elem.setImportfield(!this.jChkDontImport.isSelected());
1134

    
1135
                /* Update type */
1136
                Fieldtype type = new DefaultFieldtype();
1137

    
1138
                if (jRadioString.isSelected()) {
1139
                        Stringvalue strval = new DefaultStringvalue();
1140
                        strval.setStringvaluewidth(50);
1141
                        type.setStringvalue(strval);
1142
                } else if (jRadioInteger.isSelected()) {
1143
                        Integervalue intval = new DefaultIntegervalue();
1144
                        intval.setIntegervaluewidth(25);
1145
                        type.setIntegervalue(intval);
1146
                } else if (jRadioDecimal.isSelected()) {
1147
                        Decimalvalue dec = new DefaultDecimalvalue();
1148
                        /* DECIMALES = 10 */
1149
                        dec.setDecimalvaluedec(10);
1150
                        dec.setDecimalvalueint(25);
1151
                        type.setDecimalvalue(dec);
1152
                } else {
1153
                        Datevalue date = new DefaultDatevalue();
1154
                        String form = jComboDate.getSelectedItem().toString();
1155
                        date.setDatevalueformat(form);
1156
                        type.setDatevalue(date);
1157
                }
1158
                elem.setFieldtype(type);
1159

    
1160
                /* Update field separator */
1161
                Fieldseparator seps = elem.getFieldseparator();
1162

    
1163
                if (elem.getFieldseparator() == null) {
1164
                        seps = new DefaultFieldseparator();
1165
                }
1166

    
1167
                boolean isFixedWidth = this.jRadioFixed.isSelected();
1168
                int val;
1169
                if (isFixedWidth) {
1170
                        try {
1171
                                val = Integer.parseInt(jTextFieldWidth.getText());
1172
                                elem.setFieldwidth(val);
1173
                        } catch (Exception e) {
1174
                                jTextFieldWidth.requestFocus();
1175
                        }
1176

    
1177
                } else {
1178
                        elem.setFieldwidth(0);
1179
                }
1180

    
1181
                seps.setJoinsep(this.jChkJoin.isSelected());
1182
                seps.setSpacesep(this.jChkSpace.isSelected());
1183
                seps.setColonsep(this.jChkComma.isSelected());
1184
                seps.setSemicolonsep(this.jChkSemicolon.isSelected());
1185
                seps.setTabsep(this.jChkTab.isSelected());
1186

    
1187
                if (jChkOther.isSelected() && jTextOther.getText().length() == 1) {
1188
                        seps.setOthersep(jTextOther.getText().trim());
1189
                } else {
1190
                        seps.setOthersep(null);
1191
                }
1192

    
1193
                /* Update In-field separator */
1194
                Infieldseparators inseps = elem.getInfieldseparators();
1195

    
1196
                if (elem.getInfieldseparators() == null) {
1197
                        inseps = new DefaultInfieldseparators();
1198
                }
1199

    
1200
                inseps.setThousandseparator(this.jTextThousand.getText().trim());
1201
                inseps.setDecimalseparator(this.jTextDecimal.getText().trim());
1202
                inseps.setTextseparator(this.jTextTextDelimiter.getText().trim());
1203
        }
1204

    
1205
        /**
1206
         * Update fields list
1207
         */
1208
        private void refreshFieldsList() {
1209
                /* Fields List */
1210
                jListFieldList.setModel(this.updateFieldsListModel());
1211
                jListFieldList.setSelectedIndex(0);
1212
        }
1213

    
1214
        /**
1215
         * Update the in-separators
1216
         */
1217
        private void updateSelectors() {
1218
                boolean isDecimal = false;
1219
                boolean isThousand = false;
1220
                boolean isText = false;
1221
                if (this.jRadioString.isSelected()) {
1222
                        isText = true;
1223
                } else if (this.jRadioInteger.isSelected()) {
1224
                        isThousand = true;
1225
                } else if (this.jRadioDecimal.isSelected()) {
1226
                        isThousand = true;
1227
                        isDecimal = true;
1228
                } else if (this.jRadioDate.isSelected()) {
1229

    
1230
                }
1231
                this.jTextDecimal.setEditable(isDecimal);
1232
                this.jTextThousand.setEditable(isThousand);
1233
                this.jTextTextDelimiter.setEditable(isText);
1234
        }
1235

    
1236
        /**
1237
         * This method creates the model of the names FieldList
1238
         * 
1239
         * @return list model
1240
         */
1241
        private ListModel updateFieldsListModel() {
1242
                ListModel dlmodel = new DefaultListModel();
1243
                Element[] adr = pattern.getArrayElements();
1244
                String name = "";
1245
                for (int i = 0; i < adr.length; i++) {
1246
                        name = adr[i].getFieldname();
1247
                        ((DefaultListModel) dlmodel).add(i, name);
1248
                }
1249
                return dlmodel;
1250
        }
1251

    
1252
        /**
1253
         * Build model of the table of samples
1254
         * 
1255
         * @return table model
1256
         * @throws DataException
1257
         */
1258
        private TableModel getSamplesDataStore(FeatureStore store, int field,
1259
                        int noRows) throws DataException {
1260

    
1261
                FeatureSet features = store.getFeatureSet();
1262
                Iterator<Feature> it = features.iterator(noRows);
1263
                int contador = 0;
1264
                while (it.hasNext()) {
1265
                        Feature feature = (Feature) it.next();
1266
                        if (contador < SAMPLES) {
1267
                                String sample = feature.get(field).toString();
1268
                                samples[contador] = sample;
1269
                                contador++;
1270
                        }
1271
                }
1272
                // String samples
1273
                Object[][] data = new Object[samples.length][1];
1274
                for (int i = 0; i < samples.length; i++) {
1275
                        data[i][0] = samples[i];
1276
                }
1277
                // table field name
1278
                String fieldname = getFeatureStore().getDefaultFeatureType()
1279
                                .getAttributeDescriptor(field).getName();
1280
                String[] names = { fieldname };
1281
                TableModel tablemodel = new DefaultTableModel(data, names) {
1282

    
1283
                        private static final long serialVersionUID = -7429493540158414622L;
1284

    
1285
                        public boolean isCellEditable(int rowIndex, int columnIndex) {
1286
                                return false;
1287
                        }
1288
                };
1289
                return tablemodel;
1290
        }
1291

    
1292
        /**
1293
         * This method up the selected element one position in the list of Elements
1294
         * 
1295
         * @param pos
1296
         */
1297
        private void fieldUp(int pos) {
1298
                int nu = pattern.getElements().size();
1299
                if (pos > 0 && nu > 1) {
1300
                        int newpos = pos - 1;
1301
                        Element[] ad = pattern.getArrayElements();
1302
                        Element ele21 = ad[pos];
1303
                        Element ele12 = ad[newpos];
1304
                        ad[newpos] = ele21;
1305
                        ad[pos] = ele12;
1306
                        List<Element> elems = new ArrayList<Element>();
1307
                        for (int i = 0; i < ad.length; i++) {
1308
                                elems.add(ad[i]);
1309
                        }
1310
                        pattern.setElements(elems);
1311
                }
1312
        }
1313

    
1314
        /**
1315
         * This method adds a new element to the pattern
1316
         */
1317
        private void addField() {
1318
                contador++;
1319
                int tam = pattern.getElements().size();
1320
                Element eleme = new DefaultElement();
1321
                Fieldseparator fsep = new DefaultFieldseparator();
1322
                fsep.setSemicolonsep(true);
1323
                fsep.setJoinsep(false);
1324
                fsep.setColonsep(false);
1325
                fsep.setSpacesep(false);
1326
                fsep.setTabsep(false);
1327
                String nam = "";
1328
                boolean isOkName = true;
1329
                do {
1330
                        isOkName = true;
1331
                        nam = "NewField" + contador;
1332
                        for (int i = 0; i < tam; i++) {
1333
                                String napat = ((Element) pattern.getElements().get(i))
1334
                                                .getFieldname();
1335
                                if (napat.compareToIgnoreCase(nam) == 0) {
1336
                                        isOkName = false;
1337
                                        break;
1338
                                }
1339
                        }
1340
                        if (!isOkName) {
1341
                                contador++;
1342
                        }
1343
                } while (!isOkName);
1344
                // validate the new field name
1345
                String vname = validateFieldName(nam);
1346
                eleme.setFieldname(vname);
1347
                eleme.setFieldseparator(fsep);
1348
                eleme.setInfieldseparators(getDefaultInfieldseparators());
1349
                eleme.setFieldtype(getDefaultNewFieldType());
1350
                eleme.setFieldwidth(0);
1351
                eleme.setImportfield(true);
1352
                List<Element> elems = pattern.getElements();
1353
                elems.add(tam, eleme);
1354
        }
1355

    
1356
        /**
1357
         * This method loads a Normalization pattern from a XML file and return the
1358
         * pattern and the String info
1359
         * 
1360
         * @return pattern
1361
         */
1362
        private Patternnormalization loadPatternXML() {
1363

    
1364
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
1365
                Patternnormalization pat = new DefaultPatternnormalization();
1366
                File thefile = null;
1367
                // Show the FileChooser to select a pattern
1368
                JFileChooser jfc = new JFileChooser();
1369
                jfc.setCurrentDirectory(new File(getFolderPattern()));
1370
                jfc.setDialogTitle(PluginServices.getText(this, "load_norm_pattern"));
1371
                String[] extensions = { "xml" };
1372
                jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
1373
                                PluginServices.getText(this, "pattern_norm_file")));
1374

    
1375
                int returnval = jfc.showOpenDialog((Component) PluginServices
1376
                                .getMainFrame());
1377

    
1378
                if (returnval == JFileChooser.APPROVE_OPTION) {
1379
                        thefile = jfc.getSelectedFile();
1380
                } else {
1381
                        return null;
1382
                }
1383

    
1384
                FileReader reader = null;
1385
                PersistentState state = null;
1386
                try {
1387
                        reader = new FileReader(thefile);
1388
                        state = manager.loadState(reader);
1389
                        pat.loadFromState(state);
1390
                        reader.close();
1391
                } catch (Exception e) {
1392
                        log.error("Error loading the pattern", e);
1393
                        return null;
1394
                }
1395
                return pat;
1396
        }
1397

    
1398
        /**
1399
         * This method down the selected element one position in the list of
1400
         * Elements
1401
         * 
1402
         * @param pos
1403
         */
1404
        private void fieldDown(int pos) {
1405
                int nu = pattern.getElements().size();
1406
                if (pos != (nu - 1) && nu > 1) {
1407
                        int newpos = pos + 1;
1408
                        Element[] ad = pattern.getArrayElements();
1409
                        Element ele21 = ad[pos];
1410
                        Element ele12 = ad[newpos];
1411
                        ad[newpos] = ele21;
1412
                        ad[pos] = ele12;
1413
                        List<Element> elems = new ArrayList<Element>();
1414
                        for (int i = 0; i < ad.length; i++) {
1415
                                elems.add(ad[i]);
1416
                        }
1417
                        pattern.setElements(elems);
1418
                }
1419
        }
1420

    
1421
        /**
1422
         * This method validates the name of a new field
1423
         * 
1424
         * @param text
1425
         * @return field name formatted
1426
         */
1427
        private String validateFieldName(String text) {
1428
                String temp = Normalizer.normalize(text, Normalizer.DECOMP, 0);
1429
                temp = temp.replaceAll("[^\\p{ASCII}]", "");
1430
                temp = temp.replaceAll("[\\s]+", "_");
1431
                temp = temp.toUpperCase();
1432
                return temp;
1433
        }
1434

    
1435
        /**
1436
         * This method return the folder where gvSIG stores the patterns
1437
         * 
1438
         * @return
1439
         */
1440
        private String getFolderPattern() {
1441
                XMLEntity xml = PluginServices.getPluginServices(this)
1442
                                .getPersistentXML();
1443
                String pathFolder = String.valueOf(xml
1444
                                .getStringProperty("Normalization_pattern_folder"));
1445
                return pathFolder;
1446
        }
1447

    
1448
        /**
1449
         * This method write the save xml file
1450
         * 
1451
         * @param file
1452
         * @throws IOException
1453
         * @throws PersistenceException
1454
         */
1455
        private void writeSaveFile(File thefile) throws IOException,
1456
                        PersistenceException {
1457
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
1458
                pattern.setPatternname(thefile.getName());
1459
                Writer writer = new FileWriter(thefile);
1460
                PersistentState state = manager.getState(pattern);
1461
                state.save(writer);
1462
                writer.close();
1463
        }
1464

    
1465
        /**
1466
         * This method generates and returns in field separators
1467
         * 
1468
         * @return special characters within one string
1469
         */
1470
        private Infieldseparators getDefaultInfieldseparators() {
1471
                /* create the default in-field separators */
1472
                Locale loc = Locale.getDefault();
1473
                DecimalFormatSymbols dfs = new DecimalFormatSymbols(loc);
1474
                Infieldseparators infilsep = new DefaultInfieldseparators();
1475
                infilsep.setThousandseparator(Character.toString(dfs
1476
                                .getGroupingSeparator()));
1477
                infilsep.setDecimalseparator(Character.toString(dfs
1478
                                .getDecimalSeparator()));
1479
                infilsep.setTextseparator("\"");
1480
                return infilsep;
1481
        }
1482

    
1483
        /**
1484
         * This method generates and returns a new field type of type Stringvalue
1485
         * 
1486
         * @return field type
1487
         */
1488
        private Fieldtype getDefaultNewFieldType() {
1489
                Fieldtype newtype = new DefaultFieldtype();
1490
                Stringvalue strval = new DefaultStringvalue();
1491
                strval.setStringvaluewidth(50);
1492
                newtype.setStringvalue(strval);
1493
                return newtype;
1494
        }
1495

    
1496
        /**
1497
         * This method returns a Element of one position
1498
         * 
1499
         * @param index
1500
         * @return
1501
         */
1502
        private Element getElement(int index) {
1503
                Element[] adrs = pattern.getArrayElements();
1504
                return adrs[index];
1505
        }
1506

    
1507
        /**
1508
         * This method generates and returns field separators
1509
         * 
1510
         * @return default separators between fields
1511
         */
1512
        private Fieldseparator getDefaultFieldseparators() {
1513
                Fieldseparator filsep = new DefaultFieldseparator();
1514
                filsep.setSemicolonsep(true);
1515
                filsep.setJoinsep(false);
1516
                filsep.setColonsep(false);
1517
                filsep.setSpacesep(false);
1518
                filsep.setTabsep(false);
1519
                return filsep;
1520
        }
1521

    
1522
        /**
1523
         * This method creates the default Normalization pattern
1524
         * 
1525
         * @return pattern
1526
         */
1527
        private Patternnormalization initializeDefaultPattern() {
1528
                Patternnormalization pat = new DefaultPatternnormalization();
1529
                pat.setPatternname("defaultPattern");
1530
                pat.setNofirstrows(0);
1531
                /* Create the first Address Element */
1532
                Element elem = new DefaultElement();
1533
                elem.setFieldname("NewField");
1534
                elem.setFieldseparator(getDefaultFieldseparators());
1535
                elem.setInfieldseparators(getDefaultInfieldseparators());
1536
                elem.setFieldtype(getDefaultNewFieldType());
1537
                elem.setFieldwidth(0);
1538
                elem.setImportfield(true);
1539
                List<Element> elems = new ArrayList<Element>();
1540
                elems.add(elem);
1541
                pat.setElements(elems);
1542
                return pat;
1543
        }
1544

    
1545
        /**
1546
         * @return the pattern
1547
         */
1548
        protected Patternnormalization getPattern() {
1549
                return pattern;
1550
        }
1551

    
1552
        /**
1553
         * This method is called when the panel is displayed
1554
         */
1555
        public void updatePanel() {
1556
                FeatureStore store = getFeatureStore();
1557
                jComboFieldType.addFeatureStore(store);
1558
                try {
1559
                        if (store.getFeatureTypes().size() == 1) {
1560
                                jComboFieldType.setEnabled(false);
1561
                        }
1562
                } catch (DataException e1) {
1563
                        e1.printStackTrace();
1564
                }
1565

    
1566
                Object obj = jComboFieldType.getSelectedItem();
1567
                if (obj != null) {
1568
                        jComboField.addFeatureAttributes(jComboFieldType
1569
                                        .getSelectedFeatureType());
1570
                }
1571

    
1572
                Object obj1 = jComboField.getSelectedItem();
1573
                if (obj1 != null) {
1574
                        TableModel model = null;
1575
                        try {
1576
                                model = getSamplesDataStore(store, 0, 0);
1577
                        } catch (DataException e) {
1578
                                log.error("Error reading data store", e);
1579
                                model = new DefaultTableModel();
1580
                        }
1581
                        jTableSamples.setModel(model);
1582
                }
1583
        }
1584

    
1585
        /**
1586
         * State Changed
1587
         */
1588
        public void stateChanged(ChangeEvent ev) {
1589

    
1590
        }
1591

    
1592
        /**
1593
         * Key pressed
1594
         */
1595
        public void keyPressed(KeyEvent ev) {
1596
                if (ev.getSource() == jTextNumberRows) {
1597
                        oldNumRows = jTextNumberRows.getText().trim();
1598
                }
1599
        }
1600

    
1601
        /**
1602
         * Key released
1603
         */
1604
        public void keyReleased(KeyEvent ev) {
1605

    
1606
                FeatureStore store = getFeatureStore();
1607
                // Change number no rows (jTextNumberRows)
1608
                if (ev.getSource() == jTextNumberRows) {
1609
                        int selfield = jComboField.getSelectedIndex();
1610
                        try {
1611
                                int norows = (new Integer(jTextNumberRows.getText()))
1612
                                                .intValue();
1613
                                TableModel model = getSamplesDataStore(store, selfield, norows);
1614
                                jTableSamples.setModel(model);
1615
                                jTableSamples.validate();
1616
                        } catch (Exception e) {
1617
                                jTextNumberRows.setText(oldNumRows);
1618
                                jTextNumberRows.requestFocus();
1619
                        }
1620
                }
1621
                // (jTextFieldWidth)
1622
                if (ev.getSource() == jTextFieldWidth) {
1623
                        boolean vali = new IntVerifier().verify(jTextFieldWidth);
1624
                        if (vali) {
1625
                                dirty = true;
1626
                        } else {
1627
                                jTextFieldWidth.setText("1");
1628
                                dirty = true;
1629
                        }
1630
                }
1631
                // (jTextFieldName)
1632
                if ((ev.getSource() == jTextFieldName)) {
1633
                        int pos = this.selectedField;
1634
                        updateFieldToModel(pos);
1635
                        refreshFieldsList();
1636
                        dirty = false;
1637
                }
1638

    
1639
        }
1640

    
1641
        /**
1642
 * 
1643
 */
1644
        public void keyTyped(KeyEvent ev) {
1645

    
1646
        }
1647

    
1648
        /**
1649
 * 
1650
 */
1651
        public void mouseClicked(MouseEvent ev) {
1652

    
1653
        }
1654

    
1655
        /**
1656
 * 
1657
 */
1658
        public void mouseEntered(MouseEvent ev) {
1659

    
1660
        }
1661

    
1662
        /**
1663
 * 
1664
 */
1665
        public void mouseExited(MouseEvent ev) {
1666

    
1667
        }
1668

    
1669
        /**
1670
 * 
1671
 */
1672
        public void mousePressed(MouseEvent ev) {
1673
                // (jListFieldList)
1674
                if (ev.getSource() == jListFieldList) {
1675
                        selectedField = jListFieldList.getSelectedIndex();
1676
                }
1677
        }
1678

    
1679
        /**
1680
 * 
1681
 */
1682
        public void mouseReleased(MouseEvent ev) {
1683

    
1684
        }
1685

    
1686
        /**
1687
 * 
1688
 */
1689
        public void valueChanged(ListSelectionEvent ev) {
1690
                // (jListFieldList)
1691
                if (ev.getSource() == jListFieldList) {
1692
                        /* Save the parameters in the model */
1693
                        boolean sucio = dirty;
1694
                        if (sucio) {
1695
                                updateFieldToModel(this.selectedField);
1696
                        }
1697
                        if (!ev.getValueIsAdjusting()) {
1698
                                int pos = this.selectedField;
1699
                                updateFieldToGUI(pos);
1700
                                jListFieldList.setSelectedIndex(pos);
1701
                        }
1702
                        dirty = false;
1703
                }
1704
        }
1705

    
1706
        /**
1707
 * 
1708
 */
1709
        public void itemStateChanged(ItemEvent ev) {
1710
                // (jRadioDate)
1711
                if (ev.getSource() == jRadioDate) {
1712
                        updateSelectors();
1713
                        boolean enable = this.jRadioDate.isSelected();
1714
                        this.jComboDate.setEnabled(enable);
1715
                        if (enable) {
1716
                                this.jComboDate.requestFocus();
1717
                        }
1718
                        dirty = true;
1719
                }
1720

    
1721
        }
1722

    
1723
        /**
1724
         * 
1725
         */
1726
        public void actionPerformed(ActionEvent ev) {
1727

    
1728
                if (ev.getSource() == jComboField) {
1729
                        FeatureStore store = getFeatureStore();
1730
                        if (store != null) {
1731
                                Object obj1 = jComboField.getSelectedItem();
1732
                                if (obj1 != null) {
1733
                                        TableModel model = null;
1734
                                        try {
1735
                                                int item = jComboField.getSelectedIndex();
1736
                                                if (jCheckFirstRow.isSelected()) {
1737
                                                        int norows = (new Integer(jTextNumberRows.getText()))
1738
                                                                        .intValue();
1739
                                                        model = getSamplesDataStore(store, item, norows);
1740
                                                        jLabelNumberRows.setEnabled(true);
1741
                                                        jCheckFirstRow.setSelected(false);
1742
                                                        jTextNumberRows.setText("0");
1743
                                                        jTextNumberRows.setEnabled(false);
1744
                                                        jLabelNumberRows.setEnabled(false);
1745
                                                } else {
1746
                                                        model = getSamplesDataStore(store, item, 0);
1747
                                                        jLabelNumberRows.setEnabled(false);
1748
                                                }
1749

    
1750
                                        } catch (DataException e) {
1751
                                                log.error("Error reading data store", e);
1752
                                                model = new DefaultTableModel();
1753
                                        }
1754
                                        jTableSamples.setModel(model);
1755
                                }
1756
                        }
1757
                }
1758

    
1759
                if (ev.getSource() == jCheckFirstRow) {
1760
                        FeatureStore store = getFeatureStore();
1761
                        /* DON'T Normalize the first rows */
1762
                        if (jCheckFirstRow.isSelected()) {
1763
                                jTextNumberRows.setText("1");
1764
                                jTextNumberRows.setEditable(true);
1765
                                this.jTextNumberRows.requestFocus();
1766

    
1767
                                Object obj1 = jComboField.getSelectedItem();
1768
                                if (obj1 != null) {
1769
                                        TableModel model = null;
1770
                                        try {
1771
                                                int item = jComboField.getSelectedIndex();
1772
                                                model = getSamplesDataStore(store, item, 1);
1773
                                                jLabelNumberRows.setEnabled(true);
1774
                                                jTextNumberRows.setEnabled(true);
1775
                                        } catch (DataException e) {
1776
                                                log.error("Error reading data store", e);
1777
                                                model = new DefaultTableModel();
1778
                                                jLabelNumberRows.setEnabled(false);
1779
                                                jTextNumberRows.setEnabled(false);
1780
                                        }
1781
                                        jTableSamples.setModel(model);
1782
                                }
1783
                        }
1784
                        /* Normalize all rows */
1785
                        else {
1786
                                jTextNumberRows.setText("0");
1787
                                jTextNumberRows.setEditable(false);
1788
                                Object obj2 = jComboField.getSelectedItem();
1789
                                if (obj2 != null) {
1790
                                        TableModel model = null;
1791
                                        try {
1792
                                                int item = jComboField.getSelectedIndex();
1793
                                                model = getSamplesDataStore(store, item, 0);
1794
                                        } catch (DataException e) {
1795
                                                log.error("Error reading data store", e);
1796
                                                model = new DefaultTableModel();
1797
                                        }
1798
                                        jTableSamples.setModel(model);
1799
                                        jLabelNumberRows.setEnabled(false);
1800
                                }
1801
                        }
1802

    
1803
                }
1804

    
1805
                if (ev.getSource() == jButAddField) {
1806
                        int pos = this.selectedField;
1807
                        updateFieldToModel(pos);
1808
                        dirty = false;
1809

    
1810
                        this.addField();
1811
                        ListModel dlm = this.updateFieldsListModel();
1812
                        int siz = ((DefaultListModel) dlm).size();
1813
                        this.selectedField = siz - 1;
1814
                        jListFieldList.setModel(dlm);
1815
                        jListFieldList.setSelectedIndex(siz - 1);
1816
                        jTextOther.setEditable(false);
1817
                }
1818

    
1819
                if (ev.getSource() == jButRemoveField) {
1820
                        int siz = jListFieldList.getModel().getSize();
1821
                        int pos = this.selectedField;
1822
                        if (siz > 0) {
1823
                                updateFieldToModel(pos);
1824
                                dirty = false;
1825
                                this.deleteField(pos);
1826
                                ListModel dlm = this.updateFieldsListModel();
1827
                                if (pos > 0) {
1828
                                        this.selectedField = pos - 1;
1829
                                        jListFieldList.setModel(dlm);
1830
                                        jListFieldList.setSelectedIndex(pos - 1);
1831
                                } else {
1832
                                        this.selectedField = pos;
1833
                                        jListFieldList.setModel(dlm);
1834
                                        jListFieldList.setSelectedIndex(pos);
1835
                                }
1836
                        }
1837
                }
1838

    
1839
                if (ev.getSource() == jButUpField) {
1840
                        int pos = this.selectedField;
1841
                        updateFieldToModel(pos);
1842
                        dirty = false;
1843

    
1844
                        this.fieldUp(pos);
1845
                        ListModel dlm = this.updateFieldsListModel();
1846
                        jListFieldList.setModel(dlm);
1847
                        if (pos > 0 && dlm.getSize() > 1) {
1848
                                this.selectedField = pos - 1;
1849
                                jListFieldList.setSelectedIndex(pos - 1);
1850
                        } else {
1851
                                this.selectedField = pos;
1852
                                jListFieldList.setSelectedIndex(pos);
1853
                        }
1854
                }
1855

    
1856
                if (ev.getSource() == jButDownField) {
1857
                        int pos = this.selectedField;
1858
                        updateFieldToModel(pos);
1859
                        dirty = false;
1860

    
1861
                        this.fieldDown(pos);
1862
                        ListModel dlm = this.updateFieldsListModel();
1863
                        jListFieldList.removeAll();
1864
                        jListFieldList.setModel(dlm);
1865
                        int can = dlm.getSize();
1866
                        if (pos < can - 1 && can > 1) {
1867
                                this.selectedField = pos + 1;
1868
                                jListFieldList.setSelectedIndex(pos + 1);
1869
                        } else {
1870
                                jListFieldList.setSelectedIndex(pos);
1871
                        }
1872
                }
1873

    
1874
                if (ev.getSource() == jChkComma) {
1875
                        dirty = true;
1876
                }
1877

    
1878
                if (ev.getSource() == jChkDontImport) {
1879
                        dirty = true;
1880
                }
1881

    
1882
                if (ev.getSource() == jChkJoin) {
1883
                        dirty = true;
1884
                }
1885

    
1886
                if (ev.getSource() == jListFieldList) {
1887
                        dirty = true;
1888
                }
1889
                // (jChkSemicolon)
1890
                if (ev.getSource() == jChkSemicolon) {
1891
                        dirty = true;
1892
                }
1893
                // (jChkSpace)
1894
                if (ev.getSource() == jChkSpace) {
1895
                        dirty = true;
1896
                }
1897
                // (jChkTab)
1898
                if (ev.getSource() == jChkTab) {
1899
                        dirty = true;
1900
                }
1901
                // (jTextFieldWidth)
1902
                if (ev.getSource() == jTextFieldWidth) {
1903
                        boolean vali = new IntVerifier().verify(jTextFieldWidth);
1904
                        if (vali) {
1905
                                dirty = true;
1906
                        } else {
1907
                                jTextFieldWidth.setText("1");
1908
                                dirty = true;
1909
                        }
1910
                }
1911
                // (jChkOther)
1912
                if (ev.getSource() == jChkOther) {
1913
                        this.jTextOther.setEditable(this.jChkOther.isSelected());
1914
                        if (this.jChkOther.isSelected()) {
1915
                                jTextOther.requestFocus();
1916
                        }
1917
                        dirty = true;
1918
                }
1919
                // (jTextOther)
1920
                if (ev.getSource() == jTextOther) {
1921
                        dirty = true;
1922
                }
1923
                // (jRadioString)
1924
                if (ev.getSource() == jRadioString) {
1925
                        updateSelectors();
1926
                        dirty = true;
1927
                }
1928
                // (jRadioDate)
1929
                if (ev.getSource() == jRadioDate) {
1930
                        updateSelectors();
1931
                        boolean enable = this.jRadioDate.isSelected();
1932
                        this.jComboDate.setEnabled(enable);
1933
                        if (enable) {
1934
                                this.jComboDate.requestFocus();
1935
                        }
1936
                        dirty = true;
1937
                }
1938
                // (jRadioInteger)
1939
                if (ev.getSource() == jRadioInteger) {
1940
                        updateSelectors();
1941
                        dirty = true;
1942
                }
1943
                // (jRadioDecimal)
1944
                if (ev.getSource() == jRadioDecimal) {
1945
                        updateSelectors();
1946
                        dirty = true;
1947
                }
1948
                // (jButsave) Button Save pattern
1949
                if (ev.getSource() == jButSave) {
1950

    
1951
                        int pos = this.selectedField;
1952
                        updateFieldToModel(pos);
1953
                        dirty = false;
1954
                        /* save the pattern */
1955
                        this.savePatternXML();
1956
                }
1957
                // (jButLoad) Button Load pattern
1958
                if (ev.getSource() == jButLoad) {
1959
                        /* update the model from the view */
1960
                        updateFieldToModel(this.selectedField);
1961
                        dirty = false;
1962

    
1963
                        /* load the model from xml file */
1964
                        Patternnormalization pat = this.loadPatternXML();
1965

    
1966
                        /* update the panel */
1967
                        if (pat != null) {
1968
                                /* save pattern in the model */
1969
                                this.setPattern(pat);
1970

    
1971
                                ListModel dlm = this.updateFieldsListModel();
1972
                                jListFieldList.setModel(dlm);
1973
                                jListFieldList.setSelectedIndex(0);
1974
                                jCheckFirstRow.setSelected(pattern.getNofirstrows() != 0);
1975
                                if (jCheckFirstRow.isSelected()) {
1976
                                        jTextNumberRows.setEditable(true);
1977
                                        jTextNumberRows.setText(pattern.getNofirstrows() + "");
1978
                                        // jTableSamples.setModel(getSourceData());
1979
                                }
1980
                                dirty = false;
1981
                        }
1982
                }
1983
                // (jButTest) Button testing normalization
1984
                if (ev.getSource() == jButTest) {
1985
                        /* Save elements */
1986
                        if (dirty == true) {
1987
                                updateFieldToModel(jListFieldList.getSelectedIndex());
1988
                        }
1989
                        /* Normalize */
1990
                        Object[][] data = this.normalizeSamples();
1991
                        String[] nam = this.getNewFieldNames();
1992
                        jTableTest.setModel(new DefaultTableModel(data, nam));
1993
                        jTableTest.setDragEnabled(false);
1994
                        for (int i = 0; i < nam.length; i++) {
1995
                                TableColumn column = jTableTest.getColumnModel().getColumn(i);
1996
                                column.setMinWidth(70);
1997
                                column.setPreferredWidth(120);
1998
                        }
1999
                }
2000
                // (jRadioFixed, fixed field width)
2001
                if (ev.getSource() == jRadioFixed) {
2002
                        this.jTextFieldWidth.setEditable(true);
2003
                        Component[] comps = this.jPanFieldSeparators.getComponents();
2004
                        for (int i = 0; i < comps.length; i++) {
2005
                                comps[i].setEnabled(false);
2006
                        }
2007
                        this.jTextFieldWidth.requestFocus();
2008
                        dirty = true;
2009
                }
2010
                // (jRadioCharacter)
2011
                if (ev.getSource() == jRadioCharacter) {
2012
                        this.jTextFieldWidth.setEditable(false);
2013
                        Component[] comps = this.jPanFieldSeparators.getComponents();
2014
                        for (int i = 0; i < comps.length; i++) {
2015
                                comps[i].setEnabled(true);
2016
                        }
2017
                        dirty = true;
2018
                }
2019
        }
2020

    
2021
        /**
2022
         * Focus gained
2023
         */
2024
        public void focusGained(FocusEvent ev) {
2025
                // nothing to do
2026
        }
2027

    
2028
        /**
2029
         * Focus lost
2030
         */
2031
        public void focusLost(FocusEvent ev) {
2032
                // (jTextDecimal)
2033
                if (ev.getSource() == jTextDecimal) {
2034
                        dirty = true;
2035
                }
2036
                // (jTextTextDelimiter)
2037
                if (ev.getSource() == jTextTextDelimiter) {
2038
                        dirty = true;
2039
                }
2040
                // (jTextThousand)
2041
                if (ev.getSource() == jTextThousand) {
2042
                        dirty = true;
2043
                }
2044
        }
2045

    
2046
        /**
2047
         * 
2048
         * @author jsanz
2049
         * 
2050
         */
2051
        class IntVerifier extends InputVerifier {
2052

    
2053
                public boolean verify(JComponent input) {
2054
                        try {
2055
                                Integer.parseInt(((JTextField) input).getText());
2056
                                return true;
2057
                        } catch (NumberFormatException e) {
2058
                                log.error("Parsing the value");
2059
                                return false;
2060
                        }
2061
                }
2062
        }
2063

    
2064
        /**
2065
         * 
2066
         * @author jsanz
2067
         * 
2068
         */
2069
        class CharVerifier extends InputVerifier {
2070

    
2071
                public boolean verify(JComponent input) {
2072
                        String text = ((JTextField) input).getText();
2073
                        if (text != null && text.length() == 1) {
2074
                                return true;
2075
                        } else {
2076
                                return false;
2077
                        }
2078
                }
2079
        }
2080

    
2081
        /**
2082
         * Set pattern
2083
         * 
2084
         * @param pattern
2085
         */
2086
        private void setPattern(Patternnormalization pattern) {
2087
                this.pattern = pattern;
2088
        }
2089

    
2090
        /**
2091
         * This method erases a selected element to the list
2092
         * 
2093
         * @param pos
2094
         *            position
2095
         */
2096
        private void deleteField(int pos) {
2097
                int conta = pattern.getElements().size();
2098
                if (conta > 1) {
2099
                        pattern.getElements().remove(pos);
2100
                }
2101
        }
2102

    
2103
        /**
2104
         * This method returns the names of the fields from the pattern
2105
         * 
2106
         * @return new fields names
2107
         */
2108
        private String[] getNewFieldNames() {
2109

    
2110
                int numFields = pattern.getElements().size();
2111
                String[] res = new String[numFields];
2112

    
2113
                for (int i = 0; i < numFields; i++) {
2114
                        res[i] = ((Element) pattern.getElements().get(i)).getFieldname();
2115
                }
2116
                return res;
2117
        }
2118

    
2119
        /**
2120
         * This method fills the GUI sample table with the samples
2121
         * 
2122
         * @return Object[][]
2123
         */
2124
        private Object[][] normalizeSamples() {
2125

    
2126
                int numFields = pattern.getElements().size();
2127
                Object[][] results = new Object[NormalizationPanel.SAMPLES][numFields];
2128

    
2129
                NormalizationAlgorithm na = new DefaultNormalizationAlgorithm(
2130
                                this.pattern);
2131
                List<String> chains = null;
2132
                for (int i = 0; i < NormalizationPanel.SAMPLES; i++) {
2133
                        chains = na.splitChain(samples[i]);
2134
                        numFields = chains.size();
2135
                        for (int j = 0; j < numFields; j++) {
2136
                                results[i][j] = chains.get(j);
2137
                        }
2138
                }
2139
                return results;
2140
        }
2141

    
2142
        /**
2143
         * get panel width
2144
         * 
2145
         * @return
2146
         */
2147
        public int getWidth() {
2148
                return WIDTH;
2149
        }
2150

    
2151
        /**
2152
         * get panel height
2153
         * 
2154
         * @return
2155
         */
2156
        public int getHeight() {
2157
                return HEIGHT;
2158
        }
2159

    
2160
}