Statistics
| Revision:

svn-gvsig-desktop / tags / PilotoRaster_Build_5 / libraries / libUIComponent_praster / src / org / gvsig / gui / beans / table / models / TableColorButtonColumnEditor.java @ 11401

History | View | Annotate | Download (2.76 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
        Color currentColor;
43
        JButton button;
44
        JColorChooser colorChooser;
45
        JDialog dialog;
46
        private TableButtonModel tableModel = null;
47
        private JTable table = null;
48
        protected static final String EDIT = "edit";
49

    
50
        public TableColorButtonColumnEditor(TableButtonModel tableModel, JTable table) {
51
                button = new JButton();
52
                button.setActionCommand(EDIT);
53
                button.addActionListener(this);
54
                button.setBorderPainted(false);
55
                this.tableModel = tableModel;
56
                this.table = table;
57

    
58
                colorChooser = new JColorChooser();
59
                dialog = JColorChooser.createDialog(button, Messages.getText("seleccion_color"), true, colorChooser, this, null); 
60
        }
61

    
62
        public void actionPerformed(ActionEvent e) {
63
                if (EDIT.equals(e.getActionCommand())) {
64
                        button.setBackground(currentColor);
65
                        colorChooser.setColor(currentColor);
66
                        dialog.setVisible(true);
67
                        if(tableModel != null && table != null)
68
                                tableModel.setValueAt(currentColor.getRed()+","+currentColor.getGreen()+","+currentColor.getBlue(), table.getSelectedRow(), 2);
69
                        fireEditingStopped();
70

    
71
                } else 
72
                        currentColor = colorChooser.getColor();
73
                
74
        }
75

    
76
        public Object getCellEditorValue() {
77
                return currentColor;
78
        }
79

    
80
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
81
                                                                                     int row, int column) {
82
                currentColor = (Color)value;
83
                return button;
84
        }
85
}