svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / swing / objectSelection / ObjectSelection.java @ 40561
History | View | Annotate | Download (2.97 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.utils.swing.objectSelection; |
25 |
|
26 |
import javax.swing.DefaultComboBoxModel; |
27 |
import javax.swing.JLabel; |
28 |
import javax.swing.JPanel; |
29 |
|
30 |
import org.gvsig.utils.swing.JComboBox; |
31 |
|
32 |
|
33 |
|
34 |
/**
|
35 |
* Control consistente en un texto y un combo autocompletable
|
36 |
*
|
37 |
* @author Fernando Gonz?lez Cort?s
|
38 |
*/
|
39 |
public class ObjectSelection extends JPanel { |
40 |
private JLabel jLabel = null; |
41 |
private JComboBox combo = null; |
42 |
private ObjectSelectionModel model;
|
43 |
private DefaultComboBoxModel cmbModel = new DefaultComboBoxModel(); |
44 |
private Object selected; |
45 |
/**
|
46 |
* This is the default constructor
|
47 |
*/
|
48 |
public ObjectSelection() {
|
49 |
super();
|
50 |
initialize(); |
51 |
} |
52 |
|
53 |
/**
|
54 |
* This method initializes this
|
55 |
*/
|
56 |
private void initialize() { |
57 |
jLabel = new JLabel(); |
58 |
this.setSize(504, 265); |
59 |
this.add(jLabel, null); |
60 |
this.add(getCombo(), null); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Obtiene una referencia al combo
|
65 |
*
|
66 |
* @return com.iver.utiles.swing.JComboBox
|
67 |
*/
|
68 |
protected JComboBox getCombo() { |
69 |
if (combo == null) { |
70 |
combo = new JComboBox(); |
71 |
combo.setModel(cmbModel); |
72 |
combo.setEditable(true);
|
73 |
combo.addItemListener(new java.awt.event.ItemListener() {
|
74 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
75 |
seleccion(); |
76 |
} |
77 |
}); |
78 |
} |
79 |
|
80 |
return combo;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* M?todo invocado cuando cambia la selecci?n del combo
|
85 |
*/
|
86 |
protected void seleccion() { |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Establece el modelo del control
|
91 |
*
|
92 |
* @param model The model to set.
|
93 |
*
|
94 |
* @throws SelectionException Si hay alg?n error leyendo los
|
95 |
* datos del modelo
|
96 |
*/
|
97 |
public void setModel(ObjectSelectionModel model) throws SelectionException { |
98 |
this.model = model;
|
99 |
|
100 |
Object[] objects = model.getObjects(); |
101 |
cmbModel.removeAllElements(); |
102 |
|
103 |
for (int i = 0; i < objects.length; i++) { |
104 |
cmbModel.addElement(objects[i]); |
105 |
} |
106 |
|
107 |
getCombo().setSelectedIndex(-1);
|
108 |
|
109 |
jLabel.setText(model.getMsg()); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Obtiene el elemento actualmente seleccionado
|
114 |
*
|
115 |
* @return Returns the selected item.
|
116 |
*/
|
117 |
public Object getSelected() { |
118 |
return cmbModel.getSelectedItem();
|
119 |
} |
120 |
} // @jve:decl-index=0:visual-constraint="10,10"
|