Revision 871
org.gvsig.tools/library/trunk/org.gvsig.tools/dynform/src/org/gvsig/tools/dynform/impl/dynformfield/JCustomTextField.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.dynform.impl.dynformfield; |
2 | 2 |
|
3 |
import javax.swing.Action; |
|
4 |
import javax.swing.JMenuItem; |
|
5 |
import javax.swing.JPopupMenu; |
|
3 | 6 |
import javax.swing.JTextField; |
7 |
import javax.swing.text.DefaultEditorKit; |
|
4 | 8 |
|
5 | 9 |
public class JCustomTextField extends JTextField { |
6 | 10 |
|
... | ... | |
8 | 12 |
* |
9 | 13 |
*/ |
10 | 14 |
private static final long serialVersionUID = 1575097883238348147L; |
15 |
private JPopupMenu popupMenu = null; |
|
16 |
|
|
17 |
public JCustomTextField(){ |
|
18 |
super(); |
|
19 |
initContextMenu(); |
|
20 |
} |
|
11 | 21 |
|
22 |
private void initContextMenu() { |
|
23 |
this.add(getJPopupMenu()); |
|
24 |
this.setComponentPopupMenu(getJPopupMenu()); |
|
25 |
} |
|
26 |
|
|
27 |
public JPopupMenu getJPopupMenu(){ |
|
28 |
if(this.popupMenu == null){ |
|
29 |
this.popupMenu = new JPopupMenu(); |
|
30 |
|
|
31 |
Action copyAction = this.getActionMap().get(DefaultEditorKit.copyAction); |
|
32 |
Action cutAction = this.getActionMap().get(DefaultEditorKit.cutAction); |
|
33 |
Action pasteAction = this.getActionMap().get(DefaultEditorKit.pasteAction); |
|
34 |
Action selectAllAction = this.getActionMap().get(DefaultEditorKit.selectAllAction); |
|
35 |
|
|
36 |
copyAction.putValue(Action.NAME, "Copy"); |
|
37 |
cutAction.putValue(Action.NAME, "Cut"); |
|
38 |
pasteAction.putValue(Action.NAME, "Paste"); |
|
39 |
selectAllAction.putValue(Action.NAME, "Select All"); |
|
40 |
|
|
41 |
this.popupMenu.add(cutAction); |
|
42 |
this.popupMenu.add(copyAction); |
|
43 |
this.popupMenu.add(pasteAction); |
|
44 |
this.popupMenu.addSeparator(); |
|
45 |
this.popupMenu.add(selectAllAction); |
|
46 |
|
|
47 |
} |
|
48 |
return this.popupMenu; |
|
49 |
} |
|
50 |
|
|
51 |
public void addActionToPopupMenu(String name, Action action){ |
|
52 |
if(name != null && !name.isEmpty()){ |
|
53 |
action.putValue(Action.NAME, name); |
|
54 |
} |
|
55 |
getJPopupMenu().add(action); |
|
56 |
} |
|
57 |
|
|
58 |
public void addSeparatorToPopupMenu(){ |
|
59 |
getJPopupMenu().addSeparator(); |
|
60 |
} |
|
61 |
|
|
12 | 62 |
} |
Also available in: Unified diff