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 / view / legend / edition / gui / IntervalCellEditor.java @ 40558
History | View | Annotate | Download (5.71 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* 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 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
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 |
*/
|
24 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
25 |
*
|
26 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
27 |
*
|
28 |
* This program is free software; you can redistribute it and/or
|
29 |
* modify it under the terms of the GNU General Public License
|
30 |
* as published by the Free Software Foundation; either version 2
|
31 |
* of the License, or (at your option) any later version.
|
32 |
*
|
33 |
* This program is distributed in the hope that it will be useful,
|
34 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
35 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
36 |
* GNU General Public License for more details.
|
37 |
*
|
38 |
* You should have received a copy of the GNU General Public License
|
39 |
* along with this program; if not, write to the Free Software
|
40 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
41 |
*
|
42 |
* For more information, contact:
|
43 |
*
|
44 |
* Generalitat Valenciana
|
45 |
* Conselleria d'Infraestructures i Transport
|
46 |
* Av. Blasco Ib??ez, 50
|
47 |
* 46010 VALENCIA
|
48 |
* SPAIN
|
49 |
*
|
50 |
* +34 963862235
|
51 |
* gvsig@gva.es
|
52 |
* www.gvsig.gva.es
|
53 |
*
|
54 |
* or
|
55 |
*
|
56 |
* IVER T.I. S.A
|
57 |
* Salamanca 50
|
58 |
* 46005 Valencia
|
59 |
* Spain
|
60 |
*
|
61 |
* +34 963163400
|
62 |
* dac@iver.es
|
63 |
*/
|
64 |
package org.gvsig.app.project.documents.view.legend.edition.gui; |
65 |
|
66 |
import java.awt.Color; |
67 |
import java.awt.Component; |
68 |
import java.awt.event.KeyAdapter; |
69 |
import java.awt.event.KeyEvent; |
70 |
import java.awt.event.MouseEvent; |
71 |
import java.awt.event.MouseListener; |
72 |
import java.util.ArrayList; |
73 |
import java.util.EventObject; |
74 |
import java.util.List; |
75 |
|
76 |
import javax.swing.JButton; |
77 |
import javax.swing.JTable; |
78 |
import javax.swing.event.CellEditorListener; |
79 |
import javax.swing.event.ChangeEvent; |
80 |
import javax.swing.table.TableCellEditor; |
81 |
|
82 |
import org.gvsig.andami.PluginServices; |
83 |
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval; |
84 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.FInterval; |
85 |
|
86 |
|
87 |
|
88 |
/**
|
89 |
* Cell Editor de intervalos. Controla los eventos de edici?n que se realicen
|
90 |
* sobre la columna de intervalos.
|
91 |
*
|
92 |
* @author Vicente Caballero Navarro
|
93 |
*/
|
94 |
public class IntervalCellEditor extends JButton |
95 |
implements TableCellEditor{ |
96 |
|
97 |
private static final long serialVersionUID = 2020808901328629215L; |
98 |
|
99 |
private List listeners = new ArrayList(); |
100 |
private IInterval interval;
|
101 |
private PanelEditInterval editPanel;
|
102 |
/**
|
103 |
* Crea un nuevo FIntervalCellEditor.
|
104 |
*/
|
105 |
public IntervalCellEditor() {
|
106 |
addMouseListener(new MouseListener(){ |
107 |
|
108 |
public void mouseClicked(MouseEvent e) { |
109 |
if (e.getClickCount()==2){ |
110 |
if (interval instanceof IInterval){ |
111 |
editPanel.setFInterval(interval); |
112 |
PluginServices.getMDIManager().addWindow(editPanel); |
113 |
if (editPanel.isOK()){
|
114 |
interval = editPanel.getFInterval(); |
115 |
setBackground(Color.white);
|
116 |
setText(interval.toString()); |
117 |
stopCellEditing(); |
118 |
} |
119 |
} |
120 |
} |
121 |
} |
122 |
|
123 |
public void mouseEntered(MouseEvent e) { |
124 |
} |
125 |
|
126 |
public void mouseExited(MouseEvent e) { |
127 |
} |
128 |
|
129 |
public void mousePressed(MouseEvent e) { |
130 |
} |
131 |
|
132 |
public void mouseReleased(MouseEvent e) { |
133 |
} |
134 |
|
135 |
}); |
136 |
addKeyListener(new KeyAdapter() { |
137 |
public void keyReleased(KeyEvent e) { |
138 |
if (e.getKeyCode() == KeyEvent.VK_ENTER){ |
139 |
stopCellEditing(); |
140 |
}else if (e.getKeyCode() == KeyEvent.VK_ESCAPE){ |
141 |
cancelCellEditing(); |
142 |
} |
143 |
} |
144 |
}); |
145 |
editPanel = new PanelEditInterval();
|
146 |
this.setBackground(Color.white); |
147 |
|
148 |
} |
149 |
|
150 |
/**
|
151 |
* Inserta el intervalo.
|
152 |
*
|
153 |
* @param i DOCUMENT ME!
|
154 |
*/
|
155 |
public void setCurrentInterval(FInterval i) { |
156 |
interval = i; |
157 |
this.setText(i.toString());
|
158 |
} |
159 |
|
160 |
//Implement the one CellEditor method that AbstractCellEditor doesn't.
|
161 |
public Object getCellEditorValue() { |
162 |
return interval;
|
163 |
} |
164 |
|
165 |
//Implement the one method defined by TableCellEditor.
|
166 |
public Component getTableCellEditorComponent(JTable table, Object value, |
167 |
boolean isSelected, int row, int column) { |
168 |
interval = (IInterval) value; |
169 |
this.setText(interval.toString());
|
170 |
editPanel.setFInterval(interval); |
171 |
return this; |
172 |
} |
173 |
|
174 |
public void cancelCellEditing() { |
175 |
for (int i = 0; i < listeners.size(); i++) { |
176 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
177 |
ChangeEvent evt = new ChangeEvent(this); |
178 |
l.editingCanceled(evt); |
179 |
} |
180 |
} |
181 |
|
182 |
public boolean stopCellEditing() { |
183 |
for (int i = 0; i < listeners.size(); i++) { |
184 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
185 |
ChangeEvent evt = new ChangeEvent(this); |
186 |
l.editingStopped(evt); |
187 |
} |
188 |
return true; |
189 |
} |
190 |
|
191 |
public boolean isCellEditable(EventObject anEvent) { |
192 |
return true; |
193 |
} |
194 |
|
195 |
public boolean shouldSelectCell(EventObject anEvent) { |
196 |
return true; |
197 |
} |
198 |
|
199 |
public void addCellEditorListener(CellEditorListener l) { |
200 |
listeners.add(l); |
201 |
} |
202 |
|
203 |
public void removeCellEditorListener(CellEditorListener l) { |
204 |
listeners.remove(l); |
205 |
} |
206 |
} |