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 javax.swing.SwingUtilities;
22 import javax.swing.event.DocumentEvent;
23 import javax.swing.text.JTextComponent;
24
25 import org.xnap.XNap;
26
27 /***
28 *
29 */
30 public class AutomaticCompletionMode extends ShortAutomaticCompletionMode
31 {
32
33 /***
34 * @param textComponent
35 * @param model
36 * @param wholeText
37 */
38 public AutomaticCompletionMode(JTextComponent textComponent,
39 CompletionModel model, boolean wholeText)
40 {
41 super(textComponent, model, wholeText);
42 }
43
44 /***
45 * @param textComponent
46 * @param wholeText
47 */
48 public AutomaticCompletionMode(JTextComponent textComponent,
49 boolean wholeText)
50 {
51 super(textComponent, wholeText);
52 }
53
54 /***
55 * @param textComponent
56 * @param model
57 */
58 public AutomaticCompletionMode(JTextComponent textComponent,
59 CompletionModel model)
60 {
61 super(textComponent, model);
62 }
63
64 /***
65 * @param textComponent
66 */
67 public AutomaticCompletionMode(JTextComponent textComponent)
68 {
69 super(textComponent);
70 }
71
72
73
74
75 public String getName()
76 {
77 return XNap.tr("Automatic");
78 }
79
80 protected void complete(String prefix)
81 {
82 if (getModel().complete(prefix)) {
83 Object obj = getModel().getElementAt(0);
84 if (obj != null && obj.toString().length() > prefix.length()) {
85 setText(obj.toString(), obj.toString().length(), prefix.length());
86 }
87 }
88 }
89
90 private class DocumentHandler extends DocumentAdapter
91 {
92 public void insertUpdate(DocumentEvent e)
93 {
94 if (e.getLength() == 1) {
95 final String text = getText();
96 Runnable r = new Runnable()
97 {
98 public void run()
99 {
100 complete(text);
101 }
102 };
103 SwingUtilities.invokeLater(r);
104 }
105 }
106 }
107 }