Search in sources :

Example 36 with Window

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

the class DOMInteractionDemo method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BoxPane boxPane = new BoxPane();
    boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
    helloButton = new PushButton("Say Hello");
    boxPane.add(helloButton);
    helloButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            BrowserApplicationContext.eval("sayHello(\"Hello from Pivot!\")", DOMInteractionDemo.this);
        }
    });
    Border border = new Border(boxPane);
    border.getStyles().put(Style.color, 7);
    border.getStyles().put(Style.padding, 5);
    window = new Window(border);
    window.setMaximized(true);
    window.open(display);
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) Window(org.apache.pivot.wtk.Window) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) PushButton(org.apache.pivot.wtk.PushButton) Border(org.apache.pivot.wtk.Border)

Example 37 with Window

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

the class ActionMappingTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    Action.getNamedActions().put("action1", new Action() {

        @Override
        public void perform(Component source) {
            Alert.alert(MessageType.INFO, "Action 1 performed.", window);
        }
    });
    Action.getNamedActions().put("action2", new Action() {

        @Override
        public void perform(Component source) {
            Alert.alert(MessageType.INFO, "Action 2 performed.", window);
        }
    });
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(ActionMappingTest.class, "action_mapping_test.bxml");
    window.getActionMappings().add(new Window.ActionMapping(new Keyboard.KeyStroke(Keyboard.KeyCode.B, Keyboard.Modifier.SHIFT.getMask()), "action2"));
    window.open(display);
    window.requestFocus();
}
Also used : Window(org.apache.pivot.wtk.Window) Action(org.apache.pivot.wtk.Action) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 38 with Window

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

the class ButtonGroupTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.getButtonGroupListeners().add(new ButtonGroupListener() {

        @Override
        public void selectionChanged(ButtonGroup buttonGroupArgument, Button previousSelection) {
            System.out.println("selectionChanged(): previousSelection = " + previousSelection + ", selection = " + buttonGroupArgument.getSelection());
        }

        @Override
        public void buttonAdded(ButtonGroup buttonGroupArgument, Button button) {
            System.out.println("buttonAdded(): " + button);
        }

        @Override
        public void buttonRemoved(ButtonGroup buttonGroupArgument, Button button) {
            System.out.println("buttonRemoved(): " + button);
        }
    });
    BoxPane boxPane = new BoxPane();
    PushButton button1 = new PushButton("One");
    button1.setToggleButton(true);
    button1.setButtonGroup(buttonGroup);
    boxPane.add(button1);
    PushButton button2 = new PushButton("Two");
    button2.setToggleButton(true);
    button2.setButtonGroup(buttonGroup);
    boxPane.add(button2);
    PushButton button3 = new PushButton("Three");
    button3.setToggleButton(true);
    button3.setButtonGroup(buttonGroup);
    boxPane.add(button3);
    PushButton button4 = new PushButton("Four");
    button4.setToggleButton(true);
    button4.setButtonGroup(buttonGroup);
    boxPane.add(button4);
    // button1.setSelected(true);
    // buttonGroup.setSelection(button1);
    // buttonGroup.setSelection(null);
    window = new Window(boxPane);
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener)

Example 39 with Window

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

the class WindowSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Window window = (Window) component;
    window.getWindowListeners().add(this);
    window.getWindowStateListeners().add(this);
    window.setFocusTraversalPolicy(new WindowFocusTraversalPolicy());
}
Also used : Window(org.apache.pivot.wtk.Window)

Example 40 with Window

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

the class TerraMenuSkin method keyPressed.

/**
 * {@link KeyCode#UP UP} Select the previous enabled menu item.<br>
 * {@link KeyCode#DOWN DOWN} Select the next enabled menu item.<br>
 * {@link KeyCode#LEFT LEFT} Close the current sub-menu.<br>
 * {@link KeyCode#RIGHT RIGHT} Open the sub-menu of the current menu
 * item.<br> {@link KeyCode#ENTER ENTER} 'presses' the active menu item if
 * it does not have a sub-menu.
 */
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
    boolean consumed = super.keyPressed(component, keyCode, keyLocation);
    Menu menu = (Menu) component;
    if (keyCode == Keyboard.KeyCode.UP) {
        Menu.SectionSequence sections = menu.getSections();
        int sectionCount = sections.getLength();
        Menu.Item activeItem = menu.getActiveItem();
        int sectionIndex;
        int itemIndex;
        if (activeItem == null) {
            sectionIndex = sectionCount - 1;
            itemIndex = -1;
        } else {
            Menu.Section section = activeItem.getSection();
            sectionIndex = sections.indexOf(section);
            itemIndex = section.indexOf(activeItem) - 1;
            if (itemIndex == -1) {
                sectionIndex--;
            }
        }
        while (sectionIndex >= 0) {
            Section section = sections.get(sectionIndex);
            if (itemIndex == -1) {
                int sectionLength = section.getLength();
                itemIndex = sectionLength - 1;
            }
            while (itemIndex >= 0) {
                Item item = section.get(itemIndex);
                if (item.isEnabled()) {
                    item.setActive(true);
                    break;
                }
                itemIndex--;
            }
            if (itemIndex >= 0) {
                break;
            }
            sectionIndex--;
        }
        consumed = true;
    } else if (keyCode == Keyboard.KeyCode.DOWN) {
        Menu.SectionSequence sections = menu.getSections();
        int sectionCount = sections.getLength();
        Menu.Item activeItem = menu.getActiveItem();
        int sectionIndex;
        int itemIndex;
        if (activeItem == null) {
            sectionIndex = 0;
            itemIndex = 0;
        } else {
            Menu.Section section = activeItem.getSection();
            sectionIndex = sections.indexOf(section);
            itemIndex = section.indexOf(activeItem) + 1;
        }
        while (sectionIndex < sectionCount) {
            Section section = sections.get(sectionIndex);
            int sectionLength = section.getLength();
            while (itemIndex < sectionLength) {
                Item item = section.get(itemIndex);
                if (item.isEnabled()) {
                    item.setActive(true);
                    break;
                }
                itemIndex++;
            }
            if (itemIndex < sectionLength) {
                break;
            }
            sectionIndex++;
            itemIndex = 0;
        }
        consumed = true;
    } else if (keyCode == Keyboard.KeyCode.LEFT) {
        // Close the window if this is not a top-level menu
        if (menu.getItem() != null) {
            Window window = menu.getWindow();
            window.close();
            consumed = true;
        }
    } else if (keyCode == Keyboard.KeyCode.RIGHT) {
        Menu.Item activeItem = menu.getActiveItem();
        // Press if the item has a sub-menu
        if (activeItem != null && activeItem.getMenu() != null) {
            activeItem.press();
            consumed = true;
        }
    } else if (keyCode == Keyboard.KeyCode.ENTER) {
        Menu.Item activeItem = menu.getActiveItem();
        // Press if the item does not have a sub-menu
        if (activeItem != null && activeItem.getMenu() == null) {
            activeItem.press();
            consumed = true;
        }
    } else if (keyCode == Keyboard.KeyCode.TAB) {
        consumed = false;
    }
    return consumed;
}
Also used : Window(org.apache.pivot.wtk.Window) Item(org.apache.pivot.wtk.Menu.Item) Item(org.apache.pivot.wtk.Menu.Item) Section(org.apache.pivot.wtk.Menu.Section) Menu(org.apache.pivot.wtk.Menu) Section(org.apache.pivot.wtk.Menu.Section)

Aggregations

Window (org.apache.pivot.wtk.Window)45 Component (org.apache.pivot.wtk.Component)14 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)13 PushButton (org.apache.pivot.wtk.PushButton)9 BoxPane (org.apache.pivot.wtk.BoxPane)8 Button (org.apache.pivot.wtk.Button)7 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)6 Display (org.apache.pivot.wtk.Display)5 Border (org.apache.pivot.wtk.Border)4 Label (org.apache.pivot.wtk.Label)4 Sheet (org.apache.pivot.wtk.Sheet)4 TablePane (org.apache.pivot.wtk.TablePane)4 File (java.io.File)3 Bounds (org.apache.pivot.wtk.Bounds)3 Point (org.apache.pivot.wtk.Point)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 Vote (org.apache.pivot.util.Vote)2 TaskExecutionException (org.apache.pivot.util.concurrent.TaskExecutionException)2