예제 #1
0
 @NotNull
 private static Color getMiddleColor(Color fg, Color bg, double factor) {
   int red = avg(fg.getRed(), bg.getRed(), factor);
   int green = avg(fg.getGreen(), bg.getGreen(), factor);
   int blue = avg(fg.getBlue(), bg.getBlue(), factor);
   return new Color(red, green, blue);
 }
예제 #2
0
  public void save() {
    Rectangle rect = this.getBounds();
    prefs.putInt(LOCATION_X, rect.x);
    prefs.putInt(LOCATION_Y, rect.y);
    prefs.putInt(WIDTH, rect.width);
    prefs.putInt(HEIGHT, rect.height);

    prefs.put(FONTSTYLE, this.myMenu.fontStyle);
    prefs.putInt(FONTSIZE, this.myMenu.fontSize);

    Color fColor = this.myMenu.fontColor;
    fRed = fColor.getRed();
    fGreen = fColor.getGreen();
    fBlue = fColor.getBlue();
    prefs.putInt(FRED, fRed);
    prefs.putInt(FGREEN, fGreen);
    prefs.putInt(FBLUE, fBlue);

    Color color = this.myMenu.getBackground();
    bgRed = color.getRed();
    bgGreen = color.getGreen();
    bgBlue = color.getBlue();
    prefs.putInt(BGRED, bgRed);
    prefs.putInt(BGGREEN, bgGreen);
    prefs.putInt(BGBLUE, bgBlue);
  }
예제 #3
0
 private void paintBell(Graphics g) {
   P9TermPreferences preferences = P9Term.getPreferences();
   if (preferences.getBoolean(P9TermPreferences.VISUAL_BELL) == false) {
     return;
   }
   Color foreground = preferences.getColor(P9TermPreferences.FOREGROUND_COLOR);
   if (preferences.getBoolean(P9TermPreferences.FANCY_BELL)) {
     // On decent hardware, we can produce a really tasteful effect by compositing a
     // semi-transparent rectangle over the terminal.
     // We need to choose a color that will show up against the background.
     // A reasonable assumption is that the user has already chosen such a color for the
     // foreground.
     Color color =
         new Color(foreground.getRed(), foreground.getGreen(), foreground.getBlue(), 100);
     g.setColor(color);
     g.fillRect(0, 0, getWidth(), getHeight());
   } else {
     // On a remote X11 display (or really rubbish hardware) the compositing effect is
     // prohibitively expensive, so we offer XOR instead.
     Color background = preferences.getColor(P9TermPreferences.BACKGROUND_COLOR);
     ;
     final int R = blend(background.getRed(), foreground.getRed());
     final int G = blend(background.getGreen(), foreground.getGreen());
     final int B = blend(background.getBlue(), foreground.getBlue());
     g.setColor(background);
     g.setXORMode(new Color(R, G, B));
     g.fillRect(0, 0, getWidth(), getHeight());
     g.setPaintMode();
   }
 }
  private static Color[] toColorsForLineMarkers(Color[] baseColors) {
    final Color[] colors = new Color[baseColors.length];
    final Color tagBackground = Gray._239;
    final double transparency = 0.4;
    final double factor = 0.8;

    for (int i = 0; i < colors.length; i++) {
      final Color color = baseColors[i];

      if (color == null) {
        colors[i] = null;
        continue;
      }

      int r = (int) (color.getRed() * factor);
      int g = (int) (color.getGreen() * factor);
      int b = (int) (color.getBlue() * factor);

      r = (int) (tagBackground.getRed() * (1 - transparency) + r * transparency);
      g = (int) (tagBackground.getGreen() * (1 - transparency) + g * transparency);
      b = (int) (tagBackground.getBlue() * (1 - transparency) + b * transparency);

      colors[i] = new Color(r, g, b);
    }

    return colors;
  }
예제 #5
0
  private static void initColorMap(IntBuffer colorMap, int stepSize, Color... colors) {
    for (int n = 0; n < colors.length - 1; n++) {
      Color color = colors[n];
      int r0 = color.getRed();
      int g0 = color.getGreen();
      int b0 = color.getBlue();

      color = colors[n + 1];
      int r1 = color.getRed();
      int g1 = color.getGreen();
      int b1 = color.getBlue();

      int deltaR = r1 - r0;
      int deltaG = g1 - g0;
      int deltaB = b1 - b0;

      for (int step = 0; step < stepSize; step++) {
        float alpha = (float) step / (stepSize - 1);
        int r = (int) (r0 + alpha * deltaR);
        int g = (int) (g0 + alpha * deltaG);
        int b = (int) (b0 + alpha * deltaB);
        colorMap.put((r << 0) | (g << 8) | (b << 16));
      }
    }
    colorMap.flip();
  }
예제 #6
0
 public static void drawGradientRect(
     int x, int y, float z, int toX, int toY, Color color, Color colorFade) {
   GL11.glDisable(GL11.GL_TEXTURE_2D);
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glDisable(GL11.GL_ALPHA_TEST);
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   GL11.glShadeModel(GL11.GL_SMOOTH);
   Tessellator tes = Tessellator.getInstance();
   VertexBuffer vb = tes.getBuffer();
   vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
   vb.pos(toX, y, z)
       .color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())
       .endVertex();
   vb.pos(x, y, z)
       .color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())
       .endVertex();
   vb.pos(x, toY, z)
       .color(colorFade.getRed(), colorFade.getGreen(), colorFade.getBlue(), colorFade.getAlpha())
       .endVertex();
   vb.pos(toX, toY, z)
       .color(colorFade.getRed(), colorFade.getGreen(), colorFade.getBlue(), colorFade.getAlpha())
       .endVertex();
   tes.draw();
   GL11.glShadeModel(GL11.GL_FLAT);
   GL11.glDisable(GL11.GL_BLEND);
   GL11.glEnable(GL11.GL_ALPHA_TEST);
   GL11.glEnable(GL11.GL_TEXTURE_2D);
 }
예제 #7
0
파일: Color.java 프로젝트: EagerLogic/Cubee
 public static Color fadeColors(Color startColor, Color endColor, double fadePosition) {
   return Color.getArgbColor(
       mixComponent(startColor.getAlpha(), endColor.getAlpha(), fadePosition),
       mixComponent(startColor.getRed(), endColor.getRed(), fadePosition),
       mixComponent(startColor.getGreen(), endColor.getGreen(), fadePosition),
       mixComponent(startColor.getBlue(), endColor.getBlue(), fadePosition));
 }
예제 #8
0
 public void fillRect(int x, int y, int width, int height) {
   HSSFSimpleShape shape =
       escherGroup.createShape(new HSSFChildAnchor(x, y, x + width, y + height));
   shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
   shape.setLineStyle(HSSFShape.LINESTYLE_NONE);
   shape.setFillColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue());
   shape.setLineStyleColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue());
 }
예제 #9
0
파일: Hero.java 프로젝트: rweichler/wuigi
  private BufferedImage figureOutDrawImage(Sprite[] imgs) {

    Sprite img;
    if (dead) {
      return imgs[5].getBuffer();
    }

    if (Math.abs((int) (vel.y * 100)) > 0 && !piped) {
      img = imgs[1];
    } else if (!(movingRight || movingLeft) && vel.x == 0) img = imgs[0];
    else {
      if (movingRight && vel.x < 0 || movingLeft && vel.x > 0) img = imgs[4];
      else {
        if (rightFoot) img = imgs[3];
        else img = imgs[2];
      }
    }

    if (star && (starTime < 8000 / 15 || System.currentTimeMillis() % 60 > 30)) {
      int width = img.getBuffer().getWidth(), height = img.getBuffer().getHeight();
      Sprite limg = new Sprite(img.getBuffer());
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          Color pixel = limg.getPixel(x, y);
          if (pixel.getAlpha() != 0) {
            limg.setPixel(
                x,
                y,
                new Color(
                    255 - pixel.getRed(),
                    255 - pixel.getGreen(),
                    255 - pixel.getBlue(),
                    pixel.getAlpha()));
          }
        }
      }
      img = limg;
    } else if (metal) {
      int width = img.getBuffer().getWidth(), height = img.getBuffer().getHeight();
      Sprite limg = new Sprite(img.getBuffer());
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          Color pixel = limg.getPixel(x, y);
          if (pixel.getAlpha() != 0) {
            int gray = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
            limg.setPixel(x, y, new Color(gray, gray, gray, pixel.getAlpha()));
          }
        }
      }
      img = limg;
    }

    if (facingRight) {
      return img.flipX();
    } else {
      return img.getBuffer();
    }
  }
예제 #10
0
 /**
  * Fills a (closed) polygon, as defined by a pair of arrays, which hold the <i>x</i> and <i>y</i>
  * coordinates.
  *
  * <p>This draws the polygon, with <code>nPoint</code> line segments. The first <code>
  * nPoint&nbsp;-&nbsp;1</code> line segments are drawn between sequential points (<code>
  * xPoints[i],yPoints[i],xPoints[i+1],yPoints[i+1]</code>). The final line segment is a closing
  * one, from the last point to the first (assuming they are different).
  *
  * <p>The area inside of the polygon is defined by using an even-odd fill rule (also known as the
  * alternating rule), and the area inside of it is filled.
  *
  * @param xPoints array of the <code>x</code> coordinates.
  * @param yPoints array of the <code>y</code> coordinates.
  * @param nPoints the total number of points in the polygon.
  * @see java.awt.Graphics#drawPolygon(int[], int[], int)
  */
 public void fillPolygon(int xPoints[], int yPoints[], int nPoints) {
   int right = findBiggest(xPoints);
   int bottom = findBiggest(yPoints);
   int left = findSmallest(xPoints);
   int top = findSmallest(yPoints);
   HSSFPolygon shape = escherGroup.createPolygon(new HSSFChildAnchor(left, top, right, bottom));
   shape.setPolygonDrawArea(right - left, bottom - top);
   shape.setPoints(addToAll(xPoints, -left), addToAll(yPoints, -top));
   shape.setLineStyleColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue());
   shape.setFillColor(foreground.getRed(), foreground.getGreen(), foreground.getBlue());
 }
예제 #11
0
  /**
   * Paints 3 different strokes around a shape to indicate focus. The widest stroke is the most
   * transparent, so this achieves a nice "glow" effect.
   *
   * <p>The catch is that you have to render this underneath the shape, and the shape should be
   * filled completely.
   *
   * @param g the graphics to paint to
   * @param shape the shape to outline
   * @param pixelSize the number of pixels the outline should cover.
   * @param focusColor the color of the focus ring to paint
   * @param changeRenderingHints if true then the rendering hints will be modified, if false they
   *     will be left in tact
   */
  public static void paintFocus(
      Graphics2D g, Shape shape, int pixelSize, Color focusColor, boolean changeRenderingHints) {
    g = (Graphics2D) g.create();
    try {
      Color[] focusArray =
          new Color[] {
            new Color(
                focusColor.getRed(),
                focusColor.getGreen(),
                focusColor.getBlue(),
                235 * focusColor.getAlpha() / 255),
            new Color(
                focusColor.getRed(),
                focusColor.getGreen(),
                focusColor.getBlue(),
                130 * focusColor.getAlpha() / 255),
            new Color(
                focusColor.getRed(),
                focusColor.getGreen(),
                focusColor.getBlue(),
                80 * focusColor.getAlpha() / 255)
          };
      if (changeRenderingHints) {
        if (JVM.usingQuartz) {
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        } else {
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setRenderingHint(
              RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
        }
      }

      g.setStroke(
          new BasicStroke(2 * pixelSize + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
      g.setColor(focusArray[2]);
      g.draw(shape);
      if (2 * pixelSize + 1 > 0) {
        g.setStroke(
            new BasicStroke(2 * pixelSize - 2 + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g.setColor(focusArray[1]);
        g.draw(shape);
      }
      if (2 * pixelSize - 4 + 1 > 0) {
        g.setStroke(
            new BasicStroke(2 * pixelSize - 4 + 1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        g.setColor(focusArray[0]);
        g.draw(shape);
      }
    } finally {
      g.dispose();
    }
  }
예제 #12
0
 /**
  * Sets the color of a pixel.
  *
  * @param x the x-coordinate (column) of the pixel
  * @param y the y-coordinate (row) of the pixel
  * @param the color of the pixel at the given row and column
  */
 public void setColorAt(int x, int y, Color color) {
   if (image == null || x < 0 || x >= image.getWidth() || y < 0 || y >= image.getHeight()) {
     throw new IndexOutOfBoundsException("(" + x + "," + y + ")");
   } else {
     if (color.getRed() < 0 || color.getRed() > 255)
       throw new IllegalArgumentException("red not between 0 and 255");
     if (color.getGreen() < 0 || color.getGreen() > 255)
       throw new IllegalArgumentException("green not between 0 and 255");
     if (color.getBlue() < 0 || color.getBlue() > 255)
       throw new IllegalArgumentException("blue not between 0 and 255");
     image.setRGB(x, y, color.getRed() * 65536 + color.getGreen() * 256 + color.getBlue());
     Canvas.getInstance().repaint();
   }
 }
예제 #13
0
  /**
   * Sets the selected color of this panel.
   *
   * <p>If this panel is in RED, GREEN, or BLUE mode, then this method converts these values to RGB
   * coordinates and calls <code>setRGB</code>.
   *
   * <p>This method may regenerate the graphic if necessary.
   *
   * @param h the hue value of the selected color.
   * @param s the saturation value of the selected color.
   * @param b the brightness value of the selected color.
   */
  public void setHSB(float h, float s, float b) {
    if (Float.isInfinite(h) || Float.isNaN(h))
      throw new IllegalArgumentException("The hue value (" + h + ") is not a valid number.");
    // hue is cyclic, so it can be any value:
    while (h < 0) h++;
    while (h > 1) h--;

    if (s < 0 || s > 1)
      throw new IllegalArgumentException("The saturation value (" + s + ") must be between [0,1]");
    if (b < 0 || b > 1)
      throw new IllegalArgumentException("The brightness value (" + b + ") must be between [0,1]");

    if (hue != h || sat != s || bri != b) {
      if (mode == ColorPicker.HUE || mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
        float lastHue = hue;
        float lastBri = bri;
        float lastSat = sat;
        hue = h;
        sat = s;
        bri = b;
        if (mode == ColorPicker.HUE) {
          if (lastHue != hue) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.SAT) {
          if (lastSat != sat) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.BRI) {
          if (lastBri != bri) {
            regenerateImage();
          }
        }
      } else {

        Color c = new Color(Color.HSBtoRGB(h, s, b));
        setRGB(c.getRed(), c.getGreen(), c.getBlue());
        return;
      }

      Color c = new Color(Color.HSBtoRGB(hue, sat, bri));
      red = c.getRed();
      green = c.getGreen();
      blue = c.getBlue();

      regeneratePoint();
      repaint();
      fireChangeListeners();
    }
  }
예제 #14
0
  public static Color mix(Color src, Color dst, double factor) {

    double fs = factor / 255.0;
    double fd = (1.0 - factor) / 255.0;

    double r = src.getRed() * fs + dst.getRed() * fd;
    double g = src.getGreen() * fs + dst.getGreen() * fd;
    double b = src.getBlue() * fs + dst.getBlue() * fd;

    int ir = Math.max(0, Math.min(255, (int) Math.round(r * 255)));
    int ig = Math.max(0, Math.min(255, (int) Math.round(g * 255)));
    int ib = Math.max(0, Math.min(255, (int) Math.round(b * 255)));

    return new Color(ir, ig, ib);
  }
예제 #15
0
  /**
   * 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);
  }
예제 #16
0
  @NotNull
  public static Icon colorize(@NotNull final Icon source, @NotNull Color color, boolean keepGray) {
    float[] base = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);

    final BufferedImage image =
        UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT);
    final Graphics2D g = image.createGraphics();
    source.paintIcon(null, g, 0, 0);
    g.dispose();

    final BufferedImage img =
        UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT);
    int[] rgba = new int[4];
    float[] hsb = new float[3];
    for (int y = 0; y < image.getRaster().getHeight(); y++) {
      for (int x = 0; x < image.getRaster().getWidth(); x++) {
        image.getRaster().getPixel(x, y, rgba);
        if (rgba[3] != 0) {
          Color.RGBtoHSB(rgba[0], rgba[1], rgba[2], hsb);
          int rgb = Color.HSBtoRGB(base[0], base[1] * (keepGray ? hsb[1] : 1f), base[2] * hsb[2]);
          img.getRaster()
              .setPixel(x, y, new int[] {rgb >> 16 & 0xff, rgb >> 8 & 0xff, rgb & 0xff, rgba[3]});
        }
      }
    }

    return createImageIcon(img);
  }
예제 #17
0
 public void addPlot(String name, int[] data) {
   plot_names.add(name);
   plot_data.add(data);
   int new_max = getMax(plot_data.size() - 1);
   if (new_max > MAX_Y) {
     MAX_Y = new_max;
   }
   if (data.length > MAX_X) {
     MAX_X = data.length;
   }
   int i = plot_data.size();
   Color c =
       new Color(
           (i * COLOR_RATIO) % 255,
           ((i + 2) * COLOR_RATIO) % 255,
           ((i + 3) * COLOR_RATIO) % 255,
           255);
   plot_colors.add(c);
   for (int j = 0; j < plot_colors.size(); j++) {
     Color color = plot_colors.get(j);
     Color new_color =
         new Color(
             color.getRed(), color.getBlue(), color.getGreen(), 127 / plot_colors.size() + 128);
     plot_colors.set(j, new_color);
   }
 }
예제 #18
0
  /**
   * Draw labels for picking.
   *
   * @param dc Current draw context.
   * @param pickSupport the PickSupport instance to be used.
   */
  protected void doPick(DrawContext dc, PickSupport pickSupport) {
    GL gl = dc.getGL();

    Angle heading = this.rotation;

    double headingDegrees;
    if (heading != null) headingDegrees = heading.degrees;
    else headingDegrees = 0;

    int x = this.screenPoint.x;
    int y = this.screenPoint.y;

    boolean matrixPushed = false;
    try {
      if (headingDegrees != 0) {
        gl.glPushMatrix();
        matrixPushed = true;

        gl.glTranslated(x, y, 0);
        gl.glRotated(headingDegrees, 0, 0, 1);
        gl.glTranslated(-x, -y, 0);
      }

      for (int i = 0; i < this.lines.length; i++) {
        Rectangle2D bounds = this.lineBounds[i];
        double width = bounds.getWidth();
        double height = bounds.getHeight();

        x = this.screenPoint.x;
        if (this.textAlign.equals(AVKey.CENTER)) x = x - (int) (width / 2.0);
        else if (this.textAlign.equals(AVKey.RIGHT)) x = x - (int) width;
        y -= this.lineHeight;

        Color color = dc.getUniquePickColor();
        int colorCode = color.getRGB();
        PickedObject po = new PickedObject(colorCode, this.getPickedObject(), this.position, false);
        pickSupport.addPickableObject(po);

        // Draw line rectangle
        gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());

        try {
          gl.glBegin(GL.GL_POLYGON);
          gl.glVertex3d(x, y, 0);
          gl.glVertex3d(x + width - 1, y, 0);
          gl.glVertex3d(x + width - 1, y + height - 1, 0);
          gl.glVertex3d(x, y + height - 1, 0);
          gl.glVertex3d(x, y, 0);
        } finally {
          gl.glEnd();
        }

        y -= this.lineSpacing;
      }
    } finally {
      if (matrixPushed) {
        gl.glPopMatrix();
      }
    }
  }
예제 #19
0
파일: Histogram.java 프로젝트: ktoso/oculus
 /**
  * Computes the combined histogram for a color pixel based on the following formula: RGB_Combined
  * = R*0.299 + G*0.587 + B*0.114
  *
  * @param c the color of a pixel.
  * @return the combined value which is computed from R, G and B colors.
  */
 private static int computeGrayColor2(Color c) {
   int r = c.getRed();
   int g = c.getGreen();
   int b = c.getBlue();
   int gray = (int) ((double) (r * 0.299) + (double) (g * 0.587) + (double) (b * 0.114));
   return gray;
 }
예제 #20
0
  /**
   * Find the color band that this value falls in and assign that color.
   *
   * @param v
   * @param color
   */
  private final void absoluteValue(final double v, final int[] color) {
    final double search;
    switch (scaling) {
      case Absolute:
        search = v;
        break;
      case MinMax:
        search = (v - min) / (max - min);
        break;
      case Modulo:
        search = v % (max - min);
        break;
      default:
        search = 0;
        break;
    }

    final Map.Entry<Double, Color> lower = floorEntry(search);

    Color c;
    if (lower == null) {
      c = entrySet().iterator().next().getValue();
    } else {
      c = lower.getValue();
    }

    color[R] = c.getRed();
    color[G] = c.getGreen();
    color[B] = c.getBlue();
    color[A] = c.getAlpha();
  }
예제 #21
0
 /** Patches attributes to be visible under debugger active line */
 @SuppressWarnings("UseJBColor")
 private static TextAttributes patchAttributesColor(
     TextAttributes attributes, TextRange range, Editor editor) {
   int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
   for (RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) {
     if (!highlighter.isValid()) continue;
     if (highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE
         && editor.offsetToLogicalPosition(highlighter.getStartOffset()).line == line) {
       TextAttributes textAttributes = highlighter.getTextAttributes();
       if (textAttributes != null) {
         Color color = textAttributes.getBackgroundColor();
         if (color != null
             && color.getBlue() > 128
             && color.getRed() < 128
             && color.getGreen() < 128) {
           TextAttributes clone = attributes.clone();
           clone.setForegroundColor(Color.orange);
           clone.setEffectColor(Color.orange);
           return clone;
         }
       }
     }
   }
   return attributes;
 }
예제 #22
0
 public static final Color contrastBW(Color c) {
   if ((c.getRed() + c.getGreen() + c.getBlue()) > 200.0) {
     return (Color.black);
   } else {
     return (Color.white);
   }
 }
예제 #23
0
  /*
   * Draws this place.
   */
  void paint(Graphics g) {
    super.paint(g); // very important, do not forget

    Graphics2D g2 = (Graphics2D) g;
    int w = this.getSize().width;
    int h = this.getSize().height;
    int x = this.getPosition().x - (w >> 1);
    int y = this.getPosition().y - (h >> 1);

    // draw forground
    if (this.getAction()) g2.setPaint(this.actionColor);
    else if (this.getSelected()) g2.setPaint(this.selectColor);
    else if (this.getEmphasized()) g2.setPaint(emphasize_color);
    // else g2.setPaint(new GradientPaint(x,y,this.foreground_color,x+w,y+h,Color.white));
    else g2.setPaint(Props.PLACE_FILL_COLOR);

    if (isMouseOver()) {
      Color c = (Color) g2.getPaint();
      g2.setPaint(new Color(c.getRed() ^ 0x66, c.getGreen() ^ 0x00, c.getBlue() ^ 0x00));
    }

    g2.fillOval(x, y, w, h);

    // draw background

    g2.setPaint(Props.PLACE_BORDER_COLOR);
    if (this.getJoined()) {
      Stroke oldStroke = g2.getStroke();
      g2.setStroke(new BasicStroke(2.5f));
      g2.drawOval(x, y, w, h);
      g2.setStroke(oldStroke);
    } else g2.drawOval(x, y, w, h);
  }
예제 #24
0
  public static void main(String[] args) {
    int x = 500, y = 80;
    DrawingKit dk = new DrawingKit("Daffodils", 800, 800);
    BufferedImage pict = dk.loadPicture("daffodils.jpg");

    // get pixel value at location (500, 80)
    int encodedPixelColor = pict.getRGB(x, y);
    Color pixelColor = new Color(encodedPixelColor);
    System.out.println(pixelColor);
    int red = pixelColor.getRed();
    int green = pixelColor.getGreen();
    int blue = pixelColor.getBlue();
    // change the color of the pixel to be pure red
    red = 255;
    green = 0;
    blue = 0;

    // update the pixel color in picture
    Color newPixelColor = new Color(red, green, blue);
    int newRgbvalue = newPixelColor.getRGB();
    pict.setRGB(x, y, newRgbvalue);
    // display the approximate location of the pixel
    dk.drawPicture(pict, 0, 0);
    BasicStroke s = new BasicStroke(3);
    dk.setStroke(s);
    Ellipse2D.Float e = new Ellipse2D.Float(x - 3, y - 3, 8, 8);
    dk.draw(e);
    dk.drawString("(600, 150)", x - 3, y - 5);
  }
예제 #25
0
 /** Patches attributes to be visible under debugger active line */
 @SuppressWarnings("UseJBColor")
 public static TextAttributes patchAttributesColor(
     TextAttributes attributes, @NotNull TextRange range, @NotNull Editor editor) {
   if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null)
     return attributes;
   MarkupModel model =
       DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
   if (model != null) {
     if (!((MarkupModelEx) model)
         .processRangeHighlightersOverlappingWith(
             range.getStartOffset(),
             range.getEndOffset(),
             highlighter -> {
               if (highlighter.isValid()
                   && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
                 TextAttributes textAttributes = highlighter.getTextAttributes();
                 if (textAttributes != null) {
                   Color color = textAttributes.getBackgroundColor();
                   return !(color != null
                       && color.getBlue() > 128
                       && color.getRed() < 128
                       && color.getGreen() < 128);
                 }
               }
               return true;
             })) {
       TextAttributes clone = attributes.clone();
       clone.setForegroundColor(Color.orange);
       clone.setEffectColor(Color.orange);
       return clone;
     }
   }
   return attributes;
 }
예제 #26
0
파일: Histogram.java 프로젝트: ktoso/oculus
 /**
  * Computes the combined histogram for a color pixel based on the following formula: RGB_Combined
  * = R*0.2126 + G*0.7152 + B*0.0722
  *
  * @param c the color of a pixel.
  * @return the combined value which is computed from R, G and B colors.
  */
 private static int computeGrayColor1(Color c) {
   int r = c.getRed();
   int g = c.getGreen();
   int b = c.getBlue();
   int gray = (int) ((double) (r * 0.2126) + (double) (g * 0.7152) + (double) (b * 0.0722));
   return gray;
 }
예제 #27
0
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   Undo.setup(Undo.ROI, imp);
   Roi roi2 = null;
   if (roi.getType() == Roi.LINE) {
     double width = roi.getStrokeWidth();
     if (width <= 1.0) roi.setStrokeWidth(1.0000001);
     FloatPolygon p = roi.getFloatPolygon();
     roi.setStrokeWidth(width);
     roi2 = new PolygonRoi(p, Roi.POLYGON);
     roi2.setDrawOffset(roi.getDrawOffset());
   } else {
     ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
     ip2.setColor(255);
     roi.drawPixels(ip2);
     // new ImagePlus("ip2", ip2.duplicate()).show();
     ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
     ThresholdToSelection tts = new ThresholdToSelection();
     roi2 = tts.convert(ip2);
   }
   transferProperties(roi, roi2);
   roi2.setStrokeWidth(0);
   Color c = roi2.getStrokeColor();
   if (c != null) // remove any transparency
   roi2.setStrokeColor(new Color(c.getRed(), c.getGreen(), c.getBlue()));
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
예제 #28
0
 @Override
 public void step(Graphics g) {
   Color c;
   double factor = new Random().nextDouble() * 2;
   double factor2 = new Random().nextDouble() * 2;
   double factor3 = new Random().nextDouble() * 2;
   // blur using averaging algorithm
   for (int y = 0; y < height; y++) {
     for (int x = 0; x < width; x++) {
       c = new Color(original.getRGB(x, y));
       switch (box.getSelectedIndex()) {
         case 0:
           g.setColor(
               new Color(
                   c.getRed(),
                   c.getGreen(),
                   (int) Math.min(Math.round(c.getBlue() * factor), 255)));
           break;
         case 1:
           g.setColor(
               new Color(
                   (int) Math.min(Math.round(c.getRed() * factor), 255),
                   c.getGreen(),
                   c.getBlue()));
           break;
         case 2:
           g.setColor(
               new Color(
                   c.getRed(),
                   (int) Math.min(Math.round(c.getGreen() * factor), 255),
                   c.getBlue()));
           break;
         case 3:
           g.setColor(
               new Color(
                   (int) Math.min(Math.round(c.getRed() * factor), 255),
                   (int) Math.min(Math.round(c.getGreen() * factor2), 255),
                   (int) Math.min(Math.round(c.getBlue() * factor3), 255)));
           break;
         default:
           System.out.println("shouldn't happen");
           break;
       }
       g.drawLine(x, y, x, y);
     }
   }
 }
예제 #29
0
  /**
   * Interpolate the color value for the given scalar value. The result is placed in color.
   *
   * @param v
   * @param color
   * @return
   */
  private final void interpolateValue(final double v, final int[] color) {
    final double search;
    switch (scaling) {
      case Absolute:
        search = v;
        break;
      case MinMax:
        search = (v - min) / (max - min);
        break;
      case Modulo:
        search = (v - min) % (max - min);
        break;
      default:
        search = 0;
        break;
    }

    final Map.Entry<Double, Color> lower = floorEntry(search);
    final Map.Entry<Double, Color> upper = higherEntry(search);

    assert (upper != null || lower != null);

    if (upper == null) {
      final Color c = lower.getValue();
      color[R] = c.getRed();
      color[G] = c.getGreen();
      color[B] = c.getBlue();
      color[A] = c.getAlpha();
    } else if (lower == null) {
      final Color c = upper.getValue();
      color[R] = c.getRed();
      color[G] = c.getGreen();
      color[B] = c.getBlue();
      color[A] = c.getAlpha();
    } else {
      final double diff = upper.getKey().doubleValue() - lower.getKey().doubleValue();
      final double lw = 1.0 - ((search - lower.getKey().doubleValue()) / diff);
      final double uw = 1.0 - lw;

      final Color lc = lower.getValue();
      final Color uc = upper.getValue();
      color[R] = (int) Math.round(lc.getRed() * lw + uc.getRed() * uw);
      color[G] = (int) Math.round(lc.getGreen() * lw + uc.getGreen() * uw);
      color[B] = (int) Math.round(lc.getBlue() * lw + uc.getBlue() * uw);
      color[A] = (int) Math.round(lc.getAlpha() * lw + uc.getAlpha() * uw);
    }
  }
예제 #30
0
 /**
  * Sets the fillColor and defines the outline color to be a non-transparent version of the fill
  * color
  */
 public void setColor(Color fillColor) {
   m_fillColor = fillColor;
   m_outlineColor =
       new Color(
           fillColor.getRed() < 255 ? 0.0f : 1.0f,
           fillColor.getGreen() < 255 ? 0.0f : 1.0f,
           fillColor.getBlue() < 255 ? 0.0f : 1.0f);
 }