String language = properties.get(LANGUAGE_PROPERTY_NAME);
locale = (language == null) ? Locale.getDefault() : new Locale(language);
resources = new Resources(getClass().getName(), locale, "UTF8");
// Load the application's UI
WTKXSerializer wtkxSerializer = new WTKXSerializer(resources);
Component content =
(Component)wtkxSerializer.readObject("pivot/tutorials/stocktracker/stocktracker.wtkx");
// Wire up event handlers
stocksTableView = (TableView)wtkxSerializer.getObjectByName("stocksTableView");
stocksTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {
public void selectedRangeAdded(TableView tableView, int rangeStart, int rangeEnd) {
// No-op
}
public void selectedRangeRemoved(TableView tableView, int rangeStart, int rangeEnd) {
// No-op
}
public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
refreshDetail();
}
});
stocksTableView.getComponentKeyListeners().add(new ComponentKeyListener() {
public boolean keyTyped(Component component, char character) {
return false;
}
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
if (keyCode == Keyboard.KeyCode.DELETE) {
removeSelectedSymbols();
}
return false;
}
public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
return false;
}
});
symbolTextInput = (TextInput)wtkxSerializer.getObjectByName("symbolTextInput");
symbolTextInput.getTextInputTextListeners().add(new TextInputTextListener() {
public void textChanged(TextInput textInput) {
TextNode textNode = textInput.getTextNode();
addSymbolButton.setEnabled(textNode.getCharacterCount() > 0);
}
});
symbolTextInput.getComponentKeyListeners().add(new ComponentKeyListener() {
public boolean keyTyped(Component component, char character) {
return false;
}
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
if (keyCode == Keyboard.KeyCode.ENTER) {
addSymbol();
}
return false;
}
public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
return false;
}
});
addSymbolButton = (Button)wtkxSerializer.getObjectByName("addSymbolButton");
addSymbolButton.getButtonPressListeners().add(new ButtonPressListener() {
public void buttonPressed(Button button) {
addSymbol();
}
});
removeSymbolsButton = (Button)wtkxSerializer.getObjectByName("removeSymbolsButton");
removeSymbolsButton.getButtonPressListeners().add(new ButtonPressListener() {
public void buttonPressed(Button button) {
removeSelectedSymbols();
}
});
lastUpdateLabel = (Label)wtkxSerializer.getObjectByName("lastUpdateLabel");
yahooFinanceButton = (Button)wtkxSerializer.getObjectByName("yahooFinanceButton");
yahooFinanceButton.getButtonPressListeners().add(new ButtonPressListener() {
public void buttonPressed(Button button) {
try {
ApplicationContext.open(new URL(YAHOO_FINANCE_HOME));
} catch(MalformedURLException exception) {
}
}
});
detailRootPane = (Container)wtkxSerializer.getObjectByName("detail.rootPane");
detailChangeLabel = (Label)wtkxSerializer.getObjectByName("detail.changeLabel");
window = new Window();
window.setTitle((String)resources.get("stockTracker"));
window.setContent(content);
window.setMaximized(true);