1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.xnap.gui.component;
20
21 import java.awt.Point;
22 import java.awt.Rectangle;
23 import org.xnap.XNap;
24 import org.xnap.gui.util.*;
25
26 import javax.swing.text.BadLocationException;
27 import javax.swing.text.JTextComponent;
28
29 public class AutomaticDropDownCompletionMode extends AutomaticCompletionMode
30 {
31
32 private CompletionPopup popup = new CompletionPopup(this);
33
34 /***
35 * @param textComponent
36 * @param model
37 * @param wholeText
38 */
39 public AutomaticDropDownCompletionMode(JTextComponent textComponent,
40 CompletionModel model,
41 boolean wholeText)
42 {
43 super(textComponent, model, wholeText);
44 }
45
46 /***
47 * @param textComponent
48 * @param wholeText
49 */
50 public AutomaticDropDownCompletionMode(JTextComponent textComponent,
51 boolean wholeText)
52 {
53 super(textComponent, wholeText);
54 }
55
56 /***
57 * @param textComponent
58 * @param model
59 */
60 public AutomaticDropDownCompletionMode(JTextComponent textComponent,
61 CompletionModel model)
62 {
63 super(textComponent, model);
64 }
65
66 /***
67 * @param textComponent
68 */
69 public AutomaticDropDownCompletionMode(JTextComponent textComponent)
70 {
71 super(textComponent);
72 }
73
74
75
76 public String getName()
77 {
78 return XNap.tr("Automatic Dropdown");
79 }
80
81 protected void enable()
82 {
83 super.enable();
84 popup.enablePopup();
85 }
86
87 protected void disable()
88 {
89 popup.disablePopup();
90 super.disable();
91 }
92
93 protected void complete(String prefix)
94 {
95 super.complete(prefix);
96 if (getModel().getSize() > 0) {
97 showPopup();
98 }
99 }
100
101
102 protected void showPopup()
103 {
104 if (isWholeTextCompletion()) {
105 GUIHelper.showPopupMenu(popup, getTextComponent(), 0,
106 getTextComponent().getHeight());
107 }
108 else {
109 try {
110 int pos = getTextComponent().getCaretPosition() + 1;
111 Rectangle r = getTextComponent().modelToView(pos);
112 Point p = r.getLocation();
113 GUIHelper.showPopupMenu(popup, getTextComponent(),
114 p.x, p.y + r.height);
115 }
116 catch (BadLocationException ble) {
117
118 }
119 }
120
121
122
123
124 getTextComponent().requestFocus();
125 }
126
127 }
128
129