Search in sources :

Example 1 with ButtonData

use of org.apache.pivot.wtk.content.ButtonData in project pivot by apache.

the class LinkButtonTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BoxPane boxPane = new BoxPane();
    boxPane.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    boxPane.getStyles().put(Style.spacing, 8);
    boxPane.getComponentMouseListeners().add(new ComponentMouseListener() {

        @Override
        public boolean mouseMove(Component component, int x, int y) {
            System.out.println("BOX PANE " + x + ", " + y);
            return false;
        }

        @Override
        public void mouseOver(Component component) {
        // empty block
        }

        @Override
        public void mouseOut(Component component) {
        // empty block
        }
    });
    Image image = Image.load(getClass().getResource("go-home.png"));
    LinkButton linkButton = null;
    linkButton = new LinkButton("ABCDE");
    boxPane.add(linkButton);
    linkButton.getComponentMouseListeners().add(new ComponentMouseListener() {

        @Override
        public boolean mouseMove(Component component, int x, int y) {
            return true;
        }

        @Override
        public void mouseOver(Component component) {
        // empty block
        }

        @Override
        public void mouseOut(Component component) {
        // empty block
        }
    });
    linkButton = new LinkButton(image);
    boxPane.add(linkButton);
    linkButton = new LinkButton(new ButtonData(image, "12345"));
    boxPane.add(linkButton);
    window.setContent(boxPane);
    window.open(display);
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) ButtonData(org.apache.pivot.wtk.content.ButtonData) Component(org.apache.pivot.wtk.Component) Image(org.apache.pivot.wtk.media.Image) ComponentMouseListener(org.apache.pivot.wtk.ComponentMouseListener) LinkButton(org.apache.pivot.wtk.LinkButton)

Example 2 with ButtonData

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

Aggregations

Component (org.apache.pivot.wtk.Component)2 ButtonData (org.apache.pivot.wtk.content.ButtonData)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 TaskExecutionException (org.apache.pivot.util.concurrent.TaskExecutionException)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 CardPane (org.apache.pivot.wtk.CardPane)1 ComponentMouseListener (org.apache.pivot.wtk.ComponentMouseListener)1 GridPane (org.apache.pivot.wtk.GridPane)1 Row (org.apache.pivot.wtk.GridPane.Row)1 LinkButton (org.apache.pivot.wtk.LinkButton)1 PushButton (org.apache.pivot.wtk.PushButton)1 Window (org.apache.pivot.wtk.Window)1 Image (org.apache.pivot.wtk.media.Image)1