Lines 56-61
Link Here
|
56 |
private KeyStroke temporaryStroke = null; |
56 |
private KeyStroke temporaryStroke = null; |
57 |
/** The text widget that is wrapped for this class. */ |
57 |
/** The text widget that is wrapped for this class. */ |
58 |
private final Text text; |
58 |
private final Text text; |
|
|
59 |
/** The listener that makes sure that the text widget remains up-to-date |
60 |
* with regards to external modification of the text (e.g., cut & pasting). |
61 |
*/ |
62 |
private final UpdateSequenceListener updateSequenceListener = new UpdateSequenceListener(); |
59 |
|
63 |
|
60 |
/** |
64 |
/** |
61 |
* Constructs an instance of <code>KeySequenceTextField</code> with the |
65 |
* Constructs an instance of <code>KeySequenceTextField</code> with the |
Lines 92-98
Link Here
|
92 |
text.addTraverseListener(new FocusTrapListener()); |
96 |
text.addTraverseListener(new FocusTrapListener()); |
93 |
|
97 |
|
94 |
// Add an internal modify listener. |
98 |
// Add an internal modify listener. |
95 |
text.addModifyListener(new UpdateSequenceListener()); |
99 |
text.addModifyListener(updateSequenceListener); |
96 |
} |
100 |
} |
97 |
|
101 |
|
98 |
/** |
102 |
/** |
Lines 121-127
Link Here
|
121 |
public final KeySequence getKeySequence() { |
125 |
public final KeySequence getKeySequence() { |
122 |
return keySequence; |
126 |
return keySequence; |
123 |
} |
127 |
} |
|
|
128 |
|
129 |
/** |
130 |
* An accessor for the <code>KeyStroke</code> that is currently held as an |
131 |
* incomplete stroke (i.e., one without a natural key). |
132 |
* @return The incomplete stroke; may be <code>null</code> if there are no |
133 |
* incomplete strokes. |
134 |
*/ |
135 |
final KeyStroke getTemporaryStroke() { |
136 |
return temporaryStroke; |
137 |
} |
138 |
|
139 |
/** |
140 |
* An accessor for the underlying text widget used by this entry field. |
141 |
* @return The <code>Text</code> instance; never <code>null</code>. |
142 |
*/ |
143 |
final Text getText() { |
144 |
return text; |
145 |
} |
124 |
|
146 |
|
|
|
147 |
/** |
148 |
* Tests whether the current key sequence has a stroke with no natural key. |
149 |
* @return <code>true</code> is there is an incomplete stroke; |
150 |
* <code>false</code> otherwise. |
151 |
*/ |
125 |
public final boolean hasIncompleteStroke() { |
152 |
public final boolean hasIncompleteStroke() { |
126 |
return (temporaryStroke != null); |
153 |
return (temporaryStroke != null); |
127 |
} |
154 |
} |
Lines 133-139
Link Here
|
133 |
* @return <code>true</code> if the key stroke has no natural key; |
160 |
* @return <code>true</code> if the key stroke has no natural key; |
134 |
* <code>false</code> otherwise. |
161 |
* <code>false</code> otherwise. |
135 |
*/ |
162 |
*/ |
136 |
private static final boolean isComplete(final KeyStroke keyStroke) { |
163 |
static final boolean isComplete(final KeyStroke keyStroke) { |
137 |
if (keyStroke != null) { |
164 |
if (keyStroke != null) { |
138 |
final NaturalKey naturalKey = keyStroke.getNaturalKey(); |
165 |
final NaturalKey naturalKey = keyStroke.getNaturalKey(); |
139 |
|
166 |
|
Lines 219-225
Link Here
|
219 |
* formatting |
246 |
* formatting |
220 |
*/ |
247 |
*/ |
221 |
final KeySequence dummySequence; |
248 |
final KeySequence dummySequence; |
222 |
|
|
|
223 |
if (keySequence == null) { |
249 |
if (keySequence == null) { |
224 |
if (temporaryStroke == null) { |
250 |
if (temporaryStroke == null) { |
225 |
dummySequence = KeySequence.getInstance(); |
251 |
dummySequence = KeySequence.getInstance(); |
Lines 233-241
Link Here
|
233 |
} |
259 |
} |
234 |
dummySequence = KeySequence.getInstance(keyStrokes); |
260 |
dummySequence = KeySequence.getInstance(keyStrokes); |
235 |
} |
261 |
} |
236 |
|
262 |
|
|
|
263 |
// We need to update the text, but we don't need to synchronize. |
264 |
text.removeModifyListener(updateSequenceListener); |
237 |
text.setText(/* TODO "carbon".equals(SWT.getPlatform()) ? KeySupport.formatCarbon(dummySequence) : */ |
265 |
text.setText(/* TODO "carbon".equals(SWT.getPlatform()) ? KeySupport.formatCarbon(dummySequence) : */ |
238 |
dummySequence.format()); |
266 |
dummySequence.format()); |
|
|
267 |
text.addModifyListener(updateSequenceListener); |
239 |
|
268 |
|
240 |
// Update the caret position. |
269 |
// Update the caret position. |
241 |
text.setSelection(text.getText().length()); |
270 |
text.setSelection(text.getText().length()); |
Lines 397-409
Link Here
|
397 |
// The original sequence. |
426 |
// The original sequence. |
398 |
final KeySequence originalSequence = getKeySequence(); |
427 |
final KeySequence originalSequence = getKeySequence(); |
399 |
final List keyStrokes = new ArrayList(originalSequence.getKeyStrokes()); |
428 |
final List keyStrokes = new ArrayList(originalSequence.getKeyStrokes()); |
400 |
if (temporaryStroke != null) { |
429 |
if (getTemporaryStroke() != null) { |
401 |
keyStrokes.add(temporaryStroke); |
430 |
keyStrokes.add(getTemporaryStroke()); |
402 |
} |
431 |
} |
403 |
final KeySequence sequenceFromStrokes = KeySequence.getInstance(keyStrokes); |
432 |
final KeySequence sequenceFromStrokes = KeySequence.getInstance(keyStrokes); |
404 |
|
433 |
|
405 |
// The new sequence drawn from the text. |
434 |
// The new sequence drawn from the text. |
406 |
final String contents = text.getText(); |
435 |
final String contents = getText().getText(); |
407 |
final KeySequence sequenceFromText = KeySequence.getInstance(contents); |
436 |
final KeySequence sequenceFromText = KeySequence.getInstance(contents); |
408 |
|
437 |
|
409 |
// Check to see if they're the same. |
438 |
// Check to see if they're the same. |
Lines 413-419
Link Here
|
413 |
while (strokeItr.hasNext()) { |
442 |
while (strokeItr.hasNext()) { |
414 |
// Make sure that it's a valid sequence. |
443 |
// Make sure that it's a valid sequence. |
415 |
if (!isComplete((KeyStroke) strokeItr.next())) { |
444 |
if (!isComplete((KeyStroke) strokeItr.next())) { |
416 |
setKeySequence(getKeySequence(), temporaryStroke); |
445 |
setKeySequence(getKeySequence(), getTemporaryStroke()); |
417 |
return; |
446 |
return; |
418 |
} |
447 |
} |
419 |
} |
448 |
} |
Lines 421-427
Link Here
|
421 |
} |
450 |
} |
422 |
} catch (final ParseException e) { |
451 |
} catch (final ParseException e) { |
423 |
// Abort any cut/paste-driven modifications |
452 |
// Abort any cut/paste-driven modifications |
424 |
setKeySequence(getKeySequence(), temporaryStroke); |
453 |
setKeySequence(getKeySequence(), getTemporaryStroke()); |
425 |
} |
454 |
} |
426 |
} |
455 |
} |
427 |
} |
456 |
} |