root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / filterPanel / AbstractFilterQueryJPanel.java @ 13136
History | View | Annotate | Download (12.5 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 operatorSymbols; |
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 |
operatorSymbols = null;
|
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 abstract javax.swing.JPanel getTopJPanel(); |
149 |
|
150 |
/**
|
151 |
* This method initializes bottomJPanel
|
152 |
*
|
153 |
* @return javax.swing.JPanel
|
154 |
*/
|
155 |
protected abstract JPanel getBottomJPanel(); |
156 |
|
157 |
/**
|
158 |
* This method initializes fieldsJLabel
|
159 |
*
|
160 |
* @return javax.swing.JLabel
|
161 |
*/
|
162 |
protected javax.swing.JLabel getFieldsJLabel() {
|
163 |
if (fieldsJLabel == null) { |
164 |
fieldsJLabel = new javax.swing.JLabel();
|
165 |
fieldsJLabel.setText(Messages.getText("fields_uppercase_first") + ":"); |
166 |
} |
167 |
|
168 |
return fieldsJLabel;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* This method initializes valuesJList
|
173 |
*
|
174 |
* @return javax.swing.JList
|
175 |
*/
|
176 |
protected abstract javax.swing.JList getValuesJList(); |
177 |
|
178 |
/**
|
179 |
* This method initializes fieldsJPanel
|
180 |
*
|
181 |
* @return javax.swing.JPanel
|
182 |
*/
|
183 |
protected abstract JPanel getFieldsJPanel(); |
184 |
|
185 |
/**
|
186 |
* This method initializes jScrollPane
|
187 |
*
|
188 |
* @return javax.swing.JScrollPane
|
189 |
*/
|
190 |
protected abstract javax.swing.JScrollPane getFieldsJScrollPane(); |
191 |
|
192 |
/**
|
193 |
* This method initializes valuesJLabel
|
194 |
*
|
195 |
* @return javax.swing.JLabel
|
196 |
*/
|
197 |
protected javax.swing.JLabel getValuesJLabel() {
|
198 |
if (valuesJLabel == null) { |
199 |
valuesJLabel = new javax.swing.JLabel();
|
200 |
valuesJLabel.setText(Messages.getText("knownValues") + ":"); |
201 |
} |
202 |
|
203 |
return valuesJLabel;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* This method initializes valuesJPanel
|
208 |
*
|
209 |
* @return javax.swing.JPanel
|
210 |
*/
|
211 |
protected abstract JPanel getValuesJPanel(); |
212 |
|
213 |
/**
|
214 |
* This method initializes jScrollPane1
|
215 |
*
|
216 |
* @return javax.swing.JScrollPane
|
217 |
*/
|
218 |
protected abstract javax.swing.JScrollPane getValuesJScrollPane(); |
219 |
|
220 |
/**
|
221 |
* This method initializes filterJScrollPane
|
222 |
*
|
223 |
* @return javax.swing.JScrollPane
|
224 |
*/
|
225 |
protected abstract javax.swing.JScrollPane getFilterJScrollPane(); |
226 |
|
227 |
/**
|
228 |
* This method initializes txtExpression
|
229 |
*
|
230 |
* @return javax.swing.JTextArea
|
231 |
*/
|
232 |
protected abstract javax.swing.JTextArea getTxtExpression(); |
233 |
|
234 |
/**
|
235 |
* DOCUMENT ME!
|
236 |
*
|
237 |
* @param symbol DOCUMENT ME!
|
238 |
*/
|
239 |
protected void putSymbol(String symbol) { |
240 |
int position = getTxtExpression().getCaretPosition();
|
241 |
|
242 |
getTxtExpression().setText(insert(getTxtExpression().getText(), position, symbol)); |
243 |
|
244 |
if (symbol.equals(" () ")) { |
245 |
position = position + 2;
|
246 |
} else {
|
247 |
position = position + symbol.length(); |
248 |
} |
249 |
|
250 |
getTxtExpression().setCaretPosition(position); |
251 |
} |
252 |
|
253 |
/**
|
254 |
* This method initializes fieldsJTree
|
255 |
*
|
256 |
* @return javax.swing.JTree
|
257 |
*/
|
258 |
/*
|
259 |
* (non-Javadoc)
|
260 |
* @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getLstCampos()
|
261 |
*/
|
262 |
protected javax.swing.JTree getFieldsJTree() {
|
263 |
if (fieldsJTree == null) { |
264 |
fieldsJTree = new javax.swing.JTree(new Vector(0,1)); |
265 |
|
266 |
// Remove icons:
|
267 |
DefaultTreeCellRenderer defaultTreeCellRenderer = new DefaultTreeCellRenderer(); |
268 |
defaultTreeCellRenderer.setOpenIcon(null);
|
269 |
defaultTreeCellRenderer.setClosedIcon(null);
|
270 |
defaultTreeCellRenderer.setLeafIcon(null);
|
271 |
|
272 |
// Root not visible
|
273 |
fieldsJTree.setRootVisible(false);
|
274 |
fieldsJTree.setCellRenderer(defaultTreeCellRenderer); |
275 |
} |
276 |
|
277 |
return fieldsJTree;
|
278 |
} |
279 |
|
280 |
/**
|
281 |
* Inserta una string en otra en la posici?n indicada
|
282 |
*
|
283 |
* @param base String donde se inserta
|
284 |
* @param position posici?n de "base" donde se inserta la String
|
285 |
* @param injerto String que se inserta en "base"
|
286 |
*
|
287 |
* @return String con la inserci?n hecha
|
288 |
*/
|
289 |
protected static String insert(String base, int position, String injerto) { |
290 |
return base.substring(0, position) + injerto + |
291 |
base.substring(position); |
292 |
} |
293 |
|
294 |
|
295 |
/**
|
296 |
* This method initializes filterButtonsJPanel
|
297 |
*
|
298 |
* @return javax.swing.JPanel
|
299 |
*/
|
300 |
protected JPanel getFilterButtonsJPanel() { |
301 |
if (filterButtonsJPanel == null) { |
302 |
filterButtonsJPanel = new FilterButtonsJPanel();
|
303 |
filterButtonsJPanel.setPreferredSize(new Dimension(filterButtonsPanelWidth, filterButtonsPanelHeight)); |
304 |
filterButtonsJPanel.addPropertyChangeListener(new PropertyChangeListener() { |
305 |
/*
|
306 |
* (non-Javadoc)
|
307 |
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
308 |
*/
|
309 |
public void propertyChange(PropertyChangeEvent arg0) { |
310 |
if (arg0.getPropertyName().equals(FilterButtonsJPanel.BUTTON_CLICKED_ACTION_COMMAND)) {
|
311 |
|
312 |
switch(Integer.parseInt(arg0.getNewValue().toString())) { |
313 |
case FilterButtonsJPanel.AND:
|
314 |
putSymbol(" and ");
|
315 |
break;
|
316 |
case FilterButtonsJPanel.DATE:
|
317 |
putSymbol( ((FilterButtonsJPanel)arg0.getSource()).getLastSelectedDate() ); |
318 |
break;
|
319 |
case FilterButtonsJPanel.DISTINCT:
|
320 |
putSymbol(" <> ");
|
321 |
break;
|
322 |
case FilterButtonsJPanel.EQUAL:
|
323 |
putSymbol(" = ");
|
324 |
break;
|
325 |
case FilterButtonsJPanel.EQUALGREATER:
|
326 |
putSymbol(" >= ");
|
327 |
break;
|
328 |
case FilterButtonsJPanel.EQUALSMALLER:
|
329 |
putSymbol(" <= ");
|
330 |
break;
|
331 |
case FilterButtonsJPanel.GREATER:
|
332 |
putSymbol(" > ");
|
333 |
break;
|
334 |
case FilterButtonsJPanel.NOT:
|
335 |
putSymbol(" not ");
|
336 |
break;
|
337 |
case FilterButtonsJPanel.OR:
|
338 |
putSymbol(" or ");
|
339 |
break;
|
340 |
case FilterButtonsJPanel.PARENTHESIS:
|
341 |
putSymbol(" () ");
|
342 |
break;
|
343 |
case FilterButtonsJPanel.SMALLER:
|
344 |
putSymbol(" < ");
|
345 |
break;
|
346 |
case FilterButtonsJPanel.DELETE_TEXT:
|
347 |
txtExpression.setText("");
|
348 |
break;
|
349 |
default: // do anything |
350 |
} |
351 |
} |
352 |
} |
353 |
}); |
354 |
} |
355 |
|
356 |
return filterButtonsJPanel;
|
357 |
} |
358 |
|
359 |
/**
|
360 |
* Returns a set with all symbols used as operators
|
361 |
*
|
362 |
* @return A set
|
363 |
*/
|
364 |
protected Set getAllOperatorSymbols() { |
365 |
|
366 |
if (operatorSymbols == null) { |
367 |
operatorSymbols = new HashSet(); |
368 |
|
369 |
operatorSymbols.add("and");
|
370 |
// operatorSymbols.add("Date");
|
371 |
operatorSymbols.add("<>"); // In SQL this is the formal operator |
372 |
operatorSymbols.add("!="); // This operator is also supported |
373 |
operatorSymbols.add("=");
|
374 |
operatorSymbols.add(">=");
|
375 |
operatorSymbols.add("<=");
|
376 |
operatorSymbols.add(">");
|
377 |
operatorSymbols.add("not");
|
378 |
operatorSymbols.add("or");
|
379 |
operatorSymbols.add("(");
|
380 |
operatorSymbols.add(")");
|
381 |
operatorSymbols.add("<");
|
382 |
} |
383 |
|
384 |
return operatorSymbols;
|
385 |
} |
386 |
|
387 |
/**
|
388 |
* Sets new height to the 'topJPanel', (new Height must be bigger than default, else do nothing)
|
389 |
*
|
390 |
* @param new_Height New height
|
391 |
*/
|
392 |
public void resizeHeight(int new_Height) { |
393 |
int difference = new_Height - DefaultHeight;
|
394 |
|
395 |
if (difference > 0) { |
396 |
this.setPreferredSize(new Dimension(this.getPreferredSize().width, this.getPreferredSize().height + difference)); |
397 |
getTopJPanel().setPreferredSize(new Dimension(getTopJPanel().getPreferredSize().width, getTopJPanel().getPreferredSize().height + difference)); |
398 |
|
399 |
getFieldsJPanel().setPreferredSize(new Dimension(getFieldsJPanel().getPreferredSize().width, getFieldsJPanel().getPreferredSize().height + difference)); |
400 |
getFieldsJScrollPane().setPreferredSize(new Dimension(getFieldsJScrollPane().getPreferredSize().width, getFieldsJScrollPane().getPreferredSize().height + difference)); |
401 |
|
402 |
getValuesJPanel().setPreferredSize(new Dimension(getValuesJPanel().getPreferredSize().width, getValuesJPanel().getPreferredSize().height + difference)); |
403 |
getValuesJScrollPane().setPreferredSize(new Dimension(getValuesJScrollPane().getPreferredSize().width, getValuesJScrollPane().getPreferredSize().height + difference)); |
404 |
} |
405 |
} |
406 |
|
407 |
/**
|
408 |
* Sets the width to this JPanel
|
409 |
*
|
410 |
* @param new_Width New width
|
411 |
*/
|
412 |
public abstract void resizeWidth(int new_Width); |
413 |
|
414 |
/*
|
415 |
* (non-Javadoc)
|
416 |
* @see java.awt.Component#resize(int, int)
|
417 |
*/
|
418 |
public void resize(int width, int height) { |
419 |
int difference = height - DefaultHeight;
|
420 |
|
421 |
if (difference != 0) |
422 |
this.resizeHeight(height);
|
423 |
|
424 |
this.resizeWidth(width);
|
425 |
} |
426 |
|
427 |
/*
|
428 |
* (non-Javadoc)
|
429 |
* @see java.awt.Component#resize(java.awt.Dimension)
|
430 |
*/
|
431 |
public void resize(Dimension d) { |
432 |
int difference = d.height - DefaultHeight;
|
433 |
|
434 |
if (difference != 0) |
435 |
this.resizeHeight(d.height);
|
436 |
|
437 |
this.resizeWidth(d.width);
|
438 |
} |
439 |
} |