/** This method is invoked before the rendered image of the figure is composited. */
  public void drawFigure(Graphics2D g) {
    AffineTransform savedTransform = null;
    if (get(TRANSFORM) != null) {
      savedTransform = g.getTransform();
      g.transform(get(TRANSFORM));
    }

    if (get(FILL_STYLE) != ODGConstants.FillStyle.NONE) {
      Paint paint = ODGAttributeKeys.getFillPaint(this);
      if (paint != null) {
        g.setPaint(paint);
        drawFill(g);
      }
    }

    if (get(STROKE_STYLE) != ODGConstants.StrokeStyle.NONE) {
      Paint paint = ODGAttributeKeys.getStrokePaint(this);
      if (paint != null) {
        g.setPaint(paint);
        g.setStroke(ODGAttributeKeys.getStroke(this));
        drawStroke(g);
      }
    }
    if (get(TRANSFORM) != null) {
      g.setTransform(savedTransform);
    }
  }
示例#2
0
  @Test
  public void drawWithClipAndTransform() throws Exception {
    graphics.setPaint(Color.BLACK);
    graphics.fill(imageBounds);

    AffineTransform tr =
        AffineTransform.getRotateInstance(
            Math.PI / 4,
            image.getMinX() + image.getWidth() / 2,
            image.getMinY() + image.getHeight() / 2);

    graphics.transform(tr);
    graphics.clip(midRect);

    graphics.setPaint(Color.RED);
    graphics.fill(imageBounds);

    showImage("drawWithClipAndTransform");

    // Outside transformed clip region
    Rectangle outer = new Rectangle(midRect);
    outer.grow(5, 5);
    Point2D[] corners = getCorners(outer);
    Point2D[] trPoints = new Point2D[corners.length];
    tr.transform(corners, 0, trPoints, 0, corners.length);
    assertColor(Color.BLACK, trPoints);

    // Inside transformed clip region
    Rectangle inner = new Rectangle(midRect);
    inner.grow(-5, -5);
    corners = getCorners(inner);
    tr.transform(corners, 0, trPoints, 0, corners.length);
    assertColor(Color.RED, trPoints);
  }
示例#3
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    g2d.setBackground(Color.LIGHT_GRAY);
    g2d.clearRect(0, 0, getParent().getWidth(), getParent().getHeight());

    // Red line
    g2d.setPaint(Color.RED);
    // 5 visible, 5 invisible
    final float dash[] = {5, 5};
    // 10 thick, end lines with no cap,
    // any joins make round, miter limit,
    // dash array, dash phase
    final BasicStroke dashed =
        new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, dash, 0);

    g2d.setStroke(dashed);
    g2d.drawLine(100, 10, 10, 110);

    // White line
    g2d.setPaint(Color.WHITE);
    g2d.setStroke(new BasicStroke(10.0f));
    g2d.draw(new Line2D.Float(150, 10, 10, 160));

    // Blue line
    g2d.setPaint(Color.BLUE);
    Stroke solidStroke = new BasicStroke(10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    g2d.setStroke(solidStroke);
    g2d.draw(new Line2D.Float(new Point2D.Float(200, 10), new Point2D.Double(10, 210)));
  }
  /**
   * Draws the textured background on the side panel
   *
   * @param g
   */
  private void drawBackground(Graphics g, int width, int height) {
    Graphics2D g2d = (Graphics2D) g;

    Color color1 = new Color(210, 230, 220, 50);
    Color color2 = new Color(40, 65, 45, 200);
    GradientPaint gp = new GradientPaint(0, 0, color1, 0, height, color2);
    TexturePaint tp =
        new TexturePaint(
            backTexture,
            new Rectangle2D.Double(0, 0, backTexture.getWidth(), backTexture.getHeight()));

    // Draw the texture
    g2d.setPaint(tp);
    g2d.fillRect(0, 0, width, height);

    // Draw the gradient
    g2d.setPaint(gp);
    g2d.fillRect(0, 0, width, height);

    // Draw the bevel
    g2d.setColor(new Color(255, 255, 255, 50));
    g2d.fillRect(0, 0, 5, height);

    g2d.setColor(new Color(0, 0, 0, 100));
    g2d.fillRect(width - 5, 0, 5, height);
  }
  public void drawConditionalSequenceFlowIndicator(Line2D.Double line) {
    int horizontal = (int) (CONDITIONAL_INDICATOR_WIDTH * 0.7);
    int halfOfHorizontal = horizontal / 2;
    int halfOfVertical = CONDITIONAL_INDICATOR_WIDTH / 2;

    Polygon conditionalIndicator = new Polygon();
    conditionalIndicator.addPoint(0, 0);
    conditionalIndicator.addPoint(-halfOfHorizontal, halfOfVertical);
    conditionalIndicator.addPoint(0, CONDITIONAL_INDICATOR_WIDTH);
    conditionalIndicator.addPoint(halfOfHorizontal, halfOfVertical);

    AffineTransform transformation = new AffineTransform();
    transformation.setToIdentity();
    double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1);
    transformation.translate(line.x1, line.y1);
    transformation.rotate((angle - Math.PI / 2d));

    AffineTransform originalTransformation = g.getTransform();
    g.setTransform(transformation);
    g.draw(conditionalIndicator);

    Paint originalPaint = g.getPaint();
    g.setPaint(CONDITIONAL_INDICATOR_COLOR);
    g.fill(conditionalIndicator);

    g.setPaint(originalPaint);
    g.setTransform(originalTransformation);
  }
示例#6
0
  @Override
  protected void paintIcon(
      java.awt.Component c,
      java.awt.Graphics2D g2,
      int width,
      int height,
      java.awt.Paint fillPaint,
      java.awt.Paint drawPaint) {
    java.awt.Font prevFont = g2.getFont();
    g2.setFont(font);

    String text = "A";
    java.awt.FontMetrics fm = g2.getFontMetrics();
    int messageWidth = fm.stringWidth(text);
    int ascent = fm.getMaxAscent();
    int descent = fm.getMaxDescent();
    int x = (width / 2) - (messageWidth / 2);
    int y = ((height / 2) + (ascent / 2)) - (descent / 2);

    java.awt.font.GlyphVector glyphVector = font.createGlyphVector(g2.getFontRenderContext(), text);
    java.awt.Shape outline = glyphVector.getOutline(x, y);
    g2.setPaint(drawPaint);
    g2.draw(outline);

    g2.setPaint(fillPaint);
    g2.fill(outline);
    //		g2.drawString( text, x, y );

    g2.setFont(prevFont);
  }
示例#7
0
  /**
   * Draws the band.
   *
   * @param g2 the graphics device.
   * @param plotArea the plot area.
   * @param dataArea the data area.
   * @param x the x-coordinate.
   * @param y the y-coordinate.
   */
  public void draw(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, double x, double y) {

    double h = getHeight(g2);
    Iterator iterator = this.markers.iterator();
    while (iterator.hasNext()) {
      IntervalMarker marker = (IntervalMarker) iterator.next();
      double start = Math.max(marker.getStartValue(), this.axis.getRange().getLowerBound());
      double end = Math.min(marker.getEndValue(), this.axis.getRange().getUpperBound());
      double s = this.axis.valueToJava2D(start, dataArea, RectangleEdge.BOTTOM);
      double e = this.axis.valueToJava2D(end, dataArea, RectangleEdge.BOTTOM);
      Rectangle2D r =
          new Rectangle2D.Double(
              s, y + this.topOuterGap, e - s, h - this.topOuterGap - this.bottomOuterGap);

      Composite originalComposite = g2.getComposite();
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, marker.getAlpha()));
      g2.setPaint(marker.getPaint());
      g2.fill(r);
      g2.setPaint(marker.getOutlinePaint());
      g2.draw(r);
      g2.setComposite(originalComposite);

      g2.setPaint(Color.black);
      drawStringInRect(g2, r, this.font, marker.getLabel());
    }
  }
示例#8
0
  /**
   * Draws the circle.
   *
   * @param g2 the graphics device.
   * @param area the area in which to draw.
   */
  public void draw(Graphics2D g2, Rectangle2D area) {
    Ellipse2D ellipse =
        new Ellipse2D.Double(
            area.getX(), area.getY(),
            area.getWidth(), area.getHeight());
    if (this.fillPaint != null) {
      g2.setPaint(this.fillPaint);
      g2.fill(ellipse);
    }
    if (this.outlinePaint != null && this.outlineStroke != null) {
      g2.setPaint(this.outlinePaint);
      g2.setStroke(this.outlineStroke);
      g2.draw(ellipse);
    }

    g2.setPaint(Color.black);
    g2.setStroke(new BasicStroke(1.0f));
    Line2D line1 =
        new Line2D.Double(
            area.getCenterX(), area.getMinY(),
            area.getCenterX(), area.getMaxY());
    Line2D line2 =
        new Line2D.Double(
            area.getMinX(), area.getCenterY(),
            area.getMaxX(), area.getCenterY());
    g2.draw(line1);
    g2.draw(line2);
  }
示例#9
0
  // Actually draws the rectangle
  public void draw(Graphics g) {
    Graphics2D g2 = (Graphics2D) g; // create a Graphics2D object

    if (getGradient()) {
      GradientPaint gradientPaint =
          new GradientPaint(
              getUpperLeftX(),
              getUpperLeftY(),
              getColor(),
              getUpperLeftX() + getWidth(),
              getUpperLeftY() + getHeight(),
              getColor2());
      g2.setPaint(gradientPaint);
    } else g2.setPaint(getColor());

    if (getDashed()) {
      float dash1[] = {10.0f};
      BasicStroke dashedLine =
          new BasicStroke(
              getDashLength(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
      g2.setStroke(dashedLine);
    } else {
      g2.setStroke(new BasicStroke(getStrokeWidth()));
    }

    if (getFilledF())
      g2.fill(new Rectangle2D.Double(getUpperLeftX(), getUpperLeftY(), getWidth(), getHeight()));
    else g2.draw(new Rectangle2D.Double(getUpperLeftX(), getUpperLeftY(), getWidth(), getHeight()));
  }
示例#10
0
  /**
   * Draws an arc.
   *
   * @param g2 the graphics device.
   * @param area the plot area.
   * @param minValue the minimum value.
   * @param maxValue the maximum value.
   * @param paint the paint.
   * @param stroke the stroke.
   */
  protected void drawArc(
      Graphics2D g2,
      Rectangle2D area,
      double minValue,
      double maxValue,
      Paint paint,
      Stroke stroke) {

    double startAngle = valueToAngle(maxValue);
    double endAngle = valueToAngle(minValue);
    double extent = endAngle - startAngle;

    double x = area.getX();
    double y = area.getY();
    double w = area.getWidth();
    double h = area.getHeight();
    g2.setPaint(paint);
    g2.setStroke(stroke);

    if (paint != null && stroke != null) {
      Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent, Arc2D.OPEN);
      g2.setPaint(paint);
      g2.setStroke(stroke);
      g2.draw(arc);
    }
  }
  /**
   * Paint a background for all groups and a round blue border and background when a cell is
   * selected.
   *
   * @param g2 the <tt>Graphics2D</tt> object through which we paint
   */
  private void internalPaintComponent(Graphics2D g2) {
    Color borderColor = Color.GRAY;

    if (isSelected) {
      g2.setPaint(
          new GradientPaint(
              0, 0, Constants.SELECTED_COLOR, 0, getHeight(), Constants.SELECTED_GRADIENT_COLOR));

      borderColor = Constants.SELECTED_COLOR;
    } else if (treeNode instanceof GroupNode) {
      g2.setPaint(
          new GradientPaint(
              0,
              0,
              Constants.CONTACT_LIST_GROUP_BG_GRADIENT_COLOR,
              0,
              getHeight(),
              Constants.CONTACT_LIST_GROUP_BG_COLOR));

      borderColor = Constants.CONTACT_LIST_GROUP_BG_COLOR;
    }

    g2.fillRect(0, 0, getWidth(), getHeight());
    g2.setColor(borderColor);
    g2.drawLine(0, 0, getWidth(), 0);
    g2.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1);
  }
示例#12
0
  /**
   * Paint 3D effect in (lighten in upper half, darken in lowerhalf) (called from paint methods)
   *
   * @param g2D Graphics
   * @param c Component
   * @param round paint round corners
   * @param out paint sticking out (not pressed)
   */
  public static void paint3Deffect(Graphics2D g2D, JComponent c, boolean round, boolean out) {
    // paint upper gradient
    GradientPaint topPaint = null;
    if (out) topPaint = new GradientPaint(0, 0, COL_1TOP, 0, c.getHeight() / 2, COL_1END);
    else topPaint = new GradientPaint(0, 0, COL_2END, 0, c.getHeight() / 2, COL_2TOP);
    g2D.setPaint(topPaint);
    //
    RectangularShape topRec = null;
    if (round) topRec = new RoundRectangle2D.Float(0, 0, c.getWidth(), c.getHeight() / 2, 15, 15);
    else topRec = new Rectangle(0, 0, c.getWidth(), c.getHeight() / 2);
    g2D.fill(topRec);

    // paint lower gradient
    GradientPaint endPaint = null;
    if (out)
      endPaint = new GradientPaint(0, c.getHeight() / 2, COL_2TOP, 0, c.getHeight(), COL_2END);
    else endPaint = new GradientPaint(0, c.getHeight() / 2, COL_1END, 0, c.getHeight(), COL_1TOP);
    g2D.setPaint(endPaint);
    //
    RectangularShape endRec = null;
    if (round)
      endRec =
          new RoundRectangle2D.Float(0, c.getHeight() / 2, c.getWidth(), c.getHeight() / 2, 15, 15);
    else endRec = new Rectangle(0, c.getHeight() / 2, c.getWidth(), c.getHeight() / 2);
    g2D.fill(endRec);
  } //  paint3Deffect
示例#13
0
  /**
   * Paint 3D effect in (lighten in upper half, darken in lowerhalf) (called from paint methods)
   *
   * @param g2D Graphics
   * @param r Ractangle
   * @param round paint round corners
   * @param out paint sticking out (not pressed)
   */
  public static void paint3Deffect(Graphics2D g2D, Rectangle r, boolean round, boolean out) {
    // paint upper gradient
    GradientPaint topPaint = null;
    if (out) topPaint = new GradientPaint(r.x, r.y, COL_1TOP, r.x, r.y + r.height / 2, COL_1END);
    else topPaint = new GradientPaint(r.x, r.y, COL_2END, r.x, r.y + r.height / 2, COL_2TOP);
    g2D.setPaint(topPaint);
    //
    RectangularShape topRec = null;
    if (round) topRec = new RoundRectangle2D.Float(r.x, r.y, r.width, r.height / 2, 15, 15);
    else topRec = new Rectangle(r.x, r.y, r.width, r.height / 2);
    g2D.fill(topRec);

    // paint lower gradient
    GradientPaint endPaint = null; // 	upper left corner to lower left
    if (out)
      endPaint =
          new GradientPaint(r.x, r.y + r.height / 2, COL_2TOP, r.x, r.y + r.height, COL_2END);
    else
      endPaint =
          new GradientPaint(r.x, r.y + r.height / 2, COL_1END, r.x, r.y + r.height, COL_1TOP);
    g2D.setPaint(endPaint);
    //
    RectangularShape endRec = null;
    if (round)
      endRec = new RoundRectangle2D.Float(r.x, r.y + r.height / 2, r.width, r.height / 2, 15, 15);
    else endRec = new Rectangle(r.x, r.y + r.height / 2, r.width, r.height / 2);
    g2D.fill(endRec);
  } //  paint3Deffect
示例#14
0
  public void paintBorder(final Component c, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2d = (Graphics2D) g;
    GradientPaint paint;
    Paint oldPaint = g2d.getPaint();
    int textX;
    Font f = c.getFont();
    g2d.setFont(f);
    x += 2;
    width -= 1;
    if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT) {
      textX = x + width - 4 - g2d.getFontMetrics().stringWidth(title);
      paint = new GradientPaint(x, y, destinationColor, width, height, sourceColor);
    } else {
      y += 2;
      textX = x + 4;
      paint = new GradientPaint(x, y, sourceColor, width, height, destinationColor);
    }

    height = f.getSize() + 6;
    g2d.setPaint(paint);
    g2d.fillRect(x, y, width, height);
    g2d.setPaint(oldPaint);

    g2d.setColor(textColor);
    g2d.drawString(title, textX, y + height - 5);
  }
  /**
   * Draws the graphic item within the specified area.
   *
   * @param g2 the graphics device.
   * @param area the area.
   */
  public void draw(Graphics2D g2, Rectangle2D area) {
    area = (Rectangle2D) area.clone();
    area = trimMargin(area);
    drawBorder(g2, area);
    area = trimBorder(area);
    area = trimPadding(area);

    if (this.lineVisible) {
      Point2D location = RectangleAnchor.coordinates(area, this.shapeLocation);
      Shape aLine =
          ShapeUtilities.createTranslatedShape(
              getLine(), this.shapeAnchor, location.getX(), location.getY());
      g2.setPaint(this.linePaint);
      g2.setStroke(this.lineStroke);
      g2.draw(aLine);
    }

    if (this.shapeVisible) {
      Point2D location = RectangleAnchor.coordinates(area, this.shapeLocation);

      Shape s =
          ShapeUtilities.createTranslatedShape(
              this.shape, this.shapeAnchor, location.getX(), location.getY());
      if (this.shapeFilled) {
        g2.setPaint(this.fillPaint);
        g2.fill(s);
      }
      if (this.shapeOutlineVisible) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
        g2.draw(s);
      }
    }
  }
  protected void paintComponent(Graphics g) {
    if (isOpaque()) {
      g.setColor(getBackground());
      g.fillRect(0, 0, getWidth(), getHeight());
    }
    Insets insets = getInsets();
    Graphics2D g2 = (Graphics2D) g.create();
    g2.translate(insets.left, insets.top);
    float strength = getStrength();
    int w = getWidth() - insets.left - insets.right;
    int h = getHeight() - insets.top - insets.bottom;
    Paint p1;
    Paint p2;
    // int p1Width = w * 5 / 8;
    int barHeight = (int) (strength * (float) h);

    int p1Width = (int) (strength * (float) h);
    // int barHeight = w * 5 / 8;

    Color[] colors;
    if (strength <= .5f) {
      colors = RED_COLORS;
    } else if (strength <= .8f) {
      colors = YELLOW_COLORS;
    } else {
      colors = GREEN_COLORS;
    }
    g2.setPaint(new GradientPaint(0, 0, colors[0], p1Width, 0, colors[1]));
    // g2.fillRect(0, h - barHeight, p1Width, barHeight);
    g2.fillRect(0, 0, p1Width, h);
    g2.setPaint(new GradientPaint(p1Width, 0, colors[1], w, 0, colors[2]));
    // g2.fillRect(p1Width, h - barHeight, w - p1Width, barHeight);
    g2.fillRect(p1Width, 0, w - p1Width, h);
    g2.dispose();
  }
示例#17
0
  /**
   * descriptif de la m�thode (fonctionnalit� de la methode + mini algorithme si elle est
   * compliqu�e)
   *
   * @param g
   */
  public void paintComponent(Graphics g) {
    boolean bOpaque = isOpaque();

    if (bOpaque) {
      Graphics2D g2d = (Graphics2D) g.create();
      GradientPaint gp = null;

      if (getOrientation() == VERTICAL) {
        gp = new GradientPaint(0, 0, colorStart, getWidth(), 0, colorEnd, false);
      } else {
        gp = new GradientPaint(0, 0, colorStart, 0, getHeight(), colorEnd, false);
      }

      Paint oldPaint = g2d.getPaint();
      g2d.setPaint(gp);
      g2d.fill(new Rectangle(0, 0, getWidth(), getHeight()));
      g2d.setPaint(oldPaint);

      g2d.dispose();
    }

    setOpaque(false);
    super.paintComponent(g);
    setOpaque(bOpaque);
  }
示例#18
0
  @Override
  protected void fillTitleBar(Graphics2D g2) {
    Paint oldPaint = g2.getPaint();
    Stroke oldStroke = g2.getStroke();

    g2.setColor(new Color(241, 241, 241));
    g2.setStroke(new BasicStroke(1));
    g2.drawLine(0, 0, getWidth(), 0);

    LinearGradientPaint p =
        new LinearGradientPaint(
            1f,
            1f,
            1f,
            getHeight() - 1,
            new float[] {0.0f, 0.499f, 0.5f, 1.0f},
            new Color[] {
              new Color(230, 230, 230),
              new Color(202, 202, 202),
              new Color(202, 202, 202),
              new Color(178, 178, 178)
            });
    g2.setPaint(p);
    g2.fillRect(0, 0, getWidth(), this.getHeight() - 1);

    g2.setPaint(oldPaint);
    g2.setColor(new Color(104, 104, 104));
    g2.setStroke(new BasicStroke(1));
    g2.drawLine(getX(), getHeight() - 1, getWidth(), getHeight() - 1);

    g2.setStroke(oldStroke);
  }
示例#19
0
  public static synchronized void drawSingleGradientRect(
      MenuItem item, float x, float y, float width, float height, float roundOff) {
    Menu menu = item.menu;
    MenuStyle style = item.getStyle();

    roundRect.setRoundRect(x, y, width, height, roundOff, roundOff);
    Graphics2D g2 = menu.buff.g2;
    /*
     * Set the correct fill gradient
     */
    if (item.isOpen()) {
      g2.setPaint(item.getStyle().getGradient(MenuItem.DOWN, y, y + height));
    } else {
      g2.setPaint(item.getStyle().getGradient(MenuItem.OVER, y, y + height));
    }
    /*
     * Only perform the fill if the mood is right.
     */
    if (item.getState() != MenuItem.UP || item.isOpen()) {
      g2.fill(roundRect);
    }
    /*
     * Draw the rounded rectangle outline.
     */
    if (item.getState() != MenuItem.UP || item.isOpen()) {
      drawRoundOutline(item, roundRect);
    }
  }
示例#20
0
  public void paintBoard(Graphics2D g2) {

    double gbwidth = boardGridSize * 8d + lineLoc, gbheight = boardGridSize * 9d + lineLoc;
    g2.setPaint(red);
    g2.draw3DRect((int) lineLoc / 2, (int) lineLoc / 2, (int) gbwidth, (int) gbheight, true);
    g2.draw3DRect(
        (int) lineLoc / 2 + 3, (int) lineLoc / 2 + 3, (int) gbwidth - 6, (int) gbheight - 7, false);
    g2.setPaint(fg);
    for (int i = 0; i < 10; i++) {
      g2.draw(
          new Line2D.Double(
              lineLoc,
              lineLoc + boardGridSize * i,
              lineLoc + boardGridSize * 8,
              lineLoc + boardGridSize * i));
    }
    for (int i = 0; i < 9; i++) {
      g2.draw(
          new Line2D.Double(
              lineLoc + boardGridSize * i,
              lineLoc,
              lineLoc + boardGridSize * i,
              lineLoc + boardGridSize * 4));
      if (i == 0 || i == 8)
        g2.draw(
            new Line2D.Double(
                lineLoc + boardGridSize * i,
                lineLoc + boardGridSize * 4,
                lineLoc + boardGridSize * i,
                lineLoc + boardGridSize * 9));
      else
        g2.draw(
            new Line2D.Double(
                lineLoc + boardGridSize * i,
                lineLoc + boardGridSize * 5,
                lineLoc + boardGridSize * i,
                lineLoc + boardGridSize * 9));
    }
    drawX(lineLoc + boardGridSize * 4, lineLoc + boardGridSize, g2);
    drawX(lineLoc + boardGridSize * 4, lineLoc + boardGridSize * 8, g2);
    // black Pao
    drawLocation(lineLoc + boardGridSize, lineLoc + boardGridSize * 2, center, g2);
    drawLocation(lineLoc + boardGridSize * 7, lineLoc + boardGridSize * 2, center, g2);
    // red Pao
    drawLocation(lineLoc + boardGridSize, lineLoc + boardGridSize * 7, center, g2);
    drawLocation(lineLoc + boardGridSize * 7, lineLoc + boardGridSize * 7, center, g2);
    // black Zu
    drawLocation(lineLoc, lineLoc + boardGridSize * 3, right, g2);
    drawLocation(lineLoc + boardGridSize * 2, lineLoc + boardGridSize * 3, center, g2);
    drawLocation(lineLoc + boardGridSize * 4, lineLoc + boardGridSize * 3, center, g2);
    drawLocation(lineLoc + boardGridSize * 6, lineLoc + boardGridSize * 3, center, g2);
    drawLocation(lineLoc + boardGridSize * 8, lineLoc + boardGridSize * 3, left, g2);
    // red bin
    drawLocation(lineLoc, lineLoc + boardGridSize * 6, right, g2);
    drawLocation(lineLoc + boardGridSize * 2, lineLoc + boardGridSize * 6, center, g2);
    drawLocation(lineLoc + boardGridSize * 4, lineLoc + boardGridSize * 6, center, g2);
    drawLocation(lineLoc + boardGridSize * 6, lineLoc + boardGridSize * 6, center, g2);
    drawLocation(lineLoc + boardGridSize * 8, lineLoc + boardGridSize * 6, left, g2);
    // ----------------------------------------------------------------------
  }
示例#21
0
  public static void main(String[] args) throws Exception {
    BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setPaint(Color.WHITE);
    g.fill(new Rectangle(image.getWidth(), image.getHeight()));
    g.scale(.9, .9);
    g.setPaint(Color.BLACK);
    g.setStroke(new BasicStroke(0.5f));
    g.draw(new Ellipse2D.Double(25, 25, 150, 150));

    // To visually check it
    // ImageIO.write(image, "PNG", new File(args[0]));

    boolean nonWhitePixelFound = false;
    for (int x = 100; x < 200; ++x) {
      if (image.getRGB(x, 90) != Color.WHITE.getRGB()) {
        nonWhitePixelFound = true;
        break;
      }
    }
    if (!nonWhitePixelFound) {
      throw new RuntimeException("A circle is rendered like a 'C' shape.");
    }
  }
  private void createImages() {
    int w = 16;
    int h = getPreferredSize().height;
    setTarget(new Rectangle(2, 0, 20, 18));
    Graphics2D g2;

    open = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    g2 = open.createGraphics();
    g2.setPaint(getBackground());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.fillRect(0, 0, w, h);
    int[] x = {2, w / 2, 14};
    int[] y = {4, 13, 4};
    Polygon p = new Polygon(x, y, 3);
    g2.setPaint(new Color(204, 204, 204));
    g2.fill(p);
    g2.draw(p);
    g2.dispose();

    closed = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    g2 = closed.createGraphics();
    g2.setPaint(getBackground());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.fillRect(0, 0, w, h);
    x = new int[] {3, 13, 3};
    y = new int[] {4, h / 2, 16};
    p = new Polygon(x, y, 3);
    g2.setPaint(new Color(102, 102, 102));
    g2.fill(p);
    g2.draw(p);
    g2.dispose();
  }
示例#23
0
  private void drawShape(Shuttle shuttle) {
    Graphics2D g = shuttle.g;
    Shape oldclip = shuttle.g.getClip();
    g.setClip(shuttle.clip);
    Composite oldcomposite = g.getComposite();
    if (shuttle.opacity != 1f) {
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, shuttle.opacity));
    }

    AffineTransform oldtr = g.getTransform();
    g.setTransform(shuttle.transform);

    Stroke oldStroke = g.getStroke();
    Stroke newStroke =
        new BasicStroke(shuttle.strokeWidth, shuttle.linecap.stroke(), shuttle.linejoin.stroke());
    g.setStroke(newStroke);

    if (shuttle.fill != null) {
      g.setPaint(shuttle.fill);
      g.fill(shuttle.shape);
    }
    if (shuttle.stroke != null) {
      g.setPaint(shuttle.stroke);
      g.draw(shuttle.shape);
    }
    g.setClip(oldclip);
    g.setStroke(oldStroke);
    g.setTransform(oldtr);
    g.setComposite(oldcomposite);
  }
示例#24
0
  @Override
  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    final Graphics2D g2d = (Graphics2D) g;
    final Insets ins = getBorderInsets(c);
    final int yOff = (ins.top + ins.bottom) / 4;
    final boolean square = DarculaButtonUI.isSquare(c);
    int offset = JBUI.scale(square ? 1 : getOffset());
    if (c.hasFocus()) {
      DarculaUIUtil.paintFocusRing(g2d, offset, yOff, width - 2 * offset, height - 2 * yOff);
    } else {
      final GraphicsConfig config = new GraphicsConfig(g);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
      g2d.setPaint(
          UIUtil.getGradientPaint(
              width / 2,
              y + yOff + 1,
              Gray._80.withAlpha(90),
              width / 2,
              height - 2 * yOff,
              Gray._90.withAlpha(90)));
      // g.drawRoundRect(x + offset + 1, y + yOff + 1, width - 2 * offset, height - 2*yOff, 5, 5);

      ((Graphics2D) g).setPaint(Gray._100.withAlpha(180));
      g.drawRoundRect(
          x + offset,
          y + yOff,
          width - 2 * offset,
          height - 2 * yOff,
          JBUI.scale(square ? 3 : 5),
          JBUI.scale(square ? 3 : 5));

      config.restore();
    }
  }
  protected void drawTask(String name, int x, int y, int width, int height, boolean thickBorder) {
    Paint originalPaint = g.getPaint();

    // Create a new gradient paint for every task box, gradient depends on x and y and is not
    // relative
    g.setPaint(new GradientPaint(x + 50, y, Color.white, x + 50, y + 50, TASK_BOX_COLOR));

    // shape
    RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, 20, 20);
    g.fill(rect);
    g.setPaint(originalPaint);

    if (thickBorder) {
      Stroke originalStroke = g.getStroke();
      g.setStroke(THICK_TASK_BORDER_STROKE);
      g.draw(rect);
      g.setStroke(originalStroke);
    } else {
      g.draw(rect);
    }

    // text
    if (name != null) {
      drawMultilineText(name, x, y, width, height);
    }
  }
示例#26
0
  @Override
  protected void paintComponent(Graphics g) {
    Graphics2D gd = (Graphics2D) g.create();

    shape = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), getHeight(), getWidth());

    if (isFokus()) {
      setForeground(Color.RED);
      paint = new GradientPaint(0, 0, Color.YELLOW, getWidth(), 0, Color.YELLOW);
    } else {
      setForeground(Color.BLACK);
      paint = new GradientPaint(0, 0, Color.white, getWidth(), 0, Color.white);
    }

    gd.setPaint(paint);
    gd.fill(shape);

    super.paintComponent(g);

    glass =
        new GradientPaint(
            0, 0, new Color(1F, 1F, 1F, 0.5F), 0, getHeight(), new Color(1F, 1F, 1F, 0F));
    gd.setPaint(glass);
    gd.fill(shape);

    gd.dispose();
  }
示例#27
0
  /**
   * Draw some graphics into an Graphics2D object.
   *
   * @param image the image to draw into
   * @throws NoninvertibleTransformException in transform errors.
   */
  private void draw(Graphics2D gr) throws NoninvertibleTransformException {
    gr.setPaint(Color.WHITE);
    gr.fill(new Rectangle(0, 0, tileWidth, tileHeight));

    // AffineTransform[[0.318755336305853, 0.0, 420.03106689453125],
    //                 [0.0, 0.318755336305853, 245.5029296875]]
    AffineTransform transform =
        new AffineTransform(
            0.318755336305853, 0.0, 0.0, 0.318755336305853, 420.03106689453125, 245.5029296875);
    gr.setTransform(transform);

    Shape s = new Rectangle(0, 0, 96, 83);

    // create an enbedded graphics
    Graphics2D grr = (Graphics2D) gr.create();
    // AffineTransform[[1.0, 0.0, -343.9285583496093],
    //                 [0.0, 1.0, -502.5158386230469]]
    grr.clip(s.getBounds());
    transform = new AffineTransform(1.0, 0.0, 0.0, 1.0, -343.9285583496093, -502.5158386230469);
    grr.transform(transform);

    AffineTransform t = transform.createInverse();
    s = t.createTransformedShape(s);

    assertTrue(s.getBounds().intersects(grr.getClip().getBounds2D()));

    grr.setPaint(Color.BLUE);
    grr.draw(s);

    grr.dispose();
    gr.dispose();
  }
 public static void smoothFillInverseHorGradient(
     Graphics g, Color[] colors, int x, int y, int w, int h) {
   if (colors != null) {
     Graphics2D g2D = (Graphics2D) g;
     Paint savedPaint = g2D.getPaint();
     int steps = colors.length;
     double dy = (double) h / (double) steps;
     int y1 = y;
     for (int i = 0; i < steps; i++) {
       int y2 = y + (int) Math.round((double) i * dy);
       g.setColor(colors[colors.length - i - 1]);
       if (i == (steps - 1)) {
         g2D.setPaint(null);
         g2D.setColor(colors[colors.length - i - 1]);
         g.fillRect(x, y1, w, y + h - y1);
       } else {
         g2D.setPaint(
             new GradientPaint(
                 0, y1, colors[colors.length - i - 1], 0, y2, colors[colors.length - i - 2]));
         g.fillRect(x, y1, w, y2 - y1);
       }
       y1 = y2;
     }
     g2D.setPaint(savedPaint);
   }
 }
示例#29
0
  private void drawArrow(Graphics2D g2d, double sx, double sy, double px, double py, int pass) {

    if (pass == 0) {

      g2d.setStroke(new BasicStroke(4.0f));
      g2d.setPaint(preSynapticSiteColor.brighter());
      g2d.draw(new Line2D.Double(sx, sy, px, py));

      return;
    }

    double dx = px - sx;
    double dy = py - sy;

    Polygon tip = new Polygon();
    tip.addPoint(0, 0);
    tip.addPoint(-10, -20);
    tip.addPoint(10, -20);

    AffineTransform transform = new AffineTransform();
    transform.concatenate(AffineTransform.getTranslateInstance(px, py));
    transform.concatenate(AffineTransform.getScaleInstance(0.5, 0.5));
    transform.concatenate(AffineTransform.getRotateInstance(Math.atan2(dy, dx) - Math.PI * 0.5));
    Shape shape = new GeneralPath(tip).createTransformedShape(transform);
    g2d.setPaint(preSynapticSiteColor.darker().darker());
    g2d.draw(shape);
    g2d.setPaint(preSynapticSiteColor.brighter().brighter());
    g2d.fill(shape);
  }
示例#30
0
  /**
   * DOCUMENT ME!
   *
   * @param g DOCUMENT ME!
   */
  public void paintComponent(Graphics g) {
    int step = 4;
    int count = 5;

    int size = step * count;

    BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
    Graphics2D biGraphics = image.createGraphics();
    biGraphics.setPaint(Color.black);

    int x = step;

    for (int i = 0; i < (count * 2); i++) {
      biGraphics.drawLine(0, x, x, 0);
      x += step;
    }

    Rectangle rect = new Rectangle(0, 0, size, size);
    TexturePaint paint = new TexturePaint(image, rect);
    ((Graphics2D) g).setPaint(paint);

    ((Graphics2D) g).setStroke(new BasicStroke(6));

    g.drawRect(10, 10, this.getWidth() - 20, this.getHeight() - 20);
  }