use of org.apache.pivot.wtk.ButtonPressListener 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.wtk.ButtonPressListener in project pivot by apache.
the class TestDialog method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
System.out.println("TestDialog initialize(...)");
this.okButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
TestDialog.this.close(true);
}
});
}
use of org.apache.pivot.wtk.ButtonPressListener in project pivot by apache.
the class Pivot862 method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(getClass().getResource("pivot_862.bxml"));
bxmlSerializer.bind(this, Pivot862.class);
selectFolderButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
// to
fileBrowserSheet.setMode(FileBrowserSheet.Mode.SAVE_TO);
// be
// able
// to
// select
// a
// folder
fileBrowserSheet.open(window, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
File loadedFile = fileBrowserSheet.getSelectedFile();
try {
selectedFolder = loadedFile.getCanonicalPath();
System.out.println("Selected folder '" + selectedFolder + "'");
// multiple tests ...
System.out.println("Verify: Root folder (display from getName) was set to '" + fileBrowserSheet.getRootDirectory().getName() + "'");
System.out.println("Verify: Root folder (display from getCanonicalPath) was set to '" + fileBrowserSheet.getRootDirectory().getCanonicalPath() + "'");
System.out.println("Verify: Root folder (display from getCanonicalFile) was set to '" + fileBrowserSheet.getRootDirectory().getCanonicalFile() + "'");
openFileButton.setEnabled(true);
} catch (IOException e) {
e.printStackTrace();
openFileButton.setEnabled(false);
}
window.setTitle("Selected folder: " + selectedFolder);
}
}
});
}
});
openFileButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
System.out.println("Now opening a BrowserSheet starting from the previous selected folder: \"" + selectedFolder + "\"");
FileBrowserSheet fileBrowserSheet = // selectedFolder); // use this as a workaround ...
new FileBrowserSheet(// test to see
FileBrowserSheet.Mode.OPEN);
// the wrong
// behavior
// new FileBrowserSheet(); // test to see the wrong behavior
// ok, but
fileBrowserSheet.setRootFolder(selectedFolder);
// doesn't solve
// this issue
// ...
System.out.println("\nNote: the behavior here is right only when using the constructor with two parameters ..." + " but in this source it's used one of other constructors.\n");
try {
// multiple tests ...
System.out.println("Verify: Root folder (display from getName) was set to '" + fileBrowserSheet.getRootDirectory().getName() + "'");
System.out.println("Verify: Root folder (display from getCanonicalPath) was set to '" + fileBrowserSheet.getRootDirectory().getCanonicalPath() + "'");
System.out.println("Verify: Root folder (display from getCanonicalFile) was set to '" + fileBrowserSheet.getRootDirectory().getCanonicalFile() + "'");
} catch (IOException e) {
e.printStackTrace();
}
fileBrowserSheet.open(window, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
// empty block
}
});
}
});
window.open(display);
}
use of org.apache.pivot.wtk.ButtonPressListener in project pivot by apache.
the class BackgroundTasks method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
activityIndicator = (ActivityIndicator) namespace.get("activityIndicator");
executeSynchronousButton = (PushButton) namespace.get("executeSynchronousButton");
executeAsynchronousButton = (PushButton) namespace.get("executeAsynchronousButton");
executeSynchronousButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
activityIndicator.setActive(true);
System.out.println("Starting synchronous task execution.");
SleepTask sleepTask = new SleepTask();
String result = null;
try {
result = sleepTask.execute();
} catch (TaskExecutionException exception) {
System.err.println(exception);
}
System.out.println("Synchronous task execution complete: \"" + result + "\"");
activityIndicator.setActive(false);
}
});
executeAsynchronousButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
activityIndicator.setActive(true);
setEnabled(false);
System.out.println("Starting asynchronous task execution.");
SleepTask sleepTask = new SleepTask();
TaskListener<String> taskListener = new TaskListener<String>() {
@Override
public void taskExecuted(Task<String> task) {
activityIndicator.setActive(false);
setEnabled(true);
System.out.println("Synchronous task execution complete: \"" + task.getResult() + "\"");
}
@Override
public void executeFailed(Task<String> task) {
activityIndicator.setActive(false);
setEnabled(true);
System.err.println(task.getFault());
}
};
sleepTask.execute(new TaskAdapter<>(taskListener));
}
});
}
use of org.apache.pivot.wtk.ButtonPressListener in project pivot by apache.
the class FileBrowserWithCharsetTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BoxPane windowContent = new BoxPane();
windowContent.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
final Checkbox showHiddenCheckbox = new Checkbox("Show hidden files");
windowContent.add(showHiddenCheckbox);
PushButton button = new PushButton("Open File Browser");
button.getStyles().put(Style.padding, "[2, 4, 2, 4]");
button.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button buttonArgument) {
final Window window = Window.getActiveWindow();
final FileBrowserWithCharsetTest fileBrowserSheet = new FileBrowserWithCharsetTest(FileBrowserSheet.Mode.OPEN);
fileBrowserSheet.getStyles().put(Style.showHiddenFiles, showHiddenCheckbox.isSelected());
fileBrowserSheet.open(window, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
Sequence<File> selectedFiles = fileBrowserSheet.getSelectedFiles();
ListView listView = new ListView();
listView.setListData(new ArrayList<>(selectedFiles));
listView.setSelectMode(ListView.SelectMode.NONE);
listView.getStyles().put(Style.backgroundColor, null);
Alert.alert(MessageType.INFO, "You selected (charset " + fileBrowserSheet.getCharsetName() + "):", listView, window);
} else {
Alert.alert(MessageType.INFO, "You didn't select anything.", window);
}
}
});
}
});
windowContent.add(button);
frame = new Frame(windowContent);
frame.setMaximized(true);
frame.open(display);
}
Aggregations