Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.raster.legend / org.gvsig.raster.legend.swing / org.gvsig.raster.legend.swing.impl / src / main / java / org / gvsig / raster / swing / legend / impl / colortable / editor / ColorChooserEditor.java @ 43803

History | View | Annotate | Download (2.41 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2017 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.raster.swing.legend.impl.colortable.editor;
24

    
25
import java.awt.Color;
26
import java.awt.Component;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29

    
30
import javax.swing.AbstractCellEditor;
31
import javax.swing.JButton;
32
import javax.swing.JColorChooser;
33
import javax.swing.JTable;
34
import javax.swing.table.TableCellEditor;
35

    
36
import org.gvsig.tools.ToolsLocator;
37
import org.gvsig.tools.i18n.I18nManager;
38

    
39

    
40
/**
41
 * @author fdiaz
42
 *
43
 */
44
class ColorChooserEditor extends AbstractCellEditor implements TableCellEditor {
45

    
46
    private JButton delegate = new JButton();
47

    
48
    Color savedColor;
49

    
50
    public ColorChooserEditor() {
51
      ActionListener actionListener = new ActionListener() {
52
        public void actionPerformed(ActionEvent actionEvent) {
53
            I18nManager i18nManager = ToolsLocator.getI18nManager();
54
          Color color = JColorChooser.showDialog(delegate, i18nManager.getTranslation("_color_chooser"), savedColor);
55
          ColorChooserEditor.this.changeColor(color);
56
        }
57
      };
58
      delegate.addActionListener(actionListener);
59
    }
60

    
61
    public Object getCellEditorValue() {
62
      return savedColor;
63
    }
64

    
65
    private void changeColor(Color color) {
66
      if (color != null) {
67
        savedColor = color;
68
        delegate.setBackground(color);
69
      }
70
    }
71

    
72
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
73
        int row, int column) {
74
      changeColor((Color) value);
75
      return delegate;
76
    }
77
  }