Search in sources :

Example 16 with ListView

use of org.apache.pivot.wtk.ListView in project pivot by apache.

the class Pivot718 method controlList.

private void controlList(BXMLSerializer bxmlSerializer) {
    listDelButton = (PushButton) bxmlSerializer.getNamespace().get("listDelButton");
    list = (ListView) bxmlSerializer.getNamespace().get("list");
    list.getListViewSelectionListeners().add(new ListViewSelectionListener() {

        @Override
        public void selectedRangeAdded(ListView listView, int rangeStart, int rangeEnd) {
            System.out.println("selectedRangeAdded");
        }

        @Override
        public void selectedRangeRemoved(ListView listView, int rangeStart, int rangeEnd) {
            System.out.println("selectedRangeRemoved");
        }

        @Override
        public void selectedRangesChanged(ListView listView, Sequence<Span> previousSelectedRanges) {
            System.out.println("selectedRangesChanged");
        }

        @Override
        public void selectedItemChanged(ListView listView, Object previousSelectedItem) {
            System.out.println("selectedItemChanged :::" + listView.getSelectedItem());
        }
    });
    listDelButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = list.getSelectedItem();
            System.out.println("delete :: " + x);
            // List data = list.getListData();
            @SuppressWarnings("unchecked") List<Object> data = (List<Object>) list.getListData();
            data.remove(x);
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ListView(org.apache.pivot.wtk.ListView) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) List(org.apache.pivot.collections.List) ListViewSelectionListener(org.apache.pivot.wtk.ListViewSelectionListener) Span(org.apache.pivot.wtk.Span)

Example 17 with ListView

use of org.apache.pivot.wtk.ListView 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);
}
Also used : Window(org.apache.pivot.wtk.Window) ListView(org.apache.pivot.wtk.ListView) ArrayList(org.apache.pivot.collections.ArrayList)

Example 18 with ListView

use of org.apache.pivot.wtk.ListView in project pivot by apache.

the class ListViewSelectionTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) {
    ArrayList<Span> selectedRanges = new ArrayList<>();
    selectedRanges.add(new Span(0, 0));
    listView.setSelectedRanges(selectedRanges);
    dumpSelection();
    listView.addSelectedRange(new Span(4, 4));
    dumpSelection();
    listView.addSelectedRange(new Span(2, 2));
    dumpSelection();
    listView.addSelectedRange(new Span(0, 4));
    dumpSelection();
    selectedRanges.clear();
    selectedRanges.add(new Span(1, 1));
    selectedRanges.add(new Span(3, 3));
    listView.setSelectedRanges(selectedRanges);
    dumpSelection();
    listView.addSelectedRange(new Span(0, 4));
    dumpSelection();
    listView.removeSelectedRange(new Span(2, 2));
    dumpSelection();
    listView.removeSelectedRange(new Span(4, 4));
    dumpSelection();
    listView.removeSelectedRange(new Span(0, 0));
    dumpSelection();
    listView.removeSelectedRange(new Span(1, 3));
    dumpSelection();
    selectedRanges.clear();
    selectedRanges.add(new Span(4, 6));
    listView.setSelectedRanges(selectedRanges);
    dumpSelection();
    listView.addSelectedRange(new Span(2, 5));
    dumpSelection();
    listView.addSelectedRange(new Span(4, 8));
    dumpSelection();
    verifySelection(0);
    verifySelection(4);
    verifySelection(6);
    verifySelection(8);
    listView.removeSelectedRange(new Span(8, 12));
    dumpSelection();
    verifySelection(8);
    listView.removeSelectedRange(new Span(0, 4));
    dumpSelection();
    verifySelection(4);
    listView.getListViewSelectionListeners().add(new ListViewSelectionListener() {

        @Override
        public void selectedRangesChanged(ListView listViewArgument, Sequence<Span> previousSelectedRanges) {
            System.out.println("Selection changed");
        }
    });
    listView.setSelectedIndex(2);
    listView.getListData().remove(2, 1);
}
Also used : ListView(org.apache.pivot.wtk.ListView) ArrayList(org.apache.pivot.collections.ArrayList) ListViewSelectionListener(org.apache.pivot.wtk.ListViewSelectionListener) Span(org.apache.pivot.wtk.Span)

Example 19 with ListView

use of org.apache.pivot.wtk.ListView 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);
}
Also used : Window(org.apache.pivot.wtk.Window) Frame(org.apache.pivot.wtk.Frame) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ListView(org.apache.pivot.wtk.ListView) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) Checkbox(org.apache.pivot.wtk.Checkbox) PushButton(org.apache.pivot.wtk.PushButton) Sheet(org.apache.pivot.wtk.Sheet) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) File(java.io.File)

Example 20 with ListView

use of org.apache.pivot.wtk.ListView in project pivot by apache.

the class VFSBrowserTest method startup.

@Override
public void startup(final Display display, final 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(final Button buttonArgument) {
            try {
                final VFSBrowserSheet vfsBrowserSheet = new VFSBrowserSheet(VFSBrowserSheet.Mode.OPEN);
                vfsBrowserSheet.getStyles().put(Style.showHiddenFiles, showHiddenCheckbox.isSelected());
                vfsBrowserSheet.open(frame, new SheetCloseListener() {

                    @Override
                    public void sheetClosed(final Sheet sheet) {
                        if (sheet.getResult()) {
                            Sequence<FileObject> selectedFiles = vfsBrowserSheet.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:", listView, frame);
                        } else {
                            Alert.alert(MessageType.INFO, "You didn't select anything.", frame);
                        }
                    }
                });
            } catch (FileSystemException fse) {
                Alert.alert(MessageType.ERROR, String.format("File System Exception: %1$s", fse.getMessage()), frame);
            }
        }
    });
    windowContent.add(button);
    frame = new Frame(windowContent);
    frame.setMaximized(true);
    frame.open(display);
}
Also used : Frame(org.apache.pivot.wtk.Frame) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) FileSystemException(org.apache.commons.vfs2.FileSystemException) VFSBrowserSheet(org.apache.pivot.wtk.VFSBrowserSheet) ListView(org.apache.pivot.wtk.ListView) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) Checkbox(org.apache.pivot.wtk.Checkbox) FileObject(org.apache.commons.vfs2.FileObject) PushButton(org.apache.pivot.wtk.PushButton) Sheet(org.apache.pivot.wtk.Sheet) VFSBrowserSheet(org.apache.pivot.wtk.VFSBrowserSheet)

Aggregations

ListView (org.apache.pivot.wtk.ListView)28 ArrayList (org.apache.pivot.collections.ArrayList)10 Button (org.apache.pivot.wtk.Button)10 List (org.apache.pivot.collections.List)8 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)7 PushButton (org.apache.pivot.wtk.PushButton)6 Span (org.apache.pivot.wtk.Span)6 ListViewSelectionListener (org.apache.pivot.wtk.ListViewSelectionListener)4 Sheet (org.apache.pivot.wtk.Sheet)4 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)4 File (java.io.File)3 Bounds (org.apache.pivot.wtk.Bounds)3 BoxPane (org.apache.pivot.wtk.BoxPane)3 Component (org.apache.pivot.wtk.Component)3 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)3 Frame (org.apache.pivot.wtk.Frame)3 Color (java.awt.Color)2 IOException (java.io.IOException)2 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 Sequence (org.apache.pivot.collections.Sequence)2