svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / legend / edition / gui / IntervalCellEditor.java @ 31631
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 org.gvsig.app.project.documents.view.legend.edition.gui; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Component; |
45 |
import java.awt.event.KeyAdapter; |
46 |
import java.awt.event.KeyEvent; |
47 |
import java.awt.event.MouseEvent; |
48 |
import java.awt.event.MouseListener; |
49 |
import java.util.ArrayList; |
50 |
import java.util.EventObject; |
51 |
import java.util.List; |
52 |
|
53 |
import javax.swing.JButton; |
54 |
import javax.swing.JTable; |
55 |
import javax.swing.event.CellEditorListener; |
56 |
import javax.swing.event.ChangeEvent; |
57 |
import javax.swing.table.TableCellEditor; |
58 |
|
59 |
import org.gvsig.andami.PluginServices; |
60 |
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval; |
61 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.FInterval; |
62 |
|
63 |
|
64 |
|
65 |
/**
|
66 |
* Cell Editor de intervalos. Controla los eventos de edici?n que se realicen
|
67 |
* sobre la columna de intervalos.
|
68 |
*
|
69 |
* @author Vicente Caballero Navarro
|
70 |
*/
|
71 |
public class IntervalCellEditor extends JButton |
72 |
implements TableCellEditor{ |
73 |
|
74 |
private static final long serialVersionUID = 2020808901328629215L; |
75 |
|
76 |
private List listeners = new ArrayList(); |
77 |
private IInterval interval;
|
78 |
private PanelEditInterval editPanel;
|
79 |
/**
|
80 |
* Crea un nuevo FIntervalCellEditor.
|
81 |
*/
|
82 |
public IntervalCellEditor() {
|
83 |
addMouseListener(new MouseListener(){ |
84 |
|
85 |
public void mouseClicked(MouseEvent e) { |
86 |
if (e.getClickCount()==2){ |
87 |
if (interval instanceof IInterval){ |
88 |
editPanel.setFInterval(interval); |
89 |
PluginServices.getMDIManager().addWindow(editPanel); |
90 |
if (editPanel.isOK()){
|
91 |
interval = editPanel.getFInterval(); |
92 |
setBackground(Color.white);
|
93 |
setText(interval.toString()); |
94 |
stopCellEditing(); |
95 |
} |
96 |
} |
97 |
} |
98 |
} |
99 |
|
100 |
public void mouseEntered(MouseEvent e) { |
101 |
} |
102 |
|
103 |
public void mouseExited(MouseEvent e) { |
104 |
} |
105 |
|
106 |
public void mousePressed(MouseEvent e) { |
107 |
} |
108 |
|
109 |
public void mouseReleased(MouseEvent e) { |
110 |
} |
111 |
|
112 |
}); |
113 |
addKeyListener(new KeyAdapter() { |
114 |
public void keyReleased(KeyEvent e) { |
115 |
if (e.getKeyCode() == KeyEvent.VK_ENTER){ |
116 |
stopCellEditing(); |
117 |
}else if (e.getKeyCode() == KeyEvent.VK_ESCAPE){ |
118 |
cancelCellEditing(); |
119 |
} |
120 |
} |
121 |
}); |
122 |
editPanel = new PanelEditInterval();
|
123 |
this.setBackground(Color.white); |
124 |
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* Inserta el intervalo.
|
129 |
*
|
130 |
* @param i DOCUMENT ME!
|
131 |
*/
|
132 |
public void setCurrentInterval(FInterval i) { |
133 |
interval = i; |
134 |
this.setText(i.toString());
|
135 |
} |
136 |
|
137 |
//Implement the one CellEditor method that AbstractCellEditor doesn't.
|
138 |
public Object getCellEditorValue() { |
139 |
return interval;
|
140 |
} |
141 |
|
142 |
//Implement the one method defined by TableCellEditor.
|
143 |
public Component getTableCellEditorComponent(JTable table, Object value, |
144 |
boolean isSelected, int row, int column) { |
145 |
interval = (IInterval) value; |
146 |
this.setText(interval.toString());
|
147 |
editPanel.setFInterval(interval); |
148 |
return this; |
149 |
} |
150 |
|
151 |
public void cancelCellEditing() { |
152 |
for (int i = 0; i < listeners.size(); i++) { |
153 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
154 |
ChangeEvent evt = new ChangeEvent(this); |
155 |
l.editingCanceled(evt); |
156 |
} |
157 |
} |
158 |
|
159 |
public boolean stopCellEditing() { |
160 |
for (int i = 0; i < listeners.size(); i++) { |
161 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
162 |
ChangeEvent evt = new ChangeEvent(this); |
163 |
l.editingStopped(evt); |
164 |
} |
165 |
return true; |
166 |
} |
167 |
|
168 |
public boolean isCellEditable(EventObject anEvent) { |
169 |
return true; |
170 |
} |
171 |
|
172 |
public boolean shouldSelectCell(EventObject anEvent) { |
173 |
return true; |
174 |
} |
175 |
|
176 |
public void addCellEditorListener(CellEditorListener l) { |
177 |
listeners.add(l); |
178 |
} |
179 |
|
180 |
public void removeCellEditorListener(CellEditorListener l) { |
181 |
listeners.remove(l); |
182 |
} |
183 |
} |