svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / tables / PopupMenu.java @ 3996
History | View | Annotate | Download (9.4 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 com.iver.cit.gvsig.gui.tables; |
42 |
|
43 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
44 |
|
45 |
import com.iver.andami.PluginServices; |
46 |
|
47 |
import com.iver.cit.gvsig.AddLayer; |
48 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
49 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
50 |
import com.iver.cit.gvsig.gui.Table; |
51 |
|
52 |
import java.awt.Point; |
53 |
import java.awt.event.ActionEvent; |
54 |
import java.awt.event.ActionListener; |
55 |
import java.io.IOException; |
56 |
|
57 |
import javax.swing.ImageIcon; |
58 |
import javax.swing.JMenuItem; |
59 |
import javax.swing.JPopupMenu; |
60 |
|
61 |
|
62 |
/**
|
63 |
* PopupMenu with options to operate on the table.
|
64 |
*
|
65 |
* @author Vicente Caballero Navarro
|
66 |
*/
|
67 |
public class PopupMenu extends JPopupMenu { |
68 |
private static final ImageIcon editcopy = new ImageIcon(AddLayer.class.getClassLoader() |
69 |
.getResource("images/editcopy.png"));
|
70 |
private static final ImageIcon editcut = new ImageIcon(AddLayer.class.getClassLoader() |
71 |
.getResource("images/editcut.png"));
|
72 |
private static final ImageIcon editpaste = new ImageIcon(AddLayer.class.getClassLoader() |
73 |
.getResource("images/editpaste.png"));
|
74 |
private static final ImageIcon editdelete = new ImageIcon(AddLayer.class.getClassLoader() |
75 |
.getResource("images/editdelete.png"));
|
76 |
private JMenuItem copy = null; |
77 |
private JMenuItem cut = null; |
78 |
private JMenuItem paste = null; |
79 |
private JMenuItem insertRow = null; |
80 |
private JMenuItem insertColumn = null; |
81 |
private JMenuItem removeRow = null; |
82 |
private JMenuItem removeColumn = null; |
83 |
private JMenuItem startEdition = null; |
84 |
private JMenuItem stopEdition = null; |
85 |
private Table table = null; |
86 |
private Point point = null; |
87 |
|
88 |
/**
|
89 |
* Create a new PopupMenu.
|
90 |
*
|
91 |
* @param p Point to location.
|
92 |
*/
|
93 |
public PopupMenu(Point p) { |
94 |
point = p; |
95 |
initialize(); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Initialize the components of Popupmenu.
|
100 |
*/
|
101 |
private void initialize() { |
102 |
copy = new JMenuItem(PluginServices.getText(this, "copiar"), editcopy); |
103 |
cut = new JMenuItem(PluginServices.getText(this, "cortar"), editcut); |
104 |
paste = new JMenuItem(PluginServices.getText(this, "pegar"), editpaste); |
105 |
insertRow = new JMenuItem(PluginServices.getText(this, "insertar_fila")); |
106 |
insertColumn = new JMenuItem(PluginServices.getText(this, |
107 |
"insertar_columna"));
|
108 |
removeRow = new JMenuItem(PluginServices.getText(this, "eliminar_fila"), |
109 |
editdelete); |
110 |
removeColumn = new JMenuItem(PluginServices.getText(this, |
111 |
"eliminar_columna"));
|
112 |
startEdition = new JMenuItem(PluginServices.getText(this, |
113 |
"comenzar_edicion"));
|
114 |
stopEdition = new JMenuItem(PluginServices.getText(this, |
115 |
"terminar_edicion"));
|
116 |
|
117 |
add(startEdition); |
118 |
add(stopEdition); |
119 |
addSeparator(); |
120 |
add(copy); |
121 |
add(cut); |
122 |
add(paste); |
123 |
addSeparator(); |
124 |
add(insertRow); |
125 |
add(removeRow); |
126 |
add(insertColumn); |
127 |
add(removeColumn); |
128 |
|
129 |
table = (Table) PluginServices.getMDIManager().getActiveView(); |
130 |
startEdition.addActionListener(new ActionListener() { |
131 |
public void actionPerformed(ActionEvent e) { |
132 |
try {
|
133 |
table.startEditing(); |
134 |
} catch (EditionException e1) {
|
135 |
// TODO Auto-generated catch block
|
136 |
e1.printStackTrace(); |
137 |
} |
138 |
PluginServices.getMainFrame().enableControls(); |
139 |
} |
140 |
}); |
141 |
stopEdition.addActionListener(new ActionListener() { |
142 |
public void actionPerformed(ActionEvent e) { |
143 |
|
144 |
table.stopEditing(); |
145 |
PluginServices.getMainFrame().enableControls(); |
146 |
|
147 |
} |
148 |
}); |
149 |
copy.addActionListener(new ActionListener() { |
150 |
public void actionPerformed(ActionEvent e) { |
151 |
|
152 |
try {
|
153 |
table.copyRow(); |
154 |
} catch (DriverIOException e1) {
|
155 |
// TODO Auto-generated catch block
|
156 |
e1.printStackTrace(); |
157 |
} catch (IOException e1) { |
158 |
// TODO Auto-generated catch block
|
159 |
e1.printStackTrace(); |
160 |
} |
161 |
PluginServices.getMainFrame().enableControls(); |
162 |
|
163 |
} |
164 |
}); |
165 |
cut.addActionListener(new ActionListener() { |
166 |
public void actionPerformed(ActionEvent e) { |
167 |
|
168 |
try {
|
169 |
table.cutRow(); |
170 |
} catch (DriverIOException e1) {
|
171 |
// TODO Auto-generated catch block
|
172 |
e1.printStackTrace(); |
173 |
} catch (IOException e1) { |
174 |
// TODO Auto-generated catch block
|
175 |
e1.printStackTrace(); |
176 |
} |
177 |
PluginServices.getMainFrame().enableControls(); |
178 |
|
179 |
} |
180 |
}); |
181 |
paste.addActionListener(new ActionListener() { |
182 |
public void actionPerformed(ActionEvent e) { |
183 |
//TODO este m?todo a?ade las filas seleccionadas previamente al final de la tabla.
|
184 |
//De momento no se puede a?adir filas en una posici?n en concreto.
|
185 |
|
186 |
try {
|
187 |
table.pasteRow(); |
188 |
} catch (DriverIOException e1) {
|
189 |
// TODO Auto-generated catch block
|
190 |
e1.printStackTrace(); |
191 |
} catch (IOException e1) { |
192 |
// TODO Auto-generated catch block
|
193 |
e1.printStackTrace(); |
194 |
} |
195 |
PluginServices.getMainFrame().enableControls(); |
196 |
|
197 |
} |
198 |
}); |
199 |
insertRow.addActionListener(new ActionListener() { |
200 |
public void actionPerformed(ActionEvent e) { |
201 |
//TODO Este m?todo a?ade filas al final de la tabla y deber?a a?adirlas justo antes de la fila que tengamos seleccionada.
|
202 |
|
203 |
try {
|
204 |
table.addRow(null);
|
205 |
} catch (DriverIOException e1) {
|
206 |
// TODO Auto-generated catch block
|
207 |
e1.printStackTrace(); |
208 |
} catch (IOException e1) { |
209 |
// TODO Auto-generated catch block
|
210 |
e1.printStackTrace(); |
211 |
} |
212 |
PluginServices.getMainFrame().enableControls(); |
213 |
|
214 |
} |
215 |
}); |
216 |
removeRow.addActionListener(new ActionListener() { |
217 |
public void actionPerformed(ActionEvent e) { |
218 |
try {
|
219 |
table.removeRow(); |
220 |
} catch (DriverIOException e1) {
|
221 |
// TODO Auto-generated catch block
|
222 |
e1.printStackTrace(); |
223 |
} catch (IOException e1) { |
224 |
// TODO Auto-generated catch block
|
225 |
e1.printStackTrace(); |
226 |
} |
227 |
PluginServices.getMainFrame().enableControls(); |
228 |
|
229 |
} |
230 |
}); |
231 |
insertColumn.addActionListener(new ActionListener() { |
232 |
public void actionPerformed(ActionEvent e) { |
233 |
//TODO Falta que implementar.
|
234 |
|
235 |
} |
236 |
}); |
237 |
removeColumn.addActionListener(new ActionListener() { |
238 |
public void actionPerformed(ActionEvent e) { |
239 |
//TODO Falta que implementar.
|
240 |
} |
241 |
}); |
242 |
editingMenu(table.isEditing()); |
243 |
setEnablePaste(table.isCopied()); |
244 |
this.show(table, point.x, point.y);
|
245 |
} |
246 |
|
247 |
/**
|
248 |
* Set the menu enabled if it?s possible.
|
249 |
*
|
250 |
* @param b boolean
|
251 |
*/
|
252 |
private void editingMenu(boolean b) { |
253 |
copy.setEnabled(false);
|
254 |
cut.setEnabled(false);
|
255 |
startEdition.setEnabled(!b); |
256 |
stopEdition.setEnabled(b); |
257 |
insertRow.setEnabled(b); |
258 |
insertColumn.setEnabled(b); |
259 |
removeRow.setEnabled(false);
|
260 |
if (table.getSelectedRowIndices().length > 0){ |
261 |
copy.setEnabled(true);
|
262 |
if(b) {
|
263 |
cut.setEnabled(true);
|
264 |
removeRow.setEnabled(true);
|
265 |
} |
266 |
} |
267 |
|
268 |
if ((table.getSelectedFieldIndices().length() > 0) && b) { |
269 |
removeColumn.setEnabled(true);
|
270 |
} else {
|
271 |
removeColumn.setEnabled(false);
|
272 |
} |
273 |
} |
274 |
|
275 |
/**
|
276 |
* Set the menu of paste enabled if it?s possible
|
277 |
*
|
278 |
* @param b boolean
|
279 |
*/
|
280 |
private void setEnablePaste(boolean b) { |
281 |
paste.setEnabled(b); |
282 |
} |
283 |
} |