Package com.vaadin.shared.ui.colorpicker

Examples of com.vaadin.shared.ui.colorpicker.Color


                            .getValue().toString())) / 100f;
                    float value = (Float.parseFloat(valueSlider.getValue()
                            .toString())) / 100f;

                    // Set the color
                    Color color = new Color(Color.HSVtoRGB(hue, saturation,
                            value));
                    setColor(color);

                    /*
                     * Set the background color of the hue gradient. This has to
                     * be done here since in the conversion the base color
                     * information is lost when color is black/white
                     */
                    Color bgColor = new Color(Color.HSVtoRGB(hue, 1f, 1f));
                    hsvGradient.setBackgroundColor(bgColor);
                }
            }
        });
        sliders.addComponent(hueSlider);

        saturationSlider.setStyleName("hsv-slider");
        saturationSlider.setWidth("220px");
        saturationSlider.setImmediate(true);
        saturationSlider.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (!updatingColors) {
                    float hue = (Float.parseFloat(hueSlider.getValue()
                            .toString())) / 360f;
                    float saturation = (Float.parseFloat(event.getProperty()
                            .getValue().toString())) / 100f;
                    float value = (Float.parseFloat(valueSlider.getValue()
                            .toString())) / 100f;
                    Color color = new Color(Color.HSVtoRGB(hue, saturation,
                            value));
                    setColor(color);
                }
            }
        });
        sliders.addComponent(saturationSlider);

        valueSlider.setStyleName("hsv-slider");
        valueSlider.setWidth("220px");
        valueSlider.setImmediate(true);
        valueSlider.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (!updatingColors) {
                    float hue = (Float.parseFloat(hueSlider.getValue()
                            .toString())) / 360f;
                    float saturation = (Float.parseFloat(saturationSlider
                            .getValue().toString())) / 100f;
                    float value = (Float.parseFloat(event.getProperty()
                            .getValue().toString())) / 100f;

                    Color color = new Color(Color.HSVtoRGB(hue, saturation,
                            value));
                    setColor(color);
                }
            }
        });
View Full Code Here


                if (value.length() == 7 && value.startsWith("#")) {
                    // CSS color format (e.g. #000000)
                    int red = Integer.parseInt(value.substring(1, 3), 16);
                    int green = Integer.parseInt(value.substring(3, 5), 16);
                    int blue = Integer.parseInt(value.substring(5, 7), 16);
                    color = new Color(red, green, blue);

                } else if (value.startsWith("rgb")) {
                    // RGB color format rgb/rgba(255,255,255,0.1)
                    String[] colors = value.substring(value.indexOf("(") + 1,
                            value.length() - 1).split(",");

                    int red = Integer.parseInt(colors[0]);
                    int green = Integer.parseInt(colors[1]);
                    int blue = Integer.parseInt(colors[2]);
                    if (colors.length > 3) {
                        int alpha = (int) (Double.parseDouble(colors[3]) * 255d);
                        color = new Color(red, green, blue, alpha);
                    } else {
                        color = new Color(red, green, blue);
                    }

                } else if (value.startsWith("hsl")) {
                    // HSL color format hsl/hsla(100,50%,50%,1.0)
                    String[] colors = value.substring(value.indexOf("(") + 1,
                            value.length() - 1).split(",");

                    int hue = Integer.parseInt(colors[0]);
                    int saturation = Integer.parseInt(colors[1]
                            .replace("%", ""));
                    int lightness = Integer
                            .parseInt(colors[2].replace("%", ""));
                    int rgb = Color.HSLtoRGB(hue, saturation, lightness);

                    if (colors.length > 3) {
                        int alpha = (int) (Double.parseDouble(colors[3]) * 255d);
                        color = new Color(rgb);
                        color.setAlpha(alpha);
                    } else {
                        color = new Color(rgb);
                    }
                }

                oldValue = value;
                fireEvent(new ColorChangeEvent((Component) field.getData(),
View Full Code Here

        TestIcon testIcon = new TestIcon(40);

        ColorPicker cp = new ColorPicker();
        cp.setDefaultCaptionEnabled(true);
        cp.setIcon(testIcon.get());
        cp.setColor(new Color(138, 73, 115));
        row.addComponent(cp);

        cp = new ColorPicker();
        cp.setPopupStyle(PopupStyle.POPUP_SIMPLE);
        cp.setTextfieldVisibility(true);
View Full Code Here

        if (value != null && value.length() == 7) {
            int red = Integer.parseInt(value.substring(1, 3), 16);
            int green = Integer.parseInt(value.substring(3, 5), 16);
            int blue = Integer.parseInt(value.substring(5, 7), 16);
            color = new Color(red, green, blue);

            fireEvent(new ColorChangeEvent((Component) field.getData(), color));
        }
    }
View Full Code Here

            String[] colors = new String[changedColors.size()];
            String[] XCoords = new String[changedColors.size()];
            String[] YCoords = new String[changedColors.size()];
            int counter = 0;
            for (Point p : changedColors.keySet()) {
                Color c = changedColors.get(p);
                if (c == null) {
                    continue;
                }

                String color = c.getCSS();

                colors[counter] = color;
                XCoords[counter] = String.valueOf((int) p.getX());
                YCoords[counter] = String.valueOf((int) p.getY());
                counter++;
View Full Code Here

                        saturation = ((row + 1f) / (rows / 2f));
                    } else {
                        value = 1f - ((row - (rows / 2f)) / (rows / 2f));
                    }

                    colors[row][col] = new Color(Color.HSVtoRGB(hue,
                            saturation, value));
                }

                // The last row should have the black&white gradient
                else {
                    float hue = 0f;
                    float saturation = 0f;
                    float value = 1f - ((float) col / (float) columns);

                    colors[row][col] = new Color(Color.HSVtoRGB(hue,
                            saturation, value));
                }
            }
        }
View Full Code Here

                    index -= ((rows * columns) / 2);
                    value = 1f - index
                            / (((float) rows * (float) columns) / 2f);
                }

                colors[row][col] = new Color(Color.HSVtoRGB(hue, saturation,
                        value));
            }
        }

        return colors;
View Full Code Here

        }

        if (event.getProperty().getValue() == ColorRangePropertyId.ALL) {
            grid.setColorGrid(createAllColors(14, 10));
        } else if (event.getProperty().getValue() == ColorRangePropertyId.RED) {
            grid.setColorGrid(createColors(new Color(0xFF, 0, 0), 14, 10));
        } else if (event.getProperty().getValue() == ColorRangePropertyId.GREEN) {
            grid.setColorGrid(createColors(new Color(0, 0xFF, 0), 14, 10));
        } else if (event.getProperty().getValue() == ColorRangePropertyId.BLUE) {
            grid.setColorGrid(createColors(new Color(0, 0, 0xFF), 14, 10));
        }
    }
View Full Code Here

        redSlider.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                double red = (Double) event.getProperty().getValue();
                if (!updatingColors) {
                    Color newColor = new Color((int) red, selectedColor
                            .getGreen(), selectedColor.getBlue());
                    setColor(newColor);
                }
            }
        });

        sliders.addComponent(redSlider);

        greenSlider.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                double green = (Double) event.getProperty().getValue();
                if (!updatingColors) {
                    Color newColor = new Color(selectedColor.getRed(),
                            (int) green, selectedColor.getBlue());
                    setColor(newColor);
                }
            }
        });
        sliders.addComponent(greenSlider);

        blueSlider.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                double blue = (Double) event.getProperty().getValue();
                if (!updatingColors) {
                    Color newColor = new Color(selectedColor.getRed(),
                            selectedColor.getGreen(), (int) blue);
                    setColor(newColor);
                }
            }
        });
View Full Code Here

                            .getValue().toString())) / 100f;
                    float value = (Float.parseFloat(valueSlider.getValue()
                            .toString())) / 100f;

                    // Set the color
                    Color color = new Color(Color.HSVtoRGB(hue, saturation,
                            value));
                    setColor(color);

                    /*
                     * Set the background color of the hue gradient. This has to
                     * be done here since in the conversion the base color
                     * information is lost when color is black/white
                     */
                    Color bgColor = new Color(Color.HSVtoRGB(hue, 1f, 1f));
                    hsvGradient.setBackgroundColor(bgColor);
                }
            }
        });
        sliders.addComponent(hueSlider);

        saturationSlider.setStyleName("hsv-slider");
        saturationSlider.setWidth("220px");
        saturationSlider.setImmediate(true);
        saturationSlider.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (!updatingColors) {
                    float hue = (Float.parseFloat(hueSlider.getValue()
                            .toString())) / 360f;
                    float saturation = (Float.parseFloat(event.getProperty()
                            .getValue().toString())) / 100f;
                    float value = (Float.parseFloat(valueSlider.getValue()
                            .toString())) / 100f;
                    Color color = new Color(Color.HSVtoRGB(hue, saturation,
                            value));
                    setColor(color);
                }
            }
        });
        sliders.addComponent(saturationSlider);

        valueSlider.setStyleName("hsv-slider");
        valueSlider.setWidth("220px");
        valueSlider.setImmediate(true);
        valueSlider.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (!updatingColors) {
                    float hue = (Float.parseFloat(hueSlider.getValue()
                            .toString())) / 360f;
                    float saturation = (Float.parseFloat(saturationSlider
                            .getValue().toString())) / 100f;
                    float value = (Float.parseFloat(event.getProperty()
                            .getValue().toString())) / 100f;

                    Color color = new Color(Color.HSVtoRGB(hue, saturation,
                            value));
                    setColor(color);
                }
            }
        });
View Full Code Here

TOP

Related Classes of com.vaadin.shared.ui.colorpicker.Color

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.