Link Buttons

The following example demonstrates use of the LinkButton class in a Pivot application. Clicking the links allows the user to navigate between two "pages":

The WTKX source for the example is below:

<Window title="Link Buttons" maximized="true"
    xmlns:wtkx="http://pivot.apache.org/wtkx"
    xmlns:content="org.apache.pivot.wtk.content"
    xmlns="org.apache.pivot.wtk">
    <content>
        <CardPane wtkx:id="cardPane" selectedIndex="0" styles="{selectionChangeEffect:'horizontal_slide'}">
            <BoxPane orientation="vertical" styles="{horizontalAlignment:'center', verticalAlignment:'center'}">
                <ImageView image="org/apache/pivot/tutorials/IMG_0735_2.jpg"/>
                <LinkButton wtkx:id="nextButton">
                    <buttonData>
                        <content:ButtonData text="Next" icon="@resultset_next.png"/>
                    </buttonData>
                </LinkButton>
            </BoxPane>

            <BoxPane orientation="vertical" styles="{horizontalAlignment:'center', verticalAlignment:'center'}">
                <ImageView image="org/apache/pivot/tutorials/IMG_0767_2.jpg"/>
                <LinkButton wtkx:id="previousButton">
                    <buttonData>
                        <content:ButtonData text="Previous" icon="@resultset_previous.png"/>
                    </buttonData>
                </LinkButton>
            </BoxPane>
        </CardPane>
    </content>
</Window>

This example uses the CardPane layout container. A card pane lays out its components like a stack of cards, only one of which is visible at a time. CardPane is discussed in more detail in the Navigation Containers section.

The following is the Java source for the example. A button press handler that simply sets the selected index of the card pane is assigned to each link button:

package org.apache.pivot.tutorials.buttons;

import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.Button;
import org.apache.pivot.wtk.ButtonPressListener;
import org.apache.pivot.wtk.CardPane;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.LinkButton;
import org.apache.pivot.wtk.Window;
import org.apache.pivot.wtkx.WTKXSerializer;

public class LinkButtons implements Application {
    private Window window = null;
    private CardPane cardPane = null;
    private LinkButton nextButton = null;
    private LinkButton previousButton = null;

    public void startup(Display display, Map<String, String> properties) throws Exception {
        WTKXSerializer wtkxSerializer = new WTKXSerializer();
        window = (Window)wtkxSerializer.readObject(this, "link_buttons.wtkx");
        cardPane = (CardPane)wtkxSerializer.get("cardPane");
        nextButton = (LinkButton)wtkxSerializer.get("nextButton");
        previousButton = (LinkButton)wtkxSerializer.get("previousButton");

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

        previousButton.getButtonPressListeners().add(new ButtonPressListener() {
            public void buttonPressed(Button button) {
                cardPane.setSelectedIndex(0);
            }
        });

        window.open(display);
    }

    public boolean shutdown(boolean optional) {
        if (window != null) {
            window.close();
        }

        return false;
    }

    public void suspend() {
    }

    public void resume() {
    }

    public static void main(String[] args) {
        DesktopApplicationContext.main(LinkButtons.class, args);
    }
}

Next: Lists