root / trunk / libraries / libUIComponent_praster / src / org / gvsig / gui / beans / table / models / TableSelectorButtonColumnEditor.java @ 8026
History | View | Annotate | Download (2.46 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.gui.beans.table.models; |
20 |
|
21 |
import java.awt.Component; |
22 |
import java.awt.event.ActionEvent; |
23 |
import java.awt.event.ActionListener; |
24 |
|
25 |
import javax.swing.AbstractCellEditor; |
26 |
import javax.swing.JButton; |
27 |
import javax.swing.JDialog; |
28 |
import javax.swing.JTable; |
29 |
import javax.swing.table.TableCellEditor; |
30 |
|
31 |
import org.gvsig.i18n.Messages; |
32 |
|
33 |
/**
|
34 |
* Componente tabla
|
35 |
*
|
36 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
37 |
*
|
38 |
*/
|
39 |
public class TableSelectorButtonColumnEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { |
40 |
String currentText = "255"; |
41 |
JButton button;
|
42 |
JValueSelector valueSelector; |
43 |
JDialog dialog;
|
44 |
protected static final String EDIT = "edit"; |
45 |
|
46 |
public TableSelectorButtonColumnEditor() {
|
47 |
button = new JButton(); |
48 |
button.setActionCommand(EDIT); |
49 |
button.addActionListener(this);
|
50 |
button.setBorderPainted(false);
|
51 |
|
52 |
valueSelector = new JValueSelector();
|
53 |
dialog = JValueSelector.createDialog(button, Messages.getText("seleccion_alpha"), true, valueSelector, this, null, currentText); |
54 |
} |
55 |
|
56 |
public void actionPerformed(ActionEvent e) { |
57 |
if (EDIT.equals(e.getActionCommand())) {
|
58 |
button.setText(currentText); |
59 |
((ValueSelector)dialog).setValue(Integer.valueOf(currentText).intValue());
|
60 |
dialog.setVisible(true);
|
61 |
|
62 |
fireEditingStopped(); |
63 |
|
64 |
}else{
|
65 |
currentText = String.valueOf((int)((ValueSelector)dialog).getValue()); |
66 |
button.setText(currentText); |
67 |
} |
68 |
} |
69 |
|
70 |
public Object getCellEditorValue() { |
71 |
return currentText;
|
72 |
} |
73 |
|
74 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, |
75 |
int row, int column) { |
76 |
currentText = (String)value;
|
77 |
return button;
|
78 |
} |
79 |
} |