Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / gui / SymbolCellEditor.java @ 29598

History | View | Annotate | Download (4.76 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 org.gvsig.app.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 org.gvsig.andami.PluginServices;
58
import org.gvsig.app.project.documents.view.legend.gui.PanelEditSymbol;
59
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
60

    
61

    
62

    
63

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

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

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

    
93
                        public void mouseEntered(MouseEvent e) {
94
                        }
95

    
96
                        public void mouseExited(MouseEvent e) {
97
                        }
98

    
99
                        public void mousePressed(MouseEvent e) {
100
                        }
101

    
102
                        public void mouseReleased(MouseEvent e) {
103
                        }
104

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

    
117
        }
118

    
119

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

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

    
131
                return this;
132
        }
133

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

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

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

    
161
                return true;
162
        }
163

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

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

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

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