@Override
@SuppressWarnings("unchecked")
public void install(Component component) {
super.install(component);
Prompt prompt = (Prompt)component;
prompt.getPromptListeners().add(this);
// Load the prompt content
WTKXSerializer wtkxSerializer = new WTKXSerializer();
Component content = null;
try {
content = (Component)wtkxSerializer.readObject(getClass().getResource("prompt_skin.wtkx"));
} catch(Exception exception) {
throw new RuntimeException(exception);
}
prompt.setContent(content);
// Set the type image
TerraTheme theme = (TerraTheme)Theme.getTheme();
ImageView typeImageView = (ImageView)wtkxSerializer.getObjectByName("typeImageView");
typeImageView.setImage(theme.getMessageIcon(prompt.getMessageType()));
// Set the message
Label messageLabel = (Label)wtkxSerializer.getObjectByName("messageLabel");
String message = prompt.getMessage();
messageLabel.setText(message);
// Set the body
FlowPane messageFlowPane = (FlowPane)wtkxSerializer.getObjectByName("messageFlowPane");
Component body = prompt.getBody();
if (body != null) {
messageFlowPane.add(body);
}
// Add the option buttons
FlowPane buttonFlowPane = (FlowPane)wtkxSerializer.getObjectByName("buttonFlowPane");
for (int i = 0, n = prompt.getOptionCount(); i < n; i++) {
Object option = prompt.getOption(i);
PushButton optionButton = new PushButton(option);
HashMap<String, Object> optionButtonStyles = new HashMap<String, Object>();
optionButtonStyles.put("color", theme.getColor(4));
optionButtonStyles.put("backgroundColor", theme.getColor(16));
optionButtonStyles.put("borderColor", theme.getColor(13));
optionButton.setStyles(optionButtonStyles);
optionButton.getStyles().put("preferredAspectRatio", 3);
optionButton.getButtonPressListeners().add(new ButtonPressListener() {
public void buttonPressed(Button button) {
int optionIndex = optionButtons.indexOf(button);
if (optionIndex >= 0) {
Prompt prompt = (Prompt)getComponent();
prompt.setSelectedOption(optionIndex);
prompt.close(true);
}
}
});
buttonFlowPane.add(optionButton);