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