root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / table / gui / CSVSeparatorOptionsPanel.java @ 29596
History | View | Annotate | Download (8.82 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.app.project.documents.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 org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
35 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
36 |
|
37 |
|
38 |
/**
|
39 |
* Class to create csv file at disk with the statistics group generated from a table with an Specifically separator
|
40 |
*
|
41 |
* Basic separator "," -> csv basic file
|
42 |
* Excel separator ";" -> csv file to work in gvSIG documents
|
43 |
*
|
44 |
* Optionally separator -> the user can enter a character or a string
|
45 |
*
|
46 |
*
|
47 |
* @author ?ngel Fraile Gri??n e-mail: angel.fraile@iver.es
|
48 |
*
|
49 |
*/
|
50 |
|
51 |
|
52 |
public class CSVSeparatorOptionsPanel extends JPanel implements IWindow,ItemListener,ActionListener{ |
53 |
|
54 |
private static final long serialVersionUID = 1L; |
55 |
|
56 |
public static final String commaChar = ","; |
57 |
public static final String semicolonChar = ";"; |
58 |
private JButton buttonAccept; |
59 |
private JButton buttonCancel; |
60 |
private JRadioButton commaOption; |
61 |
private JRadioButton semicolonOption; |
62 |
private JRadioButton otherSymbol; |
63 |
private JTextField symbol; |
64 |
private String separator = null; |
65 |
|
66 |
|
67 |
public CSVSeparatorOptionsPanel() {
|
68 |
|
69 |
setName("Separation options");
|
70 |
// Initialize component
|
71 |
inicialize(); |
72 |
|
73 |
} |
74 |
/**
|
75 |
* Creating a basic option separator panel
|
76 |
*
|
77 |
*/
|
78 |
private void inicialize() { |
79 |
|
80 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
81 |
|
82 |
setLayout(new java.awt.GridBagLayout());
|
83 |
|
84 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
85 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
86 |
gridBagConstraints.insets = new java.awt.Insets(10, 10, 5, 5); |
87 |
add(getJCheckBoxPointComma(), gridBagConstraints); |
88 |
|
89 |
|
90 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
91 |
gridBagConstraints.gridwidth = 2;
|
92 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
93 |
gridBagConstraints.weightx = 1.0;
|
94 |
gridBagConstraints.insets = new java.awt.Insets(10, 5, 5, 10); |
95 |
add(getJCheckBoxComma(), gridBagConstraints); |
96 |
|
97 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
98 |
gridBagConstraints.gridx = 0;
|
99 |
gridBagConstraints.gridy = 1;
|
100 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
101 |
gridBagConstraints.weighty = 1.0;
|
102 |
gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 5); |
103 |
add(getJCheckBoxOtherSymbol(), gridBagConstraints); |
104 |
|
105 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
106 |
gridBagConstraints.gridx = 1;
|
107 |
gridBagConstraints.gridy = 1;
|
108 |
gridBagConstraints.gridwidth = 2;
|
109 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
110 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
111 |
gridBagConstraints.weightx = 1.0;
|
112 |
gridBagConstraints.weighty = 1.0;
|
113 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 10); |
114 |
add(getTextFieldSymbol(), gridBagConstraints); |
115 |
|
116 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
117 |
gridBagConstraints.gridx = 1;
|
118 |
gridBagConstraints.gridy = 2;
|
119 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
120 |
gridBagConstraints.weightx = 1.0;
|
121 |
gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); |
122 |
add(getAcceptButton(), gridBagConstraints); |
123 |
|
124 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
125 |
gridBagConstraints.gridx = 2;
|
126 |
gridBagConstraints.gridy = 2;
|
127 |
add(getCancelButton(), gridBagConstraints); |
128 |
|
129 |
ButtonGroup group = new ButtonGroup(); |
130 |
group.add(commaOption); |
131 |
group.add(semicolonOption); |
132 |
group.add(otherSymbol); |
133 |
|
134 |
} |
135 |
|
136 |
|
137 |
/**
|
138 |
* Selection option comma as the separator
|
139 |
*
|
140 |
*
|
141 |
* @return JRadioButton
|
142 |
*/
|
143 |
|
144 |
private JRadioButton getJCheckBoxComma() { |
145 |
if (commaOption == null) { |
146 |
commaOption = new JRadioButton(PluginServices.getText(this, "comma"), |
147 |
false);
|
148 |
commaOption.setEnabled(true);
|
149 |
commaOption.setToolTipText(PluginServices.getText(this, "sepatator_info_coma")); |
150 |
} |
151 |
return commaOption;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* Selection option semicolon as the separator
|
156 |
*
|
157 |
* @return JRadioButton
|
158 |
*/
|
159 |
private JRadioButton getJCheckBoxPointComma() { |
160 |
if (semicolonOption == null) { |
161 |
semicolonOption = new JRadioButton(PluginServices.getText(this, "semicolon"), |
162 |
true);
|
163 |
semicolonOption.setEnabled(true);
|
164 |
semicolonOption.setToolTipText(PluginServices.getText(this, "sepatator_info_semicolon")); |
165 |
} |
166 |
return semicolonOption;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* The user can enter the separator
|
171 |
*
|
172 |
* @return JRadioButton
|
173 |
*/
|
174 |
private JRadioButton getJCheckBoxOtherSymbol() { |
175 |
if (otherSymbol == null) { |
176 |
otherSymbol = new JRadioButton(PluginServices.getText(this, "otro_simbolo"), |
177 |
false);
|
178 |
otherSymbol.setEnabled(true);
|
179 |
otherSymbol.addItemListener(this);
|
180 |
otherSymbol.setToolTipText(PluginServices.getText(this, "sepatator_info_other")); |
181 |
} |
182 |
return otherSymbol;
|
183 |
} |
184 |
|
185 |
|
186 |
/**
|
187 |
* Return textfield where the user can enter a separator (char or string)
|
188 |
*
|
189 |
* @return TextField.
|
190 |
*/
|
191 |
private JTextField getTextFieldSymbol() { |
192 |
if (symbol == null) { |
193 |
symbol = new JTextField(null, 4); |
194 |
symbol.setHorizontalAlignment(JTextField.RIGHT);
|
195 |
symbol.setEnabled(otherSymbol.isSelected()); |
196 |
symbol.setToolTipText(PluginServices.getText(this, "sepatator_info")); |
197 |
} |
198 |
return symbol;
|
199 |
} |
200 |
|
201 |
/**
|
202 |
* Method that generates the button to accept selected separator
|
203 |
*
|
204 |
* @return JButton
|
205 |
*/
|
206 |
private JButton getAcceptButton() { |
207 |
if (buttonAccept == null) { |
208 |
buttonAccept = new JButton(); |
209 |
buttonAccept.setText(PluginServices.getText(this, "Aceptar")); |
210 |
buttonAccept.addActionListener(this);
|
211 |
buttonAccept.setToolTipText(PluginServices.getText(this, "Aceptar")); |
212 |
} |
213 |
return buttonAccept;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Method that generates the button to cancel csv file creation
|
218 |
*
|
219 |
* @return JButton
|
220 |
*/
|
221 |
private JButton getCancelButton() { |
222 |
if (buttonCancel == null) { |
223 |
buttonCancel = new JButton(); |
224 |
buttonCancel.setText(PluginServices.getText(this, "Cancelar")); |
225 |
buttonCancel.addActionListener(this);
|
226 |
buttonCancel.setToolTipText(PluginServices.getText(this, "Cancelar")); |
227 |
} |
228 |
return buttonCancel;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Window properties
|
233 |
*
|
234 |
* @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowInfo()
|
235 |
*/
|
236 |
public WindowInfo getWindowInfo() {
|
237 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
238 |
m_viewinfo.setTitle(PluginServices.getText(this, "opciones_separacion")); |
239 |
m_viewinfo.setHeight(100);
|
240 |
m_viewinfo.setWidth(300);
|
241 |
return m_viewinfo;
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* Getting the window profile
|
246 |
*/
|
247 |
// public Object getWindowProfile() {
|
248 |
// return WindowInfo.DIALOG_PROFILE;
|
249 |
// }
|
250 |
|
251 |
/**
|
252 |
* JRadioButton to enter the separator listener
|
253 |
*/
|
254 |
public void itemStateChanged(ItemEvent e) { |
255 |
symbol.setEnabled(otherSymbol.isSelected()); |
256 |
} |
257 |
|
258 |
/**
|
259 |
* JButtons Accept and Cancel listener
|
260 |
*/
|
261 |
public void actionPerformed(ActionEvent event) { |
262 |
if (event.getSource() == this.buttonAccept) { |
263 |
if(commaOption.isSelected()) {
|
264 |
separator = commaChar; |
265 |
|
266 |
}else if(semicolonOption.isSelected()) { |
267 |
separator = semicolonChar; |
268 |
}else if(otherSymbol.isSelected()) { |
269 |
separator = symbol.getText(); |
270 |
|
271 |
} |
272 |
PluginServices.getMDIManager().closeWindow(this);
|
273 |
|
274 |
} |
275 |
if (event.getSource() == this.buttonCancel) { |
276 |
separator = null;
|
277 |
PluginServices.getMDIManager().closeWindow(this);
|
278 |
return;
|
279 |
} |
280 |
|
281 |
} |
282 |
|
283 |
/**
|
284 |
*
|
285 |
* @return separator
|
286 |
* - Chosen as the separator character or separator string
|
287 |
*/
|
288 |
public String getSeparator() { |
289 |
return separator;
|
290 |
} |
291 |
|
292 |
public Object getWindowProfile() { |
293 |
return WindowInfo.DIALOG_PROFILE;
|
294 |
} |
295 |
|
296 |
} |