Search in sources :

Example 6 with SheetCloseListener

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

the class TabPanes method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    confirmCloseTabPrompt = (Prompt) namespace.get("confirmCloseTabPrompt");
    tabPane = (TabPane) namespace.get("tabPane");
    closeableCheckbox = (Checkbox) namespace.get("closeableCheckbox");
    collapsibleCheckbox = (Checkbox) namespace.get("collapsibleCheckbox");
    horizontalRadioButton = (RadioButton) namespace.get("horizontalRadioButton");
    verticalRadioButton = (RadioButton) namespace.get("verticalRadioButton");
    cornerBoxPane = (BoxPane) namespace.get("cornerBoxPane");
    tabPane.getTabPaneListeners().add(new TabPaneListener() {

        @Override
        public Vote previewRemoveTabs(final TabPane tabPaneArgument, final int index, final int count) {
            Vote vote;
            if (confirmCloseTab) {
                confirmCloseTabPrompt.open(TabPanes.this, new SheetCloseListener() {

                    @Override
                    public void sheetClosed(Sheet sheet) {
                        if (confirmCloseTabPrompt.getResult() && confirmCloseTabPrompt.getSelectedOptionIndex() == 1) {
                            confirmCloseTab = false;
                            int n = tabPaneArgument.getTabs().getLength();
                            if (index < n - 1) {
                                tabPaneArgument.setSelectedIndex(index + 1);
                            } else {
                                tabPaneArgument.setSelectedIndex(index - 1);
                            }
                            tabPaneArgument.getTabs().remove(index, count);
                            confirmCloseTab = true;
                        }
                    }
                });
                vote = Vote.DENY;
            } else {
                vote = Vote.APPROVE;
            }
            return vote;
        }
    });
    ButtonStateListener checkboxStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            updateTabPane();
        }
    };
    closeableCheckbox.getButtonStateListeners().add(checkboxStateListener);
    collapsibleCheckbox.getButtonStateListeners().add(checkboxStateListener);
    ButtonStateListener radioButtonStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            if (button.isSelected()) {
                updateTabPane();
            }
        }
    };
    horizontalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    verticalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    updateTabPane();
}
Also used : TabPaneListener(org.apache.pivot.wtk.TabPaneListener) TabPane(org.apache.pivot.wtk.TabPane) Vote(org.apache.pivot.util.Vote) RadioButton(org.apache.pivot.wtk.RadioButton) Button(org.apache.pivot.wtk.Button) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) Sheet(org.apache.pivot.wtk.Sheet)

Example 7 with SheetCloseListener

use of org.apache.pivot.wtk.SheetCloseListener 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);
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) IOException(java.io.IOException) Sheet(org.apache.pivot.wtk.Sheet) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) File(java.io.File) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 8 with SheetCloseListener

use of org.apache.pivot.wtk.SheetCloseListener 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 9 with SheetCloseListener

use of org.apache.pivot.wtk.SheetCloseListener 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)

Example 10 with SheetCloseListener

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

the class SheetExampleWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    editGreetingButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            HashMap<String, Object> context = new HashMap<>();
            store(context);
            editGreetingSheet.load(context);
            editGreetingSheet.open(SheetExampleWindow.this, new SheetCloseListener() {

                @Override
                public void sheetClosed(Sheet sheet) {
                    if (sheet.getResult()) {
                        HashMap<String, Object> contextLocal = new HashMap<>();
                        editGreetingSheet.store(contextLocal);
                        load(contextLocal);
                    }
                }
            });
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) HashMap(org.apache.pivot.collections.HashMap) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) Sheet(org.apache.pivot.wtk.Sheet)

Aggregations

Sheet (org.apache.pivot.wtk.Sheet)11 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)11 Button (org.apache.pivot.wtk.Button)8 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)7 PushButton (org.apache.pivot.wtk.PushButton)7 File (java.io.File)5 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)5 ListView (org.apache.pivot.wtk.ListView)4 IOException (java.io.IOException)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 ArrayList (org.apache.pivot.collections.ArrayList)3 HashMap (org.apache.pivot.collections.HashMap)3 List (org.apache.pivot.collections.List)3 TaskAdapter (org.apache.pivot.wtk.TaskAdapter)3 BoxPane (org.apache.pivot.wtk.BoxPane)2 Checkbox (org.apache.pivot.wtk.Checkbox)2 Frame (org.apache.pivot.wtk.Frame)2 ListButton (org.apache.pivot.wtk.ListButton)2 Color (java.awt.Color)1 Font (java.awt.Font)1