svn-gvsig-desktop / trunk / libraries / libIverUtiles / src / com / iver / utiles / swing / objectSelection / ObjectSelection.java @ 1836
History | View | Annotate | Download (2.07 KB)
1 |
package com.iver.utiles.swing.objectSelection; |
---|---|
2 |
|
3 |
import javax.swing.DefaultComboBoxModel; |
4 |
import javax.swing.JLabel; |
5 |
import javax.swing.JPanel; |
6 |
|
7 |
import com.iver.utiles.swing.JComboBox; |
8 |
|
9 |
|
10 |
/**
|
11 |
* Control consistente en un texto y un combo autocompletable
|
12 |
*
|
13 |
* @author Fernando Gonz?lez Cort?s
|
14 |
*/
|
15 |
public class ObjectSelection extends JPanel { |
16 |
private JLabel jLabel = null; |
17 |
private JComboBox combo = null; |
18 |
private ObjectSelectionModel model;
|
19 |
private DefaultComboBoxModel cmbModel = new DefaultComboBoxModel(); |
20 |
private Object selected; |
21 |
/**
|
22 |
* This is the default constructor
|
23 |
*/
|
24 |
public ObjectSelection() {
|
25 |
super();
|
26 |
initialize(); |
27 |
} |
28 |
|
29 |
/**
|
30 |
* This method initializes this
|
31 |
*/
|
32 |
private void initialize() { |
33 |
jLabel = new JLabel(); |
34 |
this.setSize(504, 265); |
35 |
jLabel.setText("Seleccione objeto:");
|
36 |
this.add(jLabel, null); |
37 |
this.add(getCombo(), null); |
38 |
} |
39 |
|
40 |
/**
|
41 |
* Obtiene una referencia al combo
|
42 |
*
|
43 |
* @return com.iver.utiles.swing.JComboBox
|
44 |
*/
|
45 |
protected JComboBox getCombo() { |
46 |
if (combo == null) { |
47 |
combo = new JComboBox(); |
48 |
combo.setModel(cmbModel); |
49 |
combo.setEditable(true);
|
50 |
combo.addItemListener(new java.awt.event.ItemListener() {
|
51 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
52 |
seleccion(); |
53 |
} |
54 |
}); |
55 |
} |
56 |
|
57 |
return combo;
|
58 |
} |
59 |
|
60 |
/**
|
61 |
* M?todo invocado cuando cambia la selecci?n del combo
|
62 |
*/
|
63 |
protected void seleccion() { |
64 |
} |
65 |
|
66 |
/**
|
67 |
* Establece el modelo del control
|
68 |
*
|
69 |
* @param model The model to set.
|
70 |
*
|
71 |
* @throws SelectionException Si hay alg?n error leyendo los
|
72 |
* datos del modelo
|
73 |
*/
|
74 |
public void setModel(ObjectSelectionModel model) throws SelectionException { |
75 |
this.model = model;
|
76 |
|
77 |
Object[] objects = model.getObjects(); |
78 |
cmbModel.removeAllElements(); |
79 |
|
80 |
for (int i = 0; i < objects.length; i++) { |
81 |
cmbModel.addElement(objects[i]); |
82 |
} |
83 |
|
84 |
getCombo().setSelectedIndex(-1);
|
85 |
|
86 |
jLabel.setText(model.getMsg()); |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Obtiene el elemento actualmente seleccionado
|
91 |
*
|
92 |
* @return Returns the selected item.
|
93 |
*/
|
94 |
public Object getSelected() { |
95 |
return cmbModel.getSelectedItem();
|
96 |
} |
97 |
} // @jve:decl-index=0:visual-constraint="10,10"
|