/** * Sets the actions that will be turned into ActionButtons at the bottom of the panel. Any action * that is clicked will also call the OptionPanel.close() method which by default removes the * panel from its parent node. */ public void setOptions(Action... options) { if (this.options == options) { return; } if (this.options != null) { // Need to clear out any old button listeners for (Node n : buttons.getLayout().getChildren()) { if (!(n instanceof Button)) { continue; } ((Button) n).removeClickCommands(listener); } } this.options = options; buttons.clearChildren(); if (options.length == 0) { options = new Action[] {new EmptyAction("Ok")}; } for (Action a : options) { ActionButton button = new ActionButton(a, getElementId().child("button"), getStyle()); button.addClickCommands(listener); buttons.addChild(button); } }
/** * Sets the message text of this option panel that will appear on the option panel's container. */ public void setMessage(String message) { if (messageLabel == null && message != null) { messageLabel = new Label(message, getElementId().child("message.label"), getStyle()); container.addChild(messageLabel); } else if (messageLabel != null && message == null) { layout.removeChild(messageLabel); messageLabel = null; } else { messageLabel.setText(message); } }
protected OptionPanel( boolean applyStyles, String title, String message, Action[] options, ElementId elementId, String style) { super(false, elementId, style); this.layout = new BorderLayout(); getControl(GuiControl.class).setLayout(layout); if (title != null) { titleLabel = new Label(title, getElementId().child("title.label"), style); layout.addChild(titleLabel, BorderLayout.Position.North); } container = new Container(getElementId().child("container"), style); layout.addChild(container, BorderLayout.Position.Center); if (message != null) { messageLabel = new Label(message, getElementId().child("message.label"), style); container.addChild(messageLabel); } buttons = new Container( new SpringGridLayout(Axis.X, Axis.Y, FillMode.ForcedEven, FillMode.Even), getElementId().child("buttons"), style); setOptions(options); layout.addChild(buttons, BorderLayout.Position.South); if (applyStyles) { Styles styles = GuiGlobals.getInstance().getStyles(); styles.applyStyles(this, elementId, style); } }
protected Component createChoices(Container parent) { PlainContainer container = new PlainContainer(); parent.addChild(container); Component focus = null; GridLayout gridLayout = new GridLayout(container, 5); container.setLayout(gridLayout); container.addStyle("pickGrid"); for (String name : this.resources.ninePatchNames()) { NinePatch ninePatch = this.resources.getNinePatch(name); AbstractComponent component = this.createNinePatchButton(ninePatch); if (ninePatch == this.defaultNinePatch) { focus = component; } gridLayout.addChild(component); } gridLayout.endRow(); return focus; }