Search in sources :

Example 31 with ButtonPressListener

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

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

the class ColorSchemeBuilderWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    Theme theme = Theme.getTheme();
    createColorPalette();
    int numberOfPaletteColors = getNumberOfPaletteColors();
    themeOriginalColors = new ArrayList<>(numberOfPaletteColors);
    for (int i = 0; i < numberOfPaletteColors; i++) {
        final ColorChooserButton colorChooserButton = new ColorChooserButton();
        colorChooserButtons.add(colorChooserButton);
        colorChooserButton.setSelectedColor(Color.BLACK);
        NumericSpinnerData colorSpinnerData = new NumericSpinnerData(0, 255);
        SpinnerItemRenderer colorSpinnerItemRenderer = new SpinnerItemRenderer();
        colorSpinnerItemRenderer.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.RIGHT);
        final Spinner redSpinner = new Spinner();
        redSpinner.setSpinnerData(colorSpinnerData);
        redSpinner.setItemRenderer(colorSpinnerItemRenderer);
        redSpinner.setPreferredWidth(40);
        redSpinner.setSelectedIndex(0);
        final Spinner greenSpinner = new Spinner();
        greenSpinner.setSpinnerData(colorSpinnerData);
        greenSpinner.setItemRenderer(colorSpinnerItemRenderer);
        greenSpinner.setPreferredWidth(40);
        greenSpinner.setSelectedIndex(0);
        final Spinner blueSpinner = new Spinner();
        blueSpinner.setSpinnerData(colorSpinnerData);
        blueSpinner.setItemRenderer(colorSpinnerItemRenderer);
        blueSpinner.setPreferredWidth(40);
        blueSpinner.setSelectedIndex(0);
        BoxPane colorBoxPane = new BoxPane();
        colorBoxPane.getStyles().put(Style.fill, true);
        colorBoxPane.getStyles().put(Style.padding, "{left:4}");
        colorBoxPane.add(redSpinner);
        colorBoxPane.add(greenSpinner);
        colorBoxPane.add(blueSpinner);
        TablePane.Row row = new TablePane.Row(colorChooserTablePane);
        row.add(colorChooserButton);
        row.add(colorBoxPane);
        // Add listeners
        ColorChooserButtonSelectionListener colorChooserButtonSelectionListener = new ColorChooserButtonSelectionListener() {

            @Override
            public void selectedColorChanged(ColorChooserButton colorChooserButtonArgument, Color previousSelectedColor) {
                Color selectedColor = colorChooserButtonArgument.getSelectedColor();
                redSpinner.setSelectedItem(selectedColor.getRed());
                greenSpinner.setSelectedItem(selectedColor.getGreen());
                blueSpinner.setSelectedItem(selectedColor.getBlue());
                // Update the theme
                Theme themeLocal = Theme.getTheme();
                int iLocal = colorChooserButtons.indexOf(colorChooserButtonArgument);
                themeLocal.setBaseColor(iLocal, colorChooserButtons.get(iLocal).getSelectedColor());
                // Update the palette
                int offset = iLocal * 3;
                for (int j = 0; j < 3; j++) {
                    Component colorPaletteCell = colorPaletteTablePane.getRows().get(iLocal).get(j);
                    colorPaletteCell.getStyles().put(Style.backgroundColor, offset + j);
                }
                // Reload the sample part of the content (but not all the application),
                // this means that the rest of the application always show original colors
                reloadContent();
            }
        };
        colorChooserButton.getColorChooserButtonSelectionListeners().add(colorChooserButtonSelectionListener);
        SpinnerSelectionListener spinnerSelectionListener = new SpinnerSelectionListener() {

            @Override
            public void selectedItemChanged(Spinner spinner, Object previousSelectedItem) {
                int red = ((Integer) redSpinner.getSelectedItem()).intValue();
                int green = ((Integer) greenSpinner.getSelectedItem()).intValue();
                int blue = ((Integer) blueSpinner.getSelectedItem()).intValue();
                colorChooserButton.setSelectedColor(new Color(red, green, blue));
            }
        };
        redSpinner.getSpinnerSelectionListeners().add(spinnerSelectionListener);
        greenSpinner.getSpinnerSelectionListeners().add(spinnerSelectionListener);
        blueSpinner.getSpinnerSelectionListeners().add(spinnerSelectionListener);
        // Initialize the button color with the theme default
        themeOriginalColors.add(theme.getBaseColor(i));
        colorChooserButton.setSelectedColor(theme.getBaseColor(i));
    }
    copyToClipboardButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            copyToClipboard();
        }
    });
    resetPaletteButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            resetPalette();
        }
    });
    // Initialize content
    reloadContent();
}
Also used : SpinnerItemRenderer(org.apache.pivot.wtk.content.SpinnerItemRenderer) Spinner(org.apache.pivot.wtk.Spinner) Color(java.awt.Color) SpinnerSelectionListener(org.apache.pivot.wtk.SpinnerSelectionListener) NumericSpinnerData(org.apache.pivot.wtk.content.NumericSpinnerData) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ColorChooserButtonSelectionListener(org.apache.pivot.wtk.ColorChooserButtonSelectionListener) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) BoxPane(org.apache.pivot.wtk.BoxPane) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) Theme(org.apache.pivot.wtk.Theme) Component(org.apache.pivot.wtk.Component) TablePane(org.apache.pivot.wtk.TablePane)

Example 33 with ButtonPressListener

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

the class DOMInteractionDemo method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BoxPane boxPane = new BoxPane();
    boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
    helloButton = new PushButton("Say Hello");
    boxPane.add(helloButton);
    helloButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            BrowserApplicationContext.eval("sayHello(\"Hello from Pivot!\")", DOMInteractionDemo.this);
        }
    });
    Border border = new Border(boxPane);
    border.getStyles().put(Style.color, 7);
    border.getStyles().put(Style.padding, 5);
    window = new Window(border);
    window.setMaximized(true);
    window.open(display);
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) Window(org.apache.pivot.wtk.Window) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) PushButton(org.apache.pivot.wtk.PushButton) Border(org.apache.pivot.wtk.Border)

Example 34 with ButtonPressListener

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

Example 35 with ButtonPressListener

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

the class TerraVFSBrowserSheetSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    final VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) component;
    fileBrowserSheet.setMinimumWidth(360);
    fileBrowserSheet.setMinimumHeight(180);
    // Load the sheet content
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    Component content;
    try {
        content = (Component) bxmlSerializer.readObject(TerraVFSBrowserSheetSkin.class, "terra_vfs_browser_sheet_skin.bxml", true);
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    } catch (SerializationException exception) {
        throw new RuntimeException(exception);
    }
    fileBrowserSheet.setContent(content);
    bxmlSerializer.bind(this, TerraVFSBrowserSheetSkin.class);
    // set the same rootDirectory as the component
    try {
        FileObject rootDirectory = fileBrowserSheet.getRootDirectory();
        fileBrowser.setRootDirectory(rootDirectory);
        setHostLabel(rootDirectory);
    } catch (FileSystemException fse) {
        throw new RuntimeException(fse);
    }
    // set the same homeDirectory as the component
    try {
        fileBrowser.setHomeDirectory(fileBrowserSheet.getHomeDirectory());
    } catch (FileSystemException fse) {
        throw new RuntimeException(fse);
    }
    saveAsTextInput.getTextInputContentListeners().add(new TextInputContentListener() {

        @Override
        public void textChanged(TextInput textInput) {
            Form.clearFlag(saveAsBoxPane);
            updateOKButtonState();
        }
    });
    fileBrowser.getFileBrowserListeners().add(new VFSBrowserListener() {

        @Override
        public void rootDirectoryChanged(VFSBrowser fileBrowserArgument, FileObject previousRootDirectory) {
            updatingSelection = true;
            try {
                FileObject rootDirectory = fileBrowserArgument.getRootDirectory();
                fileBrowserSheet.setRootDirectory(rootDirectory);
                setHostLabel(rootDirectory);
            } catch (FileSystemException fse) {
                throw new RuntimeException(fse);
            }
            updatingSelection = false;
            selectedDirectoryCount = 0;
            updateOKButtonState();
        }

        @Override
        public void homeDirectoryChanged(VFSBrowser fileBrowserArgument, FileObject previousHomeDirectory) {
            updatingSelection = true;
            try {
                fileBrowserSheet.setHomeDirectory(fileBrowserArgument.getHomeDirectory());
            } catch (FileSystemException fse) {
                throw new RuntimeException(fse);
            }
            updatingSelection = false;
        }

        @Override
        public void selectedFileAdded(VFSBrowser fileBrowserArgument, FileObject file) {
            if (file.getName().getType() == FileType.FOLDER) {
                selectedDirectoryCount++;
            }
            updateOKButtonState();
        }

        @Override
        public void selectedFileRemoved(VFSBrowser fileBrowserArgument, FileObject file) {
            if (file.getName().getType() == FileType.FOLDER) {
                selectedDirectoryCount--;
            }
            updateOKButtonState();
        }

        @Override
        public void selectedFilesChanged(VFSBrowser fileBrowserArgument, Sequence<FileObject> previousSelectedFiles) {
            selectedDirectoryCount = 0;
            Sequence<FileObject> selectedFiles = fileBrowserArgument.getSelectedFiles();
            for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
                FileObject selectedFile = selectedFiles.get(i);
                if (selectedFile.getName().getType() == FileType.FOLDER) {
                    selectedDirectoryCount++;
                }
            }
            if (!fileBrowserArgument.isMultiSelect()) {
                FileObject selectedFile = fileBrowserArgument.getSelectedFile();
                if (selectedFile != null && selectedFile.getName().getType() != FileType.FOLDER) {
                    saveAsTextInput.setText(selectedFile.getName().getPath());
                }
            }
            updateOKButtonState();
        }
    });
    fileBrowser.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {

        private FileObject file = null;

        @Override
        public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, int count) {
            boolean consumed = false;
            VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
            if (count == 1) {
                file = fileBrowser.getFileAt(x, y);
            } else if (count == 2) {
                FileObject fileLocal = fileBrowser.getFileAt(x, y);
                if (fileLocal != null && this.file != null && fileLocal.equals(this.file) && fileBrowser.isFileSelected(fileLocal)) {
                    if (mode == VFSBrowserSheet.Mode.OPEN || mode == VFSBrowserSheet.Mode.OPEN_MULTIPLE) {
                        if (fileLocal.getName().getType() != FileType.FOLDER) {
                            fileBrowserSheet.close(true);
                            consumed = true;
                        }
                    }
                }
            }
            return consumed;
        }
    });
    okButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            fileBrowserSheet.close(true);
        }
    });
    cancelButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            fileBrowserSheet.close(false);
        }
    });
    // Add this as a file browser sheet listener
    fileBrowserSheet.getFileBrowserSheetListeners().add(this);
    modeChanged(fileBrowserSheet, null);
    homeDirectoryChanged(fileBrowserSheet, null);
    rootDirectoryChanged(fileBrowserSheet, null);
    selectedFilesChanged(fileBrowserSheet, null);
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) VFSBrowserListener(org.apache.pivot.wtk.VFSBrowserListener) IOException(java.io.IOException) Sequence(org.apache.pivot.collections.Sequence) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) FileSystemException(org.apache.commons.vfs2.FileSystemException) TextInputContentListener(org.apache.pivot.wtk.TextInputContentListener) VFSBrowserSheet(org.apache.pivot.wtk.VFSBrowserSheet) Mouse(org.apache.pivot.wtk.Mouse) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ComponentMouseButtonListener(org.apache.pivot.wtk.ComponentMouseButtonListener) FileObject(org.apache.commons.vfs2.FileObject) Component(org.apache.pivot.wtk.Component) TextInput(org.apache.pivot.wtk.TextInput) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) VFSBrowser(org.apache.pivot.wtk.VFSBrowser)

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