svn-gvsig-desktop / trunk / extensions / extTableSummarize / src / org / gvsig / app / documents / table / summarize / utils / JComboBoxExt.java @ 27691
History | View | Annotate | Download (2.78 KB)
1 |
package org.gvsig.app.documents.table.summarize.utils; |
---|---|
2 |
|
3 |
import javax.swing.JComboBox; |
4 |
import javax.swing.JTextField; |
5 |
import javax.swing.text.AbstractDocument; |
6 |
|
7 |
/**
|
8 |
* JComboBoxExt es una clase que extiende JComboBox para incorporar nuevas caracter?sticas como
|
9 |
* lo posibilidad de bloquear la edici?n en el control por parte del usuario.
|
10 |
*/
|
11 |
public class JComboBoxExt extends JComboBox{ |
12 |
|
13 |
|
14 |
private static final long serialVersionUID = 1L; |
15 |
private DocumentFilterExt loDocumentFilterExt = null; //El control del m?ximo n?mero de caracteres admitidos, etc. se realiza desde este objeto |
16 |
//private boolean locked = false; //Atributo de loDocumentFilterExt
|
17 |
//private int maxLength = 0; //Atributo de loDocumentFilterExt
|
18 |
|
19 |
|
20 |
public JComboBoxExt(){
|
21 |
super();
|
22 |
|
23 |
Object c = getEditor().getEditorComponent();
|
24 |
if (c instanceof JTextField){ |
25 |
loDocumentFilterExt = new DocumentFilterExt();
|
26 |
((AbstractDocument)((JTextField)c).getDocument()).setDocumentFilter(loDocumentFilterExt); |
27 |
}//if (c instanceof JTextField){
|
28 |
|
29 |
} |
30 |
|
31 |
public void setLocked(boolean locked){ |
32 |
//this.locked = locked;
|
33 |
if (loDocumentFilterExt == null) return; |
34 |
loDocumentFilterExt.setLocked(locked); |
35 |
} |
36 |
|
37 |
public boolean isLocked(){ |
38 |
//return this.locked;
|
39 |
if (loDocumentFilterExt == null) return false; |
40 |
return loDocumentFilterExt.isLocked();
|
41 |
} |
42 |
|
43 |
public int getMaxLength(){ |
44 |
if (loDocumentFilterExt == null) return 0; |
45 |
return loDocumentFilterExt.getMaxLength();
|
46 |
} |
47 |
|
48 |
public void setMaxLength(int maxLength){ |
49 |
if (loDocumentFilterExt == null) return; |
50 |
loDocumentFilterExt.setMaxLength(maxLength); |
51 |
} |
52 |
|
53 |
|
54 |
public void setSelectedIndex(int anIndex) { |
55 |
setSelectedIndex(anIndex, false);
|
56 |
} |
57 |
/*
|
58 |
public void setSelectedItem(Object anObject) {
|
59 |
setSelectedItem(anObject, false);
|
60 |
}
|
61 |
*/
|
62 |
/**
|
63 |
* @param anIndex
|
64 |
* @param forceSelection - Si True, se intenta seleccionar el elemento independientemente
|
65 |
* de si el control est? bloqueado o no (locked)
|
66 |
*/
|
67 |
public void setSelectedIndex(int anIndex, boolean forceSelection) { |
68 |
if (isLocked() && !forceSelection) return; |
69 |
//OJO: setSelectedIndex llama internamente a super.setSelectedItem() que a su vez llamar? a setSelectedItem(anObject, false)!!!
|
70 |
//Con este flujo, el valor de forceSelection en este m?todo no se propaga! Para solucionar esto no debemos sobrescribir
|
71 |
//setSelectedItem. El boqueo sigue funcionando igual porque cuando act?as desde el interfaz de usuario, para seleccionar un
|
72 |
//elemento siempre se "entra" por setSelectedIndex.
|
73 |
super.setSelectedIndex(anIndex);
|
74 |
} |
75 |
/*
|
76 |
public void setSelectedItem(Object anObject, boolean forceSelection) {
|
77 |
if (locked && !forceSelection) return;
|
78 |
super.setSelectedItem(anObject);
|
79 |
}
|
80 |
*/
|
81 |
} |