Search in sources :

Example 6 with ButtonPressListener

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

the class FileBrowsing method initialize.

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

        @Override
        public void buttonPressed(Button button) {
            Button selection = fileBrowserSheetModeGroup.getSelection();
            String mode = (String) selection.getUserData().get("mode");
            FileBrowserSheet.Mode fileBrowserSheetMode = FileBrowserSheet.Mode.valueOf(mode.toUpperCase());
            final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet();
            if (fileBrowserSheetMode == FileBrowserSheet.Mode.SAVE_AS) {
                fileBrowserSheet.setSelectedFile(new File(fileBrowserSheet.getRootDirectory(), "New File"));
            }
            fileBrowserSheet.setMode(fileBrowserSheetMode);
            fileBrowserSheet.open(FileBrowsing.this, 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:", listView, FileBrowsing.this);
                    } else {
                        Alert.alert(MessageType.INFO, "You didn't select anything.", FileBrowsing.this);
                    }
                }
            });
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ListView(org.apache.pivot.wtk.ListView) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) File(java.io.File) Sheet(org.apache.pivot.wtk.Sheet) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet)

Example 7 with ButtonPressListener

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

the class Forms method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    titleListButton = (ListButton) namespace.get("titleListButton");
    nameBoxPane = (BoxPane) namespace.get("nameBoxPane");
    lastNameTextInput = (TextInput) namespace.get("lastNameTextInput");
    firstNameTextInput = (TextInput) namespace.get("firstNameTextInput");
    submitButton = (PushButton) namespace.get("submitButton");
    errorLabel = (Label) namespace.get("errorLabel");
    submitButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            String titleOfPerson = (String) titleListButton.getButtonData();
            System.out.println("The title of the person is: \"" + titleOfPerson + "\"");
            String lastName = lastNameTextInput.getText();
            String firstName = firstNameTextInput.getText();
            Form.Flag flag = null;
            if (lastName.length() == 0 || firstName.length() == 0) {
                flag = new Form.Flag(MessageType.ERROR, "Name is required.");
            }
            Form.setFlag(nameBoxPane, flag);
            if (flag == null) {
                errorLabel.setText("");
                Prompt.prompt("Pretending to submit...", Forms.this);
            } else {
                errorLabel.setText("Some required information is missing.");
            }
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton)

Example 8 with ButtonPressListener

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

the class Pivot859 method initializeFields.

private void initializeFields(BXMLSerializer serializer) {
    System.out.println("initializeFields: start");
    urlInput = (TextInput) serializer.getNamespace().get("textInput");
    if (defaultURL.length() > 0) {
        urlInput.setText(defaultURL);
    }
    goButton = (PushButton) serializer.getNamespace().get("goButton");
    goButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            clearContent();
            retrieveURLContentSync();
        }
    });
    contentArea = (TextArea) serializer.getNamespace().get("textArea");
    clearButton = (PushButton) serializer.getNamespace().get("clearButton");
    clearButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            clearContent();
        }
    });
    statusLabel = (Label) serializer.getNamespace().get("textStatus");
    System.out.println("initializeFields: end");
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button)

Example 9 with ButtonPressListener

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

the class Pivot734WithWorkaround method controlTree.

private void controlTree(BXMLSerializer bxmlSerializer) {
    treeButtonAdd = (PushButton) bxmlSerializer.getNamespace().get("treeButtonAdd");
    treeButtonRemove = (PushButton) bxmlSerializer.getNamespace().get("treeButtonRemove");
    tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
    boolean treeStyleForShowEmptyBranchControls = tree.getStyles().getBoolean(Style.showEmptyBranchControls);
    System.out.println("tree style for showEmptyBranchControls is " + treeStyleForShowEmptyBranchControls);
    tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        @Override
        public void selectedPathAdded(TreeView treeView, Path path) {
            System.out.println("selectedPathAdded");
        }

        @Override
        public void selectedPathRemoved(TreeView treeView, Path path) {
            System.out.println("selectedPathRemoved");
        }

        @Override
        public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
            System.out.println("selectedPathsChanged");
        }

        @Override
        public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
            System.out.println("selectedNodeChanged");
        }
    });
    treeButtonAdd.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("add a 'new branch' element to the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                // workaround for PIVOT-734
                Path path = tree.getSelectedPath();
                tree.setBranchExpanded(path, true);
                // end of workaround for PIVOT-734
                ((TreeBranch) x).add(newBranch);
            }
        }
    });
    treeButtonRemove.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("remove a 'new branch' element under the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                ((TreeBranch) x).remove(newBranch);
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView)

Example 10 with ButtonPressListener

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

the class Pivot832 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_832.bxml"));
    bxmlSerializer.bind(this, Pivot832.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 + "\"");
            final FileBrowserSheet fileBrowserSheet = new FileBrowserSheet(FileBrowserSheet.Mode.OPEN, selectedFolder);
            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)

Aggregations

ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)44 Button (org.apache.pivot.wtk.Button)43 PushButton (org.apache.pivot.wtk.PushButton)40 Component (org.apache.pivot.wtk.Component)13 IOException (java.io.IOException)11 File (java.io.File)9 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)9 ListButton (org.apache.pivot.wtk.ListButton)8 Sheet (org.apache.pivot.wtk.Sheet)8 ListView (org.apache.pivot.wtk.ListView)7 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)7 Sequence (org.apache.pivot.collections.Sequence)6 BoxPane (org.apache.pivot.wtk.BoxPane)6 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)6 Span (org.apache.pivot.wtk.Span)6 Window (org.apache.pivot.wtk.Window)6 List (org.apache.pivot.collections.List)5 SerializationException (org.apache.pivot.serialization.SerializationException)5 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)5 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)5