Search in sources :

Example 1 with CardPaneListener

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

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

the class CardPanes method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    cardPane = (CardPane) namespace.get("cardPane");
    previousButton = (LinkButton) namespace.get("previousButton");
    nextButton = (LinkButton) namespace.get("nextButton");
    sizeToSelectionCheckbox = (Checkbox) namespace.get("sizeToSelectionCheckbox");
    crossfadeRadioButton = (RadioButton) namespace.get("crossfadeRadioButton");
    horizontalSlideRadioButton = (RadioButton) namespace.get("horizontalSlideRadioButton");
    verticalSlideRadioButton = (RadioButton) namespace.get("verticalSlideRadioButton");
    horizontalFlipRadioButton = (RadioButton) namespace.get("horizontalFlipRadioButton");
    verticalFlipRadioButton = (RadioButton) namespace.get("verticalFlipRadioButton");
    zoomRadioButton = (RadioButton) namespace.get("zoomRadioButton");
    noneRadioButton = (RadioButton) namespace.get("noneRadioButton");
    cardPane.getCardPaneListeners().add(new CardPaneListener() {

        @Override
        public void selectedIndexChanged(CardPane cardPaneArgument, int previousSelectedIndex) {
            updateLinkButtonState();
        }
    });
    previousButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            cardPane.setSelectedIndex(cardPane.getSelectedIndex() - 1);
        }
    });
    nextButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            cardPane.setSelectedIndex(cardPane.getSelectedIndex() + 1);
        }
    });
    ButtonStateListener checkboxStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            updateCardPane();
        }
    };
    sizeToSelectionCheckbox.getButtonStateListeners().add(checkboxStateListener);
    ButtonStateListener radioButtonStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            if (button.isSelected()) {
                updateCardPane();
            }
        }
    };
    crossfadeRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    horizontalSlideRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    verticalSlideRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    horizontalFlipRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    verticalFlipRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    zoomRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    noneRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    updateCardPane();
    updateLinkButtonState();
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) CardPane(org.apache.pivot.wtk.CardPane) LinkButton(org.apache.pivot.wtk.LinkButton) RadioButton(org.apache.pivot.wtk.RadioButton) Button(org.apache.pivot.wtk.Button) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener) CardPaneListener(org.apache.pivot.wtk.CardPaneListener)

Aggregations

Button (org.apache.pivot.wtk.Button)2 CardPane (org.apache.pivot.wtk.CardPane)2 CardPaneListener (org.apache.pivot.wtk.CardPaneListener)2 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Vote (org.apache.pivot.util.Vote)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 Frame (org.apache.pivot.wtk.Frame)1 LinkButton (org.apache.pivot.wtk.LinkButton)1 RadioButton (org.apache.pivot.wtk.RadioButton)1