Search in sources :

Example 1 with MenuHandler

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

the class MenuBarTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
    boxPane.add(new TextInput());
    boxPane.add(new TextInput());
    boxPane.add(new TextInput());
    frame1 = new Frame(boxPane);
    frame1.setLocation(50, 50);
    frame1.setPreferredSize(320, 240);
    frame1.setTitle("Frame 1");
    // put this before loading the related bxml, or an
    // IllegalArgumentException will be thrown
    Action.getNamedActions().put("about", new Action() {

        @Override
        public void perform(Component source) {
            String msg = "Hello from Pivot-" + ApplicationContext.getPivotVersion().toString() + ", running from Java " + // + ApplicationContext.getJVMVersion().toString()
            System.getProperty("java.version");
            // frame2);
            Alert.alert(msg, frame2.getRootOwner());
            System.out.println("Help triggered");
        }
    });
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    frame2 = (Frame) bxmlSerializer.readObject(MenuBarTest.class, "menu_bar_test.bxml");
    frame2.setTitle("Frame 2, from bxml");
    bxmlSerializer.bind(this, MenuBarTest.class);
    MenuHandler menuHandler = new MenuHandler() {

        @Override
        public void configureMenuBar(Component component, MenuBar menuBar) {
            System.out.println("Configure menu bar: got focus on " + component.getName());
        }

        @Override
        public void cleanupMenuBar(Component component, MenuBar menuBar) {
            System.out.println("Clean up menu bar: lost focus on " + component.getName());
        }
    };
    textInput1.setMenuHandler(menuHandler);
    textInput2.setMenuHandler(menuHandler);
    textInput3.setMenuHandler(menuHandler);
    frame1.open(display);
    frame2.open(display);
}
Also used : Frame(org.apache.pivot.wtk.Frame) Action(org.apache.pivot.wtk.Action) MenuHandler(org.apache.pivot.wtk.MenuHandler) BoxPane(org.apache.pivot.wtk.BoxPane) MenuBar(org.apache.pivot.wtk.MenuBar) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 2 with MenuHandler

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

the class ContextMenuTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(ContextMenuTest.class, "context_menu_test.bxml");
    bxmlSerializer.bind(this, ContextMenuTest.class);
    window.setMenuHandler(new MenuHandler() {

        @Override
        public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
            menu.getSections().add(globalSection);
            menu.getSections().add(helpSection);
            menu.getSections().add(hoursSection);
            return false;
        }
    });
    window.open(display);
}
Also used : MenuHandler(org.apache.pivot.wtk.MenuHandler) Menu(org.apache.pivot.wtk.Menu) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 Component (org.apache.pivot.wtk.Component)2 MenuHandler (org.apache.pivot.wtk.MenuHandler)2 Action (org.apache.pivot.wtk.Action)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 Frame (org.apache.pivot.wtk.Frame)1 Menu (org.apache.pivot.wtk.Menu)1 MenuBar (org.apache.pivot.wtk.MenuBar)1 TextInput (org.apache.pivot.wtk.TextInput)1