svn-gvsig-desktop / branches / v10 / libraries / libUI / src / org / gvsig / gui / beans / filterPanel / AbstractFilterQueryJPanel.java @ 9623
History | View | Annotate | Download (13.4 KB)
1 | 7962 | ppiqueras | package org.gvsig.gui.beans.filterPanel; |
---|---|---|---|
2 | |||
3 | import java.awt.Dimension; |
||
4 | import java.awt.GridBagConstraints; |
||
5 | import java.awt.GridBagLayout; |
||
6 | 7988 | ppiqueras | import java.beans.PropertyChangeEvent; |
7 | import java.beans.PropertyChangeListener; |
||
8 | 7962 | ppiqueras | import java.io.Serializable; |
9 | 9575 | ppiqueras | import java.util.HashSet; |
10 | import java.util.Set; |
||
11 | 8012 | ppiqueras | import java.util.Vector; |
12 | 7962 | ppiqueras | |
13 | 8074 | ppiqueras | import javax.swing.DefaultListModel; |
14 | 7962 | ppiqueras | import javax.swing.JPanel; |
15 | 8074 | ppiqueras | import javax.swing.tree.DefaultTreeCellRenderer; |
16 | import javax.swing.tree.DefaultTreeModel; |
||
17 | 7962 | ppiqueras | |
18 | import org.gvsig.gui.beans.filterPanel.filterButtons.FilterButtonsJPanel; |
||
19 | 9037 | ppiqueras | import org.gvsig.gui.beans.Messages; |
20 | 7962 | ppiqueras | |
21 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
22 | *
|
||
23 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
24 | *
|
||
25 | * This program is free software; you can redistribute it and/or
|
||
26 | * modify it under the terms of the GNU General Public License
|
||
27 | * as published by the Free Software Foundation; either version 2
|
||
28 | * of the License, or (at your option) any later version.
|
||
29 | *
|
||
30 | * This program is distributed in the hope that it will be useful,
|
||
31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
33 | * GNU General Public License for more details.
|
||
34 | *
|
||
35 | * You should have received a copy of the GNU General Public License
|
||
36 | * along with this program; if not, write to the Free Software
|
||
37 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
38 | *
|
||
39 | * For more information, contact:
|
||
40 | *
|
||
41 | * Generalitat Valenciana
|
||
42 | * Conselleria d'Infraestructures i Transport
|
||
43 | * Av. Blasco Ib??ez, 50
|
||
44 | * 46010 VALENCIA
|
||
45 | * SPAIN
|
||
46 | *
|
||
47 | * +34 963862235
|
||
48 | * gvsig@gva.es
|
||
49 | * www.gvsig.gva.es
|
||
50 | *
|
||
51 | * or
|
||
52 | *
|
||
53 | * IVER T.I. S.A
|
||
54 | * Salamanca 50
|
||
55 | * 46005 Valencia
|
||
56 | * Spain
|
||
57 | *
|
||
58 | * +34 963163400
|
||
59 | * dac@iver.es
|
||
60 | */
|
||
61 | |||
62 | /**
|
||
63 | * This abstract class represents the common components of the FilterQuery panels
|
||
64 | *
|
||
65 | * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
||
66 | */
|
||
67 | public abstract class AbstractFilterQueryJPanel extends JPanel implements Serializable { |
||
68 | 8390 | ppiqueras | public static final int DefaultHeight = 280; |
69 | public static final int DefaultWidth = 490; |
||
70 | 7962 | ppiqueras | |
71 | 9575 | ppiqueras | protected final int fieldsJPanelHeight = 145; |
72 | 8034 | ppiqueras | protected final int fieldsJPanelWidth = 145; |
73 | 7962 | ppiqueras | protected final int valuesJPanelHeight = fieldsJPanelHeight; |
74 | protected final int valuesJPanelWidth = fieldsJPanelWidth; |
||
75 | protected final int defaultBottomJPanelWidth = 480; |
||
76 | 9575 | ppiqueras | protected final int defaultBottomJPanelHeight = 110; |
77 | 7962 | ppiqueras | protected int filterJScrollPaneHeight; |
78 | protected int filterJScrollPanelWidth; |
||
79 | 9575 | ppiqueras | protected final int filterButtonsPanelHeight = FilterButtonsJPanel.default_FilterButtonsJPanelHeight; |
80 | 7962 | ppiqueras | protected final int filterButtonsPanelWidth = FilterButtonsJPanel.default_FilterButtonsJPanelWidth; |
81 | 8034 | ppiqueras | protected final int defaultTopJPanelWidth = defaultBottomJPanelWidth; |
82 | 9575 | ppiqueras | protected final int defaultTopJPanelHeight = 145; |
83 | protected int fieldsAndValuesJScrollPaneHeight = 110; |
||
84 | 7988 | ppiqueras | protected int fieldsAndValuesJScrollPaneWidth = fieldsJPanelWidth; |
85 | 7962 | ppiqueras | |
86 | 7988 | ppiqueras | protected javax.swing.JLabel fieldsJLabel = null; |
87 | protected javax.swing.JLabel valuesJLabel = null; |
||
88 | 7962 | ppiqueras | protected javax.swing.JPanel fieldsJPanel = null; |
89 | protected javax.swing.JPanel valuesJPanel = null; |
||
90 | protected FilterButtonsJPanel filterButtonsJPanel = null; |
||
91 | protected javax.swing.JScrollPane filterJScrollPane = null; |
||
92 | protected javax.swing.JPanel topJPanel = null; |
||
93 | protected javax.swing.JPanel bottomJPanel = null; |
||
94 | protected javax.swing.JTextArea txtExpression = null; |
||
95 | 8012 | ppiqueras | protected javax.swing.JTree fieldsJTree = null; |
96 | protected javax.swing.JList valuesJList = null; |
||
97 | 7988 | ppiqueras | protected javax.swing.JScrollPane fieldsJScrollPane = null; |
98 | 8074 | ppiqueras | protected javax.swing.JScrollPane valuesJScrollPane = null; |
99 | |||
100 | 7962 | ppiqueras | protected String title; |
101 | |||
102 | 8074 | ppiqueras | protected DefaultTreeModel defaultTreeModel; |
103 | 8390 | ppiqueras | protected DefaultListModel valuesListModel; |
104 | 9575 | ppiqueras | |
105 | // A set with all simbols or operator names used
|
||
106 | private Set operatorNamesAndSymbols; |
||
107 | 8074 | ppiqueras | |
108 | |||
109 | 7962 | ppiqueras | /**
|
110 | * This is the default constructor
|
||
111 | */
|
||
112 | public AbstractFilterQueryJPanel(String _title) { |
||
113 | super();
|
||
114 | title = _title; |
||
115 | } |
||
116 | /**
|
||
117 | * This is the default constructor
|
||
118 | */
|
||
119 | public AbstractFilterQueryJPanel() {
|
||
120 | super();
|
||
121 | } |
||
122 | |||
123 | /**
|
||
124 | * This method initializes this
|
||
125 | */
|
||
126 | protected void initialize() { |
||
127 | 9575 | ppiqueras | operatorNamesAndSymbols = new HashSet(); |
128 | |||
129 | 8390 | ppiqueras | this.setPreferredSize(new Dimension(DefaultWidth, DefaultHeight)); |
130 | |||
131 | 7962 | ppiqueras | this.setLayout(new GridBagLayout()); |
132 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
||
133 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
134 | gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
|
||
135 | 7988 | ppiqueras | |
136 | 7962 | ppiqueras | gridBagConstraints.anchor = GridBagConstraints.NORTH;
|
137 | this.add(getTopJPanel(), gridBagConstraints);
|
||
138 | 7988 | ppiqueras | |
139 | 7962 | ppiqueras | gridBagConstraints.anchor = GridBagConstraints.SOUTH;
|
140 | 7988 | ppiqueras | this.add(getBottomJPanel(), gridBagConstraints);
|
141 | 7962 | ppiqueras | } |
142 | |||
143 | /**
|
||
144 | * This method initializes topJPanel
|
||
145 | *
|
||
146 | * @return javax.swing.JPanel
|
||
147 | */
|
||
148 | 7988 | ppiqueras | protected javax.swing.JPanel getTopJPanel() {
|
149 | 7962 | ppiqueras | if (topJPanel == null) { |
150 | topJPanel = new JPanel(); |
||
151 | |||
152 | topJPanel.setPreferredSize(new Dimension(defaultTopJPanelWidth, defaultTopJPanelHeight)); |
||
153 | topJPanel.setLayout(new GridBagLayout()); |
||
154 | |||
155 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
||
156 | 7988 | ppiqueras | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
157 | 7962 | ppiqueras | |
158 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
159 | topJPanel.add(getFieldsJPanel(), gridBagConstraints); |
||
160 | |||
161 | gridBagConstraints.anchor = GridBagConstraints.CENTER;
|
||
162 | topJPanel.add(getFilterButtonsJPanel(), gridBagConstraints); |
||
163 | |||
164 | gridBagConstraints.anchor = GridBagConstraints.EAST;
|
||
165 | topJPanel.add(getValuesJPanel(), gridBagConstraints); |
||
166 | } |
||
167 | |||
168 | return topJPanel;
|
||
169 | } |
||
170 | |||
171 | /**
|
||
172 | * This method initializes bottomJPanel
|
||
173 | *
|
||
174 | * @return javax.swing.JPanel
|
||
175 | */
|
||
176 | protected abstract JPanel getBottomJPanel(); |
||
177 | |||
178 | /**
|
||
179 | * This method initializes fieldsJLabel
|
||
180 | *
|
||
181 | * @return javax.swing.JLabel
|
||
182 | */
|
||
183 | protected javax.swing.JLabel getFieldsJLabel() {
|
||
184 | if (fieldsJLabel == null) { |
||
185 | fieldsJLabel = new javax.swing.JLabel();
|
||
186 | 9575 | ppiqueras | fieldsJLabel.setText(Messages.getText("fields") + ":"); |
187 | 7962 | ppiqueras | } |
188 | |||
189 | return fieldsJLabel;
|
||
190 | } |
||
191 | 9575 | ppiqueras | |
192 | /**
|
||
193 | * This method initializes valuesJList
|
||
194 | *
|
||
195 | * @return javax.swing.JList
|
||
196 | */
|
||
197 | protected abstract javax.swing.JList getValuesJList(); |
||
198 | 7962 | ppiqueras | |
199 | /**
|
||
200 | * This method initializes fieldsJPanel
|
||
201 | *
|
||
202 | * @return javax.swing.JPanel
|
||
203 | */
|
||
204 | protected abstract JPanel getFieldsJPanel(); |
||
205 | |||
206 | /**
|
||
207 | 9575 | ppiqueras | * This method initializes jScrollPane
|
208 | *
|
||
209 | * @return javax.swing.JScrollPane
|
||
210 | */
|
||
211 | protected abstract javax.swing.JScrollPane getFieldsJScrollPane(); |
||
212 | |||
213 | /**
|
||
214 | 7962 | ppiqueras | * This method initializes valuesJLabel
|
215 | *
|
||
216 | * @return javax.swing.JLabel
|
||
217 | */
|
||
218 | protected javax.swing.JLabel getValuesJLabel() {
|
||
219 | if (valuesJLabel == null) { |
||
220 | valuesJLabel = new javax.swing.JLabel();
|
||
221 | 9583 | ppiqueras | valuesJLabel.setText(Messages.getText("values") + ":"); |
222 | 7962 | ppiqueras | } |
223 | |||
224 | return valuesJLabel;
|
||
225 | } |
||
226 | |||
227 | /**
|
||
228 | * This method initializes valuesJPanel
|
||
229 | *
|
||
230 | * @return javax.swing.JPanel
|
||
231 | */
|
||
232 | protected abstract JPanel getValuesJPanel(); |
||
233 | |||
234 | /**
|
||
235 | 9575 | ppiqueras | * This method initializes jScrollPane1
|
236 | *
|
||
237 | * @return javax.swing.JScrollPane
|
||
238 | */
|
||
239 | protected abstract javax.swing.JScrollPane getValuesJScrollPane(); |
||
240 | |||
241 | /**
|
||
242 | 7962 | ppiqueras | * This method initializes filterJScrollPane
|
243 | *
|
||
244 | * @return javax.swing.JScrollPane
|
||
245 | */
|
||
246 | protected abstract javax.swing.JScrollPane getFilterJScrollPane(); |
||
247 | 9575 | ppiqueras | |
248 | /**
|
||
249 | * This method initializes txtExpression
|
||
250 | *
|
||
251 | * @return javax.swing.JTextArea
|
||
252 | */
|
||
253 | protected abstract javax.swing.JTextArea getTxtExpression(); |
||
254 | 7962 | ppiqueras | |
255 | /**
|
||
256 | * DOCUMENT ME!
|
||
257 | *
|
||
258 | * @param symbol DOCUMENT ME!
|
||
259 | */
|
||
260 | protected void putSymbol(String symbol) { |
||
261 | 9575 | ppiqueras | int position = getTxtExpression().getCaretPosition();
|
262 | 7962 | ppiqueras | |
263 | 9575 | ppiqueras | getTxtExpression().setText(insert(getTxtExpression().getText(), position, symbol)); |
264 | 7962 | ppiqueras | |
265 | if (symbol.equals(" () ")) { |
||
266 | position = position + 2;
|
||
267 | } else {
|
||
268 | position = position + symbol.length(); |
||
269 | } |
||
270 | |||
271 | 9575 | ppiqueras | getTxtExpression().setCaretPosition(position); |
272 | 7962 | ppiqueras | } |
273 | |||
274 | 8012 | ppiqueras | /**
|
275 | * This method initializes fieldsJTree
|
||
276 | *
|
||
277 | * @return javax.swing.JTree
|
||
278 | */
|
||
279 | 8074 | ppiqueras | /*
|
280 | * (non-Javadoc)
|
||
281 | * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getLstCampos()
|
||
282 | */
|
||
283 | protected javax.swing.JTree getFieldsJTree() {
|
||
284 | if (fieldsJTree == null) { |
||
285 | fieldsJTree = new javax.swing.JTree(new Vector(0,1)); |
||
286 | |||
287 | // Remove icons:
|
||
288 | DefaultTreeCellRenderer defaultTreeCellRenderer = new DefaultTreeCellRenderer(); |
||
289 | defaultTreeCellRenderer.setOpenIcon(null);
|
||
290 | defaultTreeCellRenderer.setClosedIcon(null);
|
||
291 | defaultTreeCellRenderer.setLeafIcon(null);
|
||
292 | |||
293 | // Root not visible
|
||
294 | fieldsJTree.setRootVisible(false);
|
||
295 | fieldsJTree.setCellRenderer(defaultTreeCellRenderer); |
||
296 | } |
||
297 | |||
298 | return fieldsJTree;
|
||
299 | } |
||
300 | 8012 | ppiqueras | |
301 | 7962 | ppiqueras | /**
|
302 | * Inserta una string en otra en la posici?n indicada
|
||
303 | *
|
||
304 | * @param base String donde se inserta
|
||
305 | * @param position posici?n de "base" donde se inserta la String
|
||
306 | * @param injerto String que se inserta en "base"
|
||
307 | *
|
||
308 | * @return String con la inserci?n hecha
|
||
309 | */
|
||
310 | protected static String insert(String base, int position, String injerto) { |
||
311 | return base.substring(0, position) + injerto + |
||
312 | base.substring(position); |
||
313 | } |
||
314 | 7988 | ppiqueras | |
315 | |||
316 | /**
|
||
317 | * This method initializes filterButtonsJPanel
|
||
318 | *
|
||
319 | * @return javax.swing.JPanel
|
||
320 | */
|
||
321 | protected JPanel getFilterButtonsJPanel() { |
||
322 | if (filterButtonsJPanel == null) { |
||
323 | filterButtonsJPanel = new FilterButtonsJPanel();
|
||
324 | filterButtonsJPanel.setPreferredSize(new Dimension(filterButtonsPanelWidth, filterButtonsPanelHeight)); |
||
325 | filterButtonsJPanel.addPropertyChangeListener(new PropertyChangeListener() { |
||
326 | /*
|
||
327 | * (non-Javadoc)
|
||
328 | * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
||
329 | */
|
||
330 | public void propertyChange(PropertyChangeEvent arg0) { |
||
331 | if (arg0.getPropertyName().equals(FilterButtonsJPanel.BUTTON_CLICKED_ACTION_COMMAND)) {
|
||
332 | |||
333 | switch(Integer.parseInt(arg0.getNewValue().toString())) { |
||
334 | case FilterButtonsJPanel.AND:
|
||
335 | 9575 | ppiqueras | operatorNamesAndSymbols.add("and");
|
336 | 7988 | ppiqueras | putSymbol(" and ");
|
337 | break;
|
||
338 | case FilterButtonsJPanel.DATE:
|
||
339 | putSymbol( ((FilterButtonsJPanel)arg0.getSource()).getLastSelectedDate() ); |
||
340 | 9575 | ppiqueras | operatorNamesAndSymbols.add("Date");
|
341 | 7988 | ppiqueras | break;
|
342 | case FilterButtonsJPanel.DISTINCT:
|
||
343 | putSymbol(" <> ");
|
||
344 | 9623 | ppiqueras | operatorNamesAndSymbols.add("<>"); // In SQL this is the formal operator |
345 | operatorNamesAndSymbols.add("!="); // This operator is also supported |
||
346 | 7988 | ppiqueras | break;
|
347 | case FilterButtonsJPanel.EQUAL:
|
||
348 | putSymbol(" = ");
|
||
349 | 9575 | ppiqueras | operatorNamesAndSymbols.add("=");
|
350 | 7988 | ppiqueras | break;
|
351 | case FilterButtonsJPanel.EQUALGREATER:
|
||
352 | putSymbol(" >= ");
|
||
353 | 9575 | ppiqueras | operatorNamesAndSymbols.add(">=");
|
354 | 7988 | ppiqueras | break;
|
355 | case FilterButtonsJPanel.EQUALSMALLER:
|
||
356 | putSymbol(" <= ");
|
||
357 | 9575 | ppiqueras | operatorNamesAndSymbols.add("<=");
|
358 | 7988 | ppiqueras | break;
|
359 | case FilterButtonsJPanel.GREATER:
|
||
360 | putSymbol(" > ");
|
||
361 | 9575 | ppiqueras | operatorNamesAndSymbols.add(">");
|
362 | 7988 | ppiqueras | break;
|
363 | case FilterButtonsJPanel.NOT:
|
||
364 | putSymbol(" not ");
|
||
365 | 9575 | ppiqueras | operatorNamesAndSymbols.add("not");
|
366 | 7988 | ppiqueras | break;
|
367 | case FilterButtonsJPanel.OR:
|
||
368 | putSymbol(" or ");
|
||
369 | 9575 | ppiqueras | operatorNamesAndSymbols.add("or");
|
370 | 7988 | ppiqueras | break;
|
371 | case FilterButtonsJPanel.PARENTHESIS:
|
||
372 | putSymbol(" () ");
|
||
373 | 9575 | ppiqueras | operatorNamesAndSymbols.add("(");
|
374 | operatorNamesAndSymbols.add(")");
|
||
375 | 7988 | ppiqueras | break;
|
376 | case FilterButtonsJPanel.SMALLER:
|
||
377 | putSymbol(" < ");
|
||
378 | 9575 | ppiqueras | operatorNamesAndSymbols.add("<");
|
379 | 7988 | ppiqueras | break;
|
380 | 8390 | ppiqueras | case FilterButtonsJPanel.DELETE_TEXT:
|
381 | txtExpression.setText("");
|
||
382 | break;
|
||
383 | 7988 | ppiqueras | default: // do anything |
384 | } |
||
385 | } |
||
386 | } |
||
387 | }); |
||
388 | } |
||
389 | |||
390 | return filterButtonsJPanel;
|
||
391 | } |
||
392 | 7997 | ppiqueras | |
393 | 9575 | ppiqueras | |
394 | 7997 | ppiqueras | /**
|
395 | 9575 | ppiqueras | * Returns a set with all symbols and names used as operators or auxiliar symbols
|
396 | *
|
||
397 | * @return A set
|
||
398 | */
|
||
399 | protected Set getOperatorNamesAndSymbols() { |
||
400 | return operatorNamesAndSymbols;
|
||
401 | } |
||
402 | |||
403 | /**
|
||
404 | 7997 | ppiqueras | * Sets new height to the 'topJPanel', (new Height must be bigger than default, else do nothing)
|
405 | *
|
||
406 | * @param new_Height New height
|
||
407 | */
|
||
408 | public void resizeHeight(int new_Height) { |
||
409 | 8390 | ppiqueras | int difference = new_Height - DefaultHeight;
|
410 | 7997 | ppiqueras | |
411 | if (difference > 0) { |
||
412 | this.setPreferredSize(new Dimension(this.getPreferredSize().width, this.getPreferredSize().height + difference)); |
||
413 | 9575 | ppiqueras | getTopJPanel().setPreferredSize(new Dimension(getTopJPanel().getPreferredSize().width, getTopJPanel().getPreferredSize().height + difference)); |
414 | 7997 | ppiqueras | |
415 | 9575 | ppiqueras | getFieldsJPanel().setPreferredSize(new Dimension(getFieldsJPanel().getPreferredSize().width, getFieldsJPanel().getPreferredSize().height + difference)); |
416 | getFieldsJScrollPane().setPreferredSize(new Dimension(getFieldsJScrollPane().getPreferredSize().width, getFieldsJScrollPane().getPreferredSize().height + difference)); |
||
417 | 7997 | ppiqueras | |
418 | 9575 | ppiqueras | getValuesJPanel().setPreferredSize(new Dimension(getValuesJPanel().getPreferredSize().width, getValuesJPanel().getPreferredSize().height + difference)); |
419 | getValuesJScrollPane().setPreferredSize(new Dimension(getValuesJScrollPane().getPreferredSize().width, getValuesJScrollPane().getPreferredSize().height + difference)); |
||
420 | 7997 | ppiqueras | } |
421 | } |
||
422 | 8244 | ppiqueras | |
423 | /**
|
||
424 | * Sets the width to this JPanel
|
||
425 | *
|
||
426 | * @param new_Width New width
|
||
427 | */
|
||
428 | public abstract void resizeWidth(int new_Width); |
||
429 | |||
430 | /*
|
||
431 | * (non-Javadoc)
|
||
432 | * @see java.awt.Component#resize(int, int)
|
||
433 | */
|
||
434 | public void resize(int width, int height) { |
||
435 | 8390 | ppiqueras | int difference = height - DefaultHeight;
|
436 | 8074 | ppiqueras | |
437 | 8244 | ppiqueras | if (difference != 0) |
438 | this.resizeHeight(height);
|
||
439 | |||
440 | this.resizeWidth(width);
|
||
441 | } |
||
442 | 8074 | ppiqueras | |
443 | 8244 | ppiqueras | /*
|
444 | * (non-Javadoc)
|
||
445 | * @see java.awt.Component#resize(java.awt.Dimension)
|
||
446 | */
|
||
447 | public void resize(Dimension d) { |
||
448 | 8390 | ppiqueras | int difference = d.height - DefaultHeight;
|
449 | 8244 | ppiqueras | |
450 | if (difference != 0) |
||
451 | this.resizeHeight(d.height);
|
||
452 | |||
453 | this.resizeWidth(d.width);
|
||
454 | } |
||
455 | 7962 | ppiqueras | } |