Search in sources :

Example 1 with Alert

use of org.apache.pivot.wtk.Alert in project pivot by apache.

the class ShutdownTest method shutdown.

@Override
public boolean shutdown(boolean optional) {
    System.out.println("shutdown()");
    if (alert == null) {
        ArrayList<String> options = new ArrayList<>();
        options.add("Yes");
        options.add("No");
        alert = new Alert(MessageType.QUESTION, "Cancel shutdown?", options);
        alert.setModal(false);
        alert.open(display, new DialogCloseListener() {

            @Override
            public void dialogClosed(Dialog dialog, boolean modal) {
                if (!(dialog instanceof Alert)) {
                    return;
                }
                Alert alertLocal = (Alert) dialog;
                if (alertLocal.getResult()) {
                    if (alertLocal.getSelectedOptionIndex() == 1) {
                        cancelShutdown = false;
                        DesktopApplicationContext.exit();
                    }
                }
                ShutdownTest.this.alert = null;
            }
        });
    }
    return cancelShutdown;
}
Also used : Dialog(org.apache.pivot.wtk.Dialog) ArrayList(org.apache.pivot.collections.ArrayList) Alert(org.apache.pivot.wtk.Alert) DialogCloseListener(org.apache.pivot.wtk.DialogCloseListener)

Example 2 with Alert

use of org.apache.pivot.wtk.Alert in project pivot by apache.

the class TerraAlertSkin method windowOpened.

@Override
public void windowOpened(Window window) {
    super.windowOpened(window);
    Alert alert = (Alert) window;
    int index = alert.getSelectedOptionIndex();
    if (index >= 0) {
        optionButtonBoxPane.get(index).requestFocus();
    } else {
        window.requestFocus();
    }
}
Also used : Alert(org.apache.pivot.wtk.Alert)

Example 3 with Alert

use of org.apache.pivot.wtk.Alert in project pivot by apache.

the class TerraAlertSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Alert alert = (Alert) component;
    alert.setPreferredWidth(320);
    alert.setMinimumWidth(160);
    alert.getAlertListeners().add(this);
    // Load the alert content
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    Component content;
    try {
        content = (Component) bxmlSerializer.readObject(TerraAlertSkin.class, "terra_alert_skin.bxml");
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
    alert.setContent(content);
    typeImageView = (ImageView) bxmlSerializer.getNamespace().get("typeImageView");
    messageLabel = (Label) bxmlSerializer.getNamespace().get("messageLabel");
    messageBorder = (Border) bxmlSerializer.getNamespace().get("messageBorder");
    messageBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("messageBoxPane");
    optionButtonBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("optionButtonBoxPane");
    // Explicitly set the message border color and background color, this can't be done properly in the constructor
    // as messageBorder is null at that point.
    setBorderBackgroundColor(borderBackgroundColor);
    setBorderColor(borderColor);
    for (Object option : alert.getOptions()) {
        PushButton optionButton = new PushButton(option);
        optionButton.setStyleName(BUTTON_STYLE_NAME);
        optionButton.getButtonPressListeners().add(optionButtonPressListener);
        optionButtonBoxPane.add(optionButton);
    }
    messageTypeChanged(alert, null);
    messageChanged(alert, null);
    bodyChanged(alert, null);
}
Also used : Alert(org.apache.pivot.wtk.Alert) Component(org.apache.pivot.wtk.Component) PushButton(org.apache.pivot.wtk.PushButton) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 4 with Alert

use of org.apache.pivot.wtk.Alert in project pivot by apache.

the class SheetTest method startup.

@SuppressWarnings("unused")
@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
    Picture picture = (Picture) Image.load(getClass().getResource("IMG_0767_2.jpg"));
    picture.resample(120);
    BoxPane windowContent = new BoxPane();
    PushButton button = new PushButton(picture);
    button.getStyles().put(Style.toolbar, true);
    windowContent.add(button);
    frame = new Frame(windowContent);
    frame.setPreferredSize(480, 360);
    frame.getStyles().put(Style.padding, 0);
    frame.open(display);
    final TablePane tablePane = new TablePane();
    tablePane.setPreferredSize(320, 240);
    new TablePane.Column(tablePane, 1, true);
    TablePane.Row row0 = new TablePane.Row(tablePane, 1, true);
    TablePane.Row row1 = new TablePane.Row(tablePane, -1);
    final Label sheetContent = new Label("Sheet Content");
    sheetContent.getStyles().put(Style.wrapText, true);
    sheetContent.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
    sheetContent.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    row0.add(sheetContent);
    Label promptBody = new Label("Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
    promptBody.getStyles().put(Style.wrapText, true);
    final Prompt prompt = new Prompt(MessageType.INFO, "Prompt", new ArrayList<>("OK"), promptBody);
    prompt.setTitle("Prompt");
    prompt.getStyles().put(Style.resizable, true);
    prompt.getComponentMouseListeners().add(new ComponentMouseListener() {

        @Override
        public void mouseOver(Component component) {
            System.out.println("Mouse Over");
        }

        @Override
        public void mouseOut(Component component) {
            System.out.println("Mouse out");
        }
    });
    Label alertBody = new Label("Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
    alertBody.getStyles().put(Style.wrapText, true);
    final Alert alert = new Alert(MessageType.INFO, "Alert", new ArrayList<>("OK"), alertBody);
    alert.setTitle("Alert");
    BoxPane boxPane = new BoxPane();
    row1.add(boxPane);
    boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.RIGHT);
    final PushButton closeButton = new PushButton("Close");
    closeButton.getStyles().put(Style.minimumAspectRatio, 3);
    boxPane.add(closeButton);
    sheet = new Sheet(tablePane);
    closeButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button buttonArgument) {
            buttonArgument.getWindow().close();
        }
    });
    button.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button buttonArgument) {
            prompt.open(frame);
            Display displayLocal = DesktopApplicationContext.createDisplay(640, 480, 100, 100, true, true, false, buttonArgument.getDisplay().getHostWindow(), null);
            Window window = new Window();
            window.setTitle("New Secondary Window");
            window.setMaximized(true);
            window.setContent(new Label("I am a secondary window!"));
            window.open(displayLocal);
        }
    });
    sheet.getWindowStateListeners().add(new WindowStateListener() {

        @Override
        public void windowOpened(Window window) {
            closeButton.requestFocus();
        }
    });
    DesktopApplicationContext.sizeHostToFit(frame);
}
Also used : Window(org.apache.pivot.wtk.Window) Frame(org.apache.pivot.wtk.Frame) WindowStateListener(org.apache.pivot.wtk.WindowStateListener) Label(org.apache.pivot.wtk.Label) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) Picture(org.apache.pivot.wtk.media.Picture) Prompt(org.apache.pivot.wtk.Prompt) Alert(org.apache.pivot.wtk.Alert) PushButton(org.apache.pivot.wtk.PushButton) Component(org.apache.pivot.wtk.Component) ComponentMouseListener(org.apache.pivot.wtk.ComponentMouseListener) Sheet(org.apache.pivot.wtk.Sheet) TablePane(org.apache.pivot.wtk.TablePane) Display(org.apache.pivot.wtk.Display)

Aggregations

Alert (org.apache.pivot.wtk.Alert)4 Component (org.apache.pivot.wtk.Component)2 PushButton (org.apache.pivot.wtk.PushButton)2 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 ArrayList (org.apache.pivot.collections.ArrayList)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 Button (org.apache.pivot.wtk.Button)1 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)1 ComponentMouseListener (org.apache.pivot.wtk.ComponentMouseListener)1 Dialog (org.apache.pivot.wtk.Dialog)1 DialogCloseListener (org.apache.pivot.wtk.DialogCloseListener)1 Display (org.apache.pivot.wtk.Display)1 Frame (org.apache.pivot.wtk.Frame)1 Label (org.apache.pivot.wtk.Label)1 Prompt (org.apache.pivot.wtk.Prompt)1 Sheet (org.apache.pivot.wtk.Sheet)1 TablePane (org.apache.pivot.wtk.TablePane)1 Window (org.apache.pivot.wtk.Window)1 WindowStateListener (org.apache.pivot.wtk.WindowStateListener)1 Picture (org.apache.pivot.wtk.media.Picture)1