root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / gui / SymbolCellEditor.java @ 38608
History | View | Annotate | Download (5.31 KB)
1 | 36411 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 11704 | jaume | *
|
3 | 36411 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | 11704 | jaume | * 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 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | 36411 | cordinyana | *
|
11 | 11704 | jaume | * 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 | 36411 | cordinyana | *
|
16 | 11704 | jaume | * 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 | 36411 | cordinyana | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | 11704 | jaume | */
|
22 | 29598 | jpiera | package org.gvsig.app.project.documents.gui; |
23 | 11704 | jaume | |
24 | import java.awt.Component; |
||
25 | import java.awt.event.KeyAdapter; |
||
26 | import java.awt.event.KeyEvent; |
||
27 | import java.awt.event.MouseEvent; |
||
28 | import java.awt.event.MouseListener; |
||
29 | import java.util.ArrayList; |
||
30 | import java.util.EventObject; |
||
31 | |||
32 | import javax.swing.JButton; |
||
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 | 29598 | jpiera | import org.gvsig.andami.PluginServices; |
39 | import org.gvsig.app.project.documents.view.legend.gui.PanelEditSymbol; |
||
40 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
41 | |||
42 | 11704 | jaume | /**
|
43 | * Cell Editor de ISymbols. Controla los eventos de edici?n que se realicen
|
||
44 | * sobre la columna de s?mbolos.
|
||
45 | 36411 | cordinyana | *
|
46 | 11704 | jaume | * @author Vicente Caballero Navarro
|
47 | */
|
||
48 | public class SymbolCellEditor extends JButton implements TableCellEditor { |
||
49 | |||
50 | 36411 | cordinyana | private static final long serialVersionUID = -913612642474934455L; |
51 | private ArrayList listeners = new ArrayList(); |
||
52 | private ISymbol symbol;
|
||
53 | private int shapeType; |
||
54 | private PanelEditSymbol symbolPanel;
|
||
55 | 11704 | jaume | |
56 | 36411 | cordinyana | public SymbolCellEditor(int shapeType) { |
57 | this.shapeType = shapeType;
|
||
58 | addMouseListener(new MouseListener() { |
||
59 | 11704 | jaume | |
60 | 36411 | cordinyana | public void mouseClicked(MouseEvent e) { |
61 | if (e.getClickCount() == 2) { |
||
62 | symbolPanel.setSymbol(symbol); |
||
63 | // symbolPanel.setShapeType(SymbolCellEditor.this.shapeType);
|
||
64 | symbolPanel.setShapeType(symbol.getSymbolType()); |
||
65 | PluginServices.getMDIManager().addWindow(symbolPanel); |
||
66 | if (symbolPanel.isOK()) {
|
||
67 | symbol = (ISymbol) symbolPanel.getSymbol(); |
||
68 | stopCellEditing(); |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | 11704 | jaume | |
73 | 36411 | cordinyana | public void mouseEntered(MouseEvent e) { |
74 | } |
||
75 | 11704 | jaume | |
76 | 36411 | cordinyana | public void mouseExited(MouseEvent e) { |
77 | } |
||
78 | 11704 | jaume | |
79 | 36411 | cordinyana | public void mousePressed(MouseEvent e) { |
80 | } |
||
81 | 11704 | jaume | |
82 | 36411 | cordinyana | public void mouseReleased(MouseEvent e) { |
83 | } |
||
84 | 11704 | jaume | |
85 | 36411 | cordinyana | }); |
86 | addKeyListener(new KeyAdapter() { |
||
87 | 11704 | jaume | |
88 | 36411 | cordinyana | public void keyReleased(KeyEvent e) { |
89 | if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
||
90 | stopCellEditing(); |
||
91 | } else
|
||
92 | if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { |
||
93 | cancelCellEditing(); |
||
94 | } |
||
95 | } |
||
96 | }); |
||
97 | symbolPanel = new PanelEditSymbol();
|
||
98 | 11704 | jaume | |
99 | 36411 | cordinyana | } |
100 | 11704 | jaume | |
101 | 36411 | cordinyana | // Implement the one CellEditor method that AbstractCellEditor doesn't.
|
102 | public Object getCellEditorValue() { |
||
103 | return symbol;
|
||
104 | } |
||
105 | 11704 | jaume | |
106 | 36411 | cordinyana | // Implement the one method defined by TableCellEditor.
|
107 | public Component getTableCellEditorComponent(JTable table, Object value, |
||
108 | boolean isSelected, int row, int column) { |
||
109 | symbol = (ISymbol) value; |
||
110 | // setBackground(symbol.getColor());
|
||
111 | 11704 | jaume | |
112 | 36411 | cordinyana | return this; |
113 | } |
||
114 | 11704 | jaume | |
115 | 36411 | cordinyana | /**
|
116 | * DOCUMENT ME!
|
||
117 | */
|
||
118 | public void cancelCellEditing() { |
||
119 | if (symbol != null) { |
||
120 | // setBackground(symbol.getColor());
|
||
121 | } |
||
122 | 11704 | jaume | |
123 | 36411 | cordinyana | for (int i = 0; i < listeners.size(); i++) { |
124 | CellEditorListener l = (CellEditorListener) listeners.get(i); |
||
125 | ChangeEvent evt = new ChangeEvent(this); |
||
126 | l.editingCanceled(evt); |
||
127 | } |
||
128 | } |
||
129 | 11704 | jaume | |
130 | 36411 | cordinyana | /**
|
131 | * DOCUMENT ME!
|
||
132 | *
|
||
133 | * @return DOCUMENT ME!
|
||
134 | */
|
||
135 | public boolean stopCellEditing() { |
||
136 | for (int i = 0; i < listeners.size(); i++) { |
||
137 | CellEditorListener l = (CellEditorListener) listeners.get(i); |
||
138 | ChangeEvent evt = new ChangeEvent(this); |
||
139 | l.editingStopped(evt); |
||
140 | } |
||
141 | 11704 | jaume | |
142 | 36411 | cordinyana | return true; |
143 | } |
||
144 | 11704 | jaume | |
145 | 36411 | cordinyana | /**
|
146 | * DOCUMENT ME!
|
||
147 | *
|
||
148 | * @param anEvent
|
||
149 | * DOCUMENT ME!
|
||
150 | *
|
||
151 | * @return DOCUMENT ME!
|
||
152 | */
|
||
153 | public boolean isCellEditable(EventObject anEvent) { |
||
154 | return true; |
||
155 | } |
||
156 | 11704 | jaume | |
157 | 36411 | cordinyana | /**
|
158 | * DOCUMENT ME!
|
||
159 | *
|
||
160 | * @param anEvent
|
||
161 | * DOCUMENT ME!
|
||
162 | *
|
||
163 | * @return DOCUMENT ME!
|
||
164 | */
|
||
165 | public boolean shouldSelectCell(EventObject anEvent) { |
||
166 | return true; |
||
167 | } |
||
168 | 11704 | jaume | |
169 | 36411 | cordinyana | /**
|
170 | * DOCUMENT ME!
|
||
171 | *
|
||
172 | * @param l
|
||
173 | * DOCUMENT ME!
|
||
174 | */
|
||
175 | public void addCellEditorListener(CellEditorListener l) { |
||
176 | listeners.add(l); |
||
177 | } |
||
178 | |||
179 | /**
|
||
180 | * DOCUMENT ME!
|
||
181 | *
|
||
182 | * @param l
|
||
183 | * DOCUMENT ME!
|
||
184 | */
|
||
185 | public void removeCellEditorListener(CellEditorListener l) { |
||
186 | listeners.remove(l); |
||
187 | } |
||
188 | 11704 | jaume | } |