Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.FileBrowser


            this.fileComparator = fileComparator;
        }

        @Override
        public ArrayList<File> execute() {
            FileBrowser fileBrowser = (FileBrowser)getComponent();
            File rootDirectory = fileBrowser.getRootDirectory();
            if (abort) {
                throw new AbortException();
            }

            File[] files = rootDirectory.listFiles(new FullFileFilter(includeFileFilter, excludeFileFilter));
View Full Code Here


    @Override
    public void install(Component component) {
        super.install(component);

        final FileBrowser fileBrowser = (FileBrowser)component;

        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        try {
            content = (Component)bxmlSerializer.readObject(TerraFileBrowserSkin.class,
                "terra_file_browser_skin.bxml", true);
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        } catch (SerializationException exception) {
            throw new RuntimeException(exception);
        }

        fileBrowser.add(content);

        bxmlSerializer.bind(this, TerraFileBrowserSkin.class);

        driveListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener.Adapter() {
            @Override
            public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
                if (previousSelectedItem != null) {
                    File drive = (File)listButton.getSelectedItem();
                    if(drive != null && drive.canRead()) {
                        if(!selectingDriveFromRootDirectory){
                            fileBrowser.setRootDirectory(drive);
                        }
                    } else {
                        refreshRoots = true;
                        listButton.setSelectedItem(previousSelectedItem);
                    }
                }
            }
        });

        pathListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener.Adapter() {
            @Override
            public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
                File ancestorDirectory = (File)listButton.getSelectedItem();

                if (ancestorDirectory != null) {
                    fileBrowser.setRootDirectory(ancestorDirectory);
                }
            }
        });

        goUpButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                File rootDirectory = fileBrowser.getRootDirectory();
                File parentDirectory = rootDirectory.getParentFile();
                fileBrowser.setRootDirectory(parentDirectory);
            }
        });

        newFolderButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                // TODO
            }
        });

        goHomeButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                fileBrowser.setRootDirectory(HOME_DIRECTORY);
            }
        });

        /**
         * {@link KeyCode#DOWN DOWN} Transfer focus to the file list and select
         * the first item.<br>
         * {@link KeyCode#ESCAPE ESCAPE} Clear the search field.
         */
        searchTextInput.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
            @Override
            public boolean keyPressed(Component componentArgument, int keyCode, Keyboard.KeyLocation keyLocation) {
                boolean consumed = super.keyPressed(componentArgument, keyCode, keyLocation);

                if (keyCode == Keyboard.KeyCode.ESCAPE) {
                    searchTextInput.setText("");
                    consumed = true;
                } else if (keyCode == Keyboard.KeyCode.DOWN) {
                    if (fileTableView.getTableData().getLength() > 0) {
                        fileTableView.setSelectedIndex(0);
                        fileTableView.requestFocus();
                    }
                }

                return consumed;
            }
        });

        searchTextInput.getTextInputContentListeners().add(new TextInputContentListener.Adapter() {
            @Override
            public void textChanged(TextInput textInput) {
                refreshFileList();
            }
        });

        fileTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {
            @Override
            @SuppressWarnings("unchecked")
            public void selectedRangeAdded(TableView tableView, int rangeStart, int rangeEnd) {
                if (!updatingSelection) {
                    updatingSelection = true;

                    for (int i = rangeStart; i <= rangeEnd; i++) {
                        List<File> files = (List<File>)fileTableView.getTableData();
                        File file = files.get(i);
                        fileBrowser.addSelectedFile(file);
                    }

                    updatingSelection = false;
                }
            }

            @Override
            @SuppressWarnings("unchecked")
            public void selectedRangeRemoved(TableView tableView, int rangeStart, int rangeEnd) {
                if (!updatingSelection) {
                    updatingSelection = true;

                    for (int i = rangeStart; i <= rangeEnd; i++) {
                        List<File> files = (List<File>)fileTableView.getTableData();
                        File file = files.get(i);
                        fileBrowser.removeSelectedFile(file);
                    }

                    updatingSelection = false;
                }
            }

            @Override
            @SuppressWarnings("unchecked")
            public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
                if (!updatingSelection && previousSelectedRanges != null) {
                    updatingSelection = true;

                    Sequence<File> files = (Sequence<File>)tableView.getSelectedRows();
                    for (int i = 0, n = files.getLength(); i < n; i++) {
                        File file = files.get(i);
                        files.update(i, file);
                    }

                    fileBrowser.setSelectedFiles(files);

                    updatingSelection = false;
                }
            }

            @Override
            public void selectedRowChanged(TableView tableView, Object previousSelectedRow) {
                // No-op
            }
        });

        fileTableView.getTableViewSortListeners().add(new TableViewSortListener.Adapter() {
            @Override
            @SuppressWarnings("unchecked")
            public void sortChanged(TableView tableView) {
                TableView.SortDictionary sort = fileTableView.getSort();

                if (!sort.isEmpty()) {
                    Dictionary.Pair<String, SortDirection> pair = fileTableView.getSort().get(0);
                    List<File> files = (List<File>)fileTableView.getTableData();
                    files.setComparator(getFileComparator(pair.key, pair.value));
                }
            }
        });

        fileTableView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
            private int index = -1;

            @Override
            public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, int count) {
                boolean consumed = super.mouseClick(componentArgument, button, x, y, count);

                if (count == 1) {
                    index = fileTableView.getRowAt(y);
                } else if (count == 2) {
                    int indexLocal = fileTableView.getRowAt(y);
                    if (indexLocal != -1
                        && indexLocal == this.index
                        && fileTableView.isRowSelected(indexLocal)) {
                        File file = (File)fileTableView.getTableData().get(indexLocal);

                        if (file.isDirectory()) {
                            fileBrowser.setRootDirectory(file);
                            consumed = true;
                        }
                    }
                }

                return consumed;
            }
        });

        fileBrowser.setFocusTraversalPolicy(new IndexFocusTraversalPolicy() {
            @Override
            public Component getNextComponent(Container container, Component componentArgument,
                FocusTraversalDirection direction) {
                Component nextComponent;
                if (componentArgument == null) {
View Full Code Here

    @Override
    public File getFileAt(int x, int y) {
        File file = null;

        FileBrowser fileBrowser = (FileBrowser)getComponent();
        Component component = fileBrowser.getDescendantAt(x, y);
        if (component == fileTableView) {
            Point location = fileTableView.mapPointFromAncestor(fileBrowser, x, y);

            int index = fileTableView.getRowAt(location.y);
            if (index != -1) {
View Full Code Here

     */
    @Override
    public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
        boolean consumed = super.keyPressed(component, keyCode, keyLocation);

        FileBrowser fileBrowser = (FileBrowser)getComponent();

        if (keyCode == Keyboard.KeyCode.ENTER
            && keyboardFolderTraversalEnabled) {
            Sequence<File> selectedFiles = fileBrowser.getSelectedFiles();

            if (selectedFiles.getLength() == 1) {
                File selectedFile = selectedFiles.get(0);
                if (selectedFile.isDirectory()) {
                    fileBrowser.setRootDirectory(selectedFile);
                    consumed = true;
                }
            }
        } else if (keyCode == Keyboard.KeyCode.DELETE
            || keyCode == Keyboard.KeyCode.BACKSPACE) {
            File rootDirectory = fileBrowser.getRootDirectory();
            File parentDirectory = rootDirectory.getParentFile();
            if (parentDirectory != null) {
                fileBrowser.setRootDirectory(parentDirectory);
                consumed = true;
            }
        } else if (keyCode == Keyboard.KeyCode.F5) {
            refreshFileList();
            consumed = true;
View Full Code Here

    @Override
    public void install(Component component) {
        super.install(component);

        final FileBrowser fileBrowser = (FileBrowser)component;

        Resources resources;
        try {
            resources = new Resources(getClass().getName());
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        } catch (SerializationException exception) {
            throw new RuntimeException(exception);
        }

        WTKXSerializer wtkxSerializer = new WTKXSerializer(resources);
        try {
            content = (Component)wtkxSerializer.readObject(this, "terra_file_browser_skin.wtkx");
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        } catch (SerializationException exception) {
            throw new RuntimeException(exception);
        }

        fileBrowser.add(content);

        wtkxSerializer.bind(this, TerraFileBrowserSkin.class);

        driveListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
            @Override
            public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex) {
                if (previousSelectedIndex != -1) {
                    File drive = (File)listButton.getSelectedItem();
                    fileBrowser.setRootDirectory(drive);
                }
            }
        });

        pathListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
            @Override
            public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex) {
                File ancestorDirectory = (File)listButton.getSelectedItem();

                if (ancestorDirectory != null) {
                    fileBrowser.setRootDirectory(ancestorDirectory);
                }
            }
        });

        goUpButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                File rootDirectory = fileBrowser.getRootDirectory();
                File parentDirectory = rootDirectory.getParentFile();
                fileBrowser.setRootDirectory(parentDirectory);
            }
        });

        newFolderButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                // TODO
            }
        });

        goHomeButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                fileBrowser.setRootDirectory(new File(System.getProperty("user.home")));
            }
        });

        searchTextInput.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
            @Override
            public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
                boolean consumed = super.keyPressed(component, keyCode, keyLocation);

                if (keyCode == Keyboard.KeyCode.ESCAPE) {
                    searchTextInput.setText("");
                    consumed = true;
                } else if (keyCode == Keyboard.KeyCode.DOWN) {
                    if (files.getLength() > 0) {
                        fileTableView.setSelectedIndex(0);
                        fileTableView.requestFocus();
                    }
                }

                return consumed;
            }
        });

        searchTextInput.getTextInputTextListeners().add(new TextInputTextListener() {
            @Override
            public void textChanged(TextInput textInput) {
                String text = textInput.getText().trim();
                if (text.length() == 0) {
                    text = null;
                }

                Filter<File> excludeFileFilter = null;
                if (hideDisabledFiles) {
                    excludeFileFilter = fileBrowser.getDisabledFileFilter();
                }

                files.setFilter(new IncludeFileFilter(text, excludeFileFilter));
            }
        });

        fileTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {
            @Override
            public void selectedRangeAdded(TableView tableView, int rangeStart, int rangeEnd) {
                updatingSelection = true;

                for (int i = rangeStart; i <= rangeEnd; i++) {
                    File file = files.get(i);
                    fileBrowser.addSelectedFile(file);
                }

                updatingSelection = false;
            }

            @Override
            public void selectedRangeRemoved(TableView tableView, int rangeStart, int rangeEnd) {
                updatingSelection = true;

                for (int i = rangeStart; i <= rangeEnd; i++) {
                    File file = files.get(i);
                    fileBrowser.removeSelectedFile(file);
                }

                updatingSelection = false;
            }

            @Override
            @SuppressWarnings("unchecked")
            public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
                updatingSelection = true;

                Sequence<File> files = (Sequence<File>)tableView.getSelectedRows();
                for (int i = 0, n = files.getLength(); i < n; i++) {
                    File file = files.get(i);
                    files.update(i, file);
                }

                fileBrowser.setSelectedFiles(files);

                updatingSelection = false;
            }
        });

        fileTableView.getTableViewSortListeners().add(new TableViewSortListener.Adapter() {
            @Override
            @SuppressWarnings("unchecked")
            public void sortChanged(TableView tableView) {
                TableView.SortDictionary sort = tableView.getSort();

                if (!sort.isEmpty()) {
                    Dictionary.Pair<String, SortDirection> pair = tableView.getSort().get(0);
                    List<File> files = (List<File>)tableView.getTableData();
                    files.setComparator(new FileComparator(pair.key, pair.value));
                }
            }
        });

        fileTableView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
            private int index = -1;

            @Override
            public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
                boolean consumed = super.mouseClick(component, button, x, y, count);

                if (count == 1) {
                    index = fileTableView.getRowAt(y);
                } else if (count == 2) {
                    int index = fileTableView.getRowAt(y);
                    if (index != -1
                        && index == this.index
                        && fileTableView.isRowSelected(index)) {
                        File file = files.get(index);

                        if (file.isDirectory()) {
                            fileBrowser.setRootDirectory(file);
                            consumed = true;
                        }
                    }
                }

                return consumed;
            }
        });

        files.getListListeners().add(new ListListener.Adapter<File>() {
            @Override
            public void comparatorChanged(List<File> list, Comparator<File> previousComparator) {
                fileBrowser.clearSelection();
            }
        });

        files.getFilteredListListeners().add(new FilteredListListener.Adapter<File>() {
            @Override
            public void filterChanged(FilteredList<File> filteredList,
                Filter<File> previousFilter) {
                fileBrowser.clearSelection();
            }
        });

        fileTableView.setTableData(files);

        fileBrowser.setFocusTraversalPolicy(new IndexFocusTraversalPolicy() {
            @Override
            public Component getNextComponent(Container container, Component component,
                Direction direction) {
                Component nextComponent;
                if (component == null) {
View Full Code Here

    @Override
    public File getFileAt(int x, int y) {
        File file = null;

        FileBrowser fileBrowser = (FileBrowser)getComponent();
        Component component = fileBrowser.getDescendantAt(x, y);
        if (component == fileTableView) {
            Point location = fileTableView.mapPointFromAncestor(fileBrowser, x, y);

            int index = fileTableView.getRowAt(location.y);
            if (index != -1) {
View Full Code Here

            text = null;
        }

        Filter<File> excludeFileFilter = null;
        if (hideDisabledFiles) {
            FileBrowser fileBrowser = (FileBrowser)getComponent();
            excludeFileFilter = fileBrowser.getDisabledFileFilter();
        }

        files.setFilter(new IncludeFileFilter(text, excludeFileFilter));
    }
View Full Code Here

    @Override
    public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
        boolean consumed = super.keyPressed(component, keyCode, keyLocation);

        FileBrowser fileBrowser = (FileBrowser)getComponent();

        if (keyCode == Keyboard.KeyCode.ENTER
            && keyboardFolderTraversalEnabled) {
            Sequence<File> selectedFiles = fileBrowser.getSelectedFiles();

            if (selectedFiles.getLength() == 1) {
                File selectedFile = selectedFiles.get(0);
                if (selectedFile.isDirectory()) {
                    fileBrowser.setRootDirectory(selectedFile);
                    consumed = true;
                }
            }
        } else if (keyCode == Keyboard.KeyCode.DELETE
            || keyCode == Keyboard.KeyCode.BACKSPACE) {
            File rootDirectory = fileBrowser.getRootDirectory();
            File parentDirectory = rootDirectory.getParentFile();
            if (parentDirectory != null) {
                fileBrowser.setRootDirectory(parentDirectory);
                consumed = true;
            }
        } else if (keyCode == Keyboard.KeyCode.F5) {
            refreshFileList();
            consumed = true;
View Full Code Here

            files.setFilter(new IncludeFileFilter(text, disabledFileFilter));
        }
    }

    private void refreshFileList() {
        FileBrowser fileBrowser = (FileBrowser)getComponent();
        File rootDirectory = fileBrowser.getRootDirectory();

        files.setSource(new ArrayList<File>(rootDirectory.listFiles(HIDDEN_FILE_FILTER)));
    }
View Full Code Here

    @Override
    public void install(Component component) {
        super.install(component);

        final FileBrowser fileBrowser = (FileBrowser)component;

        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        try {
            content = (Component)bxmlSerializer.readObject(TerraFileBrowserSkin.class,
                "terra_file_browser_skin.bxml", true);
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        } catch (SerializationException exception) {
            throw new RuntimeException(exception);
        }

        fileBrowser.add(content);

        bxmlSerializer.bind(this, TerraFileBrowserSkin.class);

        driveListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener.Adapter() {
            @Override
            public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
                if (previousSelectedItem != null) {
                    File drive = (File)listButton.getSelectedItem();
                    if(drive != null && drive.canRead()) {
                        fileBrowser.setRootDirectory(drive);
                    } else {
                        refreshRoots = true;
                        listButton.setSelectedItem(previousSelectedItem);
                    }
                }
            }
        });

        pathListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener.Adapter() {
            @Override
            public void selectedItemChanged(ListButton listButton, Object previousSelectedItem) {
                File ancestorDirectory = (File)listButton.getSelectedItem();

                if (ancestorDirectory != null) {
                    fileBrowser.setRootDirectory(ancestorDirectory);
                }
            }
        });

        goUpButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                File rootDirectory = fileBrowser.getRootDirectory();
                File parentDirectory = rootDirectory.getParentFile();
                fileBrowser.setRootDirectory(parentDirectory);
            }
        });

        newFolderButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                // TODO
            }
        });

        goHomeButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                fileBrowser.setRootDirectory(HOME_DIRECTORY);
            }
        });

        /**
         * {@link KeyCode#DOWN DOWN} Transfer focus to the file list and select
         * the first item.<br>
         * {@link KeyCode#ESCAPE ESCAPE} Clear the search field.
         */
        searchTextInput.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
            @Override
            public boolean keyPressed(Component componentArgument, int keyCode, Keyboard.KeyLocation keyLocation) {
                boolean consumed = super.keyPressed(componentArgument, keyCode, keyLocation);

                if (keyCode == Keyboard.KeyCode.ESCAPE) {
                    searchTextInput.setText("");
                    consumed = true;
                } else if (keyCode == Keyboard.KeyCode.DOWN) {
                    if (fileTableView.getTableData().getLength() > 0) {
                        fileTableView.setSelectedIndex(0);
                        fileTableView.requestFocus();
                    }
                }

                return consumed;
            }
        });

        searchTextInput.getTextInputContentListeners().add(new TextInputContentListener.Adapter() {
            @Override
            public void textChanged(TextInput textInput) {
                refreshFileList();
            }
        });

        fileTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {
            @Override
            @SuppressWarnings("unchecked")
            public void selectedRangeAdded(TableView tableView, int rangeStart, int rangeEnd) {
                if (!updatingSelection) {
                    updatingSelection = true;

                    for (int i = rangeStart; i <= rangeEnd; i++) {
                        List<File> files = (List<File>)fileTableView.getTableData();
                        File file = files.get(i);
                        fileBrowser.addSelectedFile(file);
                    }

                    updatingSelection = false;
                }
            }

            @Override
            @SuppressWarnings("unchecked")
            public void selectedRangeRemoved(TableView tableView, int rangeStart, int rangeEnd) {
                if (!updatingSelection) {
                    updatingSelection = true;

                    for (int i = rangeStart; i <= rangeEnd; i++) {
                        List<File> files = (List<File>)fileTableView.getTableData();
                        File file = files.get(i);
                        fileBrowser.removeSelectedFile(file);
                    }

                    updatingSelection = false;
                }
            }

            @Override
            @SuppressWarnings("unchecked")
            public void selectedRangesChanged(TableView tableView, Sequence<Span> previousSelectedRanges) {
                if (!updatingSelection && previousSelectedRanges != null) {
                    updatingSelection = true;

                    Sequence<File> files = (Sequence<File>)tableView.getSelectedRows();
                    for (int i = 0, n = files.getLength(); i < n; i++) {
                        File file = files.get(i);
                        files.update(i, file);
                    }

                    fileBrowser.setSelectedFiles(files);

                    updatingSelection = false;
                }
            }

            @Override
            public void selectedRowChanged(TableView tableView, Object previousSelectedRow) {
                // No-op
            }
        });

        fileTableView.getTableViewSortListeners().add(new TableViewSortListener.Adapter() {
            @Override
            @SuppressWarnings("unchecked")
            public void sortChanged(TableView tableView) {
                TableView.SortDictionary sort = fileTableView.getSort();

                if (!sort.isEmpty()) {
                    Dictionary.Pair<String, SortDirection> pair = fileTableView.getSort().get(0);
                    List<File> files = (List<File>)fileTableView.getTableData();
                    files.setComparator(getFileComparator(pair.key, pair.value));
                }
            }
        });

        fileTableView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
            private int index = -1;

            @Override
            public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, int count) {
                boolean consumed = super.mouseClick(componentArgument, button, x, y, count);

                if (count == 1) {
                    index = fileTableView.getRowAt(y);
                } else if (count == 2) {
                    int indexLocal = fileTableView.getRowAt(y);
                    if (indexLocal != -1
                        && indexLocal == this.index
                        && fileTableView.isRowSelected(indexLocal)) {
                        File file = (File)fileTableView.getTableData().get(indexLocal);

                        if (file.isDirectory()) {
                            fileBrowser.setRootDirectory(file);
                            consumed = true;
                        }
                    }
                }

                return consumed;
            }
        });

        fileBrowser.setFocusTraversalPolicy(new IndexFocusTraversalPolicy() {
            @Override
            public Component getNextComponent(Container container, Component componentArgument,
                FocusTraversalDirection direction) {
                Component nextComponent;
                if (componentArgument == null) {
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.FileBrowser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.