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