Search in sources :

Example 6 with CardPane

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

the class Pivot894 method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    System.out.println("public startup(...)");
    System.out.println("\n" + "Attention: now the application will go in an infinite loop, to be able to see the memory leak.\n" + "Note that probably you'll have to kill the application from outside (kill the Java process).\n" + "\n");
    // add some sleep to let users see the warning messages in console ...
    Thread.sleep(2000);
    final CardPane cardPane = new CardPane();
    cardPane.getStyles().put(Style.selectionChangeEffect, CardPaneSkin.SelectionChangeEffect.HORIZONTAL_SLIDE);
    final Window window = new Window(cardPane);
    window.open(display);
    ApplicationContext.scheduleRecurringCallback(new Runnable() {

        @Override
        public void run() {
            Thread.currentThread().setName("switcher-thread");
            // temp
            System.out.println("Run num " + num++);
            // 
            try {
                // Before the fixes for PIVOT-861 (part two) it was causing
                // out of memory ...
                // 
                // Note that this has been moved to another issue, but the
                // problem is due to the usage
                // of dataRenderer tags (and then instancing
                // ButtonDataRenderer) in the loaded bxml,
                // so probably even this test will be updated ...
                // 
                final GridPane grid = (GridPane) new BXMLSerializer().readObject(Pivot894.class, "btn_grid.bxml");
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        Iterator<Component> iterator = cardPane.iterator();
                        List<Component> componentList = new ArrayList<>();
                        while (iterator.hasNext()) {
                            Component card = iterator.next();
                            if (!card.isShowing()) {
                                componentList.add(card);
                            }
                        }
                        for (Component card : componentList) {
                            cardPane.remove(card);
                        }
                        cardPane.setSelectedIndex(cardPane.add(grid));
                        System.out.println(cardPane.getSelectedIndex());
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @SuppressWarnings("unused")
        private Row createGridRow() {
            Row row = new Row();
            try {
                // note that this method doesn't use ApplicationContext
                // cache for images ...
                row.add(new PushButton(new ButtonData(Image.load(new File("clock_icon.png").toURI().toURL()), "Clock")));
                row.add(new PushButton(new ButtonData(Image.load(new File("clock_icon.png").toURI().toURL()), "Clock")));
                row.add(new PushButton(new ButtonData(Image.load(new File("clock_icon.png").toURI().toURL()), "Clock")));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (TaskExecutionException e) {
                e.printStackTrace();
            }
            return row;
        }
    }, 100);
}
Also used : Window(org.apache.pivot.wtk.Window) CardPane(org.apache.pivot.wtk.CardPane) MalformedURLException(java.net.MalformedURLException) GridPane(org.apache.pivot.wtk.GridPane) ArrayList(java.util.ArrayList) MalformedURLException(java.net.MalformedURLException) TaskExecutionException(org.apache.pivot.util.concurrent.TaskExecutionException) TaskExecutionException(org.apache.pivot.util.concurrent.TaskExecutionException) ButtonData(org.apache.pivot.wtk.content.ButtonData) Row(org.apache.pivot.wtk.GridPane.Row) Component(org.apache.pivot.wtk.Component) PushButton(org.apache.pivot.wtk.PushButton) File(java.io.File) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 7 with CardPane

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

the class CardPaneSkin method componentInserted.

@Override
public void componentInserted(Container container, int index) {
    if (selectionChangeTransition != null) {
        selectionChangeTransition.end();
    }
    super.componentInserted(container, index);
    CardPane cardPane = (CardPane) container;
    Component card = cardPane.get(index);
    card.setVisible(false);
    if (cardPane.getLength() == 1) {
        cardPane.setSelectedIndex(0);
    }
    invalidateComponent();
}
Also used : CardPane(org.apache.pivot.wtk.CardPane) Component(org.apache.pivot.wtk.Component)

Example 8 with CardPane

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

the class CardPaneSkin method getPreferredWidth.

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

Example 9 with CardPane

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

the class CardPaneSkin method layout.

@Override
public void layout() {
    // Set the size of all components to match the size of the card pane,
    // minus padding
    CardPane cardPane = (CardPane) getComponent();
    int width = Math.max(getWidth() - padding.getWidth(), 0);
    int height = Math.max(getHeight() - padding.getHeight(), 0);
    for (Component card : cardPane) {
        card.setLocation(padding.left, padding.top);
        card.setSize(width, height);
    }
}
Also used : CardPane(org.apache.pivot.wtk.CardPane) Component(org.apache.pivot.wtk.Component)

Example 10 with CardPane

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

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