Search in sources :

Example 6 with Frame

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

the class CardPaneTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    frame = new Frame(new BoxPane());
    frame.getStyles().put(Style.padding, 0);
    frame.setTitle("Component Pane Test");
    frame.setPreferredSize(800, 600);
    frame.setLocation(20, 20);
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    sheet = (Sheet) bxmlSerializer.readObject(CardPaneTest.class, "card_pane_test.bxml");
    cardPane = (CardPane) bxmlSerializer.getNamespace().get("cardPane");
    sizeGroup = (ButtonGroup) bxmlSerializer.getNamespace().get("sizeGroup");
    sizeGroup.getButtonGroupListeners().add(new ButtonGroupListener() {

        @Override
        public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
            final Button selection = buttonGroup.getSelection();
            int selectedIndex = selection == null ? -1 : selection.getParent().indexOf(selection);
            cardPane.getCardPaneListeners().add(new CardPaneListener() {

                @Override
                public Vote previewSelectedIndexChange(CardPane cardPaneArgument, int selectedIndexArgument) {
                    if (selection != null) {
                        selection.getParent().setEnabled(false);
                    }
                    return Vote.APPROVE;
                }

                @Override
                public void selectedIndexChangeVetoed(CardPane cardPaneArgument, Vote reason) {
                    if (selection != null && reason == Vote.DENY) {
                        selection.getParent().setEnabled(true);
                    }
                }

                @Override
                public void selectedIndexChanged(CardPane cardPaneArgument, int previousSelectedIndex) {
                    if (selection != null) {
                        selection.getParent().setEnabled(true);
                    }
                }
            });
            cardPane.setSelectedIndex(selectedIndex);
        }
    });
    frame.open(display);
    ApplicationContext.queueCallback(() -> sheet.open(frame));
}
Also used : Frame(org.apache.pivot.wtk.Frame) CardPane(org.apache.pivot.wtk.CardPane) Vote(org.apache.pivot.util.Vote) BoxPane(org.apache.pivot.wtk.BoxPane) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) Button(org.apache.pivot.wtk.Button) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener) CardPaneListener(org.apache.pivot.wtk.CardPaneListener)

Example 7 with Frame

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

the class LabelTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    frame = new Frame();
    frame.setTitle("Label Test");
    String line1 = "There's a lady who's sure all that glitters is gold, and " + "she's buying a stairway to heaven. When she gets there she knows, " + "if the stores are closed, with a word she can get what she came " + "for. Woe oh oh oh oh oh and she's buying a stairway to heaven. " + "There's a sign on the wall, but she wants to be sure, and you know " + "sometimes words have two meanings. In a tree by the brook there's " + "a songbird who sings, sometimes all of our thoughts are misgiven. " + "Woe oh oh oh oh oh and she's buying a stairway to heaven.";
    String line2 = "And as we wind on down the road, our shadows taller than " + "our souls, there walks a lady we all know who shines white light " + "and wants to show how everything still turns to gold; and if you " + "listen very hard the tune will come to you at last when all are " + "one and one is all:\nto be a rock and not to roll.";
    BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
    Label label1 = new Label(line1);
    label1.getStyles().put(Style.wrapText, true);
    label1.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.LEFT);
    boxPane.add(label1);
    // strikethrough
    Label label2 = new Label(line2);
    label2.getStyles().put(Style.wrapText, true);
    label2.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.LEFT);
    label2.getStyles().put(Style.textDecoration, TextDecoration.STRIKETHROUGH);
    boxPane.add(label2);
    // disabled
    Label label3 = new Label(line2);
    label3.getStyles().put(Style.wrapText, true);
    label3.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.LEFT);
    label3.setEnabled(false);
    boxPane.add(label3);
    boxPane.getStyles().put(Style.fill, true);
    boxPane.getStyles().put(Style.padding, new Insets(10));
    frame.setContent(boxPane);
    frame.setPreferredSize(340, 400);
    frame.open(display);
}
Also used : Frame(org.apache.pivot.wtk.Frame) Insets(org.apache.pivot.wtk.Insets) BoxPane(org.apache.pivot.wtk.BoxPane) Label(org.apache.pivot.wtk.Label)

Example 8 with Frame

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

the class SpinnerFocusTest method startup.

@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
    Action action = new Action() {

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public void perform(final Component source) {
            String msg = "Selected: " + spinner.getSelectedItem().toString();
            Alert.alert(msg, frame);
            spinner.requestFocus();
            System.out.println("Focus transferred to spinner");
        }
    };
    Action.getNamedActions().put("buttonAction", action);
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    frame = new Frame((Component) bxmlSerializer.readObject(getClass().getResource("spinner_focus_test.bxml")));
    frame.setTitle("Spinner Focus Test");
    frame.open(display);
    spinner = (Spinner) bxmlSerializer.getNamespace().get("spinner");
    spinner.requestFocus();
// action.setEnabled(false);
}
Also used : Action(org.apache.pivot.wtk.Action) Frame(org.apache.pivot.wtk.Frame) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 9 with Frame

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

the class TerraFrameSkin method mouseDown.

@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
    boolean consumed = super.mouseDown(component, button, x, y);
    Frame frame = (Frame) getComponent();
    boolean maximized = frame.isMaximized();
    if (button == Mouse.Button.LEFT && !maximized) {
        Bounds titleBarBounds = titleBarTablePane.getBounds();
        if (titleBarBounds.contains(x, y)) {
            dragOffset = new Point(x, y);
            Mouse.capture(component);
        } else {
            if (resizable && x > resizeHandle.getX() && y > resizeHandle.getY()) {
                resizeOffset = new Point(getWidth() - x, getHeight() - y);
                Mouse.capture(component);
            }
        }
    }
    return consumed;
}
Also used : Frame(org.apache.pivot.wtk.Frame) Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point)

Example 10 with Frame

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

the class TerraFrameSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    Frame frame = (Frame) getComponent();
    // Include title bar width plus left/right title bar borders
    Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
    preferredWidth = Math.max(titleBarSize.width + 2, preferredWidth);
    if (height != -1) {
        // Subtract title bar height and top/bottom title bar borders
        // from height constraint
        height -= titleBarSize.height + 2;
    }
    // Include menu bar width
    MenuBar menuBar = frame.getMenuBar();
    if (menuBar != null) {
        Dimensions menuBarSize = menuBar.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, menuBarSize.width);
        if (height != -1) {
            // Subtract menu bar height from height constraint
            height -= menuBarSize.height;
        }
    }
    Component content = frame.getContent();
    if (content != null) {
        if (height != -1) {
            // Subtract padding, top/bottom content borders, and content bevel
            // from height constraint
            height -= (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
            height = Math.max(height, 0);
        }
        preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(height));
    }
    // Add padding and left/right content borders
    preferredWidth += (padding.left + padding.right) + 2;
    return preferredWidth;
}
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)

Aggregations

Frame (org.apache.pivot.wtk.Frame)29 Component (org.apache.pivot.wtk.Component)13 BoxPane (org.apache.pivot.wtk.BoxPane)9 Point (org.apache.pivot.wtk.Point)9 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)8 GradientPaint (java.awt.GradientPaint)7 MenuBar (org.apache.pivot.wtk.MenuBar)6 Button (org.apache.pivot.wtk.Button)5 Label (org.apache.pivot.wtk.Label)5 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)4 PushButton (org.apache.pivot.wtk.PushButton)4 Sheet (org.apache.pivot.wtk.Sheet)4 Bounds (org.apache.pivot.wtk.Bounds)3 ListView (org.apache.pivot.wtk.ListView)3 Color (java.awt.Color)2 IOException (java.io.IOException)2 Action (org.apache.pivot.wtk.Action)2 Checkbox (org.apache.pivot.wtk.Checkbox)2 Dimensions (org.apache.pivot.wtk.Dimensions)2 Display (org.apache.pivot.wtk.Display)2