Search in sources :

Example 41 with Button

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

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

the class ButtonGroupTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.getButtonGroupListeners().add(new ButtonGroupListener() {

        @Override
        public void selectionChanged(ButtonGroup buttonGroupArgument, Button previousSelection) {
            System.out.println("selectionChanged(): previousSelection = " + previousSelection + ", selection = " + buttonGroupArgument.getSelection());
        }

        @Override
        public void buttonAdded(ButtonGroup buttonGroupArgument, Button button) {
            System.out.println("buttonAdded(): " + button);
        }

        @Override
        public void buttonRemoved(ButtonGroup buttonGroupArgument, Button button) {
            System.out.println("buttonRemoved(): " + button);
        }
    });
    BoxPane boxPane = new BoxPane();
    PushButton button1 = new PushButton("One");
    button1.setToggleButton(true);
    button1.setButtonGroup(buttonGroup);
    boxPane.add(button1);
    PushButton button2 = new PushButton("Two");
    button2.setToggleButton(true);
    button2.setButtonGroup(buttonGroup);
    boxPane.add(button2);
    PushButton button3 = new PushButton("Three");
    button3.setToggleButton(true);
    button3.setButtonGroup(buttonGroup);
    boxPane.add(button3);
    PushButton button4 = new PushButton("Four");
    button4.setToggleButton(true);
    button4.setButtonGroup(buttonGroup);
    boxPane.add(button4);
    // button1.setSelected(true);
    // buttonGroup.setSelection(button1);
    // buttonGroup.setSelection(null);
    window = new Window(boxPane);
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener)

Example 43 with Button

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

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

the class TerraRadioButtonSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    RadioButton radioButton = (RadioButton) getComponent();
    int width = getWidth();
    int height = getHeight();
    // Paint the button
    int offset = (height - BUTTON_DIAMETER) / 2;
    graphics.translate(0, offset);
    paintButton(graphics, radioButton.isEnabled(), radioButton.isSelected());
    graphics.translate(0, -offset);
    // Paint the content
    Button.DataRenderer dataRenderer = radioButton.getDataRenderer();
    Object buttonData = radioButton.getButtonData();
    dataRenderer.render(buttonData, radioButton, false);
    dataRenderer.setSize(Math.max(width - (BUTTON_DIAMETER + spacing * 2), 0), height);
    Graphics2D contentGraphics = (Graphics2D) graphics.create();
    contentGraphics.translate(BUTTON_DIAMETER + spacing, 0);
    contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
    dataRenderer.paint(contentGraphics);
    contentGraphics.dispose();
    // Paint the focus state
    if (radioButton.isFocused()) {
        if (buttonData == null) {
            Color focusColor = ColorUtilities.setTransparencyInColor(buttonSelectionColor, ALPHA);
            graphics.setColor(focusColor);
            graphics.fillOval(0, 0, BUTTON_DIAMETER - 1, BUTTON_DIAMETER - 1);
        } else {
            BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 0.0f, 2.0f }, 0.0f);
            graphics.setStroke(dashStroke);
            graphics.setColor(buttonBorderColor);
            GraphicsUtilities.setAntialiasingOn(graphics);
            Rectangle2D focusRectangle = new Rectangle2D.Double(BUTTON_DIAMETER + 1, 0.5, dataRenderer.getWidth() + spacing * 2 - 2, dataRenderer.getHeight() - 1);
            graphics.draw(focusRectangle);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) RadioButton(org.apache.pivot.wtk.RadioButton) Button(org.apache.pivot.wtk.Button) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) RadioButton(org.apache.pivot.wtk.RadioButton) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Example 45 with Button

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

Button (org.apache.pivot.wtk.Button)61 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)43 PushButton (org.apache.pivot.wtk.PushButton)40 Component (org.apache.pivot.wtk.Component)15 ListButton (org.apache.pivot.wtk.ListButton)12 IOException (java.io.IOException)11 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)11 File (java.io.File)9 BoxPane (org.apache.pivot.wtk.BoxPane)9 Sheet (org.apache.pivot.wtk.Sheet)9 ListView (org.apache.pivot.wtk.ListView)8 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)8 ButtonStateListener (org.apache.pivot.wtk.ButtonStateListener)7 List (org.apache.pivot.collections.List)6 Sequence (org.apache.pivot.collections.Sequence)6 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)6 Point (org.apache.pivot.wtk.Point)6 Span (org.apache.pivot.wtk.Span)6 GradientPaint (java.awt.GradientPaint)5 SerializationException (org.apache.pivot.serialization.SerializationException)5