Search in sources :

Example 26 with BXMLSerializer

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);
}
Also used : ListViewItemStateListener(org.apache.pivot.wtk.ListViewItemStateListener) Keyboard(org.apache.pivot.wtk.Keyboard) Sequence(org.apache.pivot.collections.Sequence) Span(org.apache.pivot.wtk.Span) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ComponentKeyListener(org.apache.pivot.wtk.ComponentKeyListener) ListView(org.apache.pivot.wtk.ListView) Button(org.apache.pivot.wtk.Button) List(org.apache.pivot.collections.List) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 27 with BXMLSerializer

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);
}
Also used : ListButton(org.apache.pivot.wtk.ListButton) TableViewRowComparator(org.apache.pivot.wtk.content.TableViewRowComparator) ListButtonSelectionListener(org.apache.pivot.wtk.ListButtonSelectionListener) TableViewSortListener(org.apache.pivot.wtk.TableViewSortListener) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) File(java.io.File) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) TableView(org.apache.pivot.wtk.TableView)

Example 28 with BXMLSerializer

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);
}
Also used : Frame(org.apache.pivot.wtk.Frame) BoxPane(org.apache.pivot.wtk.BoxPane) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) ReflectionDecorator(org.apache.pivot.wtk.effects.ReflectionDecorator)

Example 29 with BXMLSerializer

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);
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) IOException(java.io.IOException) BeanAdapter(org.apache.pivot.beans.BeanAdapter) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 30 with BXMLSerializer

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);
}
Also used : 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