Search in sources :

Example 1 with Display

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

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

the class ListViewItemEditor method close.

@Override
public void close() {
    Display display = getDisplay();
    display.getContainerMouseListeners().remove(displayMouseHandler);
    super.close();
}
Also used : Display(org.apache.pivot.wtk.Display)

Example 3 with Display

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

the class MenuBarItemSkin method activeChanged.

@Override
public void activeChanged(MenuBar.Item menuBarItem) {
    if (menuBarItem.isActive()) {
        Display display = menuBarItem.getDisplay();
        Point menuBarItemLocation = menuBarItem.mapPointToAncestor(display, 0, getHeight());
        // TODO Ensure that the popup remains within the bounds of the
        // display
        menuPopup.setLocation(menuBarItemLocation.x, menuBarItemLocation.y);
        menuPopup.open(menuBarItem.getWindow());
        menuPopup.requestFocus();
    } else {
        menuPopup.close(true);
    }
    repaintComponent();
}
Also used : Point(org.apache.pivot.wtk.Point) Display(org.apache.pivot.wtk.Display)

Example 4 with Display

use of org.apache.pivot.wtk.Display 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 5 with Display

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

the class TerraTooltipSkin method windowOpened.

@Override
public void windowOpened(Window window) {
    super.windowOpened(window);
    // Add this as a display mouse and key listener
    Display display = window.getDisplay();
    display.getContainerMouseListeners().add(displayMouseListener);
    display.getComponentKeyListeners().add(displayKeyListener);
}
Also used : Display(org.apache.pivot.wtk.Display)

Aggregations

Display (org.apache.pivot.wtk.Display)20 Point (org.apache.pivot.wtk.Point)9 Window (org.apache.pivot.wtk.Window)5 Button (org.apache.pivot.wtk.Button)4 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)4 Component (org.apache.pivot.wtk.Component)4 Container (org.apache.pivot.wtk.Container)4 PushButton (org.apache.pivot.wtk.PushButton)4 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 Cursor (org.apache.pivot.wtk.Cursor)3 ListButton (org.apache.pivot.wtk.ListButton)3 Menu (org.apache.pivot.wtk.Menu)3 GradientPaint (java.awt.GradientPaint)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (org.apache.pivot.collections.ArrayList)2 List (org.apache.pivot.collections.List)2 Sequence (org.apache.pivot.collections.Sequence)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)2