/**
   * Compute a contrasting background color to draw the label's outline.
   *
   * @param color Label color.
   * @return A color that contrasts with {@code color}.
   */
  protected Color computeBackgroundColor(Color color) {
    float[] colorArray = new float[4];
    Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), colorArray);

    if (colorArray[2] > 0.5) return new Color(0, 0, 0, 0.7f);
    else return new Color(1, 1, 1, 0.7f);
  }
Example #2
0
 // Compute background color for best contrast
 private Color getBackgroundColor(Color color) {
   Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), compArray);
   if (compArray[2] > 0.5) return new Color(0, 0, 0, 0.7f);
   else return new Color(1, 1, 1, 0.7f);
 }