コード例 #1
0
 private void validateAndUpdatePreview(JTextField src) {
   Color color;
   if (myHex.hasFocus()) {
     Color c = ColorUtil.fromHex(myHex.getText(), null);
     color = c != null ? ColorUtil.toAlpha(c, myColorWheelPanel.myColorWheel.myOpacity) : null;
   } else {
     color = gatherRGB();
   }
   if (color != null) {
     if (myColorWheelPanel.myOpacityComponent != null) {
       color = ColorUtil.toAlpha(color, myColorWheelPanel.myOpacityComponent.getValue());
     }
     updatePreview(color, src == myHex);
   }
 }
コード例 #2
0
ファイル: Tabs.java プロジェクト: NissanNut/NovaBot
 /**
  * Finds the tab that is open.
  *
  * @return The open Tab
  */
 public Tab getOpenTab() {
   Point p = ColorUtil.getPointWithColor(Game.getImage(), BOUNDS, OPEN_COLOR, 1);
   for (Tab tab : Tabs.Tab.values()) {
     if (tab.bounds.contains(p)) return tab;
   }
   return null;
 }
コード例 #3
0
ファイル: GraphicsUtil.java プロジェクト: adufour/Icy-Kernel
  /**
   * Draw multi line Hint type text in the specified Graphics context<br>
   * at the specified location.
   */
  public static void drawHint(
      Graphics2D g, String text, int x, int y, Color bgColor, Color textColor) {
    final Graphics2D g2 = (Graphics2D) g.create();

    final Rectangle2D stringRect = getStringBounds(g, text);
    // calculate hint rect
    final RoundRectangle2D backgroundRect =
        new RoundRectangle2D.Double(
            x, y, (int) (stringRect.getWidth() + 10), (int) (stringRect.getHeight() + 8), 8, 8);

    g2.setStroke(new BasicStroke(1.3f));
    // draw translucent background
    g2.setColor(bgColor);
    mixAlpha(g2, AlphaComposite.SRC_OVER, 1f / 2f);
    // g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    g2.fill(backgroundRect);
    // draw background border
    g2.setColor(ColorUtil.mix(bgColor, Color.black));
    mixAlpha(g2, AlphaComposite.SRC_OVER, 2f / 1f);
    // g2.setComposite(AlphaComposite.Src);
    g2.draw(backgroundRect);
    // draw text
    g2.setColor(textColor);
    drawString(g2, text, x + 5, y + 4, false);

    g2.dispose();
  }
コード例 #4
0
ファイル: CompositeColor.java プロジェクト: ilyessou/jhotdraw
 /**
  * Creates a color in the specified <code>ColorSpace</code> with the color components specified in
  * the <code>float</code> array and the specified alpha. The number of components is determined by
  * the type of the <code>ColorSpace</code>. For example, RGB requires 3 components, but CMYK
  * requires 4 components.
  *
  * @param cspace the <code>ColorSpace</code> to be used to interpret the components
  * @param components an arbitrary number of color components that is compatible with the <code>
  *     ColorSpace</code>
  * @param alpha alpha value
  * @throws IllegalArgumentException if any of the values in the <code>components</code> array or
  *     <code>alpha</code> is outside of the range supported by cspace.
  * @see #getComponents
  * @see #getColorComponents
  */
 public CompositeColor(ColorSpace cspace, float components[], float alpha) {
   super(((int) (alpha * 255) << 24) | ColorUtil.toRGB24(cspace, components), true);
   boolean rangeError = false;
   StringBuilder badComponentString = new StringBuilder();
   int n = cspace.getNumComponents();
   fvalue = new float[n];
   for (int i = 0; i < n; i++) {
     if (components[i] < cspace.getMinValue(i) || components[i] > cspace.getMaxValue(i)) {
       rangeError = true;
       badComponentString.append("Component ");
       badComponentString.append(i);
       badComponentString.append(' ');
     } else {
       fvalue[i] = components[i];
     }
   }
   if (alpha < 0.0 || alpha > 1.0) {
     rangeError = true;
     badComponentString.append("Alpha");
   } else {
     falpha = alpha;
   }
   if (rangeError) {
     throw new IllegalArgumentException(
         "Color parameter outside of expected range: " + badComponentString);
   }
   cs = cspace;
 }
 private void drawRoundedBackgroundWithBorders(Canvas canvas) {
   updatePath();
   int useColor = ColorUtil.multiplyColorAlpha(mColor, mAlpha);
   if ((useColor >>> 24) != 0) { // color is not transparent
     mPaint.setColor(useColor);
     mPaint.setStyle(Paint.Style.FILL);
     canvas.drawPath(mPathForBorderRadius, mPaint);
   }
   // maybe draw borders?
   float fullBorderWidth = getFullBorderWidth();
   if (fullBorderWidth > 0) {
     int borderColor = getFullBorderColor();
     mPaint.setColor(ColorUtil.multiplyColorAlpha(borderColor, mAlpha));
     mPaint.setStyle(Paint.Style.STROKE);
     mPaint.setStrokeWidth(fullBorderWidth);
     canvas.drawPath(mPathForBorderRadius, mPaint);
   }
 }
コード例 #6
0
ファイル: Menu.java プロジェクト: Thunar/Runeshark
 public static Rectangle getBounds() {
   Point[] arr = ColorUtil.findAllColorWithinTolerance(MENU, new Color(1, 1, 1));
   try {
     Point left = Calc.getLeftMax(arr);
     Point right = Calc.getRightMax(arr);
     Point high = Calc.getNorthern(arr);
     Point low = Calc.getSouthern(arr);
     return new Rectangle(left.x, high.y, right.x - left.x, low.y - high.y);
   } catch (Exception ignored) {
   }
   return null;
 }
コード例 #7
0
  protected void paintComponent(Graphics g) {
    Insets ins = new Insets(5, 5, 5, 5);
    if (colorwell != null) {
      ColorUtil.tileStretchPaint(g, this, colorwell, ins);
    }

    // 0, 23, 255  = 235o, 100%, 100%
    // 31, 0, 204 =  249o, 100%,  80%
    g.setColor(ColorUtil.removeAlpha(getBackground()));
    g.fillRect(
        ins.left, ins.top, getWidth() - ins.left - ins.right, getHeight() - ins.top - ins.bottom);
    g.setColor(ColorUtil.setBrightness(getBackground(), 0.85f));
    g.drawRect(
        ins.left,
        ins.top,
        getWidth() - ins.left - ins.right - 1,
        getHeight() - ins.top - ins.bottom - 1);
    g.drawRect(
        ins.left + 1,
        ins.top + 1,
        getWidth() - ins.left - ins.right - 3,
        getHeight() - ins.top - ins.bottom - 3);
  }
コード例 #8
0
ファイル: GraphicsUtil.java プロジェクト: adufour/Icy-Kernel
  /**
   * Draw a text in the specified Graphics context and at the specified position.<br>
   * This function handles multi lines string ('\n' character used a line separator).
   */
  public static void drawString(Graphics g, String text, int x, int y, boolean shadow) {
    if (StringUtil.isEmpty(text)) return;

    final Color color = g.getColor();
    final Color shadowColor;
    if (ColorUtil.getLuminance(color) > 128) shadowColor = ColorUtil.sub(color, Color.gray);
    else shadowColor = ColorUtil.add(color, Color.gray);
    final Rectangle2D textRect = getStringBounds(g, "M");

    // get height for a single line of text
    final double lineH = textRect.getHeight();
    final int curX = (int) (x - textRect.getX());
    double curY = y - textRect.getY();

    for (String s : text.split("\n")) {
      if (shadow) {
        g.setColor(shadowColor);
        g.drawString(s, curX + 1, (int) (curY + 1));
        g.setColor(color);
      }
      g.drawString(s, curX, (int) curY);
      curY += lineH;
    }
  }
コード例 #9
0
ファイル: Menu.java プロジェクト: Thunar/Runeshark
 public static void clickIndex(int index) {
   if (!isOpen()) {
     return;
   }
   Point[] arr = ColorUtil.findAllColorWithinTolerance(MENU, new Color(1, 1, 1));
   if (arr.length < 0) {
     return;
   }
   int menuY = 8;
   for (int x = 0; x < index; x++) {
     menuY += 16;
   }
   Point left = Calc.getLeftMax(arr);
   Point right = Calc.getRightMax(arr);
   Point high = Calc.getNorthern(arr);
   Mouse.click(left.x + (right.x - left.x) / 2, high.y + menuY, true);
 }
コード例 #10
0
  @Override
  public void generateColorWheel() {
    if (!isLookupValid) {
      generateLookupTables();
    }

    float[] components = new float[colorSpace.getNumComponents()];
    for (int index = 0; index < pixels.length; index++) {
      if (alphas[index] != 0) {
        components[angularIndex] = angulars[index];
        components[radialIndex] = radials[index];
        components[verticalIndex] = verticalValue;
        pixels[index] = alphas[index] | 0xffffff & ColorUtil.toRGB(colorSpace, components);
      }
    }
    newPixels();
    isPixelsValid = true;
  }
コード例 #11
0
ファイル: GraphicsUtil.java プロジェクト: adufour/Icy-Kernel
  /**
   * Draw a horizontal and vertical centered text on specified position. This function handle multi
   * lines string ('\n' character used a line separator).
   */
  public static void drawCenteredString(Graphics g, String text, int x, int y, boolean shadow) {
    if (StringUtil.isEmpty(text)) return;

    final Color color = g.getColor();
    final Color shadowColor = ColorUtil.mix(color, Color.black);
    final Rectangle2D textRect = getStringBounds(g, text);

    final double offX = textRect.getX();
    double curY = y - (textRect.getY() + (textRect.getHeight() / 2));

    for (String s : text.split("\n")) {
      final Rectangle2D r = getStringBounds(g, s);
      final int curX = (int) (x - (offX + (r.getWidth() / 2)));

      if (shadow) {
        g.setColor(shadowColor);
        g.drawString(s, curX + 1, (int) (curY + 1));
        g.setColor(color);
      }
      g.drawString(s, curX, (int) curY);
      curY += r.getHeight();
    }
  }
コード例 #12
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testRedFromString() {
   Assert.assertEquals("Red from string", Color.red, ColorUtil.stringToColor("red"));
 }
コード例 #13
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromRed() {
   Assert.assertEquals("Red to String", "red", ColorUtil.colorToString(Color.red));
 }
コード例 #14
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromBlue() {
   Assert.assertEquals("Blue to string", "blue", ColorUtil.colorToString(Color.blue));
 }
コード例 #15
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromGreen() {
   Assert.assertEquals("Green to String", "green", ColorUtil.colorToString(Color.green));
 }
コード例 #16
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testYellowFromString() {
   Assert.assertEquals("Yellow from string", Color.yellow, ColorUtil.stringToColor("yellow"));
 }
コード例 #17
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromOrange() {
   Assert.assertEquals("Orange to string", "orange", ColorUtil.colorToString(Color.orange));
 }
コード例 #18
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromPink() {
   Assert.assertEquals("Pink to string", "pink", ColorUtil.colorToString(Color.pink));
 }
コード例 #19
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testPinkFromString() {
   Assert.assertEquals("Pink from string", Color.pink, ColorUtil.stringToColor("pink"));
 }
コード例 #20
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromGray() {
   Assert.assertEquals("Gray to string", "gray", ColorUtil.colorToString(Color.gray));
 }
コード例 #21
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testOrangeFromString() {
   Assert.assertEquals("Orange from string", Color.orange, ColorUtil.stringToColor("orange"));
 }
コード例 #22
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testLightGrayFromString() {
   Assert.assertEquals(
       "LightGray from string", Color.lightGray, ColorUtil.stringToColor("lightGray"));
 }
コード例 #23
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromYellow() {
   Assert.assertEquals("Yellow to string", "yellow", ColorUtil.colorToString(Color.yellow));
 }
コード例 #24
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromLightGray() {
   Assert.assertEquals(
       "LightGray to string", "lightGray", ColorUtil.colorToString(Color.lightGray));
 }
コード例 #25
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testGreenFromString() {
   Assert.assertEquals("Green from string", Color.green, ColorUtil.stringToColor("green"));
 }
コード例 #26
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromDarkGray() {
   Assert.assertEquals("DarkGray to string", "darkGray", ColorUtil.colorToString(Color.darkGray));
 }
 @Override
 public int getOpacity() {
   return ColorUtil.getOpacityFromColor(ColorUtil.multiplyColorAlpha(mColor, mAlpha));
 }
コード例 #28
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testWhiteFromString() {
   Assert.assertEquals("White from string", Color.white, ColorUtil.stringToColor("white"));
 }
  private void drawRectangularBackgroundWithBorders(Canvas canvas) {
    int useColor = ColorUtil.multiplyColorAlpha(mColor, mAlpha);
    if ((useColor >>> 24) != 0) { // color is not transparent
      mPaint.setColor(useColor);
      mPaint.setStyle(Paint.Style.FILL);
      canvas.drawRect(getBounds(), mPaint);
    }
    // maybe draw borders?
    if (getBorderWidth(Spacing.LEFT) > 0
        || getBorderWidth(Spacing.TOP) > 0
        || getBorderWidth(Spacing.RIGHT) > 0
        || getBorderWidth(Spacing.BOTTOM) > 0) {
      Rect bounds = getBounds();

      int borderLeft = getBorderWidth(Spacing.LEFT);
      int borderTop = getBorderWidth(Spacing.TOP);
      int borderRight = getBorderWidth(Spacing.RIGHT);
      int borderBottom = getBorderWidth(Spacing.BOTTOM);
      int colorLeft = getBorderColor(Spacing.LEFT);
      int colorTop = getBorderColor(Spacing.TOP);
      int colorRight = getBorderColor(Spacing.RIGHT);
      int colorBottom = getBorderColor(Spacing.BOTTOM);

      int top = bounds.top;
      int left = bounds.left;
      int width = bounds.width();
      int height = bounds.height();

      // If the path drawn previously is of the same color,
      // there would be a slight white space between borders
      // with anti-alias set to true.
      // Therefore we need to disable anti-alias, and
      // after drawing is done, we will re-enable it.

      mPaint.setAntiAlias(false);

      if (mPathForBorder == null) {
        mPathForBorder = new Path();
      }

      if (borderLeft > 0 && colorLeft != Color.TRANSPARENT) {
        mPaint.setColor(colorLeft);
        mPathForBorder.reset();
        mPathForBorder.moveTo(left, top);
        mPathForBorder.lineTo(left + borderLeft, top + borderTop);
        mPathForBorder.lineTo(left + borderLeft, top + height - borderBottom);
        mPathForBorder.lineTo(left, top + height);
        mPathForBorder.lineTo(left, top);
        canvas.drawPath(mPathForBorder, mPaint);
      }

      if (borderTop > 0 && colorTop != Color.TRANSPARENT) {
        mPaint.setColor(colorTop);
        mPathForBorder.reset();
        mPathForBorder.moveTo(left, top);
        mPathForBorder.lineTo(left + borderLeft, top + borderTop);
        mPathForBorder.lineTo(left + width - borderRight, top + borderTop);
        mPathForBorder.lineTo(left + width, top);
        mPathForBorder.lineTo(left, top);
        canvas.drawPath(mPathForBorder, mPaint);
      }

      if (borderRight > 0 && colorRight != Color.TRANSPARENT) {
        mPaint.setColor(colorRight);
        mPathForBorder.reset();
        mPathForBorder.moveTo(left + width, top);
        mPathForBorder.lineTo(left + width, top + height);
        mPathForBorder.lineTo(left + width - borderRight, top + height - borderBottom);
        mPathForBorder.lineTo(left + width - borderRight, top + borderTop);
        mPathForBorder.lineTo(left + width, top);
        canvas.drawPath(mPathForBorder, mPaint);
      }

      if (borderBottom > 0 && colorBottom != Color.TRANSPARENT) {
        mPaint.setColor(colorBottom);
        mPathForBorder.reset();
        mPathForBorder.moveTo(left, top + height);
        mPathForBorder.lineTo(left + width, top + height);
        mPathForBorder.lineTo(left + width - borderRight, top + height - borderBottom);
        mPathForBorder.lineTo(left + borderLeft, top + height - borderBottom);
        mPathForBorder.lineTo(left, top + height);
        canvas.drawPath(mPathForBorder, mPaint);
      }

      // re-enable anti alias
      mPaint.setAntiAlias(true);
    }
  }
コード例 #30
0
ファイル: ColorUtilTest.java プロジェクト: KenC57/JMRI
 public void testStringFromWhite() {
   Assert.assertEquals("White to string", "white", ColorUtil.colorToString(Color.white));
 }