Statistics
| Revision:

svn-gvsig-desktop / branches / simbologia / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / edition / gui / SymbolCellEditor.java @ 10437

History | View | Annotate | Download (4.77 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.view.legend.edition.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

    
60

    
61

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

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

    
78
                        public void mouseClicked(MouseEvent e) {
79
                                if (e.getClickCount()==2){
80
                                        symbolPanel.setSymbol(symbol);
81
                                        symbolPanel.setShapeType(SymbolCellEditor.this.shapeType);
82
                                        PluginServices.getMDIManager().addWindow(symbolPanel);
83
                                        if (symbolPanel.isOK()){
84
                                    // FIXME: AQU? PETA SEGURO; PORQUE AHORA ES UN ISYMBOL LO QUE LLEGA
85
                                        symbol = (ISymbol) symbolPanel.getSymbol();
86
//                                        setBackground(symbol.getColor());
87
                                        stopCellEditing();
88
                                        }
89
                                }
90
                        }
91

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

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

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

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

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

    
116
        }
117

    
118

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

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

    
130
                return this;
131
        }
132

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

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

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

    
160
                return true;
161
        }
162

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

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

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

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