Search in sources :

Example 6 with ColorChooserButton

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

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

the class ColorChooserButtonSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    ColorChooserButton colorChooserButton = (ColorChooserButton) component;
    colorChooserButton.getColorChooserButtonSelectionListeners().add(this);
}
Also used : ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton)

Example 8 with ColorChooserButton

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

the class TerraColorChooserButtonSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    ColorChooserButton colorChooserButton = (ColorChooserButton) getComponent();
    int width = getWidth();
    int height = getHeight();
    Color backgroundColorLocal = null;
    Color bevelColorLocal = null;
    Color borderColorLocal = null;
    if (colorChooserButton.isEnabled()) {
        backgroundColorLocal = this.backgroundColor;
        bevelColorLocal = (pressed || (colorChooserPopup.isOpen() && !colorChooserPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
        borderColorLocal = this.borderColor;
    } else {
        backgroundColorLocal = disabledBackgroundColor;
        bevelColorLocal = disabledBevelColor;
        borderColorLocal = disabledBorderColor;
    }
    // Paint the background
    GraphicsUtilities.setAntialiasingOn(graphics);
    if (!themeIsFlat()) {
        graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height / 2f, backgroundColorLocal));
    } else {
        graphics.setPaint(backgroundColorLocal);
    }
    graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
    // Paint the content
    GraphicsUtilities.setAntialiasingOff(graphics);
    Bounds contentBounds = new Bounds(0, 0, Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(height - 1, 0));
    Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
    dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);
    dataRenderer.setSize(Math.max(contentBounds.width - (padding.getWidth() + 2) + 1, 0), Math.max(contentBounds.height - (padding.getHeight() + 2) + 1, 0));
    Graphics2D contentGraphics = (Graphics2D) graphics.create();
    contentGraphics.translate(padding.left + 1, padding.top + 1);
    contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
    dataRenderer.paint(contentGraphics);
    contentGraphics.dispose();
    GraphicsUtilities.setAntialiasingOn(graphics);
    if (!themeIsFlat()) {
        // Paint the border
        if (borderColorLocal != null) {
            graphics.setPaint(borderColorLocal);
            graphics.setStroke(new BasicStroke(1));
            graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
        }
    }
    // Paint the focus state
    if (colorChooserButton.isFocused()) {
        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(this.borderColor);
        graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(width - 5, 0), Math.max(height - 5, 0), CORNER_RADIUS / 2, CORNER_RADIUS / 2));
    }
    GraphicsUtilities.setAntialiasingOff(graphics);
    // Paint the trigger
    GeneralPath triggerIconShape = new GeneralPath(Path2D.WIND_EVEN_ODD);
    triggerIconShape.moveTo(0, 0);
    triggerIconShape.lineTo(3, 3);
    triggerIconShape.lineTo(6, 0);
    triggerIconShape.closePath();
    Graphics2D triggerGraphics = (Graphics2D) graphics.create();
    triggerGraphics.setStroke(new BasicStroke(0));
    triggerGraphics.setPaint(color);
    Bounds triggerBounds = new Bounds(Math.max(width - (padding.right + TRIGGER_WIDTH), 0), 0, TRIGGER_WIDTH, Math.max(height - padding.getHeight(), 0));
    int tx = triggerBounds.x + (triggerBounds.width - triggerIconShape.getBounds().width) / 2;
    int ty = triggerBounds.y + (triggerBounds.height - triggerIconShape.getBounds().height) / 2;
    triggerGraphics.translate(tx, ty);
    triggerGraphics.draw(triggerIconShape);
    triggerGraphics.fill(triggerIconShape);
    triggerGraphics.dispose();
}
Also used : BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) Button(org.apache.pivot.wtk.Button) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 9 with ColorChooserButton

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

the class TerraColorChooserButtonSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    ColorChooserButton colorChooserButton = (ColorChooserButton) getComponent();
    Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
    dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);
    Dimensions contentSize = dataRenderer.getPreferredSize();
    int preferredWidth = contentSize.width + paddingWidth();
    int preferredHeight = contentSize.height + paddingHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) Button(org.apache.pivot.wtk.Button) Dimensions(org.apache.pivot.wtk.Dimensions) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 10 with ColorChooserButton

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

the class TerraColorChooserButtonSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    ColorChooserButton colorChooserButton = (ColorChooserButton) getComponent();
    Button.DataRenderer dataRenderer = colorChooserButton.getDataRenderer();
    dataRenderer.render(colorChooserButton.getButtonData(), colorChooserButton, false);
    int preferredHeight = dataRenderer.getPreferredHeight(-1) + paddingHeight();
    return preferredHeight;
}
Also used : ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) ColorChooserButton(org.apache.pivot.wtk.ColorChooserButton) Button(org.apache.pivot.wtk.Button) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Aggregations

ColorChooserButton (org.apache.pivot.wtk.ColorChooserButton)11 Button (org.apache.pivot.wtk.Button)7 Color (java.awt.Color)6 GradientPaint (java.awt.GradientPaint)5 Point (org.apache.pivot.wtk.Point)5 ColorChooserButtonSelectionListener (org.apache.pivot.wtk.ColorChooserButtonSelectionListener)3 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)2 PushButton (org.apache.pivot.wtk.PushButton)2 NumericSpinnerData (org.apache.pivot.wtk.content.NumericSpinnerData)2 BasicStroke (java.awt.BasicStroke)1 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 RoundRectangle2D (java.awt.geom.RoundRectangle2D)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1