Esempio n. 1
0
 public void tree(Graphics2D g2d, double size, int phase) {
   g2d.setColor(colors[phase % 3]);
   new TextLayout(theT.toString(), theFont, g2d.getFontRenderContext()).draw(g2d, 0.0f, 0.0f);
   if (size > 10.0) {
     AffineTransform at = new AffineTransform();
     at.setToTranslation(Twidth, -0.1);
     at.scale(0.6, 0.6);
     g2d.transform(at);
     size *= 0.6;
     new TextLayout(theR.toString(), theFont, g2d.getFontRenderContext()).draw(g2d, 0.0f, 0.0f);
     at.setToTranslation(Rwidth + 0.75, 0);
     g2d.transform(at);
     Graphics2D g2dt = (Graphics2D) g2d.create();
     at.setToRotation(-Math.PI / 2.0);
     g2dt.transform(at);
     tree(g2dt, size, phase + 1);
     g2dt.dispose();
     at.setToTranslation(.75, 0);
     at.rotate(-Math.PI / 2.0);
     at.scale(-1.0, 1.0);
     at.translate(-Twidth, 0);
     g2d.transform(at);
     tree(g2d, size, phase);
   }
   g2d.setTransform(new AffineTransform());
 }
  /**
   * A static method for drawing an image (adapted from my first assignment)
   *
   * @param x horizontal position
   * @param y vertical position
   * @param w the scaled image width
   * @param h the scaled image height
   * @param angle the angle of rotation of the image
   * @param hflip whether or not to flip the image horizontally
   * @param vflip whether or not to flip the image vertically
   * @param canvas the image to draw
   * @param screen the destination to render to
   */
  public static void drawImage(
      double x,
      double y,
      double w,
      double h,
      double angle,
      boolean hflip,
      boolean vflip,
      BufferedImage canvas,
      Graphics2D screen) {
    AffineTransform oldTransform = screen.getTransform();
    double widthRatio = (double) w / (double) canvas.getWidth();
    double heightRatio = (double) h / (double) canvas.getHeight();

    AffineTransform affine = new AffineTransform();
    affine.translate(x, y);
    affine.scale(widthRatio, heightRatio);
    affine.scale((hflip ? -1 : 1) * 1.0, (vflip ? -1 : 1) * 1.0);
    affine.rotate(angle);
    affine.translate((double) -canvas.getWidth() / 2.0, (double) -canvas.getHeight() / 2.0);

    screen.transform(affine);

    screen.drawImage(canvas, 0, 0, null);
    screen.setTransform(oldTransform);
  }
Esempio n. 3
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();
  }
  @Override
  public void update() {
    // Draw the component
    graphics.drawImage(componentImage, 0, 0, null);

    // Draw the reflection
    int width = componentImage.getWidth();
    int height = componentImage.getHeight();

    GradientPaint mask =
        new GradientPaint(
            0,
            height / 4f,
            new Color(1.0f, 1.0f, 1.0f, 0.0f),
            0,
            height,
            new Color(1.0f, 1.0f, 1.0f, 0.5f));
    componentImageGraphics.setPaint(mask);

    componentImageGraphics.setComposite(AlphaComposite.DstIn);
    componentImageGraphics.fillRect(0, 0, width, height);

    componentImageGraphics.dispose();
    componentImageGraphics = null;

    componentImage.flush();

    graphics.transform(getTransform(component));

    graphics.drawImage(componentImage, 0, 0, null);

    componentImage = null;
    component = null;
    graphics = null;
  }
Esempio n. 5
0
  private void drawSliders(Graphics2D g2d) {
    g2d.translate(sliderBaseLineRect.x, sliderBaseLineRect.y);
    g2d.setStroke(STROKE_1);
    for (int i = 0; i < getSliderCount(); i++) {
      if (isSliderVisible(i)) {
        double sliderPos = getRelativeSliderPos(getSliderSample(i));

        g2d.translate(sliderPos, 0.0);

        final Color sliderColor = getSliderColor(i);
        g2d.setPaint(sliderColor);
        g2d.fill(sliderShape);

        int gray = (sliderColor.getRed() + sliderColor.getGreen() + sliderColor.getBlue()) / 3;
        g2d.setColor(gray < 128 ? Color.white : Color.black);
        g2d.draw(sliderShape);

        String text = getFormattedValue(getSliderSample(i));
        g2d.setColor(Color.black);
        // save the old transformation
        final AffineTransform oldTransform = g2d.getTransform();
        g2d.transform(AffineTransform.getRotateInstance(Math.PI / 2));
        g2d.drawString(text, 3 + 0.5f * SLIDER_HEIGHT, 0.35f * FONT_SIZE);
        // restore the old transformation
        g2d.setTransform(oldTransform);

        g2d.translate(-sliderPos, 0.0);
      }
    }

    g2d.translate(-sliderBaseLineRect.x, -sliderBaseLineRect.y);
  }
 private void paintBars(Graphics2D g) {
   g.transform(AffineTransform.getTranslateInstance(getWidth() / 2, getHeight() / 2));
   for (int i = 0; i < bars.length; ++i) {
     g.setColor(colors[(currentBar + i) % colors.length]);
     g.fill(bars[i]);
   }
 }
Esempio n. 7
0
  /**
   * Render the View to the given graphic context. This implementation render the interior first,
   * then the outline.
   */
  public void paint(Graphics2D g, Rectangle2D a) {
    if (!a.intersects(getBounds())) return;
    if (image != null) { // paint bitmap
      g.drawImage(image, text2ModelTr, null);
      // debug:
      g.setPaint(Color.red);
      g.draw(this.bounds);
      super.paint(g, a); // possibly paint framebox if non-null
    } else { // paint textlayout
      super.paint(g, a); // possibly paint framebox if non-null

      AffineTransform oldAT = g.getTransform();
      // paint text in black
      g.setPaint(Color.black);
      // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font
      // being mirrored...
      g.transform(text2ModelTr); // also include rotation
      textLayout.draw(g, 0.0f, 0.0f);
      // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre)
      // get back to previous transform
      g.setTransform(oldAT);
      if (DEBUG) {
        g.setPaint(Color.red);
        g.draw(bounds);
      }
    }
  }
Esempio n. 8
0
  /** 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);
    }
  }
Esempio n. 9
0
  public void render(Vehicle vehicle) {
    Vector adjustedPosition = vehicle.position().add(viewPoint);
    int x = (int) adjustedPosition.x();
    int y = (int) adjustedPosition.y();

    Vector tip = new Vector(x + vehicle.boundingRadius(), y);
    Vector left = new Vector(x - 5, y - 5);
    Vector right = new Vector(x - 5, y + 5);

    int[] xPos = {(int) tip.x(), (int) left.x(), (int) right.x()};
    int[] yPos = {(int) tip.y(), (int) left.y(), (int) right.y()};

    AffineTransform orig = graphics.getTransform();

    AffineTransform rot =
        AffineTransform.getRotateInstance(vehicle.heading().x(), vehicle.heading().y(), x, y);
    graphics.transform(rot);
    graphics.drawPolygon(xPos, yPos, 3);
    graphics.setTransform(orig);

    if (showFeelers) {
      Vector[] feelers = createFeelersFor(vehicle);
      for (Vector feeler : feelers) {
        graphics.drawLine(x, y, (int) feeler.x(), (int) feeler.y());
      }
    }
    renderHealthBar(vehicle, x, y);
    renderEnergyBar(vehicle, x, y);
  }
Esempio n. 10
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);
  }
  public void exportReportToGraphics2D() throws JRException {
    grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    grx.setRenderingHint(
        RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    grx.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    AffineTransform atrans = new AffineTransform();
    atrans.translate(globalOffsetX, globalOffsetY);
    atrans.scale(zoom, zoom);
    grx.transform(atrans);

    java.util.List pages = jasperPrint.getPages();
    if (pages != null) {
      Shape oldClipShape = grx.getClip();

      grx.clip(new Rectangle(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()));

      try {
        JRPrintPage page = (JRPrintPage) pages.get(startPageIndex);
        exportPage(page);
      } finally {
        grx.setClip(oldClipShape);
      }
    }
  }
 @Override
 public void paintObjectOn(GC gc) {
   Graphics2D g2d = (Graphics2D) gc.getGraphics2D().create();
   g2d.setPaint(getDrawingObject().getColor());
   g2d.transform(getViewer().getObjectToDisplayTransform());
   g2d.setStroke(new BasicStroke(0));
   g2d.draw(getDrawingObject().getBounds2D());
 }
Esempio n. 13
0
 public void init(Graphics2D g2d, Context ctx, Dimension dim) {
   int w = dim.width;
   int h = dim.height;
   AffineTransform at = new AffineTransform();
   at.translate(1.5, 1.5);
   g2d.transform(at);
   dim.setSize(w - 3, h - 3);
 }
Esempio n. 14
0
 public void init(Graphics2D g2d, Context ctx, Dimension dim) {
   int w = dim.width;
   int h = dim.height;
   AffineTransform at = new AffineTransform();
   at.translate((w - (w * h) / (h + w * 0.1)) / 2, 0.0);
   at.shear(0.0, 0.1);
   g2d.transform(at);
   dim.setSize(scaleForTransform(at, dim));
 }
Esempio n. 15
0
 public void init(Graphics2D g2d, Context ctx, Dimension dim) {
   int w = dim.width;
   int h = dim.height;
   AffineTransform at = new AffineTransform();
   at.scale(2.0, 2.0);
   g2d.transform(at);
   dim.setSize(w / 2, h / 2);
   ctx.pixscale = 4;
 }
Esempio n. 16
0
  /**
   * Draws a shape with the specified rotation about <code>(x, y)</code>.
   *
   * @param g2 the graphics device (<code>null</code> not permitted).
   * @param shape the shape (<code>null</code> not permitted).
   * @param angle the angle (in radians).
   * @param x the x coordinate for the rotation point.
   * @param y the y coordinate for the rotation point.
   */
  public static void drawRotatedShape(
      final Graphics2D g2, final Shape shape, final double angle, final float x, final float y) {

    final AffineTransform saved = g2.getTransform();
    final AffineTransform rotate = AffineTransform.getRotateInstance(angle, x, y);
    g2.transform(rotate);
    g2.draw(shape);
    g2.setTransform(saved);
  }
Esempio n. 17
0
  /**
   * Función de pintado del canvas. Pintamos un marco a la imagen para saber donde la movemos.
   *
   * <p>Para dibujar el marco alrededor del raster hacemos lo mismo que para pintar el raster
   * rotado. En realidad dibujamos un cuadrado y luego le aplicamos las transformaciones necesarias
   * para que se vea con la misma forma del raster al que representa.
   */
  public void paintComponent(Graphics g) {
    if (isMoveable && lyr != null && ptoFin != null && ptoIni != null) {
      try {
        ViewPort vp = grBehavior.getMapControl().getMapContext().getViewPort();
        AffineTransform at = (AffineTransform) lyr.getAffineTransform().clone();
        at.preConcatenate(vp.getAffineTransform());
        Extent ext = lyr.getFullRasterExtent();

        Point2D pt = new Point2D.Double(ext.getULX(), ext.getULY());
        vp.getAffineTransform().transform(pt, pt);
        at.inverseTransform(pt, pt);

        Point2D size = new Point2D.Double(ext.getLRX(), ext.getLRY());
        vp.getAffineTransform().transform(size, size);
        at.inverseTransform(size, size);

        double distX = ptoFin.getX() - ptoIni.getX();
        double distY = ptoFin.getY() - ptoIni.getY();
        Point2D d = new Point2D.Double(ext.getULX() + distX, ext.getULY() + distY);
        vp.getAffineTransform().transform(d, d);
        at.inverseTransform(d, d);

        // Giramos el graphics se dibuja y se vuelve a dejar como estaba
        ((Graphics2D) g).transform(at);
        g.setColor(rectangleColor);
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f);
        ((Graphics2D) g).setComposite(alpha);
        g.fillRect(
            (int) pt.getX() + (int) d.getX(),
            (int) pt.getY() + (int) d.getY(),
            (int) size.getX(),
            (int) size.getY());
        ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
        g.drawRect(
            (int) pt.getX() + (int) d.getX(),
            (int) pt.getY() + (int) d.getY(),
            (int) size.getX(),
            (int) size.getY());
        ((Graphics2D) g).transform(at.createInverse());
      } catch (NoninvertibleTransformException e1) {
        RasterToolsUtil.messageBoxError("error_transformacion1", this, e1);
      }
    }
  }
  /** Draws this handle. */
  public void draw(Graphics2D g) {
    Graphics2D gg = (Graphics2D) g.create();
    gg.transform(view.getDrawingToViewTransform());
    for (Connector c : connectors) {
      c.draw(gg);
    }

    gg.dispose();
    drawCircle(g, (getTarget() == null) ? Color.red : Color.green, Color.black);
  }
Esempio n. 19
0
 public void render(int w, int h, Graphics2D g2) {
   int mindim = Math.min(w, h);
   AffineTransform at = new AffineTransform();
   at.translate((w - mindim) / 2.0, (h - mindim) / 2.0);
   at.scale(mindim, mindim);
   at.translate(0.5, 0.5);
   at.scale(0.3, 0.3);
   at.translate(-(Twidth + Rwidth), FontHeight / 4.0);
   g2.transform(at);
   tree(g2, mindim * 0.3, 0);
 }
Esempio n. 20
0
  private void transformGraphics(Graphics2D g, Vec2 center) {
    Vec2 e = viewportTransform.getExtents();
    Vec2 vc = viewportTransform.getCenter();
    Mat22 vt = viewportTransform.getMat22Representation();

    int flip = yFlip ? -1 : 1;
    tr.setTransform(vt.ex.x, flip * vt.ex.y, vt.ey.x, flip * vt.ey.y, e.x, e.y);
    tr.translate(-vc.x, -vc.y);
    tr.translate(center.x, center.y);
    g.transform(tr);
  }
Esempio n. 21
0
  @Override
  public void paintCellROIs(ImageListViewCellPaintEvent evt) {
    ImageListViewCell cell = evt.getSource();
    Graphics2D g2d = (Graphics2D) evt.getGc().getGraphics2D().create();
    Graphics2D userGraphics = (Graphics2D) g2d.create();
    Point2D imageOffset = getImageOffset(cell);

    userGraphics.transform(
        AffineTransform.getTranslateInstance(imageOffset.getX(), imageOffset.getY()));
    cell.getRoiDrawingViewer().paint(new GC(userGraphics));
  }
Esempio n. 22
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   if (ico != null) {
     Graphics2D g2d = (Graphics2D) g;
     g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     g2d.setRenderingHint(
         RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
     AffineTransform oldt = g2d.getTransform();
     g2d.transform(AffineTransform.getScaleInstance(zoom, zoom));
     ico.paintIcon(c, g2d, (int) (x / zoom), (int) (y / zoom));
     g2d.setTransform(oldt);
   }
 }
Esempio n. 23
0
  @Test
  public void clipWithExistingTransform() throws Exception {
    AffineTransform tr = AffineTransform.getRotateInstance(Math.PI / 4);
    graphics.transform(tr);
    graphics.clip(midRect);

    /*
     * getClip should return the untransformed region - however we
     * allow for some slope because DiskMemImageGraphics is actually
     * returning the inverse-transformed version of its internal user
     * clip (transformed) shape.
     */
    assertBounds(midRect, graphics.getClipBounds(), 2);
  }
Esempio n. 24
0
    public void drawStuff(Graphics2D g2) {

      if (onMagnet) {
        return;
      }

      g2.transform(myTransform);
      positionInCrane.concatenate(g2.getTransform());

      g2.setColor(Color.RED);
      g2.fillRect(0, 0, width, height);
      g2.setColor(Color.BLACK);
      g2.drawRect(0, 0, width, height);
    }
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      Graphics2D g2 = (Graphics2D) g;

      if (!text.equals("")) {
        g2.translate(0, getSize().getHeight());
        g2.rotate(-Math.PI / 2);
        g2.setColor(Color.black);
        g2.drawString(text, 20, 14);

        g2.translate(0, -getSize().getHeight());
        g2.transform(AffineTransform.getQuadrantRotateInstance(1));
      }
    }
Esempio n. 26
0
  @Override
  protected void paintComponent(Graphics g) {
    if (_popupUtil == null) {
      super.paintComponent(g);
    } else {
      Graphics2D gr = (Graphics2D) g.create();

      switch (_popupUtil.getOrientation()) {
        case PositionablePopupUtil.VERTICAL_UP:
          gr.translate(0, getSize().getHeight());
          gr.transform(AffineTransform.getQuadrantRotateInstance(-1));
          break;
        case PositionablePopupUtil.VERTICAL_DOWN:
          gr.transform(AffineTransform.getQuadrantRotateInstance(1));
          gr.translate(0, -getSize().getWidth());
          break;
        default:
      }

      needsRotate = true;
      super.paintComponent(gr);
      needsRotate = false;
    }
  }
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g2.setColor(Color.white);
   g2.fillRect(0, 0, getWidth(), getHeight());
   AffineTransform at = new AffineTransform(0.5, 0, 0, -0.5, 30, getHeight() * 3 / 4);
   g2.transform(at);
   g2.setColor(Color.black);
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setRenderingHint(
       RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   //	System.out.println("Showing="+showing);
   if (showing != null) {
     showing.draw(g2);
   }
 }
  void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) {
    Graphics2D g = (Graphics2D) g1.create();

    double dx = x2 - x1, dy = y2 - y1;
    double angle = Math.atan2(dy, dx);
    int len = (int) Math.sqrt(dx * dx + dy * dy);
    AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
    at.concatenate(AffineTransform.getRotateInstance(angle));
    g.transform(at);

    // Draw horizontal arrow starting in (0, 0)
    g.drawLine(0, 0, len, 0);
    g.fillPolygon(
        new int[] {len, len - ARR_SIZE, len - ARR_SIZE, len},
        new int[] {0, -ARR_SIZE, ARR_SIZE, 0},
        4);
  }
Esempio n. 29
0
  public void render(Miner miner) {
    Vector adjustedPosition = miner.position().add(viewPoint);
    int x = (int) adjustedPosition.x();
    int y = (int) adjustedPosition.y();

    AffineTransform orig = graphics.getTransform();
    AffineTransform rot =
        AffineTransform.getRotateInstance(miner.heading().x(), miner.heading().y(), x, y);
    graphics.transform(rot);
    graphics.drawRect(
        x - (int) miner.boundingRadius(),
        y - ((int) miner.boundingRadius() / 2),
        (int) miner.boundingRadius() * 2,
        (int) miner.boundingRadius());
    graphics.setTransform(orig);
    renderHealthBar(miner, x, y);
    renderEnergyBar(miner, x, y);
  }
Esempio n. 30
0
  @Override
  public void paintCellImage(ImageListViewCellPaintEvent e) {
    ImageListViewCell cell = e.getSource();
    Graphics2D g2d = (Graphics2D) e.getGc().getGraphics2D().create();

    // give the render* methods a Graphics2D whose coordinate system
    // (and eventually, clipping) is already relative to the area in
    // which the image should be drawn
    Graphics2D userGraphics = (Graphics2D) g2d.create();
    Point2D imageOffset = getImageOffset(cell);
    userGraphics.transform(
        AffineTransform.getTranslateInstance(imageOffset.getX(), imageOffset.getY()));

    // render the image
    BufferedImageOp scaleImageOp =
        new AffineTransformOp(getDicomToUiTransform(cell), AffineTransformOp.TYPE_BILINEAR);
    userGraphics.drawImage(getWindowedImage(cell), scaleImageOp, 0, 0);
  }