svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / editionpopupmenu / JOptionsEditionByMousePopupMenu.java @ 40561
History | View | Annotate | Download (13.5 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 |
package org.gvsig.gui.beans.editionpopupmenu; |
25 |
|
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.io.Serializable; |
29 |
import java.util.HashMap; |
30 |
|
31 |
import javax.swing.ImageIcon; |
32 |
import javax.swing.JMenuItem; |
33 |
import javax.swing.JPopupMenu; |
34 |
import javax.swing.border.BevelBorder; |
35 |
|
36 |
import org.gvsig.gui.beans.Messages; |
37 |
|
38 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
39 |
*
|
40 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
41 |
*
|
42 |
* This program is free software; you can redistribute it and/or
|
43 |
* modify it under the terms of the GNU General Public License
|
44 |
* as published by the Free Software Foundation; either version 2
|
45 |
* of the License, or (at your option) any later version.
|
46 |
*
|
47 |
* This program is distributed in the hope that it will be useful,
|
48 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
49 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
50 |
* GNU General Public License for more details.
|
51 |
*
|
52 |
* You should have received a copy of the GNU General Public License
|
53 |
* along with this program; if not, write to the Free Software
|
54 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
55 |
*
|
56 |
* For more information, contact:
|
57 |
*
|
58 |
* Generalitat Valenciana
|
59 |
* Conselleria d'Infraestructures i Transport
|
60 |
* Av. Blasco Ib??ez, 50
|
61 |
* 46010 VALENCIA
|
62 |
* SPAIN
|
63 |
*
|
64 |
* +34 963862235
|
65 |
* gvsig@gva.es
|
66 |
* www.gvsig.gva.es
|
67 |
*
|
68 |
* or
|
69 |
*
|
70 |
* IVER T.I. S.A
|
71 |
* Salamanca 50
|
72 |
* 46005 Valencia
|
73 |
* Spain
|
74 |
*
|
75 |
* +34 963163400
|
76 |
* dac@iver.es
|
77 |
*/
|
78 |
|
79 |
|
80 |
/**
|
81 |
* <p>This class is a JPopupMenu that can be used with another component.</p>
|
82 |
* <p>The items showed in this menu are for editing: UNDO, REDO, CUT, COPY, PASTE, DELETE and SELECT ALL.</p>
|
83 |
* <p>When the user clicks on a item, this Component fires a property change event that its value allows identify the item clicked.</p>
|
84 |
* <p>(The icons used are from the open-source 'Tango Icon Library' project: (http://tango.freedesktop.org/Tango_Icon_Library)).</p>
|
85 |
*
|
86 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
87 |
*/
|
88 |
public class JOptionsEditionByMousePopupMenu extends JPopupMenu implements Serializable{ |
89 |
private static final long serialVersionUID = -142360699557710223L; |
90 |
|
91 |
// Items of this JPopupMenu
|
92 |
private JMenuItem jMenuItemUndo = null; |
93 |
private JMenuItem jMenuItemRedo = null; |
94 |
private JMenuItem jMenuItemCut = null; |
95 |
private JMenuItem jMenuItemCopy = null; |
96 |
private JMenuItem jMenuItemPaste = null; |
97 |
private JMenuItem jMenuItemDelete = null; |
98 |
private JMenuItem jMenuItemSelectAll = null; |
99 |
|
100 |
// Values of the events fired when has been clicked an item
|
101 |
public static final int DEFAULT = 0; |
102 |
public static final int UNDO = 1; |
103 |
public static final int REDO = 2; |
104 |
public static final int CUT = 3; |
105 |
public static final int COPY = 4; |
106 |
public static final int PASTE = 5; |
107 |
public static final int DELETE = 6; |
108 |
public static final int SELECT_ALL = 7; |
109 |
|
110 |
// Values of the type of event fired
|
111 |
public static final int VISIBILITY = 8; |
112 |
public static final String SELECTEDOPTION = "SelectedOption"; |
113 |
public static final String VISIBILITYCHANGED = "Visibility"; |
114 |
|
115 |
// Hash map for the items
|
116 |
private HashMap<String, String> map; |
117 |
|
118 |
// Action listener for notify (fire) some events that had happened to this component
|
119 |
private ActionListener menuListener = null; |
120 |
|
121 |
/**
|
122 |
* Default constructor
|
123 |
*/
|
124 |
public JOptionsEditionByMousePopupMenu() {
|
125 |
super();
|
126 |
initialize(); |
127 |
} |
128 |
|
129 |
/**
|
130 |
* This method initializes this component
|
131 |
*/
|
132 |
private void initialize() { |
133 |
map = new HashMap<String, String>(); |
134 |
this.add(getJMenuItemUndo());
|
135 |
this.add(getJMenuItemRedo());
|
136 |
this.addSeparator();
|
137 |
this.add(getJMenuItemCut());
|
138 |
this.add(getJMenuItemCopy());
|
139 |
this.add(getJMenuItemPaste());
|
140 |
this.add(getJMenuItemDelete());
|
141 |
this.addSeparator();
|
142 |
this.add(getJMenuItemSelectAll());
|
143 |
this.setLabel("Edition"); |
144 |
this.setBorder(new BevelBorder(BevelBorder.RAISED)); |
145 |
} |
146 |
|
147 |
/**
|
148 |
* This method initializes jMenuItemUndo
|
149 |
*
|
150 |
* @return javax.swing.JMenuItem
|
151 |
*/
|
152 |
private JMenuItem getJMenuItemUndo() { |
153 |
if (jMenuItemUndo == null) { |
154 |
ImageIcon undoIcon = new ImageIcon(JOptionsEditionByMousePopupMenu.class.getResource("images/edit-undo.png"), Messages.getText("edit_undo")); |
155 |
jMenuItemUndo = new JMenuItem(Messages.getText("edit_undo"), undoIcon); |
156 |
jMenuItemUndo.setHorizontalTextPosition(JMenuItem.RIGHT);
|
157 |
jMenuItemUndo.addActionListener(this.getMenuListener());
|
158 |
map.put(Messages.getText("edit_undo"), Integer.toString(JOptionsEditionByMousePopupMenu.UNDO)); |
159 |
} |
160 |
return jMenuItemUndo;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* This method initializes jMenuItemRedo
|
165 |
*
|
166 |
* @return javax.swing.JMenuItem
|
167 |
*/
|
168 |
private JMenuItem getJMenuItemRedo() { |
169 |
if (jMenuItemRedo == null) { |
170 |
ImageIcon redoIcon = new ImageIcon(JOptionsEditionByMousePopupMenu.class.getResource("images/edit-redo.png"), Messages.getText("edit_redo")); |
171 |
jMenuItemRedo = new JMenuItem(Messages.getText("edit_redo"), redoIcon); |
172 |
jMenuItemRedo.setHorizontalTextPosition(JMenuItem.RIGHT);
|
173 |
jMenuItemRedo.addActionListener(this.getMenuListener());
|
174 |
map.put(Messages.getText("edit_redo"), Integer.toString(JOptionsEditionByMousePopupMenu.REDO)); |
175 |
} |
176 |
return jMenuItemRedo;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* This method initializes jMenuItemCut
|
181 |
*
|
182 |
* @return javax.swing.JMenuItem
|
183 |
*/
|
184 |
private JMenuItem getJMenuItemCut() { |
185 |
if (jMenuItemCut == null) { |
186 |
ImageIcon cutIcon = new ImageIcon(JOptionsEditionByMousePopupMenu.class.getResource("images/edit-cut.png"), Messages.getText("edit_cut")); |
187 |
jMenuItemCut = new JMenuItem(Messages.getText("edit_cut"), cutIcon); |
188 |
jMenuItemCut.setHorizontalTextPosition(JMenuItem.RIGHT);
|
189 |
jMenuItemCut.addActionListener(this.getMenuListener());
|
190 |
map.put(Messages.getText("edit_cut"), Integer.toString(JOptionsEditionByMousePopupMenu.CUT)); |
191 |
} |
192 |
return jMenuItemCut;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* This method initializes jMenuItemCopy
|
197 |
*
|
198 |
* @return javax.swing.JMenuItem
|
199 |
*/
|
200 |
private JMenuItem getJMenuItemCopy() { |
201 |
if (jMenuItemCopy == null) { |
202 |
ImageIcon copyIcon = new ImageIcon(JOptionsEditionByMousePopupMenu.class.getResource("images/edit-copy.png"), Messages.getText("edit_copy")); |
203 |
jMenuItemCopy = new JMenuItem(Messages.getText("edit_copy"), copyIcon); |
204 |
jMenuItemCopy.setHorizontalTextPosition(JMenuItem.RIGHT);
|
205 |
jMenuItemCopy.addActionListener(this.getMenuListener());
|
206 |
map.put(Messages.getText("edit_copy"), Integer.toString(JOptionsEditionByMousePopupMenu.COPY)); |
207 |
} |
208 |
return jMenuItemCopy;
|
209 |
} |
210 |
|
211 |
/**
|
212 |
* This method initializes jMenuItemPaste
|
213 |
*
|
214 |
* @return javax.swing.JMenuItem
|
215 |
*/
|
216 |
private JMenuItem getJMenuItemPaste() { |
217 |
if (jMenuItemPaste == null) { |
218 |
ImageIcon pasteIcon = new ImageIcon(JOptionsEditionByMousePopupMenu.class.getResource("images/edit-paste.png"), Messages.getText("edit_paste")); |
219 |
jMenuItemPaste = new JMenuItem(Messages.getText("edit_paste"), pasteIcon); |
220 |
jMenuItemPaste.setHorizontalTextPosition(JMenuItem.RIGHT);
|
221 |
jMenuItemPaste.addActionListener(this.getMenuListener());
|
222 |
map.put(Messages.getText("edit_paste"), Integer.toString(JOptionsEditionByMousePopupMenu.PASTE)); |
223 |
} |
224 |
return jMenuItemPaste;
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* This method initializes jMenuItemDelete
|
229 |
*
|
230 |
* @return javax.swing.JMenuItem
|
231 |
*/
|
232 |
private JMenuItem getJMenuItemDelete() { |
233 |
if (jMenuItemDelete == null) { |
234 |
ImageIcon deleteIcon = new ImageIcon(JOptionsEditionByMousePopupMenu.class.getResource("images/edit-delete.png"), Messages.getText("edit_delete")); |
235 |
jMenuItemDelete = new JMenuItem(Messages.getText("edit_delete"), deleteIcon); |
236 |
jMenuItemDelete.setHorizontalTextPosition(JMenuItem.RIGHT);
|
237 |
jMenuItemDelete.addActionListener(this.getMenuListener());
|
238 |
map.put(Messages.getText("edit_delete"), Integer.toString(JOptionsEditionByMousePopupMenu.DELETE)); |
239 |
} |
240 |
return jMenuItemDelete;
|
241 |
} |
242 |
|
243 |
/**
|
244 |
* This method initializes jMenuItemSelectAll
|
245 |
*
|
246 |
* @return javax.swing.JMenuItem
|
247 |
*/
|
248 |
private JMenuItem getJMenuItemSelectAll() { |
249 |
if (jMenuItemSelectAll == null) { |
250 |
ImageIcon selectAllIcon = new ImageIcon(JOptionsEditionByMousePopupMenu.class.getResource("images/edit-select-all.png"), Messages.getText("edit_select_all")); |
251 |
jMenuItemSelectAll = new JMenuItem(Messages.getText("edit_select_all"), selectAllIcon); |
252 |
jMenuItemSelectAll.setHorizontalTextPosition(JMenuItem.RIGHT);
|
253 |
jMenuItemSelectAll.addActionListener(this.getMenuListener());
|
254 |
map.put(Messages.getText("edit_select_all"), Integer.toString(JOptionsEditionByMousePopupMenu.SELECT_ALL)); |
255 |
} |
256 |
return jMenuItemSelectAll;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* This method initializes the "menuListener" ActionListener
|
261 |
*
|
262 |
* @return ActionListener
|
263 |
*/
|
264 |
private ActionListener getMenuListener() { |
265 |
if (menuListener == null) { |
266 |
menuListener = new ActionListener() { |
267 |
/*
|
268 |
* (non-Javadoc)
|
269 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
270 |
*/
|
271 |
public void actionPerformed(ActionEvent event) { |
272 |
// Notifies that the Visibility of this component has changed
|
273 |
if (event.getActionCommand().equals(JOptionsEditionByMousePopupMenu.VISIBILITYCHANGED))
|
274 |
firePropertyChange( |
275 |
JOptionsEditionByMousePopupMenu.VISIBILITYCHANGED, |
276 |
JOptionsEditionByMousePopupMenu.DEFAULT, |
277 |
JOptionsEditionByMousePopupMenu.VISIBILITY); |
278 |
else // Notifies that has been clicked on an item |
279 |
firePropertyChange( |
280 |
JOptionsEditionByMousePopupMenu.SELECTEDOPTION, |
281 |
JOptionsEditionByMousePopupMenu.DEFAULT, |
282 |
map.get(event.getActionCommand())); |
283 |
} |
284 |
}; |
285 |
} |
286 |
return menuListener;
|
287 |
} |
288 |
|
289 |
/**
|
290 |
* Enables or disables the undo option item
|
291 |
*
|
292 |
* @param b Value true or false
|
293 |
*/
|
294 |
public void setEnabledUndoOption(boolean b) { |
295 |
jMenuItemUndo.setEnabled(b); |
296 |
} |
297 |
|
298 |
/**
|
299 |
* Returns if the undo option item is enabled or not
|
300 |
*
|
301 |
* @return Value true or false
|
302 |
*/
|
303 |
public boolean isEnabledUndoOption() { |
304 |
return jMenuItemUndo.isEnabled();
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* Enables or disables the redo option item
|
309 |
*
|
310 |
* @param b Value true or false
|
311 |
*/
|
312 |
public void setEnabledRedoOption(boolean b) { |
313 |
jMenuItemRedo.setEnabled(b); |
314 |
} |
315 |
|
316 |
/**
|
317 |
* Returns if the redo option item is enabled or not
|
318 |
*
|
319 |
* @return Value true or false
|
320 |
*/
|
321 |
public boolean isEnabledRedoOption() { |
322 |
return jMenuItemRedo.isEnabled();
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* Enables or disables the cut option item
|
327 |
*
|
328 |
* @param b Value true or false
|
329 |
*/
|
330 |
public void setEnabledCutOption(boolean b) { |
331 |
jMenuItemCut.setEnabled(b); |
332 |
} |
333 |
|
334 |
/**
|
335 |
* Returns if the cut option item is enabled or not
|
336 |
*
|
337 |
* @return Value true or false
|
338 |
*/
|
339 |
public boolean isEnabledCutOption() { |
340 |
return jMenuItemCut.isEnabled();
|
341 |
} |
342 |
|
343 |
/**
|
344 |
* Enables or disables the copy option item
|
345 |
*
|
346 |
* @param b Value true or false
|
347 |
*/
|
348 |
public void setEnabledCopyOption(boolean b) { |
349 |
jMenuItemCopy.setEnabled(b); |
350 |
} |
351 |
|
352 |
/**
|
353 |
* Returns if the copy option item is enabled or not
|
354 |
*
|
355 |
* @return Value true or false
|
356 |
*/
|
357 |
public boolean isEnabledCopyOption() { |
358 |
return jMenuItemCopy.isEnabled();
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* Enables or disables the paste option item
|
363 |
*
|
364 |
* @param b Value true or false
|
365 |
*/
|
366 |
public void setEnabledPasteOption(boolean b) { |
367 |
jMenuItemPaste.setEnabled(b); |
368 |
} |
369 |
|
370 |
/**
|
371 |
* Returns if the paste option item is enabled or not
|
372 |
*
|
373 |
* @return Value true or false
|
374 |
*/
|
375 |
public boolean isEnabledPasteOption() { |
376 |
return jMenuItemPaste.isEnabled();
|
377 |
} |
378 |
|
379 |
/**
|
380 |
* Enables or disables the delete option item
|
381 |
*
|
382 |
* @param b Value true or false
|
383 |
*/
|
384 |
public void setEnabledDeleteOption(boolean b) { |
385 |
jMenuItemDelete.setEnabled(b); |
386 |
} |
387 |
|
388 |
/**
|
389 |
* Returns if the delete option item is enabled or not
|
390 |
*
|
391 |
* @return Value true or false
|
392 |
*/
|
393 |
public boolean isEnabledDeleteOption() { |
394 |
return jMenuItemDelete.isEnabled();
|
395 |
} |
396 |
|
397 |
/**
|
398 |
* Enables or disables the select all option item
|
399 |
*
|
400 |
* @param b Value true or false
|
401 |
*/
|
402 |
public void setEnabledSelectAllOption(boolean b) { |
403 |
jMenuItemSelectAll.setEnabled(b); |
404 |
} |
405 |
|
406 |
/**
|
407 |
* Returns if the select all option item is enabled or not
|
408 |
*
|
409 |
* @return Value true or false
|
410 |
*/
|
411 |
public boolean isEnabledelectAllOption() { |
412 |
return jMenuItemSelectAll.isEnabled();
|
413 |
} |
414 |
|
415 |
/**
|
416 |
* Enables or disables all option items
|
417 |
*
|
418 |
* @param b Value true or false
|
419 |
*/
|
420 |
public void setEnabledAllOptions(boolean b) { |
421 |
this.setEnabledUndoOption(b);
|
422 |
this.setEnabledRedoOption(b);
|
423 |
this.setEnabledCutOption(b);
|
424 |
this.setEnabledCopyOption(b);
|
425 |
this.setEnabledPasteOption(b);
|
426 |
this.setEnabledDeleteOption(b);
|
427 |
this.setEnabledSelectAllOption(b);
|
428 |
} |
429 |
|
430 |
/*
|
431 |
* (non-Javadoc)
|
432 |
* @see javax.swing.JPopupMenu#setVisible(boolean)
|
433 |
*/
|
434 |
public void setVisible(boolean b) { |
435 |
// Notifies that has changed the visibility of this component
|
436 |
super.setVisible(b);
|
437 |
this.getMenuListener().actionPerformed(new ActionEvent(this, JOptionsEditionByMousePopupMenu.VISIBILITY, JOptionsEditionByMousePopupMenu.VISIBILITYCHANGED)); |
438 |
} |
439 |
} |