private void setFillOverride(Paint fillOverride) {
   if (fillOverride instanceof Color) {
     Color c = (Color) fillOverride;
     progress.setStyle(
         "-fx-background-color: rgba("
             + ((int) (255 * c.getRed()))
             + ","
             + ""
             + ((int) (255 * c.getGreen()))
             + ","
             + ((int) (255 * c.getBlue()))
             + ","
             + ""
             + c.getOpacity()
             + ");");
   } else {
     progress.setStyle(null);
   }
 }
 private void rebuild() {
   // update indeterminate indicator
   final int segments = skin.indeterminateSegmentCount.get();
   opacities.clear();
   pathsG.getChildren().clear();
   final double step = 0.8 / (segments - 1);
   for (int i = 0; i < segments; i++) {
     Region region = new Region();
     region.setScaleShape(false);
     region.setCenterShape(false);
     region.getStyleClass().addAll("segment", "segment" + i);
     if (fillOverride instanceof Color) {
       Color c = (Color) fillOverride;
       region.setStyle(
           "-fx-background-color: rgba("
               + ((int) (255 * c.getRed()))
               + ","
               + ""
               + ((int) (255 * c.getGreen()))
               + ","
               + ((int) (255 * c.getBlue()))
               + ","
               + ""
               + c.getOpacity()
               + ");");
     } else {
       region.setStyle(null);
     }
     double opacity = Math.min(1, i * step);
     opacities.add(opacity);
     region.setOpacity(opacity);
     pathsG.getChildren().add(region);
   }
 }
Beispiel #3
0
 @Override
 public void encode(DataOutputStream os, Color c) throws IOException {
   os.writeDouble(c.getRed());
   os.writeDouble(c.getGreen());
   os.writeDouble(c.getBlue());
   os.writeDouble(c.getOpacity());
 }
 private String formatWebColor(Color c) {
   String r = Integer.toHexString((int) (c.getRed() * 255));
   if (r.length() == 1) r = "0" + r;
   String g = Integer.toHexString((int) (c.getGreen() * 255));
   if (g.length() == 1) g = "0" + g;
   String b = Integer.toHexString((int) (c.getBlue() * 255));
   if (b.length() == 1) b = "0" + b;
   return "#" + r + g + b;
 }
Beispiel #5
0
  public void write(DataOutputStream dis) throws IOException {
    dis.writeDouble(X1);
    dis.writeDouble(Y1);
    dis.writeDouble(X2);
    dis.writeDouble(Y2);

    dis.writeDouble(color.getRed());
    dis.writeDouble(color.getGreen());
    dis.writeDouble(color.getBlue());
  }
 public static String encodeColorToRGBA(Color color) {
   final String result;
   if (color == null) {
     result = "null"; // NOI18N
   } else {
     final int red = (int) (color.getRed() * 255);
     final int green = (int) (color.getGreen() * 255);
     final int blue = (int) (color.getBlue() * 255);
     result = "rgba(" + red + "," + green + "," + blue + "," + color.getOpacity() + ")"; // NOI18N
   }
   return result;
 }
Beispiel #7
0
 @Override
 public String toString() {
   return X1
       + " "
       + Y1
       + " "
       + X2
       + " "
       + Y2
       + " "
       + color.getRed()
       + " "
       + color.getGreen()
       + " "
       + color.getBlue();
 }
  /*
   * Private
   */
  private static String makeColorEncoding(Color c) {
    final int red, green, blue, alpha;
    final String result;

    red = (int) Math.round(c.getRed() * 255.0);
    green = (int) Math.round(c.getGreen() * 255.0);
    blue = (int) Math.round(c.getBlue() * 255.0);
    alpha = (int) Math.round(c.getOpacity() * 255.0);
    if (alpha == 255) {
      result = String.format((Locale) null, "#%02x%02x%02x", red, green, blue); // NOI18N
    } else {
      result = String.format((Locale) null, "#%02x%02x%02x%02x", red, green, blue, alpha); // NOI18N
    }

    return result;
  }
Beispiel #9
0
 private static void setRGBMatrix() {
   int height = (int) image.getHeight();
   int width = (int) image.getWidth();
   imgR = new double[width][height];
   imgG = new double[width][height];
   imgB = new double[width][height];
   PixelReader reader = image.getPixelReader();
   for (int readY = 0; readY < height; readY++) {
     for (int readX = 0; readX < width; readX++) {
       Color color = reader.getColor(readX, readY);
       imgG[readX][readY] = color.getGreen();
       imgB[readX][readY] = color.getBlue();
       imgR[readX][readY] = color.getRed();
     }
   }
 }
Beispiel #10
0
 private void updateSectionColors() {
   int listSize = sections.size();
   sectionColorMap.clear();
   for (int i = 0; i < listSize; i++) {
     Color sectionColor = sections.get(i).getColor();
     Color lcdForegroundColor;
     if (Helper.isMonochrome(sectionColor)) {
       lcdForegroundColor = Helper.isDark(sectionColor) ? Color.WHITE : Color.BLACK;
     } else {
       lcdForegroundColor =
           Color.hsb(
               sectionColor.getHue(),
               sectionColor.getSaturation(),
               sectionColor.getBrightness() * 0.3);
     }
     Color lcdBackgroundColor =
         Color.color(sectionColor.getRed(), sectionColor.getGreen(), sectionColor.getBlue(), 0.1);
     sectionColorMap.put(
         sections.get(i), getSectionColors(lcdBackgroundColor, lcdForegroundColor));
   }
 }
Beispiel #11
0
  private Color[] getSectionColors(
      final Color LCD_BACKGROUND_COLOR, final Color LCD_FOREGROUND_COLOR) {
    double hue = LCD_BACKGROUND_COLOR.getHue();
    double sat = LCD_BACKGROUND_COLOR.getSaturation();

    Color[] colors;
    if (Helper.isMonochrome(LCD_BACKGROUND_COLOR)) {
      // Section color is monochrome
      colors =
          new Color[] {
            Color.hsb(hue, 0, 0.69),
            Color.hsb(hue, 0, 1.0),
            Color.hsb(hue, 0, 0.76),
            Color.hsb(hue, 0, 0.76),
            Color.hsb(hue, sat, 0.69),
            Helper.isDark(LCD_BACKGROUND_COLOR) ? Color.WHITE : Color.BLACK,
            Helper.isDark(LCD_BACKGROUND_COLOR)
                ? Color.rgb(255, 255, 255, 0.1)
                : Color.rgb(0, 0, 0, 0.1)
          };
    } else {
      // Section color is not monochrome
      colors =
          new Color[] {
            Color.hsb(hue, sat, 0.69),
            Color.hsb(hue, sat, 1.0),
            Color.hsb(hue, sat, 0.76),
            Color.hsb(hue, sat, 0.76),
            Color.hsb(hue, sat, 0.69),
            LCD_FOREGROUND_COLOR,
            Color.color(
                LCD_BACKGROUND_COLOR.getRed(),
                LCD_BACKGROUND_COLOR.getGreen(),
                LCD_BACKGROUND_COLOR.getBlue(),
                0.1)
          };
    }
    return colors;
  }
  public static int[][] convertImageTo2DIntArray(Image image, int width, int height) {

    int[][] returnArray = new int[height][width];

    // Obtain PixelReader
    PixelReader pixelReader = image.getPixelReader();

    int xSegmentLength = divideAByBThenRoundDown(image.getWidth(), width);
    int ySegmentLength = divideAByBThenRoundDown(image.getHeight(), height);

    BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null);

    for (int row = 0; row < height; row++) {

      for (int column = 0; column < width; column++) {

        BufferedImage tempBufferedImage =
            bufferedImage.getSubimage(
                xSegmentLength * column, ySegmentLength * row, xSegmentLength, ySegmentLength);

        Color averageColor =
            AverageColorFinder.findAverageColorFromImage(
                SwingFXUtils.toFXImage(tempBufferedImage, null));

        int argb =
            ((int) (averageColor.getOpacity() * 255) << 24)
                | ((int) (averageColor.getRed() * 255) << 16)
                | ((int) (averageColor.getGreen() * 255) << 8)
                | ((int) (averageColor.getBlue() * 255));

        returnArray[row][column] = argb;
      }
    }

    return returnArray;
  }
Beispiel #13
0
  private void updateLcdDesign(final double HEIGHT) {
    LcdDesign lcdDesign = getSkinnable().getLcdDesign();
    Color[] lcdColors = lcdDesign.getColors();

    if (LcdDesign.SECTIONS == lcdDesign) {
      double currentValue = getSkinnable().getCurrentValue();
      int listSize = sections.size();
      for (int i = 0; i < listSize; i++) {
        Section section = sections.get(i);
        if (section.contains(currentValue)) {
          lcdColors = sectionColorMap.get(section);
          break;
        }
      }
    }

    lcdPaint =
        new LinearGradient(
            0,
            1,
            0,
            HEIGHT - 1,
            false,
            CycleMethod.NO_CYCLE,
            new Stop(0, lcdColors[0]),
            new Stop(0.03, lcdColors[1]),
            new Stop(0.5, lcdColors[2]),
            new Stop(0.5, lcdColors[3]),
            new Stop(1.0, lcdColors[4]));
    if (lcdDesign.name().startsWith("FLAT")) {
      lcdFramePaint = getSkinnable().getBorderPaint();

      lcdPaint = getSkinnable().getBackgroundPaint();

      Color lcdForegroundColor = (Color) getSkinnable().getForegroundPaint();
      backgroundText.setFill(
          Color.color(
              lcdForegroundColor.getRed(),
              lcdForegroundColor.getGreen(),
              lcdForegroundColor.getBlue(),
              0.1));
      valueText.setFill(lcdForegroundColor);
      upperLeftText.setFill(lcdForegroundColor);
      title.setFill(lcdForegroundColor);
      upperRightText.setFill(lcdForegroundColor);
      unitText.setFill(lcdForegroundColor);
      lowerRightText.setFill(lcdForegroundColor);
      lowerCenterText.setFill(lcdForegroundColor);
      threshold.setFill(lcdForegroundColor);
    } else {
      lcdFramePaint =
          new LinearGradient(
              0,
              0.02083333 * height,
              0,
              HEIGHT - 0.02083333 * HEIGHT,
              false,
              CycleMethod.NO_CYCLE,
              new Stop(0.0, Color.rgb(26, 26, 26)),
              new Stop(0.015, Color.rgb(77, 77, 77)),
              new Stop(0.985, Color.rgb(77, 77, 77)),
              new Stop(1.0, Color.rgb(221, 221, 221)));

      lcdPaint =
          new LinearGradient(
              0,
              1,
              0,
              HEIGHT - 1,
              false,
              CycleMethod.NO_CYCLE,
              new Stop(0, lcdColors[0]),
              new Stop(0.03, lcdColors[1]),
              new Stop(0.5, lcdColors[2]),
              new Stop(0.5, lcdColors[3]),
              new Stop(1.0, lcdColors[4]));

      backgroundText.setFill(lcdDesign.lcdBackgroundColor);
      valueText.setFill(lcdDesign.lcdForegroundColor);
      upperLeftText.setFill(lcdDesign.lcdForegroundColor);
      title.setFill(lcdDesign.lcdForegroundColor);
      upperRightText.setFill(lcdDesign.lcdForegroundColor);
      unitText.setFill(lcdDesign.lcdForegroundColor);
      lowerRightText.setFill(lcdDesign.lcdForegroundColor);
      lowerCenterText.setFill(lcdDesign.lcdForegroundColor);
      threshold.setFill(lcdDesign.lcdForegroundColor);
    }

    pane.setBackground(
        new Background(
            new BackgroundFill(lcdPaint, new CornerRadii(0.10416667 * HEIGHT), Insets.EMPTY)));
    pane.setBorder(
        new Border(
            new BorderStroke(
                lcdFramePaint,
                BorderStrokeStyle.SOLID,
                new CornerRadii(0.05 * HEIGHT),
                new BorderWidths(0.02083333 * HEIGHT))));
  }
Beispiel #14
0
 private static String cssColor(Color color) {
   int red = (int) (color.getRed() * 255);
   int green = (int) (color.getGreen() * 255);
   int blue = (int) (color.getBlue() * 255);
   return "rgb(" + red + ", " + green + ", " + blue + ")";
 }
 /**
  * @param color JavaFX color
  * @return AWT Color
  */
 final java.awt.Color scene2awtColor(javafx.scene.paint.Color color) {
   return new java.awt.Color(
       (float) color.getRed(), (float) color.getGreen(), (float) color.getBlue());
 }
Beispiel #16
0
  private void resize() {
    width =
        getSkinnable().getWidth()
            - getSkinnable().getInsets().getLeft()
            - getSkinnable().getInsets().getRight();
    height =
        getSkinnable().getHeight()
            - getSkinnable().getInsets().getTop()
            - getSkinnable().getInsets().getBottom();

    if (width > 0 && height > 0) {
      orientation = getSkinnable().getOrientation();

      double currentValue = getSkinnable().getCurrentValue();
      Color tickMarkColor = getSkinnable().getTickMarkColor();
      Color barBorderColor =
          Color.color(
              tickMarkColor.getRed(), tickMarkColor.getGreen(), tickMarkColor.getBlue(), 0.5);
      boolean isFlatLed = LedType.FLAT == getSkinnable().getLedType();

      if (Orientation.VERTICAL == orientation) {
        width = height / aspectRatio;
        size = width < height ? width : height;
        stepSize = Math.abs((0.66793 * height) / getSkinnable().getRange());

        pane.setMaxSize(width, height);
        pane.relocate(
            (getSkinnable().getWidth() - width) * 0.5, (getSkinnable().getHeight() - height) * 0.5);

        barBackground.setWidth(0.14286 * width);
        barBackground.setHeight(0.67143 * height);
        barBackground.relocate(
            (width - barBackground.getWidth()) * 0.5, (height - barBackground.getHeight()) * 0.5);
        barBackground.setStroke(null);
        barBackground.setFill(
            new LinearGradient(
                0,
                barBackground.getLayoutBounds().getMinY(),
                0,
                barBackground.getLayoutBounds().getMaxY(),
                false,
                CycleMethod.NO_CYCLE,
                new Stop(0.0, Color.rgb(255, 255, 255, 0.05)),
                new Stop(0.5, Color.rgb(255, 255, 255, 0.15)),
                new Stop(1.0, Color.rgb(255, 255, 255, 0.05))));

        minValuePosition = barBackground.getLayoutY() + barBackground.getLayoutBounds().getHeight();
        maxValuePosition = barBackground.getLayoutY();
        zeroPosition = minValuePosition + getSkinnable().getMinValue() * stepSize;
        zeroPosition = zeroPosition > minValuePosition ? minValuePosition : zeroPosition;

        barBorder1.setStartX(barBackground.getLayoutX() - 1);
        barBorder1.setStartY(maxValuePosition);
        barBorder1.setEndX(barBackground.getLayoutX() - 1);
        barBorder1.setEndY(minValuePosition);
        barBorder2.setStartX(
            barBackground.getLayoutX() + barBackground.getLayoutBounds().getWidth() + 1);
        barBorder2.setStartY(maxValuePosition);
        barBorder2.setEndX(
            barBackground.getLayoutX() + barBackground.getLayoutBounds().getWidth() + 1);
        barBorder2.setEndY(minValuePosition);

        barBorder1.setStroke(barBorderColor);
        barBorder2.setStroke(barBorderColor);

        bar.setWidth(0.14286 * width);
        bar.setTranslateX((width - bar.getWidth()) * 0.5);
        bar.setTranslateY(getSkinnable().isStartFromZero() ? zeroPosition : minValuePosition);

        barHighlight.setWidth(bar.getWidth());
        barHighlight.setTranslateX(bar.getTranslateX());
        barHighlight.setTranslateY(bar.getTranslateY());

        setBar(currentValue);

        ticksAndSectionsCanvas.setCache(false);
        ticksAndSectionsCanvas.setWidth(height / aspectRatio);
        ticksAndSectionsCanvas.setHeight(height);
        ticksAndSections.clearRect(
            0, 0, ticksAndSectionsCanvas.getWidth(), ticksAndSectionsCanvas.getHeight());
        drawTickMarks(ticksAndSections);
        ticksAndSectionsCanvas.setCache(true);
        ticksAndSectionsCanvas.setCacheHint(CacheHint.QUALITY);

        ledSize = isFlatLed ? 0.08 * width : 0.09 * width;
        ledCanvas.setWidth(ledSize);
        ledCanvas.setHeight(ledSize);
        ledCanvas.relocate((width - ledSize) * 0.5, 0.12 * height);
        ledOffShadow =
            isFlatLed
                ? null
                : new InnerShadow(
                    BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * ledSize, 0, 0, 0);
        ledOnShadow =
            isFlatLed
                ? null
                : new InnerShadow(
                    BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * ledSize, 0, 0, 0);
        if (!isFlatLed)
          ledOnShadow.setInput(
              new DropShadow(
                  BlurType.TWO_PASS_BOX, getSkinnable().getLedColor(), 0.36 * ledSize, 0, 0, 0));

        lcd.setWidth(0.8 * width);
        lcd.setHeight(0.22 * width);
        lcd.setArcWidth(0.0125 * size);
        lcd.setArcHeight(0.0125 * size);
        lcd.relocate((width - lcd.getWidth()) * 0.5, 0.87 * height);
      } else {
        height = width / aspectRatio;
        size = width < height ? width : height;
        stepSize = Math.abs(0.9 * width / getSkinnable().getRange());

        pane.setMaxSize(width, height);
        pane.relocate(
            (getSkinnable().getWidth() - width) * 0.5, (getSkinnable().getHeight() - height) * 0.5);

        barBackground.setWidth(0.9 * width);
        barBackground.setHeight(0.14286 * height);
        barBackground.relocate(
            (width - barBackground.getWidth()) * 0.5, (height - barBackground.getHeight()) * 0.5);
        barBackground.setStroke(null);
        barBackground.setFill(
            new LinearGradient(
                barBackground.getLayoutBounds().getMinX(),
                0,
                barBackground.getLayoutBounds().getMaxX(),
                0,
                false,
                CycleMethod.NO_CYCLE,
                new Stop(0.0, Color.rgb(255, 255, 255, 0.05)),
                new Stop(0.5, Color.rgb(255, 255, 255, 0.15)),
                new Stop(1.0, Color.rgb(255, 255, 255, 0.05))));

        minValuePosition = barBackground.getLayoutX();
        maxValuePosition = barBackground.getLayoutX() + barBackground.getLayoutBounds().getWidth();
        zeroPosition = minValuePosition - getSkinnable().getMinValue() * stepSize;
        zeroPosition = zeroPosition < minValuePosition ? minValuePosition : zeroPosition;

        barBorder1.setStartX(minValuePosition);
        barBorder1.setStartY(barBackground.getLayoutY() - 1);
        barBorder1.setEndX(maxValuePosition);
        barBorder1.setEndY(barBackground.getLayoutY() - 1);
        barBorder2.setStartX(minValuePosition);
        barBorder2.setStartY(
            barBackground.getLayoutY() + barBackground.getLayoutBounds().getHeight() + 1);
        barBorder2.setEndX(maxValuePosition);
        barBorder2.setEndY(
            barBackground.getLayoutY() + barBackground.getLayoutBounds().getHeight() + 1);

        barBorder1.setStroke(barBorderColor);
        barBorder2.setStroke(barBorderColor);

        bar.setHeight(0.14286 * height);
        bar.setTranslateX(getSkinnable().isStartFromZero() ? zeroPosition : minValuePosition);
        bar.setTranslateY((height - bar.getHeight()) * 0.5);

        barHighlight.setHeight(bar.getHeight());
        barHighlight.setTranslateX(bar.getTranslateX());
        barHighlight.setTranslateY(bar.getTranslateY());

        setBar(currentValue);

        ticksAndSectionsCanvas.setCache(false);
        ticksAndSectionsCanvas.setWidth(width);
        ticksAndSectionsCanvas.setHeight(height);
        ticksAndSections.clearRect(
            0, 0, ticksAndSectionsCanvas.getWidth(), ticksAndSectionsCanvas.getHeight());
        drawTickMarks(ticksAndSections);
        ticksAndSectionsCanvas.setCache(true);
        ticksAndSectionsCanvas.setCacheHint(CacheHint.QUALITY);

        ledSize = isFlatLed ? 0.08 * height : 0.09 * height;
        ledCanvas.setWidth(ledSize);
        ledCanvas.setHeight(ledSize);
        ledCanvas.relocate(0.955 * width, (height - ledSize) * 0.5);
        ledOffShadow =
            isFlatLed
                ? null
                : new InnerShadow(
                    BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * ledSize, 0, 0, 0);
        ledOnShadow =
            isFlatLed
                ? null
                : new InnerShadow(
                    BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * ledSize, 0, 0, 0);
        if (!isFlatLed)
          ledOnShadow.setInput(
              new DropShadow(
                  BlurType.TWO_PASS_BOX, getSkinnable().getLedColor(), 0.36 * ledSize, 0, 0, 0));

        lcd.setWidth(0.3 * width);
        lcd.setHeight(0.22 * height);
        lcd.setArcWidth(0.0125 * size);
        lcd.setArcHeight(0.0125 * size);
        lcd.relocate((width - lcd.getWidth()) - 0.03571429 * height, 0.03571429 * height);
      }

      resizeText();
    }
  }