svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / utils / ResourcesTable / ButtonEditor.java @ 3566
History | View | Annotate | Download (3.78 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci??n Geogr??fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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 2
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib????ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
package es.gva.cit.catalogClient.utils.ResourcesTable; |
43 |
import es.gva.cit.catalogClient.schemas.discoverer.Resource; |
44 |
import es.gva.cit.catalogClient.ui.chooseResource.ChooseResourceDialogPanel; |
45 |
import java.awt.Component; |
46 |
import java.awt.event.ActionEvent; |
47 |
import java.awt.event.ActionListener; |
48 |
import java.util.Collection; |
49 |
import javax.swing.DefaultCellEditor; |
50 |
import javax.swing.JButton; |
51 |
import javax.swing.JCheckBox; |
52 |
import javax.swing.JTable; |
53 |
|
54 |
/**
|
55 |
*
|
56 |
*
|
57 |
*
|
58 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
59 |
*/
|
60 |
public class ButtonEditor extends DefaultCellEditor { |
61 |
/**
|
62 |
*
|
63 |
*
|
64 |
*/
|
65 |
protected JButton button; |
66 |
|
67 |
/**
|
68 |
*
|
69 |
*
|
70 |
*/
|
71 |
private String label; |
72 |
|
73 |
/**
|
74 |
*
|
75 |
*
|
76 |
*/
|
77 |
private boolean isPushed; |
78 |
/**
|
79 |
*
|
80 |
*
|
81 |
*/
|
82 |
private ChooseResourceDialogPanel dialog;
|
83 |
|
84 |
/**
|
85 |
*
|
86 |
*
|
87 |
*/
|
88 |
private java.util.Collection resources = new java.util.ArrayList(); |
89 |
|
90 |
/**
|
91 |
*
|
92 |
*
|
93 |
*
|
94 |
* @param checkBox
|
95 |
* @param resources
|
96 |
* @param dialog
|
97 |
*/
|
98 |
public ButtonEditor(JCheckBox checkBox, Collection resources, ChooseResourceDialogPanel dialog) { |
99 |
super(checkBox);
|
100 |
this.resources = resources;
|
101 |
this.dialog = dialog;
|
102 |
button = new JButton(); |
103 |
button.setOpaque(true);
|
104 |
button.addActionListener(new ActionListener() { |
105 |
public void actionPerformed(ActionEvent e) { |
106 |
fireEditingStopped(); |
107 |
} |
108 |
}); |
109 |
} |
110 |
|
111 |
/**
|
112 |
*
|
113 |
*
|
114 |
*
|
115 |
* @return
|
116 |
* @param table
|
117 |
* @param value
|
118 |
* @param isSelected
|
119 |
* @param row
|
120 |
* @param column
|
121 |
*/
|
122 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
123 |
if (isSelected) {
|
124 |
button.setForeground(table.getSelectionForeground()); |
125 |
button.setBackground(table.getSelectionBackground()); |
126 |
} else{
|
127 |
button.setForeground(table.getForeground()); |
128 |
button.setBackground(table.getBackground()); |
129 |
} |
130 |
label = (value == null) ? "" : value.toString(); |
131 |
button.setText( label ); |
132 |
button.setName(String.valueOf(row));
|
133 |
isPushed = true;
|
134 |
return button;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
*
|
139 |
*
|
140 |
*
|
141 |
* @return
|
142 |
*/
|
143 |
public Object getCellEditorValue() { |
144 |
if (isPushed) {
|
145 |
Resource resource = (Resource)resources.toArray()[Integer.valueOf(button.getName()).intValue()];
|
146 |
this.dialog.resourceButtonActionPerformed(resource);
|
147 |
|
148 |
} |
149 |
isPushed = false;
|
150 |
return new String(label) ; |
151 |
} |
152 |
|
153 |
/**
|
154 |
*
|
155 |
*
|
156 |
*
|
157 |
* @return
|
158 |
*/
|
159 |
public boolean stopCellEditing() { |
160 |
isPushed = false;
|
161 |
return super.stopCellEditing(); |
162 |
} |
163 |
|
164 |
/**
|
165 |
*
|
166 |
*
|
167 |
*/
|
168 |
protected void fireEditingStopped() { |
169 |
super.fireEditingStopped();
|
170 |
} |
171 |
} |