Search in sources :

Example 1 with Spinner

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

the class Pivot964Pivot method startup.

@Override
public void startup(Display display, Map<String, String> properties) {
    // force dimensions for host frame
    display.getHostWindow().setSize(1028, 600);
    window = new Window();
    prepareSVG();
    final ImageView image = new ImageView(new Drawing(diagram));
    BoxPane bp = new BoxPane();
    TablePane tp = new TablePane();
    setStyles(tp, "{padding: 4}");
    TablePane.Column c1 = new TablePane.Column(-1);
    TablePane.Column c2 = new TablePane.Column(-1);
    tp.getColumns().add(c1);
    tp.getColumns().add(c2);
    TablePane.Row r1 = new TablePane.Row(-1);
    TablePane.Row r2 = new TablePane.Row(-1);
    TablePane.Row r3 = new TablePane.Row(-1);
    PushButton pb1 = new PushButton("Visible");
    PushButton pb2 = new PushButton("Invisible (bug)");
    r1.add(pb1);
    r1.add(pb2);
    final Spinner sp1 = new Spinner(new ListAdapter<>(spinnerData));
    sp1.setPreferredWidth(80);
    sp1.setSelectedIndex(0);
    final Spinner sp2 = new Spinner(new ListAdapter<>(spinnerData));
    sp2.setPreferredWidth(80);
    sp2.setSelectedIndex(0);
    BoxPane bp1 = new BoxPane();
    setStyles(bp1, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp1.add(new Label("X:"));
    bp1.add(sp1);
    r2.add(bp1);
    BoxPane bp2 = new BoxPane();
    setStyles(bp2, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp2.add(new Label("Y:"));
    bp2.add(sp2);
    r2.add(bp2);
    tp.getRows().add(r1);
    tp.getRows().add(r2);
    r3.add(new Label("   Max X=507"));
    r3.add(new Label("   Max Y=269"));
    tp.getRows().add(r3);
    bp.add(image);
    bp.add(tp);
    pb1.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    pb2.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                String xOffset = (String) sp1.getSelectedItem();
                String yOffset = (String) sp2.getSelectedItem();
                String viewBox = String.format("%1$s %2$s 2368 1652", xOffset, yOffset);
                root.setAttribute("viewBox", AnimationElement.AT_XML, viewBox);
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    window.setContent(bp);
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Drawing(org.apache.pivot.wtk.media.Drawing) Spinner(org.apache.pivot.wtk.Spinner) SVGException(com.kitfox.svg.SVGException) Label(org.apache.pivot.wtk.Label) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ImageView(org.apache.pivot.wtk.ImageView) SVGElementException(com.kitfox.svg.SVGElementException) PushButton(org.apache.pivot.wtk.PushButton) TablePane(org.apache.pivot.wtk.TablePane)

Example 2 with Spinner

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

the class TerraSpinnerSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Spinner spinner = (Spinner) component;
    spinner.getSpinnerListeners().add(this);
    spinner.getSpinnerSelectionListeners().add(this);
    spinner.add(spinnerContent);
    spinner.add(upButton);
    spinner.add(downButton);
}
Also used : Spinner(org.apache.pivot.wtk.Spinner)

Example 3 with Spinner

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

the class LabelAntialiasTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) {
    window = new Window();
    showFontDesktopHints();
    showFontFamilies();
    TablePane content = new TablePane();
    new TablePane.Column(content, 1, true);
    BoxPane topBox = new BoxPane(Orientation.HORIZONTAL);
    topBox.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    topBox.add(new Label("Rotation angle:"));
    rotationAngleSpinner = new Spinner(new NumericSpinnerData(0, 359));
    rotationAngleSpinner.setCircular(true);
    rotationAngleSpinner.setPreferredWidth(40);
    topBox.add(rotationAngleSpinner);
    TablePane.Row topRow = new TablePane.Row(content, -1);
    topRow.add(topBox);
    labelRow = new TablePane.Row(content, 1, true);
    window.setContent(content);
    window.setTitle("Label Antialiasing Test");
    window.setMaximized(true);
    rotationAngleSpinner.getSpinnerSelectionListeners().add(new SpinnerSelectionListener() {

        @Override
        public void selectedItemChanged(Spinner spinner, Object previousSelectedItem) {
            currentRotationAngle = (Integer) spinner.getSelectedItem();
            if (labelRow.getLength() > 0) {
                labelRow.remove(0, labelRow.getLength());
            }
            labelRow.add(buildLabel(currentRotationAngle));
        }
    });
    rotationAngleSpinner.setSelectedItem(45);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Spinner(org.apache.pivot.wtk.Spinner) SpinnerSelectionListener(org.apache.pivot.wtk.SpinnerSelectionListener) Label(org.apache.pivot.wtk.Label) NumericSpinnerData(org.apache.pivot.wtk.content.NumericSpinnerData) BoxPane(org.apache.pivot.wtk.BoxPane) TablePane(org.apache.pivot.wtk.TablePane)

Example 4 with Spinner

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

Aggregations

Spinner (org.apache.pivot.wtk.Spinner)4 BoxPane (org.apache.pivot.wtk.BoxPane)3 TablePane (org.apache.pivot.wtk.TablePane)3 Button (org.apache.pivot.wtk.Button)2 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)2 Label (org.apache.pivot.wtk.Label)2 PushButton (org.apache.pivot.wtk.PushButton)2 SpinnerSelectionListener (org.apache.pivot.wtk.SpinnerSelectionListener)2 Window (org.apache.pivot.wtk.Window)2 NumericSpinnerData (org.apache.pivot.wtk.content.NumericSpinnerData)2 SVGElementException (com.kitfox.svg.SVGElementException)1 SVGException (com.kitfox.svg.SVGException)1 Color (java.awt.Color)1 ColorChooserButton (org.apache.pivot.wtk.ColorChooserButton)1 ColorChooserButtonSelectionListener (org.apache.pivot.wtk.ColorChooserButtonSelectionListener)1 Component (org.apache.pivot.wtk.Component)1 ImageView (org.apache.pivot.wtk.ImageView)1 Theme (org.apache.pivot.wtk.Theme)1 SpinnerItemRenderer (org.apache.pivot.wtk.content.SpinnerItemRenderer)1 Drawing (org.apache.pivot.wtk.media.Drawing)1