use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.
the class CheckedListViewTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer serializer = new BXMLSerializer();
mainWindow = (Window) serializer.readObject(CheckedListViewTest.class, "checked_list_view_test.bxml");
serializer.bind(this);
allowMixedStateCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
listView.setAllowTriStateCheckmarks(button.isSelected());
// Not sure why, but changing this setting clears all the checks but doesn't
// trigger the item state listener (it's documented, but ...)
selectedItemsLabel.setText("");
}
});
showMixedAsSelectedCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
listView.setCheckmarksMixedAsChecked(button.isSelected());
}
});
listView.getComponentKeyListeners().add(new ComponentKeyListener() {
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
if (keyCode == Keyboard.KeyCode.DELETE) {
@SuppressWarnings("unchecked") List<Object> listData = (List<Object>) listView.getListData();
Sequence<Span> selectedRanges = listView.getSelectedRanges();
for (int i = selectedRanges.getLength() - 1; i >= 0; i--) {
Span selectedRange = selectedRanges.get(i);
listData.remove(selectedRange.start, selectedRange.end - selectedRange.start + 1);
}
}
return false;
}
});
listView.getListViewItemStateListeners().add(new ListViewItemStateListener() {
private void displayCheckedItems(ListView listView) {
List<?> listData = listView.getListData();
StringBuffer buf = new StringBuffer();
for (Integer i : listView.getCheckedIndexes()) {
if (buf.length() > 0) {
buf.append(",");
}
Object item = listData.get(i);
buf.append(item.toString());
}
selectedItemsLabel.setText(buf.toString());
}
@Override
public void itemCheckedChanged(ListView listView, int index) {
displayCheckedItems(listView);
}
@Override
public void itemCheckedStateChanged(ListView listView, int index) {
displayCheckedItems(listView);
}
});
listView.setItemChecked(0, true);
listView.setItemChecked(2, true);
mainWindow.open(display);
}
use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.
the class LargeData method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
basePath = properties.get(BASE_PATH_KEY);
if (basePath == null) {
throw new IllegalArgumentException(BASE_PATH_KEY + " is required.");
}
origin = ApplicationContext.getOrigin();
if (origin == null) {
System.out.println("Running as a Standalone Java Application, with user home: \"" + USER_HOME + "\"");
if (USER_HOME != null) {
System.out.println("Set as origin the user home");
origin = (new File(USER_HOME).toURI()).toURL();
}
}
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(LargeData.class, "large_data.bxml");
fileListButton = (ListButton) bxmlSerializer.getNamespace().get("fileListButton");
loadDataButton = (PushButton) bxmlSerializer.getNamespace().get("loadDataButton");
cancelButton = (PushButton) bxmlSerializer.getNamespace().get("cancelButton");
clearButton = (PushButton) bxmlSerializer.getNamespace().get("clearButton");
statusLabel = (Label) bxmlSerializer.getNamespace().get("statusLabel");
tableView = (TableView) bxmlSerializer.getNamespace().get("tableView");
fileListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
@Override
public void selectedItemChanged(ListButton listButtonArgument, Object previousSelectedItem) {
Object selectedItem = listButtonArgument.getSelectedItem();
System.out.println("Selected: " + selectedItem.toString() + ", now clear table data ...");
// empty the table
tableView.getTableData().clear();
}
});
loadDataButton.getButtonPressListeners().add((button) -> {
loadDataButton.setEnabled(false);
cancelButton.setEnabled(true);
loadData();
});
cancelButton.getButtonPressListeners().add((button) -> {
if (loadDataTask != null) {
loadDataTask.abort();
}
loadDataButton.setEnabled(true);
cancelButton.setEnabled(false);
});
clearButton.getButtonPressListeners().add((button) -> {
if (loadDataTask != null) {
loadDataTask.abort();
}
// empty the table
tableView.getTableData().clear();
statusLabel.setText("");
});
tableView.getTableViewSortListeners().add(new TableViewSortListener() {
@Override
public void sortChanged(TableView tableViewArgument) {
@SuppressWarnings("unchecked") List<Object> tableData = (List<Object>) tableViewArgument.getTableData();
long startTime = System.currentTimeMillis();
tableData.setComparator(new TableViewRowComparator(tableViewArgument));
long endTime = System.currentTimeMillis();
statusLabel.setText("Data sorted in " + (endTime - startTime) + " ms.");
}
});
window.open(display);
}
use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.
the class ColorListButtonTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
BoxPane boxPane = (BoxPane) bxmlSerializer.readObject(ColorListButtonTest.class, "color_list_button_test.bxml");
listButton = (ListButton) bxmlSerializer.getNamespace().get("listButton");
// test the getListPopup() method
listButton.getListPopup().getDecorators().add(new ReflectionDecorator());
frame = new Frame(boxPane);
frame.setTitle("Color List Button Test");
frame.setPreferredSize(480, 360);
frame.open(display);
}
use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.
the class EnumBeanTest method main.
public static void main(String[] args) {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
try {
EnumBean enumBean = (EnumBean) bxmlSerializer.readObject(EnumBeanTest.class, "enum_bean.bxml");
System.out.println("Bean read OK - " + enumBean);
} catch (IOException e) {
e.printStackTrace();
} catch (SerializationException e) {
e.printStackTrace();
}
EnumBean enumBean = new EnumBean();
BeanAdapter ba = new BeanAdapter(enumBean);
ba.put("orientationField", Orientation.HORIZONTAL);
dumpField(enumBean, ba);
ba.put("orientationField", "vertical");
dumpField(enumBean, ba);
ba.put("orientation", Orientation.HORIZONTAL);
dumpSetter(enumBean, ba);
ba.put("orientation", Orientation.VERTICAL);
dumpSetter(enumBean, ba);
ba.put("orientation", null);
dumpSetter(enumBean, ba);
// Force an error to check the IllegalArgumentException message
// ba.put("orientation", Vote.APPROVE);
}
use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.
the class GaugeTest method startup.
@Override
@SuppressWarnings("unchecked")
public void startup(final Display display, final Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(getClass().getResource("gauge_test.bxml"));
gasPedal = (PushButton) bxmlSerializer.getNamespace().get("gasPedal");
brakePedal = (PushButton) bxmlSerializer.getNamespace().get("brakePedal");
speedGauge = (Gauge<Integer>) bxmlSerializer.getNamespace().get("speedGauge");
maxCheck = (Checkbox) bxmlSerializer.getNamespace().get("maxCheck");
warningColor = speedGauge.getStyles().getColor("warningColor");
criticalColor = speedGauge.getStyles().getColor("criticalColor");
textColor = Theme.getTheme().getColor(6);
setSpeed(speedGauge.getValue());
gasPedal.getButtonPressListeners().add((button) -> hitTheGas());
brakePedal.getButtonPressListeners().add((button) -> hitTheBrakes());
maxCheck.getButtonStateListeners().add((button, previous) -> toggleMax(button.getState()));
ApplicationContext.scheduleRecurringCallback(() -> varyTheSpeed(), 500L);
window.open(display);
}
Aggregations