Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / gui / SymbolCellEditor.java @ 11704

History | View | Annotate | Download (4.71 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.project.documents.gui;
42

    
43
import java.awt.Component;
44
import java.awt.event.KeyAdapter;
45
import java.awt.event.KeyEvent;
46
import java.awt.event.MouseEvent;
47
import java.awt.event.MouseListener;
48
import java.util.ArrayList;
49
import java.util.EventObject;
50

    
51
import javax.swing.JButton;
52
import javax.swing.JTable;
53
import javax.swing.event.CellEditorListener;
54
import javax.swing.event.ChangeEvent;
55
import javax.swing.table.TableCellEditor;
56

    
57
import com.iver.andami.PluginServices;
58
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
59
import com.iver.cit.gvsig.project.documents.view.legend.gui.PanelEditSymbol;
60

    
61

    
62

    
63
/**
64
 * Cell Editor de ISymbols. Controla los eventos de edici?n que se realicen
65
 * sobre la columna de s?mbolos.
66
 *
67
 * @author Vicente Caballero Navarro
68
 */
69
public class SymbolCellEditor extends JButton implements TableCellEditor {
70
        private ArrayList listeners = new ArrayList();
71
        private ISymbol symbol;
72
        private int shapeType;
73
        private PanelEditSymbol symbolPanel;
74

    
75
        public SymbolCellEditor(int shapeType) {
76
                this.shapeType = shapeType;
77
                addMouseListener(new MouseListener(){
78

    
79
                        public void mouseClicked(MouseEvent e) {
80
                                if (e.getClickCount()==2){
81
                                        symbolPanel.setSymbol(symbol);
82
                                        symbolPanel.setShapeType(SymbolCellEditor.this.shapeType);
83
                                        PluginServices.getMDIManager().addWindow(symbolPanel);
84
                                        if (symbolPanel.isOK()){
85
                                    symbol = (ISymbol) symbolPanel.getSymbol();
86
                                        stopCellEditing();
87
                                        }
88
                                }
89
                        }
90

    
91
                        public void mouseEntered(MouseEvent e) {
92
                        }
93

    
94
                        public void mouseExited(MouseEvent e) {
95
                        }
96

    
97
                        public void mousePressed(MouseEvent e) {
98
                        }
99

    
100
                        public void mouseReleased(MouseEvent e) {
101
                        }
102

    
103
                });
104
                addKeyListener(new KeyAdapter() {
105
                                public void keyReleased(KeyEvent e) {
106
                                        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
107
                                                stopCellEditing();
108
                                        } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
109
                                                cancelCellEditing();
110
                                        }
111
                                }
112
                        });
113
                symbolPanel = new PanelEditSymbol();
114

    
115
        }
116

    
117

    
118
        //Implement the one CellEditor method that AbstractCellEditor doesn't.
119
        public Object getCellEditorValue() {
120
                return symbol;
121
        }
122

    
123
        //Implement the one method defined by TableCellEditor.
124
        public Component getTableCellEditorComponent(JTable table, Object value,
125
                boolean isSelected, int row, int column) {
126
                symbol = (ISymbol) value;
127
//                setBackground(symbol.getColor());
128

    
129
                return this;
130
        }
131

    
132
        /**
133
         * DOCUMENT ME!
134
         */
135
        public void cancelCellEditing() {
136
                if (symbol != null) {
137
//                        setBackground(symbol.getColor());
138
                }
139

    
140
                for (int i = 0; i < listeners.size(); i++) {
141
                        CellEditorListener l = (CellEditorListener) listeners.get(i);
142
                        ChangeEvent evt = new ChangeEvent(this);
143
                        l.editingCanceled(evt);
144
                }
145
        }
146

    
147
        /**
148
         * DOCUMENT ME!
149
         *
150
         * @return DOCUMENT ME!
151
         */
152
        public boolean stopCellEditing() {
153
                for (int i = 0; i < listeners.size(); i++) {
154
                        CellEditorListener l = (CellEditorListener) listeners.get(i);
155
                        ChangeEvent evt = new ChangeEvent(this);
156
                        l.editingStopped(evt);
157
                }
158

    
159
                return true;
160
        }
161

    
162
        /**
163
         * DOCUMENT ME!
164
         *
165
         * @param anEvent DOCUMENT ME!
166
         *
167
         * @return DOCUMENT ME!
168
         */
169
        public boolean isCellEditable(EventObject anEvent) {
170
                return true;
171
        }
172

    
173
        /**
174
         * DOCUMENT ME!
175
         *
176
         * @param anEvent DOCUMENT ME!
177
         *
178
         * @return DOCUMENT ME!
179
         */
180
        public boolean shouldSelectCell(EventObject anEvent) {
181
                return true;
182
        }
183

    
184
        /**
185
         * DOCUMENT ME!
186
         *
187
         * @param l DOCUMENT ME!
188
         */
189
        public void addCellEditorListener(CellEditorListener l) {
190
                listeners.add(l);
191
        }
192

    
193
        /**
194
         * DOCUMENT ME!
195
         *
196
         * @param l DOCUMENT ME!
197
         */
198
        public void removeCellEditorListener(CellEditorListener l) {
199
                listeners.remove(l);
200
        }
201
}