@Override
public void install(Component component) {
super.install(component);
Alert alert = (Alert)component;
alert.getAlertListeners().add(this);
// Load the alert content
WTKXSerializer wtkxSerializer = new WTKXSerializer();
Component content = null;
try {
content = (Component)wtkxSerializer.readObject(this, "terra_alert_skin.wtkx");
} catch(Exception exception) {
throw new RuntimeException(exception);
}
alert.setContent(content);
// Set the type image
TerraTheme theme = (TerraTheme)Theme.getTheme();
ImageView typeImageView = (ImageView)wtkxSerializer.get("typeImageView");
typeImageView.setImage(theme.getMessageIcon(alert.getMessageType()));
// Set the message
Label messageLabel = (Label)wtkxSerializer.get("messageLabel");
String message = alert.getMessage();
messageLabel.setText(message);
// Set the body
BoxPane messageBoxPane = (BoxPane)wtkxSerializer.get("messageBoxPane");
Component body = alert.getBody();
if (body != null) {
messageBoxPane.add(body);
}
// Add the option buttons
BoxPane buttonBoxPane = (BoxPane)wtkxSerializer.get("buttonBoxPane");
for (int i = 0, n = alert.getOptionCount(); i < n; i++) {
Object option = alert.getOption(i);
PushButton optionButton = new PushButton(option);
optionButton.setStyles(commandButtonStyles);
optionButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
int optionIndex = optionButtons.indexOf(button);
if (optionIndex >= 0) {
Alert alert = (Alert)getComponent();
alert.setSelectedOption(optionIndex);
alert.close(true);
}
}
});
buttonBoxPane.add(optionButton);