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));
}
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);
}
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);
}
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);
}
}
});
}
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);
}
Aggregations