Search in sources :

Example 1 with WindowStateListener

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

the class Pivot765 method startup.

@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
    final MenuButton button = new MenuButton();
    button.setButtonData("Populate menu and open!");
    Window window = new Window(button);
    button.getListPopup().getWindowStateListeners().add(new WindowStateListener() {

        @Override
        public Vote previewWindowOpen(Window windowArgument) {
            Menu menu = new Menu();
            Menu.Section section = new Menu.Section();
            menu.getSections().add(section);
            section.add(new Menu.Item("A dynamically added menu item"));
            button.setMenu(menu);
            menuPopulated = true;
            return Vote.APPROVE;
        }

        @Override
        public void windowOpened(Window windowArgument) {
            if (!menuPopulated) {
                Alert.alert("Window was opened before the menu was populated." + "Either previewWindowOpen threw an exception, or it wasn't called before the Window was opened.", windowArgument);
            }
        }

        @Override
        public void windowClosed(Window windowArgument, Display displayArgument, Window owner) {
            // Remove menu for subsequent open attempt
            button.setMenu(null);
            menuPopulated = false;
        }
    });
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Vote(org.apache.pivot.util.Vote) WindowStateListener(org.apache.pivot.wtk.WindowStateListener) MenuButton(org.apache.pivot.wtk.MenuButton) Menu(org.apache.pivot.wtk.Menu) Display(org.apache.pivot.wtk.Display)

Example 2 with WindowStateListener

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

the class SheetSlideDirectionWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    // Populate the ListButton with values from the enum
    listButton.setListData(new ArrayList<>(SheetPlacement.values()));
    listButton = null;
    // Populate the form with data from the Sheet's styles
    form.load(sheet.getStyles());
    // Common ButtonPressListener to be applied to all four of
    // the PushButtons representing a slide direction
    ButtonPressListener openSheetButtonPressListener = new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            StyleDictionary sheetStyles = sheet.getStyles();
            form.store(sheetStyles);
            button.store(sheetStyles);
            form.load(sheetStyles);
            sheet.load(sheetStyles);
            sheet.open(button.getWindow());
        }
    };
    // Apply the common ButtonPressListener to the PushButtons
    for (Iterator<Component> it = tablePane.iterator(); it.hasNext(); ) {
        Component component = it.next();
        if (component instanceof PushButton) {
            PushButton button = (PushButton) component;
            button.getButtonPressListeners().add(openSheetButtonPressListener);
            button.setTooltipText("Press me!");
        }
    }
    tablePane = null;
    // Mouse handler to enable users to quickly close the sheet
    final ContainerMouseListener displayMouseHandler = new ContainerMouseListener() {

        @Override
        public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
            Display display = (Display) container;
            Component component = display.getComponentAt(x, y);
            // Close the sheet by clicking away from it.
            // This allows resizing etc to work without requiring
            // a close button or similar on the sheet.
            boolean consumed = (component != sheet);
            if (consumed) {
                sheet.close();
            }
            return consumed;
        }
    };
    // Add/remove the mouse handler based on the Sheet's state
    sheet.getWindowStateListeners().add(new WindowStateListener() {

        @Override
        public void windowOpened(Window window) {
            window.getDisplay().getContainerMouseListeners().add(displayMouseHandler);
        }

        @Override
        public void windowClosed(Window window, Display display, Window owner) {
            display.getContainerMouseListeners().remove(displayMouseHandler);
        }
    });
}
Also used : Window(org.apache.pivot.wtk.Window) WindowStateListener(org.apache.pivot.wtk.WindowStateListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) Container(org.apache.pivot.wtk.Container) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) ContainerMouseListener(org.apache.pivot.wtk.ContainerMouseListener) Component(org.apache.pivot.wtk.Component) PushButton(org.apache.pivot.wtk.PushButton) Display(org.apache.pivot.wtk.Display)

Example 3 with WindowStateListener

use of org.apache.pivot.wtk.WindowStateListener 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

Display (org.apache.pivot.wtk.Display)3 Window (org.apache.pivot.wtk.Window)3 WindowStateListener (org.apache.pivot.wtk.WindowStateListener)3 Button (org.apache.pivot.wtk.Button)2 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)2 Component (org.apache.pivot.wtk.Component)2 PushButton (org.apache.pivot.wtk.PushButton)2 Vote (org.apache.pivot.util.Vote)1 Alert (org.apache.pivot.wtk.Alert)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 ComponentMouseListener (org.apache.pivot.wtk.ComponentMouseListener)1 Container (org.apache.pivot.wtk.Container)1 ContainerMouseListener (org.apache.pivot.wtk.ContainerMouseListener)1 Frame (org.apache.pivot.wtk.Frame)1 Label (org.apache.pivot.wtk.Label)1 ListButton (org.apache.pivot.wtk.ListButton)1 Menu (org.apache.pivot.wtk.Menu)1 MenuButton (org.apache.pivot.wtk.MenuButton)1 Prompt (org.apache.pivot.wtk.Prompt)1 Sheet (org.apache.pivot.wtk.Sheet)1