root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / project / document / table / gui / CSVSeparatorOptionsPanel.java @ 26241
History | View | Annotate | Download (8.73 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.project.document.table.gui; |
20 |
|
21 |
import java.awt.GridBagConstraints; |
22 |
import java.awt.event.ActionEvent; |
23 |
import java.awt.event.ActionListener; |
24 |
import java.awt.event.ItemEvent; |
25 |
import java.awt.event.ItemListener; |
26 |
|
27 |
import javax.swing.ButtonGroup; |
28 |
import javax.swing.JButton; |
29 |
import javax.swing.JPanel; |
30 |
import javax.swing.JRadioButton; |
31 |
import javax.swing.JTextField; |
32 |
|
33 |
import com.iver.andami.PluginServices; |
34 |
import com.iver.andami.ui.mdiManager.IWindow; |
35 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
36 |
|
37 |
/**
|
38 |
* Class to create csv file at disk with the statistics group generated from a table with an Specifically separator
|
39 |
*
|
40 |
* Basic separator "," -> csv basic file
|
41 |
* Excel separator ";" -> csv file to work in gvSIG documents
|
42 |
*
|
43 |
* Optionally separator -> the user can enter a character or a string
|
44 |
*
|
45 |
*
|
46 |
* @author ?ngel Fraile Gri??n e-mail: angel.fraile@iver.es
|
47 |
*
|
48 |
*/
|
49 |
|
50 |
|
51 |
public class CSVSeparatorOptionsPanel extends JPanel implements IWindow,ItemListener,ActionListener{ |
52 |
|
53 |
private static final long serialVersionUID = 1L; |
54 |
|
55 |
public static final String commaChar = ","; |
56 |
public static final String semicolonChar = ";"; |
57 |
private JButton buttonAccept; |
58 |
private JButton buttonCancel; |
59 |
private JRadioButton commaOption; |
60 |
private JRadioButton semicolonOption; |
61 |
private JRadioButton otherSymbol; |
62 |
private JTextField symbol; |
63 |
private String separator = null; |
64 |
|
65 |
|
66 |
public CSVSeparatorOptionsPanel() {
|
67 |
|
68 |
setName("Separation options");
|
69 |
// Initialize component
|
70 |
inicialize(); |
71 |
|
72 |
} |
73 |
/**
|
74 |
* Creating a basic option separator panel
|
75 |
*
|
76 |
*/
|
77 |
private void inicialize() { |
78 |
|
79 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
80 |
|
81 |
setLayout(new java.awt.GridBagLayout());
|
82 |
|
83 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
84 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
85 |
gridBagConstraints.insets = new java.awt.Insets(10, 10, 5, 5); |
86 |
add(getJCheckBoxPointComma(), gridBagConstraints); |
87 |
|
88 |
|
89 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
90 |
gridBagConstraints.gridwidth = 2;
|
91 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
92 |
gridBagConstraints.weightx = 1.0;
|
93 |
gridBagConstraints.insets = new java.awt.Insets(10, 5, 5, 10); |
94 |
add(getJCheckBoxComma(), gridBagConstraints); |
95 |
|
96 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
97 |
gridBagConstraints.gridx = 0;
|
98 |
gridBagConstraints.gridy = 1;
|
99 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
100 |
gridBagConstraints.weighty = 1.0;
|
101 |
gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 5); |
102 |
add(getJCheckBoxOtherSymbol(), gridBagConstraints); |
103 |
|
104 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
105 |
gridBagConstraints.gridx = 1;
|
106 |
gridBagConstraints.gridy = 1;
|
107 |
gridBagConstraints.gridwidth = 2;
|
108 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
109 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
110 |
gridBagConstraints.weightx = 1.0;
|
111 |
gridBagConstraints.weighty = 1.0;
|
112 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 10); |
113 |
add(getTextFieldSymbol(), gridBagConstraints); |
114 |
|
115 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
116 |
gridBagConstraints.gridx = 1;
|
117 |
gridBagConstraints.gridy = 2;
|
118 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
119 |
gridBagConstraints.weightx = 1.0;
|
120 |
gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); |
121 |
add(getAcceptButton(), gridBagConstraints); |
122 |
|
123 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
124 |
gridBagConstraints.gridx = 2;
|
125 |
gridBagConstraints.gridy = 2;
|
126 |
add(getCancelButton(), gridBagConstraints); |
127 |
|
128 |
ButtonGroup group = new ButtonGroup(); |
129 |
group.add(commaOption); |
130 |
group.add(semicolonOption); |
131 |
group.add(otherSymbol); |
132 |
|
133 |
} |
134 |
|
135 |
|
136 |
/**
|
137 |
* Selection option comma as the separator
|
138 |
*
|
139 |
*
|
140 |
* @return JRadioButton
|
141 |
*/
|
142 |
|
143 |
private JRadioButton getJCheckBoxComma() { |
144 |
if (commaOption == null) { |
145 |
commaOption = new JRadioButton(PluginServices.getText(this, "comma"), |
146 |
false);
|
147 |
commaOption.setEnabled(true);
|
148 |
commaOption.setToolTipText(PluginServices.getText(this, "sepatator_info_coma")); |
149 |
} |
150 |
return commaOption;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Selection option semicolon as the separator
|
155 |
*
|
156 |
* @return JRadioButton
|
157 |
*/
|
158 |
private JRadioButton getJCheckBoxPointComma() { |
159 |
if (semicolonOption == null) { |
160 |
semicolonOption = new JRadioButton(PluginServices.getText(this, "semicolon"), |
161 |
true);
|
162 |
semicolonOption.setEnabled(true);
|
163 |
semicolonOption.setToolTipText(PluginServices.getText(this, "sepatator_info_semicolon")); |
164 |
} |
165 |
return semicolonOption;
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* The user can enter the separator
|
170 |
*
|
171 |
* @return JRadioButton
|
172 |
*/
|
173 |
private JRadioButton getJCheckBoxOtherSymbol() { |
174 |
if (otherSymbol == null) { |
175 |
otherSymbol = new JRadioButton(PluginServices.getText(this, "otro_simbolo"), |
176 |
false);
|
177 |
otherSymbol.setEnabled(true);
|
178 |
otherSymbol.addItemListener(this);
|
179 |
otherSymbol.setToolTipText(PluginServices.getText(this, "sepatator_info_other")); |
180 |
} |
181 |
return otherSymbol;
|
182 |
} |
183 |
|
184 |
|
185 |
/**
|
186 |
* Return textfield where the user can enter a separator (char or string)
|
187 |
*
|
188 |
* @return TextField.
|
189 |
*/
|
190 |
private JTextField getTextFieldSymbol() { |
191 |
if (symbol == null) { |
192 |
symbol = new JTextField(null, 4); |
193 |
symbol.setHorizontalAlignment(JTextField.RIGHT);
|
194 |
symbol.setEnabled(otherSymbol.isSelected()); |
195 |
symbol.setToolTipText(PluginServices.getText(this, "sepatator_info")); |
196 |
} |
197 |
return symbol;
|
198 |
} |
199 |
|
200 |
/**
|
201 |
* Method that generates the button to accept selected separator
|
202 |
*
|
203 |
* @return JButton
|
204 |
*/
|
205 |
private JButton getAcceptButton() { |
206 |
if (buttonAccept == null) { |
207 |
buttonAccept = new JButton(); |
208 |
buttonAccept.setText(PluginServices.getText(this, "Aceptar")); |
209 |
buttonAccept.addActionListener(this);
|
210 |
buttonAccept.setToolTipText(PluginServices.getText(this, "Aceptar")); |
211 |
} |
212 |
return buttonAccept;
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* Method that generates the button to cancel csv file creation
|
217 |
*
|
218 |
* @return JButton
|
219 |
*/
|
220 |
private JButton getCancelButton() { |
221 |
if (buttonCancel == null) { |
222 |
buttonCancel = new JButton(); |
223 |
buttonCancel.setText(PluginServices.getText(this, "Cancelar")); |
224 |
buttonCancel.addActionListener(this);
|
225 |
buttonCancel.setToolTipText(PluginServices.getText(this, "Cancelar")); |
226 |
} |
227 |
return buttonCancel;
|
228 |
} |
229 |
|
230 |
/**
|
231 |
* Window properties
|
232 |
*
|
233 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
234 |
*/
|
235 |
public WindowInfo getWindowInfo() {
|
236 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
237 |
m_viewinfo.setTitle(PluginServices.getText(this, "opciones_separacion")); |
238 |
m_viewinfo.setHeight(100);
|
239 |
m_viewinfo.setWidth(300);
|
240 |
return m_viewinfo;
|
241 |
} |
242 |
|
243 |
/**
|
244 |
* Getting the window profile
|
245 |
*/
|
246 |
// public Object getWindowProfile() {
|
247 |
// return WindowInfo.DIALOG_PROFILE;
|
248 |
// }
|
249 |
|
250 |
/**
|
251 |
* JRadioButton to enter the separator listener
|
252 |
*/
|
253 |
public void itemStateChanged(ItemEvent e) { |
254 |
symbol.setEnabled(otherSymbol.isSelected()); |
255 |
} |
256 |
|
257 |
/**
|
258 |
* JButtons Accept and Cancel listener
|
259 |
*/
|
260 |
public void actionPerformed(ActionEvent event) { |
261 |
if (event.getSource() == this.buttonAccept) { |
262 |
if(commaOption.isSelected()) {
|
263 |
separator = commaChar; |
264 |
|
265 |
}else if(semicolonOption.isSelected()) { |
266 |
separator = semicolonChar; |
267 |
}else if(otherSymbol.isSelected()) { |
268 |
separator = symbol.getText(); |
269 |
|
270 |
} |
271 |
PluginServices.getMDIManager().closeWindow(this);
|
272 |
|
273 |
} |
274 |
if (event.getSource() == this.buttonCancel) { |
275 |
separator = null;
|
276 |
PluginServices.getMDIManager().closeWindow(this);
|
277 |
return;
|
278 |
} |
279 |
|
280 |
} |
281 |
|
282 |
/**
|
283 |
*
|
284 |
* @return separator
|
285 |
* - Chosen as the separator character or separator string
|
286 |
*/
|
287 |
public String getSeparator() { |
288 |
return separator;
|
289 |
} |
290 |
} |