Search in sources :

Example 56 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class SplashScreenTest method startup.

@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
    File splashFile = new File("org/apache/pivot/tests/splash.png");
    System.out.println("Startup the application at " + new Date());
    System.out.println("To show the Splash Screen, remember to run as a Standard Java Application this way:\n" + "java -splash:" + splashFile.getPath() + " <mainclassname> --preserveSplashScreen=true\n" + "or no splash screen will be shown.");
    // Create a Task that will load a BXML file and simulate some other
    // processing while updating a progress meter on the SplashScreen
    final Task<Void> prepareApplicationTask = new Task<Void>() {

        final SplashScreenProgressOverlay progressOverlay = new SplashScreenProgressOverlay();

        @Override
        public Void execute() throws TaskExecutionException {
            // Load the main BXML
            progressOverlay.increment(0);
            loadBXML(display, 0.1);
            // Simulate other tasks until the progress meter has been filled
            final Random random = new Random();
            while (progressOverlay.getPercentage() < 1.0) {
                // Short random sleep to simulate some processing
                try {
                    Thread.sleep(random.nextInt(50) + 100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                // Update the progress meter by a random amount
                progressOverlay.increment((1 + random.nextInt(10)) / 100.0);
            }
            return null;
        }

        // Load the Pivot UI
        private void loadBXML(final Display displayArgument, final double weight) {
            try {
                ApplicationContext.queueCallback(() -> {
                    Window window = null;
                    try {
                        window = (Window) new BXMLSerializer().readObject(this.getClass().getResource("splash.bxml"));
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    if (window != null) {
                        window.open(displayArgument);
                        progressOverlay.increment(weight);
                    }
                });
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    // Hide the SplashScreen when the Task finishes by making the Pivot host
    // window visible.
    final TaskListener<Void> taskListener = new TaskListener<Void>() {

        @Override
        public void taskExecuted(final Task<Void> task) {
            finished();
        }

        @Override
        public void executeFailed(final Task<Void> task) {
            System.err.println(String.format("Failed\n%s", task.getFault()));
            task.getFault().printStackTrace();
            finished();
        }

        private void finished() {
            DesktopApplicationContext.replaceSplashScreen(display);
        }
    };
    // Run the Task asynchronously
    prepareApplicationTask.execute(new TaskAdapter<>(taskListener));
}
Also used : Window(org.apache.pivot.wtk.Window) Task(org.apache.pivot.util.concurrent.Task) Date(java.util.Date) TaskExecutionException(org.apache.pivot.util.concurrent.TaskExecutionException) Random(java.util.Random) TaskListener(org.apache.pivot.util.concurrent.TaskListener) File(java.io.File) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) Display(org.apache.pivot.wtk.Display)

Example 57 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class ListViewTest2 method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    System.out.println("Left   Click on List elements to Select a Row");
    window = new Window((Component) bxmlSerializer.readObject(getClass().getResource("listview_test2.bxml")));
    menu = (Window) bxmlSerializer.readObject(TableViewTest2.class, "context_menus.bxml");
    window.setMenuHandler(new ContextMenusSampleMenuHandlerAdapter());
    System.out.println("Right  Click on Window (and List elements) to display Contextual Menu: " + menu);
    window.setTitle("ListView Test2");
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 58 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class ContextMenuTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(ContextMenuTest.class, "context_menu_test.bxml");
    bxmlSerializer.bind(this, ContextMenuTest.class);
    window.setMenuHandler(new MenuHandler() {

        @Override
        public boolean configureContextMenu(Component component, Menu menu, int x, int y) {
            menu.getSections().add(globalSection);
            menu.getSections().add(helpSection);
            menu.getSections().add(hoursSection);
            return false;
        }
    });
    window.open(display);
}
Also used : MenuHandler(org.apache.pivot.wtk.MenuHandler) Menu(org.apache.pivot.wtk.Menu) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 59 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class DataBindingTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(DataBindingTest.class, "data_binding_test.bxml");
    window.open(display);
    context.put("id1", "1");
    context.put("id2", "2");
    context.put("id3", "3");
    window.getContent().load(context);
    final Label textLabel = (Label) (bxmlSerializer.getNamespace().get("bindingDataText"));
    textLabel.setText(JSONSerializer.toString(context));
    Button storeButton = (Button) (bxmlSerializer.getNamespace().get("storeButton"));
    storeButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            window.getContent().store(context);
            try {
                textLabel.setText(JSONSerializer.toString(context));
                textLabel.getStyles().put(Style.color, getNextColor());
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) Button(org.apache.pivot.wtk.Button) Label(org.apache.pivot.wtk.Label) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 60 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class FormTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    frame = new Frame((Component) bxmlSerializer.readObject(getClass().getResource("form_test.bxml")));
    frame.setTitle("Form Test");
    frame.setPreferredSize(480, 360);
    frame.open(display);
}
Also used : Frame(org.apache.pivot.wtk.Frame) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)86 Component (org.apache.pivot.wtk.Component)24 IOException (java.io.IOException)19 SerializationException (org.apache.pivot.serialization.SerializationException)14 Window (org.apache.pivot.wtk.Window)13 Button (org.apache.pivot.wtk.Button)11 PushButton (org.apache.pivot.wtk.PushButton)11 File (java.io.File)9 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)9 Frame (org.apache.pivot.wtk.Frame)8 TextInput (org.apache.pivot.wtk.TextInput)8 ArrayList (org.apache.pivot.collections.ArrayList)7 List (org.apache.pivot.collections.List)7 Mouse (org.apache.pivot.wtk.Mouse)6 Sequence (org.apache.pivot.collections.Sequence)5 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)5 ListButton (org.apache.pivot.wtk.ListButton)5 TextInputContentListener (org.apache.pivot.wtk.TextInputContentListener)5 URL (java.net.URL)4 MalformedURLException (java.net.MalformedURLException)3