Methods Summary |
---|
protected abstract java.lang.String | doGetPattern(java.lang.String patternKey)
|
protected abstract void | doParseAndRememberPattern(java.lang.String pattern)Parses the specified pattern and remembers it for formatting input later.
|
protected abstract void | doParseInput(java.lang.String toParse, com.google.gwt.user.client.ui.HasText output, com.google.gwt.user.client.ui.HasText error)
|
private void | initWidgetsForInput()
txtInput.addKeyboardListener(new KeyboardListenerAdapter() {
public void onKeyUp(Widget sender, char keyCode, int modifiers) {
tryToParseInput(false);
}
});
|
private void | initWidgetsForPattern(java.util.Map patternMap)
txtCurrentPattern.addKeyboardListener(new KeyboardListenerAdapter() {
public void onKeyUp(Widget sender, char keyCode, int modifiers) {
String pattern = txtCurrentPattern.getText();
// Update the active pattern.
tryToActivatePattern(pattern);
}
});
// Load pattern choices.
for (Iterator iter = patternMap.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String patternKey = (String) entry.getKey();
String caption = (String) entry.getValue();
lstSamplePatterns.addItem(caption, patternKey);
}
lstSamplePatterns.addChangeListener(new ChangeListener() {
public void onChange(Widget sender) {
syncPatternToList();
}
});
lstSamplePatterns.setSelectedIndex(0);
syncPatternToList();
|
private void | syncPatternToList()
int sel = lstSamplePatterns.getSelectedIndex();
assert (sel >= 0) && (sel < lstSamplePatterns.getItemCount());
// Update the current pattern.
String patternKey = lstSamplePatterns.getValue(sel);
String pattern;
if (PATTERN_KEY_CUSTOM.equals(patternKey)) {
// Make the pattern text box editable.
txtCurrentPattern.setReadOnly(false);
pattern = txtCurrentPattern.getText();
txtCurrentPattern.setText(pattern);
txtCurrentPattern.selectAll();
txtCurrentPattern.setFocus(true);
} else {
// Make the pattern text box read only.
txtCurrentPattern.setReadOnly(true);
pattern = doGetPattern(patternKey);
txtCurrentPattern.setText(pattern);
}
// Make the new pattern active.
tryToActivatePattern(pattern);
|
private void | tryToActivatePattern(java.lang.String pattern)
if (!pattern.equals(prevPattern)) {
prevPattern = pattern;
lblPatternError.setText("");
try {
// Allow the subclass to parse the pattern.
doParseAndRememberPattern(pattern);
// Parse and format the input again since the pattern changed.
tryToParseInput(true);
} catch (IllegalArgumentException e) {
lblPatternError.setText(e.getMessage());
}
}
|
private void | tryToParseInput(boolean forceReparse)
String toParse = txtInput.getText();
if (forceReparse || !toParse.equals(prevInput)) {
prevInput = toParse;
lblParseError.setText("");
doParseInput(toParse, lblFormattedOutput, lblParseError);
}
|