Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / project / documents / view / legend / edition / gui / IconOptionCellEditor.java @ 40557

History | View | Annotate | Download (3.85 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.editing.project.documents.view.legend.edition.gui;
25

    
26
import java.awt.Component;
27
import java.awt.event.KeyAdapter;
28
import java.awt.event.KeyEvent;
29
import java.util.ArrayList;
30
import java.util.EventObject;
31

    
32
import javax.swing.ImageIcon;
33
import javax.swing.JTable;
34
import javax.swing.event.CellEditorListener;
35
import javax.swing.event.ChangeEvent;
36
import javax.swing.table.TableCellEditor;
37

    
38
import org.gvsig.app.project.documents.view.legend.edition.gui.PreviewIcon;
39
import org.gvsig.editing.fmap.rendering.EditionManagerLegend;
40

    
41

    
42

    
43

    
44
/**
45
 * Cell Editor de iconos. Controla los eventos de edici?n que se realicen
46
 * sobre la columna de iconos.
47
 *
48
 * @author Vicente Caballero Navarro
49
 */
50
public class IconOptionCellEditor extends PreviewIcon implements TableCellEditor {
51
        private ArrayList listeners = new ArrayList();
52
        private ImageIcon sel;
53
        private ImageIcon notSel;
54
        protected EditionManagerLegend eml;
55
        protected JTable table;
56

    
57
        public IconOptionCellEditor(EditionManagerLegend el,JTable tab,ImageIcon sel, ImageIcon notSel) {
58
                this.eml=el;
59
                this.table=tab;
60
                this.sel=sel;
61
                this.notSel=notSel;
62
                        addKeyListener(new KeyAdapter() {
63
                                public void keyReleased(KeyEvent e) {
64
                                        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
65
                                                stopCellEditing();
66
                                        } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
67
                                                cancelCellEditing();
68
                                        }
69
                                }
70
                        });
71
        }
72

    
73
        //Implement the one CellEditor method that AbstractCellEditor doesn't.
74
        public Object getCellEditorValue() {
75
                return getIcon();
76
        }
77

    
78
        //Implement the one method defined by TableCellEditor.
79
        public Component getTableCellEditorComponent(JTable table, Object value,
80
                boolean isSelected, int row, int column) {
81
                return this;
82
        }
83

    
84
        /**
85
         * DOCUMENT ME!
86
         */
87
        public void cancelCellEditing() {
88
                for (int i = 0; i < listeners.size(); i++) {
89
                        CellEditorListener l = (CellEditorListener) listeners.get(i);
90
                        ChangeEvent evt = new ChangeEvent(this);
91
                        l.editingCanceled(evt);
92
                }
93
        }
94

    
95
        /**
96
         * DOCUMENT ME!
97
         *
98
         * @return DOCUMENT ME!
99
         */
100
        public boolean stopCellEditing() {
101
//                for (int i = 0; i < listeners.size(); i++) {
102
//                        CellEditorListener l = (CellEditorListener) listeners.get(i);
103
//                        ChangeEvent evt = new ChangeEvent(this);
104
//                        l.editingStopped(evt);
105
//                }
106

    
107
                return true;
108
        }
109

    
110
        /**
111
         * DOCUMENT ME!
112
         *
113
         * @param anEvent DOCUMENT ME!
114
         *
115
         * @return DOCUMENT ME!
116
         */
117
        public boolean isCellEditable(EventObject anEvent) {
118
                return true;
119
        }
120

    
121
        /**
122
         * DOCUMENT ME!
123
         *
124
         * @param anEvent DOCUMENT ME!
125
         *
126
         * @return DOCUMENT ME!
127
         */
128
        public boolean shouldSelectCell(EventObject anEvent) {
129
                return true;
130
        }
131

    
132
        /**
133
         * DOCUMENT ME!
134
         *
135
         * @param l DOCUMENT ME!
136
         */
137
        public void addCellEditorListener(CellEditorListener l) {
138
                listeners.add(l);
139
        }
140

    
141
        /**
142
         * DOCUMENT ME!
143
         *
144
         * @param l DOCUMENT ME!
145
         */
146
        public void removeCellEditorListener(CellEditorListener l) {
147
                listeners.remove(l);
148
        }
149

    
150
        public ImageIcon getSel() {
151
                return sel;
152
        }
153

    
154
        public ImageIcon getNotSel() {
155
                return notSel;
156
        }
157
}