svn-gvsig-desktop / branches / v10 / libraries / libUI / src / org / gvsig / gui / beans / filterPanel / AbstractFilterQueryJPanel.java @ 9623
History | View | Annotate | Download (13.4 KB)
1 |
package org.gvsig.gui.beans.filterPanel; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.GridBagConstraints; |
5 |
import java.awt.GridBagLayout; |
6 |
import java.beans.PropertyChangeEvent; |
7 |
import java.beans.PropertyChangeListener; |
8 |
import java.io.Serializable; |
9 |
import java.util.HashSet; |
10 |
import java.util.Set; |
11 |
import java.util.Vector; |
12 |
|
13 |
import javax.swing.DefaultListModel; |
14 |
import javax.swing.JPanel; |
15 |
import javax.swing.tree.DefaultTreeCellRenderer; |
16 |
import javax.swing.tree.DefaultTreeModel; |
17 |
|
18 |
import org.gvsig.gui.beans.filterPanel.filterButtons.FilterButtonsJPanel; |
19 |
import org.gvsig.gui.beans.Messages; |
20 |
|
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 |
public static final int DefaultHeight = 280; |
69 |
public static final int DefaultWidth = 490; |
70 |
|
71 |
protected final int fieldsJPanelHeight = 145; |
72 |
protected final int fieldsJPanelWidth = 145; |
73 |
protected final int valuesJPanelHeight = fieldsJPanelHeight; |
74 |
protected final int valuesJPanelWidth = fieldsJPanelWidth; |
75 |
protected final int defaultBottomJPanelWidth = 480; |
76 |
protected final int defaultBottomJPanelHeight = 110; |
77 |
protected int filterJScrollPaneHeight; |
78 |
protected int filterJScrollPanelWidth; |
79 |
protected final int filterButtonsPanelHeight = FilterButtonsJPanel.default_FilterButtonsJPanelHeight; |
80 |
protected final int filterButtonsPanelWidth = FilterButtonsJPanel.default_FilterButtonsJPanelWidth; |
81 |
protected final int defaultTopJPanelWidth = defaultBottomJPanelWidth; |
82 |
protected final int defaultTopJPanelHeight = 145; |
83 |
protected int fieldsAndValuesJScrollPaneHeight = 110; |
84 |
protected int fieldsAndValuesJScrollPaneWidth = fieldsJPanelWidth; |
85 |
|
86 |
protected javax.swing.JLabel fieldsJLabel = null; |
87 |
protected javax.swing.JLabel valuesJLabel = null; |
88 |
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 |
protected javax.swing.JTree fieldsJTree = null; |
96 |
protected javax.swing.JList valuesJList = null; |
97 |
protected javax.swing.JScrollPane fieldsJScrollPane = null; |
98 |
protected javax.swing.JScrollPane valuesJScrollPane = null; |
99 |
|
100 |
protected String title; |
101 |
|
102 |
protected DefaultTreeModel defaultTreeModel; |
103 |
protected DefaultListModel valuesListModel; |
104 |
|
105 |
// A set with all simbols or operator names used
|
106 |
private Set operatorNamesAndSymbols; |
107 |
|
108 |
|
109 |
/**
|
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 |
operatorNamesAndSymbols = new HashSet(); |
128 |
|
129 |
this.setPreferredSize(new Dimension(DefaultWidth, DefaultHeight)); |
130 |
|
131 |
this.setLayout(new GridBagLayout()); |
132 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
133 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
134 |
gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
|
135 |
|
136 |
gridBagConstraints.anchor = GridBagConstraints.NORTH;
|
137 |
this.add(getTopJPanel(), gridBagConstraints);
|
138 |
|
139 |
gridBagConstraints.anchor = GridBagConstraints.SOUTH;
|
140 |
this.add(getBottomJPanel(), gridBagConstraints);
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* This method initializes topJPanel
|
145 |
*
|
146 |
* @return javax.swing.JPanel
|
147 |
*/
|
148 |
protected javax.swing.JPanel getTopJPanel() {
|
149 |
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 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
157 |
|
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 |
fieldsJLabel.setText(Messages.getText("fields") + ":"); |
187 |
} |
188 |
|
189 |
return fieldsJLabel;
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* This method initializes valuesJList
|
194 |
*
|
195 |
* @return javax.swing.JList
|
196 |
*/
|
197 |
protected abstract javax.swing.JList getValuesJList(); |
198 |
|
199 |
/**
|
200 |
* This method initializes fieldsJPanel
|
201 |
*
|
202 |
* @return javax.swing.JPanel
|
203 |
*/
|
204 |
protected abstract JPanel getFieldsJPanel(); |
205 |
|
206 |
/**
|
207 |
* This method initializes jScrollPane
|
208 |
*
|
209 |
* @return javax.swing.JScrollPane
|
210 |
*/
|
211 |
protected abstract javax.swing.JScrollPane getFieldsJScrollPane(); |
212 |
|
213 |
/**
|
214 |
* 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 |
valuesJLabel.setText(Messages.getText("values") + ":"); |
222 |
} |
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 |
* This method initializes jScrollPane1
|
236 |
*
|
237 |
* @return javax.swing.JScrollPane
|
238 |
*/
|
239 |
protected abstract javax.swing.JScrollPane getValuesJScrollPane(); |
240 |
|
241 |
/**
|
242 |
* This method initializes filterJScrollPane
|
243 |
*
|
244 |
* @return javax.swing.JScrollPane
|
245 |
*/
|
246 |
protected abstract javax.swing.JScrollPane getFilterJScrollPane(); |
247 |
|
248 |
/**
|
249 |
* This method initializes txtExpression
|
250 |
*
|
251 |
* @return javax.swing.JTextArea
|
252 |
*/
|
253 |
protected abstract javax.swing.JTextArea getTxtExpression(); |
254 |
|
255 |
/**
|
256 |
* DOCUMENT ME!
|
257 |
*
|
258 |
* @param symbol DOCUMENT ME!
|
259 |
*/
|
260 |
protected void putSymbol(String symbol) { |
261 |
int position = getTxtExpression().getCaretPosition();
|
262 |
|
263 |
getTxtExpression().setText(insert(getTxtExpression().getText(), position, symbol)); |
264 |
|
265 |
if (symbol.equals(" () ")) { |
266 |
position = position + 2;
|
267 |
} else {
|
268 |
position = position + symbol.length(); |
269 |
} |
270 |
|
271 |
getTxtExpression().setCaretPosition(position); |
272 |
} |
273 |
|
274 |
/**
|
275 |
* This method initializes fieldsJTree
|
276 |
*
|
277 |
* @return javax.swing.JTree
|
278 |
*/
|
279 |
/*
|
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 |
|
301 |
/**
|
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 |
|
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 |
operatorNamesAndSymbols.add("and");
|
336 |
putSymbol(" and ");
|
337 |
break;
|
338 |
case FilterButtonsJPanel.DATE:
|
339 |
putSymbol( ((FilterButtonsJPanel)arg0.getSource()).getLastSelectedDate() ); |
340 |
operatorNamesAndSymbols.add("Date");
|
341 |
break;
|
342 |
case FilterButtonsJPanel.DISTINCT:
|
343 |
putSymbol(" <> ");
|
344 |
operatorNamesAndSymbols.add("<>"); // In SQL this is the formal operator |
345 |
operatorNamesAndSymbols.add("!="); // This operator is also supported |
346 |
break;
|
347 |
case FilterButtonsJPanel.EQUAL:
|
348 |
putSymbol(" = ");
|
349 |
operatorNamesAndSymbols.add("=");
|
350 |
break;
|
351 |
case FilterButtonsJPanel.EQUALGREATER:
|
352 |
putSymbol(" >= ");
|
353 |
operatorNamesAndSymbols.add(">=");
|
354 |
break;
|
355 |
case FilterButtonsJPanel.EQUALSMALLER:
|
356 |
putSymbol(" <= ");
|
357 |
operatorNamesAndSymbols.add("<=");
|
358 |
break;
|
359 |
case FilterButtonsJPanel.GREATER:
|
360 |
putSymbol(" > ");
|
361 |
operatorNamesAndSymbols.add(">");
|
362 |
break;
|
363 |
case FilterButtonsJPanel.NOT:
|
364 |
putSymbol(" not ");
|
365 |
operatorNamesAndSymbols.add("not");
|
366 |
break;
|
367 |
case FilterButtonsJPanel.OR:
|
368 |
putSymbol(" or ");
|
369 |
operatorNamesAndSymbols.add("or");
|
370 |
break;
|
371 |
case FilterButtonsJPanel.PARENTHESIS:
|
372 |
putSymbol(" () ");
|
373 |
operatorNamesAndSymbols.add("(");
|
374 |
operatorNamesAndSymbols.add(")");
|
375 |
break;
|
376 |
case FilterButtonsJPanel.SMALLER:
|
377 |
putSymbol(" < ");
|
378 |
operatorNamesAndSymbols.add("<");
|
379 |
break;
|
380 |
case FilterButtonsJPanel.DELETE_TEXT:
|
381 |
txtExpression.setText("");
|
382 |
break;
|
383 |
default: // do anything |
384 |
} |
385 |
} |
386 |
} |
387 |
}); |
388 |
} |
389 |
|
390 |
return filterButtonsJPanel;
|
391 |
} |
392 |
|
393 |
|
394 |
/**
|
395 |
* 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 |
* 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 |
int difference = new_Height - DefaultHeight;
|
410 |
|
411 |
if (difference > 0) { |
412 |
this.setPreferredSize(new Dimension(this.getPreferredSize().width, this.getPreferredSize().height + difference)); |
413 |
getTopJPanel().setPreferredSize(new Dimension(getTopJPanel().getPreferredSize().width, getTopJPanel().getPreferredSize().height + difference)); |
414 |
|
415 |
getFieldsJPanel().setPreferredSize(new Dimension(getFieldsJPanel().getPreferredSize().width, getFieldsJPanel().getPreferredSize().height + difference)); |
416 |
getFieldsJScrollPane().setPreferredSize(new Dimension(getFieldsJScrollPane().getPreferredSize().width, getFieldsJScrollPane().getPreferredSize().height + difference)); |
417 |
|
418 |
getValuesJPanel().setPreferredSize(new Dimension(getValuesJPanel().getPreferredSize().width, getValuesJPanel().getPreferredSize().height + difference)); |
419 |
getValuesJScrollPane().setPreferredSize(new Dimension(getValuesJScrollPane().getPreferredSize().width, getValuesJScrollPane().getPreferredSize().height + difference)); |
420 |
} |
421 |
} |
422 |
|
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 |
int difference = height - DefaultHeight;
|
436 |
|
437 |
if (difference != 0) |
438 |
this.resizeHeight(height);
|
439 |
|
440 |
this.resizeWidth(width);
|
441 |
} |
442 |
|
443 |
/*
|
444 |
* (non-Javadoc)
|
445 |
* @see java.awt.Component#resize(java.awt.Dimension)
|
446 |
*/
|
447 |
public void resize(Dimension d) { |
448 |
int difference = d.height - DefaultHeight;
|
449 |
|
450 |
if (difference != 0) |
451 |
this.resizeHeight(d.height);
|
452 |
|
453 |
this.resizeWidth(d.width);
|
454 |
} |
455 |
} |