Search in sources :

Example 26 with BoxPane

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

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

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

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

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

the class BoxPaneSkin method layout.

@Override
public void layout() {
    BoxPane boxPane = (BoxPane) getComponent();
    int n = boxPane.getLength();
    int width = getWidth();
    int height = getHeight();
    Orientation orientation = boxPane.getOrientation();
    if (orientation == Orientation.HORIZONTAL) {
        int preferredWidth = getPreferredWidth(fill ? height : -1);
        // Determine the starting x-coordinate
        int x = 0;
        switch(horizontalAlignment) {
            case CENTER:
                {
                    x = (width - preferredWidth) / 2;
                    break;
                }
            case RIGHT:
                {
                    x = width - preferredWidth;
                    break;
                }
            case LEFT:
                {
                    break;
                }
            default:
                {
                    break;
                }
        }
        x += padding.left;
        // Lay out the components
        for (int i = 0; i < n; i++) {
            Component component = boxPane.get(i);
            if (component.isVisible()) {
                int componentWidth = 0;
                int componentHeight = 0;
                int y = 0;
                if (fill) {
                    componentHeight = Math.max(height - padding.getHeight(), 0);
                    componentWidth = component.getPreferredWidth(componentHeight);
                } else {
                    Dimensions preferredComponentSize = component.getPreferredSize();
                    componentWidth = preferredComponentSize.width;
                    componentHeight = preferredComponentSize.height;
                }
                switch(verticalAlignment) {
                    case TOP:
                        {
                            y = padding.top;
                            break;
                        }
                    case CENTER:
                        {
                            y = (height - componentHeight) / 2;
                            break;
                        }
                    case BOTTOM:
                        {
                            y = height - padding.bottom - componentHeight;
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
                // Set the component's size and position
                component.setSize(componentWidth, componentHeight);
                component.setLocation(x, y);
                // Increment the x-coordinate
                x += componentWidth + spacing;
            }
        }
    } else {
        int preferredHeight = getPreferredHeight(fill ? width : -1);
        // Determine the starting y-coordinate
        int y = 0;
        switch(verticalAlignment) {
            case CENTER:
                {
                    y = (height - preferredHeight) / 2;
                    break;
                }
            case BOTTOM:
                {
                    y = height - preferredHeight;
                    break;
                }
            case TOP:
                break;
            default:
                {
                    break;
                }
        }
        y += padding.top;
        // Lay out the components
        for (int i = 0; i < n; i++) {
            Component component = boxPane.get(i);
            if (component.isVisible()) {
                int componentWidth = 0;
                int componentHeight = 0;
                int x = 0;
                if (fill) {
                    componentWidth = Math.max(width - padding.getWidth(), 0);
                    componentHeight = component.getPreferredHeight(componentWidth);
                } else {
                    Dimensions preferredComponentSize = component.getPreferredSize();
                    componentWidth = preferredComponentSize.width;
                    componentHeight = preferredComponentSize.height;
                }
                switch(horizontalAlignment) {
                    case LEFT:
                        {
                            x = padding.left;
                            break;
                        }
                    case CENTER:
                        {
                            x = (width - componentWidth) / 2;
                            break;
                        }
                    case RIGHT:
                        {
                            x = width - padding.right - componentWidth;
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
                // Set the component's size and position
                component.setSize(componentWidth, componentHeight);
                component.setLocation(x, y);
                // Increment the y-coordinate
                y += componentHeight + spacing;
            }
        }
    }
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) Dimensions(org.apache.pivot.wtk.Dimensions) Orientation(org.apache.pivot.wtk.Orientation) Component(org.apache.pivot.wtk.Component)

Aggregations

BoxPane (org.apache.pivot.wtk.BoxPane)38 Component (org.apache.pivot.wtk.Component)18 Label (org.apache.pivot.wtk.Label)15 TextInput (org.apache.pivot.wtk.TextInput)15 Button (org.apache.pivot.wtk.Button)9 Frame (org.apache.pivot.wtk.Frame)9 PushButton (org.apache.pivot.wtk.PushButton)9 Window (org.apache.pivot.wtk.Window)8 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)7 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)7 FlowPane (org.apache.pivot.wtk.FlowPane)7 IntValidator (org.apache.pivot.wtk.validation.IntValidator)7 Dimensions (org.apache.pivot.wtk.Dimensions)5 Border (org.apache.pivot.wtk.Border)4 TablePane (org.apache.pivot.wtk.TablePane)4 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 ListView (org.apache.pivot.wtk.ListView)3 Sheet (org.apache.pivot.wtk.Sheet)3 Spinner (org.apache.pivot.wtk.Spinner)3 Color (java.awt.Color)2