Revision 9855 trunk/libraries/libUI/src/org/gvsig/gui/beans/filterPanel/filterQueryPanel/FilterQueryJPanel.java
FilterQueryJPanel.java | ||
---|---|---|
1 | 1 |
package org.gvsig.gui.beans.filterPanel.filterQueryPanel; |
2 | 2 |
|
3 |
import java.awt.Color; |
|
4 | 3 |
import java.awt.Dimension; |
5 | 4 |
import java.awt.GridBagConstraints; |
6 | 5 |
import java.awt.GridBagLayout; |
... | ... | |
8 | 7 |
|
9 | 8 |
import javax.swing.BorderFactory; |
10 | 9 |
import javax.swing.DefaultListModel; |
11 |
import javax.swing.JLabel;
|
|
10 |
import javax.swing.JCheckBox;
|
|
12 | 11 |
import javax.swing.JPanel; |
13 | 12 |
import javax.swing.JScrollPane; |
14 | 13 |
|
15 | 14 |
import org.gvsig.gui.beans.Messages; |
16 | 15 |
import org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel; |
17 | 16 |
import org.gvsig.gui.beans.filterPanel.JLabelCellRenderer; |
17 |
import org.gvsig.gui.beans.filterPanel.filterQueryPanel.jLabelAsCell.DefaultListModelForJLabelAsCell; |
|
18 | 18 |
|
19 | 19 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
20 | 20 |
* |
... | ... | |
64 | 64 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com) |
65 | 65 |
*/ |
66 | 66 |
public class FilterQueryJPanel extends AbstractFilterQueryJPanel implements Serializable{ |
67 |
private static final long serialVersionUID = -5772343767095703604L; |
|
68 |
|
|
67 |
protected JPanel topCenterJPanel = null; |
|
68 |
protected JCheckBox validateFilterExpressionJCheckBox = null; |
|
69 |
|
|
69 | 70 |
protected int filterJScrollPaneHeight = defaultBottomJPanelHeight - 10; |
70 | 71 |
protected int filterJScrollPanelWidth = defaultBottomJPanelWidth; |
72 |
protected int validateFilterExpressionJCheckBoxHeight = 20; |
|
71 | 73 |
|
72 | 74 |
/** |
73 | 75 |
* @see AbstractFilterQueryJPanel#AbstractFilterQueryJPanel() |
... | ... | |
220 | 222 |
txtExpression.setLineWrap(true); |
221 | 223 |
} |
222 | 224 |
|
225 |
|
|
223 | 226 |
return txtExpression; |
224 | 227 |
} |
228 |
|
|
229 |
/* |
|
230 |
* (non-Javadoc) |
|
231 |
* @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getTopJPanel() |
|
232 |
*/ |
|
233 |
protected JPanel getTopJPanel() { |
|
234 |
if (topJPanel == null) { |
|
235 |
topJPanel = new JPanel(); |
|
236 |
|
|
237 |
topJPanel.setPreferredSize(new Dimension(defaultTopJPanelWidth, defaultTopJPanelHeight)); |
|
238 |
topJPanel.setLayout(new GridBagLayout()); |
|
239 |
|
|
240 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
241 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; |
|
242 |
|
|
243 |
gridBagConstraints.anchor = GridBagConstraints.WEST; |
|
244 |
topJPanel.add(getFieldsJPanel(), gridBagConstraints); |
|
245 |
|
|
246 |
gridBagConstraints.anchor = GridBagConstraints.CENTER; |
|
247 |
// topJPanel.add(getFilterButtonsJPanel(), gridBagConstraints); |
|
248 |
topJPanel.add(getTopCenterJPanel(), gridBagConstraints); |
|
249 |
// topJPanel.add(getValidateFilterExpressionJCheckBox(), gridBagConstraints); |
|
250 |
|
|
251 |
gridBagConstraints.anchor = GridBagConstraints.EAST; |
|
252 |
topJPanel.add(getValuesJPanel(), gridBagConstraints); |
|
253 |
} |
|
254 |
|
|
255 |
return topJPanel; |
|
256 |
} |
|
225 | 257 |
|
258 |
/** |
|
259 |
* This method initializes topCenterJPanel |
|
260 |
* |
|
261 |
* @return javax.swing.JPanel |
|
262 |
*/ |
|
263 |
protected JPanel getTopCenterJPanel() { |
|
264 |
if (topCenterJPanel == null) { |
|
265 |
topCenterJPanel = new JPanel(); |
|
266 |
topCenterJPanel.setPreferredSize(new Dimension(getFilterButtonsJPanel().getPreferredSize().width, getFilterButtonsJPanel().getPreferredSize().height + validateFilterExpressionJCheckBoxHeight)); |
|
267 |
topCenterJPanel.setLayout(null); |
|
268 |
|
|
269 |
getFilterButtonsJPanel().setBounds(0, 0, getFilterButtonsJPanel().getPreferredSize().width, getFilterButtonsJPanel().getPreferredSize().height); |
|
270 |
topCenterJPanel.add(getFilterButtonsJPanel()); |
|
271 |
topCenterJPanel.add(getValidateFilterExpressionJCheckBox()); |
|
272 |
} |
|
273 |
return topCenterJPanel; |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* This method initializes validateFilterExpressionJCheckBox |
|
278 |
* |
|
279 |
* @return javax.swing.JCheckBox |
|
280 |
*/ |
|
281 |
protected JCheckBox getValidateFilterExpressionJCheckBox() { |
|
282 |
if (validateFilterExpressionJCheckBox == null) { |
|
283 |
validateFilterExpressionJCheckBox = new JCheckBox(); |
|
284 |
validateFilterExpressionJCheckBox.setBounds(3, getFilterButtonsJPanel().getPreferredSize().height, getFilterButtonsJPanel().getWidth(), validateFilterExpressionJCheckBoxHeight); |
|
285 |
validateFilterExpressionJCheckBox.setText(Messages.getText("validate_expression")); |
|
286 |
validateFilterExpressionJCheckBox.setToolTipText(Messages.getText("validate_filter_expression_explanation")); |
|
287 |
} |
|
288 |
return validateFilterExpressionJCheckBox; |
|
289 |
} |
|
290 |
|
|
226 | 291 |
/* |
227 | 292 |
* (non-Javadoc) |
228 | 293 |
* @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getBottomJPanel() |
... | ... | |
261 | 326 |
getValuesJScrollPane().setPreferredSize(new Dimension(getValuesJScrollPane().getPreferredSize().width + halfDifference, getValuesJScrollPane().getPreferredSize().height)); |
262 | 327 |
} |
263 | 328 |
} |
264 |
|
|
265 |
/** |
|
266 |
* Extension of JLabel that has some specific characteristics -> Version for values that are loaded in layer in view |
|
267 |
* |
|
268 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com) |
|
269 |
*/ |
|
270 |
protected final class JLabelValueLoaded extends JLabel implements Comparable { |
|
271 |
|
|
272 |
/** |
|
273 |
* Default constructor without parameters |
|
274 |
*/ |
|
275 |
public JLabelValueLoaded() { |
|
276 |
super(); |
|
277 |
this.configure(); |
|
278 |
} |
|
279 |
|
|
280 |
/** |
|
281 |
* Default constructor with a parameter |
|
282 |
* |
|
283 |
* @param text |
|
284 |
*/ |
|
285 |
public JLabelValueLoaded(String text) { |
|
286 |
super(text); |
|
287 |
this.configure(); |
|
288 |
} |
|
289 |
|
|
290 |
/** |
|
291 |
* Configures some characteristics |
|
292 |
*/ |
|
293 |
private void configure() { |
|
294 |
this.setBackground(Color.yellow); |
|
295 |
this.setForeground(Color.blue); |
|
296 |
} |
|
297 |
|
|
298 |
/* |
|
299 |
* (non-Javadoc) |
|
300 |
* @see java.lang.Comparable#compareTo(java.lang.Object) |
|
301 |
*/ |
|
302 |
public int compareTo(Object o) { |
|
303 |
// It's supposed that 'o' is an string |
|
304 |
return this.getText().compareTo((String)o); |
|
305 |
} |
|
306 |
|
|
307 |
/* |
|
308 |
* (non-Javadoc) |
|
309 |
* @see java.lang.Object#toString() |
|
310 |
*/ |
|
311 |
public String toString() { |
|
312 |
return this.getText(); |
|
313 |
} |
|
314 |
} |
|
315 |
|
|
316 |
/** |
|
317 |
* Extension of JLabel that has some specific characteristics -> Version for values that aren't loaded in layer in view |
|
318 |
* |
|
319 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com) |
|
320 |
*/ |
|
321 |
protected final class JLabelValueNotLoaded extends JLabel implements Comparable{ |
|
322 |
|
|
323 |
/** |
|
324 |
* Default constructor without parameters |
|
325 |
*/ |
|
326 |
public JLabelValueNotLoaded() { |
|
327 |
super(); |
|
328 |
this.configure(); |
|
329 |
} |
|
330 |
|
|
331 |
/** |
|
332 |
* Default constructor with a parameter |
|
333 |
* |
|
334 |
* @param text |
|
335 |
*/ |
|
336 |
public JLabelValueNotLoaded(String text) { |
|
337 |
super(text); |
|
338 |
this.configure(); |
|
339 |
} |
|
340 |
|
|
341 |
/** |
|
342 |
* Configures some characteristics |
|
343 |
*/ |
|
344 |
private void configure() { |
|
345 |
this.setBackground(Color.white); |
|
346 |
} |
|
347 |
|
|
348 |
/* |
|
349 |
* (non-Javadoc) |
|
350 |
* @see java.lang.Comparable#compareTo(java.lang.Object) |
|
351 |
*/ |
|
352 |
public int compareTo(Object o) { |
|
353 |
// It's supposed that 'o' is an string |
|
354 |
return this.getText().compareTo((String)o); |
|
355 |
} |
|
356 |
|
|
357 |
/* |
|
358 |
* (non-Javadoc) |
|
359 |
* @see java.lang.Object#toString() |
|
360 |
*/ |
|
361 |
public String toString() { |
|
362 |
return this.getText(); |
|
363 |
} |
|
364 |
} |
|
365 |
|
|
366 |
/** |
|
367 |
* This class reimplements the "contains()" method of "DefaultListModel" for |
|
368 |
* |
|
369 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com) |
|
370 |
* |
|
371 |
*/ |
|
372 |
protected final class DefaultListModelForJLabelAsCell extends DefaultListModel{ |
|
373 |
|
|
374 |
/** |
|
375 |
* Represents the start index of the group of not loaded values (that should be after the group of loaded values) |
|
376 |
* -2 -> if elements aren't grouped (in two lists: first for loaded, after for not loaded) |
|
377 |
* -1 -> if there isn't elements |
|
378 |
* 0 -> if there are only not loaded elements |
|
379 |
* = (capacity() -1) -> if there are only loaded elements |
|
380 |
*/ |
|
381 |
private int startIndexOfNotLoadedValues; |
|
382 |
|
|
383 |
/** |
|
384 |
* Default constructor without parameters |
|
385 |
*/ |
|
386 |
public DefaultListModelForJLabelAsCell() { |
|
387 |
super(); |
|
388 |
startIndexOfNotLoadedValues = -1; |
|
389 |
} |
|
390 |
|
|
391 |
/** |
|
392 |
* Method that returns true if there is a inner JLabel that has as inner text the same text as 'patternText' |
|
393 |
* |
|
394 |
* @param patternText |
|
395 |
* @return A boolean value |
|
396 |
*/ |
|
397 |
public boolean containsJLabelText(String patternText) { |
|
398 |
for (int i = 0; i < super.getSize(); i++) { |
|
399 |
if (((JLabel)super.get(i)).getText().compareTo(patternText) == 0) |
|
400 |
return true; |
|
401 |
} |
|
402 |
|
|
403 |
return false; |
|
404 |
} |
|
405 |
|
|
406 |
/** |
|
407 |
* Returns the position of first JLabel that has as text the same text as 'patternText', or -1 if no JLabel has that text |
|
408 |
* |
|
409 |
* @param patternText An String |
|
410 |
* @return An integer value |
|
411 |
*/ |
|
412 |
public int getIndexOfJLabelText(String patternText) { |
|
413 |
for (int i = 0; i < super.getSize(); i++) { |
|
414 |
if (((JLabel)super.get(i)).getText().compareTo(patternText) == 0) |
|
415 |
return i; |
|
416 |
} |
|
417 |
|
|
418 |
return -1; // If not found |
|
419 |
} |
|
420 |
|
|
421 |
/** |
|
422 |
* Changes element to |
|
423 |
* |
|
424 |
* @param patternText |
|
425 |
*/ |
|
426 |
public void changeElementThatHasTextToJLabelLoadedValue(String patternText) { |
|
427 |
int index = getIndexOfJLabelText(patternText); |
|
428 |
|
|
429 |
if (index != -1) |
|
430 |
super.set(index, new JLabelValueLoaded(patternText)); |
|
431 |
} |
|
432 |
|
|
433 |
/** |
|
434 |
* Sets all elements to 'JLabelValueNotLoaded' |
|
435 |
*/ |
|
436 |
public void setAllElementsToNotLoaded() { |
|
437 |
if (startIndexOfNotLoadedValues == -1) { |
|
438 |
for (int i = 0; i < super.getSize(); i++) { |
|
439 |
if (super.get(i) instanceof JLabelValueLoaded) { |
|
440 |
JLabelValueNotLoaded jL = new JLabelValueNotLoaded(((JLabelValueLoaded)super.get(i)).getText()); |
|
441 |
super.remove(i); |
|
442 |
super.add(i, jL);///// REIMPLEMENTATION OF SOME METHODS OF 'DefaultListModel' ///// |
|
443 |
} |
|
444 |
} |
|
445 |
} |
|
446 |
else { |
|
447 |
for (int i = 0; i < startIndexOfNotLoadedValues; i++) { |
|
448 |
if (super.get(i) instanceof JLabelValueLoaded) { |
|
449 |
JLabelValueNotLoaded jL = new JLabelValueNotLoaded(((JLabelValueLoaded)super.get(i)).getText()); |
|
450 |
super.set(i, jL); // replacement |
|
451 |
} |
|
452 |
} |
|
453 |
} |
|
454 |
|
|
455 |
startIndexOfNotLoadedValues = 0; |
|
456 |
} |
|
457 |
|
|
458 |
///// REIMPLEMENTATION OF SOME METHODS OF 'DefaultListModel' ///// |
|
459 |
|
|
460 |
/* |
|
461 |
* (non-Javadoc) |
|
462 |
* @see javax.swing.DefaultListModel#clear() |
|
463 |
*/ |
|
464 |
public void clear() { |
|
465 |
super.clear(); |
|
466 |
startIndexOfNotLoadedValues = -1; |
|
467 |
} |
|
468 |
|
|
469 |
/* |
|
470 |
* (non-Javadoc) |
|
471 |
* @see javax.swing.DefaultListModel#insertElementAt(java.lang.Object, int) |
|
472 |
*/ |
|
473 |
public void insertElementAt(Object obj, int index) { |
|
474 |
super.insertElementAt(obj, index); |
|
475 |
|
|
476 |
if ((obj instanceof JLabelValueNotLoaded) && (index > -1) && (index < startIndexOfNotLoadedValues)) |
|
477 |
startIndexOfNotLoadedValues = index; |
|
478 |
} |
|
479 |
|
|
480 |
/* |
|
481 |
* (non-Javadoc) |
|
482 |
* @see javax.swing.DefaultListModel#remove(int) |
|
483 |
*/ |
|
484 |
public Object remove(int index) { |
|
485 |
if ( (index > -1) && (index == startIndexOfNotLoadedValues) && (index == (super.capacity() -1)) ) { |
|
486 |
startIndexOfNotLoadedValues = -1; |
|
487 |
} |
|
488 |
|
|
489 |
return super.remove(index); |
|
490 |
} |
|
491 |
|
|
492 |
/* |
|
493 |
* (non-Javadoc) |
|
494 |
* @see javax.swing.DefaultListModel#removeAllElements() |
|
495 |
*/ |
|
496 |
public void removeAllElements() { |
|
497 |
super.removeAllElements(); |
|
498 |
startIndexOfNotLoadedValues = -1; |
|
499 |
} |
|
500 |
|
|
501 |
/* |
|
502 |
* (non-Javadoc) |
|
503 |
* @see javax.swing.DefaultListModel#removeElement(java.lang.Object) |
|
504 |
*/ |
|
505 |
public boolean removeElement(Object obj) { |
|
506 |
int index = super.indexOf(obj); |
|
507 |
|
|
508 |
if ( (index > -1) && (index == startIndexOfNotLoadedValues) && (index == (super.capacity() -1)) ) { |
|
509 |
startIndexOfNotLoadedValues = -1; |
|
510 |
} |
|
511 |
|
|
512 |
return super.removeElement(obj); |
|
513 |
} |
|
514 |
|
|
515 |
/* |
|
516 |
* (non-Javadoc) |
|
517 |
* @see javax.swing.DefaultListModel#removeElementAt(int) |
|
518 |
*/ |
|
519 |
public void removeElementAt(int index) { |
|
520 |
if ( (index > -1) && (index == startIndexOfNotLoadedValues) && (index == (super.capacity() -1)) ) { |
|
521 |
startIndexOfNotLoadedValues = -1; |
|
522 |
} |
|
523 |
|
|
524 |
super.removeElementAt(index); |
|
525 |
} |
|
526 |
|
|
527 |
/* |
|
528 |
* (non-Javadoc) |
|
529 |
* @see javax.swing.DefaultListModel#removeRange(int, int) |
|
530 |
*/ |
|
531 |
public void removeRange(int fromIndex, int toIndex) { |
|
532 |
super.removeRange(fromIndex, toIndex); |
|
533 |
|
|
534 |
// Try to find any element of type 'JLabelNotLoadedValue' |
|
535 |
for (int i = 0; i < super.capacity(); i++) { |
|
536 |
if (super.get(i) instanceof JLabelValueNotLoaded) { |
|
537 |
if ( ( (i == (super.capacity() -1) || (i < (super.capacity() -1)) && (super.get(super.capacity() -1) instanceof JLabelValueNotLoaded) ) ) ) |
|
538 |
startIndexOfNotLoadedValues = i; |
|
539 |
else |
|
540 |
startIndexOfNotLoadedValues = -1; |
|
541 |
} |
|
542 |
} |
|
543 |
} |
|
544 |
|
|
545 |
/* |
|
546 |
* (non-Javadoc) |
|
547 |
* @see javax.swing.DefaultListModel#set(int, java.lang.Object) |
|
548 |
*/ |
|
549 |
public Object set(int index, Object element) { |
|
550 |
if ((element instanceof JLabelValueNotLoaded) && (index > -1) && (index < startIndexOfNotLoadedValues)) |
|
551 |
startIndexOfNotLoadedValues = index; |
|
552 |
|
|
553 |
return super.set(index, element); |
|
554 |
} |
|
555 |
|
|
556 |
/* |
|
557 |
* (non-Javadoc) |
|
558 |
* @see javax.swing.DefaultListModel#setElementAt(java.lang.Object, int) |
|
559 |
*/ |
|
560 |
public void setElementAt(Object obj, int index) { |
|
561 |
super.setElementAt(obj, index); |
|
562 |
|
|
563 |
if ((obj instanceof JLabelValueNotLoaded) && (index > -1) && (index < startIndexOfNotLoadedValues)) |
|
564 |
startIndexOfNotLoadedValues = index; |
|
565 |
} |
|
566 |
|
|
567 |
///// END REIMPLEMENTATION OF SOME METHODS OF 'DefaultListModel' ///// |
|
568 |
} |
|
569 | 329 |
} |
Also available in: Unified diff