use of org.apache.pivot.wtk.Window in project pivot by apache.
the class ListViewTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) {
ListView listView = new ListView();
List<String> listData = new ArrayList<>();
listData.add("0");
listData.add("1");
listData.add("2");
listData.add("3");
listData.add("4");
listData.add("5");
listData.add("6");
listData.add("7");
listData.add("8");
listData.add("9");
listData.add("A");
listData.add("B");
listData.add("C");
listData.add("D");
listData.add("E");
listData.add("F");
listView.setListData(listData);
listView.setDisabledItemFilter(new Filter<String>() {
@Override
public boolean include(String item) {
return !Character.isDigit(item.charAt(0));
}
});
listView.setCheckmarksEnabled(true);
listView.setItemChecked(4, true);
listView.setItemChecked(6, true);
window = new Window(listView);
window.open(display);
listData.insert("-1", 0);
listData.insert("-2", 0);
listData.remove(0, 3);
}
use of org.apache.pivot.wtk.Window in project pivot by apache.
the class SheetTest method startup.
@SuppressWarnings("unused")
@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
Picture picture = (Picture) Image.load(getClass().getResource("IMG_0767_2.jpg"));
picture.resample(120);
BoxPane windowContent = new BoxPane();
PushButton button = new PushButton(picture);
button.getStyles().put(Style.toolbar, true);
windowContent.add(button);
frame = new Frame(windowContent);
frame.setPreferredSize(480, 360);
frame.getStyles().put(Style.padding, 0);
frame.open(display);
final TablePane tablePane = new TablePane();
tablePane.setPreferredSize(320, 240);
new TablePane.Column(tablePane, 1, true);
TablePane.Row row0 = new TablePane.Row(tablePane, 1, true);
TablePane.Row row1 = new TablePane.Row(tablePane, -1);
final Label sheetContent = new Label("Sheet Content");
sheetContent.getStyles().put(Style.wrapText, true);
sheetContent.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
sheetContent.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
row0.add(sheetContent);
Label promptBody = new Label("Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
promptBody.getStyles().put(Style.wrapText, true);
final Prompt prompt = new Prompt(MessageType.INFO, "Prompt", new ArrayList<>("OK"), promptBody);
prompt.setTitle("Prompt");
prompt.getStyles().put(Style.resizable, true);
prompt.getComponentMouseListeners().add(new ComponentMouseListener() {
@Override
public void mouseOver(Component component) {
System.out.println("Mouse Over");
}
@Override
public void mouseOut(Component component) {
System.out.println("Mouse out");
}
});
Label alertBody = new Label("Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
alertBody.getStyles().put(Style.wrapText, true);
final Alert alert = new Alert(MessageType.INFO, "Alert", new ArrayList<>("OK"), alertBody);
alert.setTitle("Alert");
BoxPane boxPane = new BoxPane();
row1.add(boxPane);
boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.RIGHT);
final PushButton closeButton = new PushButton("Close");
closeButton.getStyles().put(Style.minimumAspectRatio, 3);
boxPane.add(closeButton);
sheet = new Sheet(tablePane);
closeButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button buttonArgument) {
buttonArgument.getWindow().close();
}
});
button.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button buttonArgument) {
prompt.open(frame);
Display displayLocal = DesktopApplicationContext.createDisplay(640, 480, 100, 100, true, true, false, buttonArgument.getDisplay().getHostWindow(), null);
Window window = new Window();
window.setTitle("New Secondary Window");
window.setMaximized(true);
window.setContent(new Label("I am a secondary window!"));
window.open(displayLocal);
}
});
sheet.getWindowStateListeners().add(new WindowStateListener() {
@Override
public void windowOpened(Window window) {
closeButton.requestFocus();
}
});
DesktopApplicationContext.sizeHostToFit(frame);
}
use of org.apache.pivot.wtk.Window in project pivot by apache.
the class SliderTest method startup.
@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = new Window((Component) bxmlSerializer.readObject(getClass().getResource("slider_test.bxml")));
slider1 = (Slider) bxmlSerializer.getNamespace().get("slider1");
slider1.getSliderValueListeners().add((slider, previousValue) -> {
valueLabel1.setText(Integer.toString(slider.getValue()));
drawPoint(slider.getValue(), slider2.getValue(), slider.getStart(), slider.getEnd(), slider2.getStart(), slider2.getEnd());
});
slider2 = (Slider) bxmlSerializer.getNamespace().get("slider2");
slider2.getSliderValueListeners().add((slider, previousValue) -> {
valueLabel2.setText(Integer.toString(slider.getValue()));
drawPoint(slider1.getValue(), slider.getValue(), slider1.getStart(), slider1.getEnd(), slider.getStart(), slider.getEnd());
});
valueLabel1 = (Label) bxmlSerializer.getNamespace().get("valueLabel1");
valueLabel2 = (Label) bxmlSerializer.getNamespace().get("valueLabel2");
image = (ImageView) bxmlSerializer.getNamespace().get("imageView");
int width = slider1.getEnd() - slider1.getStart();
int height = slider2.getEnd() - slider2.getStart();
picture = new SliderPicture(width, height);
picture.clear(Color.LIGHT_GRAY);
drawPoint(slider1.getValue(), slider2.getValue(), slider1.getStart(), slider1.getEnd(), slider2.getStart(), slider2.getEnd());
image.setImage(picture);
window.setTitle("Slider Test");
window.setMaximized(true);
window.open(display);
}
use of org.apache.pivot.wtk.Window 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.wtk.Window 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);
}
Aggregations