1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.menu;
21
22 import java.awt.event.ActionEvent;
23
24 import javax.swing.AbstractAction;
25 import javax.swing.Action;
26 import javax.swing.JMenu;
27 import javax.swing.text.JTextComponent;
28
29 import org.xnap.XNap;
30 import org.xnap.gui.action.ActionHelper;
31 import org.xnap.gui.component.Completable;
32 import org.xnap.gui.component.XNapMenuItem;
33 import org.xnap.util.Preferences;
34 import org.xnap.util.PreferencesProvider;
35
36 public class TextFieldMenu extends JMenu
37 {
38
39
40
41
42
43 private JTextComponent field;
44
45 private CompletionModeMenu menu = null;
46
47
48
49 public TextFieldMenu(JTextComponent field)
50 {
51 super(XNap.tr("Edit"));
52
53 this.field = field;
54
55 add(new XNapMenuItem(ActionHelper.cutAction));
56 add(new XNapMenuItem(ActionHelper.copyAction));
57 add(new XNapMenuItem(ActionHelper.pasteAction));
58 addSeparator();
59 add(new SelectAllAction());
60 }
61
62 public TextFieldMenu(Completable comp)
63 {
64 this(comp.getTextComponent());
65 addSeparator();
66 menu = new CompletionModeMenu(comp);
67 add(menu);
68 }
69
70 public TextFieldMenu(Completable comp, String prefsKey,
71 PreferencesProvider prefs)
72 {
73 this(comp.getTextComponent());
74 addSeparator();
75 menu = new CompletionModeMenu(comp, prefsKey, prefs);
76 add(menu);
77 }
78
79 public TextFieldMenu(Completable comp, String prefsKey)
80 {
81 this(comp, prefsKey, Preferences.getInstance());
82 }
83
84
85
86 public void setPreferences(String prefsKey, PreferencesProvider prefs)
87 {
88 if (menu != null) {
89 menu.setPreferences(prefsKey, prefs);
90 }
91 }
92
93
94
95
96 /***
97 *
98 */
99 private class SelectAllAction extends AbstractAction
100 {
101
102 public SelectAllAction()
103 {
104 putValue(Action.NAME, XNap.tr("Select All"));
105 putValue(Action.SHORT_DESCRIPTION,
106 XNap.tr("Selects all text."));
107 }
108
109
110
111 public void actionPerformed(ActionEvent event)
112 {
113 field.selectAll();
114 }
115
116 }
117 }