Search in sources :

Example 6 with MenuBar

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

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

the class MenuBarItemSkin method mouseOver.

@Override
public void mouseOver(Component component) {
    super.mouseOver(component);
    MenuBar.Item menuBarItem = (MenuBar.Item) getComponent();
    MenuBar menuBar = (MenuBar) menuBarItem.getParent();
    if (menuBar.getActiveItem() != null) {
        menuBarItem.setActive(true);
    }
}
Also used : MenuBar(org.apache.pivot.wtk.MenuBar)

Example 8 with MenuBar

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

the class TerraFrameSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = 0;
    Frame frame = (Frame) getComponent();
    // Include title bar width plus left/right title bar borders
    Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
    preferredWidth = Math.max(preferredWidth, titleBarSize.width + 2);
    // Include title bar height plus top/bottom title bar borders
    preferredHeight += titleBarSize.height + 2;
    // Include menu bar size
    MenuBar menuBar = frame.getMenuBar();
    if (menuBar != null) {
        Dimensions preferredMenuBarSize = menuBar.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, preferredMenuBarSize.width);
        preferredHeight += preferredMenuBarSize.height;
    }
    Component content = frame.getContent();
    if (content != null) {
        Dimensions preferredContentSize = content.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, preferredContentSize.width);
        preferredHeight += preferredContentSize.height;
    }
    // Add padding, borders, and content bevel
    preferredWidth += (padding.left + padding.right) + 2;
    preferredHeight += (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Frame(org.apache.pivot.wtk.Frame) Dimensions(org.apache.pivot.wtk.Dimensions) MenuBar(org.apache.pivot.wtk.MenuBar) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 9 with MenuBar

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

the class TerraFrameSkin method layout.

@Override
public void layout() {
    Frame frame = (Frame) getComponent();
    int width = getWidth();
    int height = getHeight();
    boolean maximized = frame.isMaximized();
    if (!maximized || getShowWindowControls()) {
        int clientX = 1;
        int clientY = 1;
        int clientWidth = Math.max(width - 2, 0);
        int clientHeight = Math.max(height - 2, 0);
        // Size/position title bar
        titleBarTablePane.setLocation(clientX, clientY);
        titleBarTablePane.setSize(clientWidth, titleBarTablePane.getPreferredHeight());
        titleBarTablePane.setVisible(true);
        // Add bottom title bar border, top content border, and content
        // bevel
        clientY += titleBarTablePane.getHeight() + (showContentBevel ? 1 : 0) + 2;
        // Size/position resize handle
        resizeHandle.setSize(resizeHandle.getPreferredSize());
        resizeHandle.setLocation(clientWidth - resizeHandle.getWidth(), clientHeight - resizeHandle.getHeight());
        resizeHandle.setVisible(resizable && !maximized && (frame.isPreferredWidthSet() || frame.isPreferredHeightSet()));
        // Size/position menu bar
        MenuBar menuBar = frame.getMenuBar();
        if (menuBar != null && menuBar.isVisible()) {
            menuBar.setLocation(clientX, clientY);
            menuBar.setSize(clientWidth, menuBar.getPreferredHeight());
            clientY += menuBar.getHeight();
        }
        // Size/position content
        Component content = frame.getContent();
        if (content != null) {
            int contentX = clientX + padding.left;
            int contentY = clientY + padding.top;
            int contentWidth = Math.max(clientWidth - (padding.left + padding.right), 0);
            int contentHeight = Math.max(clientHeight - (clientY + padding.top + padding.bottom) + (showContentBevel ? 1 : 0), 0);
            content.setLocation(contentX, contentY);
            content.setSize(contentWidth, contentHeight);
        }
    } else {
        titleBarTablePane.setVisible(false);
        resizeHandle.setVisible(false);
        // Size/position menu bar
        int clientY = 0;
        MenuBar menuBar = frame.getMenuBar();
        if (menuBar != null && menuBar.isVisible()) {
            menuBar.setLocation(0, clientY);
            menuBar.setSize(width, menuBar.getPreferredHeight());
            clientY += menuBar.getHeight();
        }
        Component content = frame.getContent();
        if (content != null) {
            content.setLocation(padding.left, clientY + padding.top);
            content.setSize(Math.max(width - (padding.left + padding.right), 0), Math.max(height - (clientY + padding.top + padding.bottom), 0));
        }
    }
}
Also used : Frame(org.apache.pivot.wtk.Frame) MenuBar(org.apache.pivot.wtk.MenuBar) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 10 with MenuBar

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

the class TerraMenuBarItemSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    MenuBar.Item menuBarItem = (MenuBar.Item) getComponent();
    int width = getWidth();
    int height = getHeight();
    boolean highlight = menuBarItem.isActive();
    // Paint highlight state
    if (highlight) {
        MenuBar menuBar = (MenuBar) menuBarItem.getParent();
        Color activeBackgroundColor = menuBar.getStyles().getColor(Style.activeBackgroundColor);
        graphics.setColor(activeBackgroundColor);
        graphics.fillRect(0, 0, width, height);
    }
    // Paint the content
    Button.DataRenderer dataRenderer = menuBarItem.getDataRenderer();
    dataRenderer.render(menuBarItem.getButtonData(), menuBarItem, highlight);
    dataRenderer.setSize(width, height);
    dataRenderer.paint(graphics);
}
Also used : Button(org.apache.pivot.wtk.Button) Color(java.awt.Color) MenuBar(org.apache.pivot.wtk.MenuBar)

Aggregations

MenuBar (org.apache.pivot.wtk.MenuBar)11 Frame (org.apache.pivot.wtk.Frame)6 Component (org.apache.pivot.wtk.Component)5 GradientPaint (java.awt.GradientPaint)4 Point (org.apache.pivot.wtk.Point)4 Color (java.awt.Color)3 Dimensions (org.apache.pivot.wtk.Dimensions)2 Font (java.awt.Font)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Action (org.apache.pivot.wtk.Action)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 Button (org.apache.pivot.wtk.Button)1 MenuHandler (org.apache.pivot.wtk.MenuHandler)1 TextInput (org.apache.pivot.wtk.TextInput)1 Image (org.apache.pivot.wtk.media.Image)1