1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.commons.gui.completion;
21
22 import javax.swing.text.JTextComponent;
23
24 /***
25 * Abstract convenience class which provides some wrapping function to ease
26 * the implementation of a {@link CompletionMode}.
27 *
28 * @author Felix Berger
29 */
30 public abstract class AbstractCompletionMode implements CompletionMode
31 {
32
33 private Completion completion;
34
35
36
37
38 public void enable(Completion completion)
39 {
40 this.completion = completion;
41 enable();
42 }
43
44 /***
45 * Has to be implemented by subclasses which don't have to worry about
46 * setting the completion object and simply use the accessors provided here.
47 */
48 protected abstract void enable();
49
50
51
52
53 public abstract void disable();
54
55 /***
56 * Convenience accessor, returns the completion model
57 */
58 protected CompletionModel getModel()
59 {
60 return completion.getModel();
61 }
62
63 /***
64 * Convenience accessor, returns the text component.
65 */
66 protected JTextComponent getTextComponent()
67 {
68 return completion.getTextComponent();
69 }
70
71 /***
72 * Returns the completion object that uses this completion mode.
73 */
74 protected Completion getCompletion()
75 {
76 return completion;
77 }
78
79 /***
80 * Convenience accessor, returns the text which should be completed.
81 * @return the whole text up to the current caret position, if
82 * {@link Completion#isWholeTextCompletion()} is true, otherwise the
83 * previous word up to the current care position
84 */
85 protected String getText()
86 {
87 return completion.getText();
88 }
89
90 /***
91 * Convenience setter, forwards to
92 * {@link Completion#setText(String, int, int)}.
93 */
94 protected void setText(String text, int selectionStart,
95 int selectionEnd)
96 {
97 completion.setText(text, selectionStart, selectionEnd);
98 }
99
100 /***
101 * Convenience setter, forwards to {@link Completion#setText(String)}.
102 */
103 protected void setText(String text)
104 {
105 completion.setText(text);
106 }
107 }