Search in sources :

Example 26 with Window

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

the class PromptTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BoxPane boxPane = new BoxPane();
    boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
    boxPane.getStyles().put(Style.verticalAlignment, VerticalAlignment.BOTTOM);
    helloButton = new PushButton("Say Hello");
    boxPane.add(helloButton);
    helloButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            String text = button.getButtonData().toString();
            if (window.isBlocked()) {
                System.out.println("I'm already saying \"" + text + "\" !");
            } else {
                Prompt.prompt(text, window);
            }
        }
    });
    Border border = new Border(boxPane);
    border.getStyles().put(Style.color, 7);
    border.getStyles().put(Style.padding, 5);
    window = new Window(border);
    window.setMaximized(true);
    window.open(display);
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) Window(org.apache.pivot.wtk.Window) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) PushButton(org.apache.pivot.wtk.PushButton) Border(org.apache.pivot.wtk.Border)

Example 27 with Window

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

the class LabelAntialiasTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) {
    window = new Window();
    showFontDesktopHints();
    showFontFamilies();
    TablePane content = new TablePane();
    new TablePane.Column(content, 1, true);
    BoxPane topBox = new BoxPane(Orientation.HORIZONTAL);
    topBox.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    topBox.add(new Label("Rotation angle:"));
    rotationAngleSpinner = new Spinner(new NumericSpinnerData(0, 359));
    rotationAngleSpinner.setCircular(true);
    rotationAngleSpinner.setPreferredWidth(40);
    topBox.add(rotationAngleSpinner);
    TablePane.Row topRow = new TablePane.Row(content, -1);
    topRow.add(topBox);
    labelRow = new TablePane.Row(content, 1, true);
    window.setContent(content);
    window.setTitle("Label Antialiasing Test");
    window.setMaximized(true);
    rotationAngleSpinner.getSpinnerSelectionListeners().add(new SpinnerSelectionListener() {

        @Override
        public void selectedItemChanged(Spinner spinner, Object previousSelectedItem) {
            currentRotationAngle = (Integer) spinner.getSelectedItem();
            if (labelRow.getLength() > 0) {
                labelRow.remove(0, labelRow.getLength());
            }
            labelRow.add(buildLabel(currentRotationAngle));
        }
    });
    rotationAngleSpinner.setSelectedItem(45);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Spinner(org.apache.pivot.wtk.Spinner) SpinnerSelectionListener(org.apache.pivot.wtk.SpinnerSelectionListener) Label(org.apache.pivot.wtk.Label) NumericSpinnerData(org.apache.pivot.wtk.content.NumericSpinnerData) BoxPane(org.apache.pivot.wtk.BoxPane) TablePane(org.apache.pivot.wtk.TablePane)

Example 28 with Window

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

the class JavascriptConsoleTest method loadWindowFromURL.

/**
 * Load (and returns) a Window, given its URL and serializer to use <p> Note
 * that if public this method could be called even from JS in a bxml file
 * (but a reference to the current application has to be put in serializer
 * namespace). <p> Note that all Exceptions are catched inside this method,
 * to not expose them to JS code.
 *
 * @param urlString the URL of the bxml file to load, as a String
 * @param bxmlSerializer the serializer to use, or if null a new one will be created
 * @return the Window instance
 */
public Window loadWindowFromURL(String urlString, final BXMLSerializer bxmlSerializer) {
    logObject("loadWindow from \"" + urlString + "\", with the serializer " + bxmlSerializer);
    BXMLSerializer serializer = bxmlSerializer;
    if (serializer == null) {
        serializer = new BXMLSerializer();
    }
    Window loadedWindow = null;
    try {
        URL url = new URL(urlString);
        // force the location, so it will be possible to decode resources
        // like labels ...
        serializer.setLocation(url);
        loadedWindow = (Window) serializer.readObject(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SerializationException e) {
        e.printStackTrace();
    }
    return loadedWindow;
}
Also used : Window(org.apache.pivot.wtk.Window) MalformedURLException(java.net.MalformedURLException) SerializationException(org.apache.pivot.serialization.SerializationException) IOException(java.io.IOException) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) URL(java.net.URL)

Example 29 with Window

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

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

the class Pivot835 method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    Window window = (Window) bxmlSerializer.readObject(getClass().getResource("pivot_835.bxml"));
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

Window (org.apache.pivot.wtk.Window)45 Component (org.apache.pivot.wtk.Component)14 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)13 PushButton (org.apache.pivot.wtk.PushButton)9 BoxPane (org.apache.pivot.wtk.BoxPane)8 Button (org.apache.pivot.wtk.Button)7 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)6 Display (org.apache.pivot.wtk.Display)5 Border (org.apache.pivot.wtk.Border)4 Label (org.apache.pivot.wtk.Label)4 Sheet (org.apache.pivot.wtk.Sheet)4 TablePane (org.apache.pivot.wtk.TablePane)4 File (java.io.File)3 Bounds (org.apache.pivot.wtk.Bounds)3 Point (org.apache.pivot.wtk.Point)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 Vote (org.apache.pivot.util.Vote)2 TaskExecutionException (org.apache.pivot.util.concurrent.TaskExecutionException)2