Search in sources :

Example 1 with CardPane

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

the class CardPaneSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    CardPane cardPane = (CardPane) component;
    cardPane.getCardPaneListeners().add(this);
}
Also used : CardPane(org.apache.pivot.wtk.CardPane)

Example 2 with CardPane

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

the class CardPaneSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    CardPane cardPane = (CardPane) getComponent();
    if (sizeToSelection) {
        if (selectionChangeTransition == null) {
            Component selectedCard = cardPane.getSelectedCard();
            if (selectedCard != null) {
                preferredHeight = selectedCard.getPreferredHeight(width);
            }
        } else {
            float percentComplete = selectionChangeTransition.getPercentComplete();
            int previousHeight;
            if (selectionChangeTransition.fromCard == null) {
                previousHeight = 0;
            } else {
                previousHeight = selectionChangeTransition.fromCard.getPreferredHeight(width);
            }
            int height;
            if (selectionChangeTransition.toCard == null) {
                height = 0;
            } else {
                height = selectionChangeTransition.toCard.getPreferredHeight(width);
            }
            preferredHeight = previousHeight + (int) ((height - previousHeight) * percentComplete);
        }
    } else {
        for (Component card : cardPane) {
            preferredHeight = Math.max(preferredHeight, card.getPreferredHeight(width));
        }
        preferredHeight += padding.getHeight();
    }
    return preferredHeight;
}
Also used : CardPane(org.apache.pivot.wtk.CardPane) Component(org.apache.pivot.wtk.Component)

Example 3 with CardPane

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

the class CardPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = 0;
    CardPane cardPane = (CardPane) getComponent();
    if (sizeToSelection) {
        if (selectionChangeTransition == null) {
            Component selectedCard = cardPane.getSelectedCard();
            if (selectedCard != null) {
                Dimensions cardSize = selectedCard.getPreferredSize();
                preferredWidth = cardSize.width;
                preferredHeight = cardSize.height;
            }
        } else {
            float percentComplete = selectionChangeTransition.getPercentComplete();
            int previousWidth;
            int previousHeight;
            if (selectionChangeTransition.fromCard == null) {
                previousWidth = 0;
                previousHeight = 0;
            } else {
                Dimensions fromSize = selectionChangeTransition.fromCard.getPreferredSize();
                previousWidth = fromSize.width;
                previousHeight = fromSize.height;
            }
            int width;
            int height;
            if (selectionChangeTransition.toCard == null) {
                width = 0;
                height = 0;
            } else {
                Dimensions toSize = selectionChangeTransition.toCard.getPreferredSize();
                width = toSize.width;
                height = toSize.height;
            }
            preferredWidth = previousWidth + (int) ((width - previousWidth) * percentComplete);
            preferredHeight = previousHeight + (int) ((height - previousHeight) * percentComplete);
        }
    } else {
        for (Component card : cardPane) {
            Dimensions cardSize = card.getPreferredSize();
            preferredWidth = Math.max(cardSize.width, preferredWidth);
            preferredHeight = Math.max(cardSize.height, preferredHeight);
        }
    }
    preferredWidth += padding.getWidth();
    preferredHeight += padding.getHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : CardPane(org.apache.pivot.wtk.CardPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 4 with CardPane

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

the class CardPaneSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    int baseline = -1;
    if (sizeToSelection) {
        CardPane cardPane = (CardPane) getComponent();
        Component selectedCard = cardPane.getSelectedCard();
        if (selectedCard != null) {
            int cardWidth = Math.max(width - padding.getWidth(), 0);
            int cardHeight = Math.max(height - padding.getHeight(), 0);
            baseline = selectedCard.getBaseline(cardWidth, cardHeight);
            if (baseline != -1) {
                baseline += padding.top;
            }
        }
    }
    return baseline;
}
Also used : CardPane(org.apache.pivot.wtk.CardPane) Component(org.apache.pivot.wtk.Component)

Example 5 with CardPane

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

Aggregations

CardPane (org.apache.pivot.wtk.CardPane)10 Component (org.apache.pivot.wtk.Component)7 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 Button (org.apache.pivot.wtk.Button)2 CardPaneListener (org.apache.pivot.wtk.CardPaneListener)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Vote (org.apache.pivot.util.Vote)1 TaskExecutionException (org.apache.pivot.util.concurrent.TaskExecutionException)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 ButtonGroup (org.apache.pivot.wtk.ButtonGroup)1 ButtonGroupListener (org.apache.pivot.wtk.ButtonGroupListener)1 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)1 ButtonStateListener (org.apache.pivot.wtk.ButtonStateListener)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Frame (org.apache.pivot.wtk.Frame)1 GridPane (org.apache.pivot.wtk.GridPane)1 Row (org.apache.pivot.wtk.GridPane.Row)1 LinkButton (org.apache.pivot.wtk.LinkButton)1