svn-gvsig-desktop / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / table / models / TableColorButtonColumnEditor.java @ 10885
History | View | Annotate | Download (2.82 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.Color; |
22 |
import java.awt.Component; |
23 |
import java.awt.event.ActionEvent; |
24 |
import java.awt.event.ActionListener; |
25 |
|
26 |
import javax.swing.AbstractCellEditor; |
27 |
import javax.swing.JButton; |
28 |
import javax.swing.JColorChooser; |
29 |
import javax.swing.JDialog; |
30 |
import javax.swing.JTable; |
31 |
import javax.swing.table.TableCellEditor; |
32 |
|
33 |
import org.gvsig.i18n.Messages; |
34 |
|
35 |
/**
|
36 |
* Editor de celda con un bot?n selector de color-
|
37 |
*
|
38 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
39 |
*
|
40 |
*/
|
41 |
public class TableColorButtonColumnEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { |
42 |
private static final long serialVersionUID = -6627842834708616873L; |
43 |
Color currentColor;
|
44 |
JButton button;
|
45 |
JColorChooser colorChooser;
|
46 |
JDialog dialog;
|
47 |
private TableButtonModel tableModel = null; |
48 |
private JTable table = null; |
49 |
protected static final String EDIT = "edit"; |
50 |
|
51 |
public TableColorButtonColumnEditor(TableButtonModel tableModel, JTable table) { |
52 |
button = new JButton(); |
53 |
button.setActionCommand(EDIT); |
54 |
button.addActionListener(this);
|
55 |
button.setBorderPainted(false);
|
56 |
this.tableModel = tableModel;
|
57 |
this.table = table;
|
58 |
|
59 |
colorChooser = new JColorChooser(); |
60 |
dialog = JColorChooser.createDialog(button, Messages.getText("seleccion_color"), true, colorChooser, this, null); |
61 |
} |
62 |
|
63 |
public void actionPerformed(ActionEvent e) { |
64 |
if (EDIT.equals(e.getActionCommand())) {
|
65 |
button.setBackground(currentColor); |
66 |
colorChooser.setColor(currentColor); |
67 |
dialog.setVisible(true);
|
68 |
if(tableModel != null && table != null) |
69 |
tableModel.setValueAt(currentColor.getRed()+","+currentColor.getGreen()+","+currentColor.getBlue(), table.getSelectedRow(), 2); |
70 |
fireEditingStopped(); |
71 |
|
72 |
} else
|
73 |
currentColor = colorChooser.getColor(); |
74 |
|
75 |
} |
76 |
|
77 |
public Object getCellEditorValue() { |
78 |
return currentColor;
|
79 |
} |
80 |
|
81 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, |
82 |
int row, int column) { |
83 |
currentColor = (Color)value;
|
84 |
return button;
|
85 |
} |
86 |
} |