예제 #1
0
 /**
  * Simple image flipper. Can flip image either vertically, horizontally or both directions
  *
  * @param source _
  * @param flipType _
  * @return BufferedImage
  * @throws NullPointerException _
  * @throws IllegalArgumentException _
  */
 public static <T> BufferedImage flipImage(final T source, final FlipType flipType)
     throws NullPointerException, IllegalArgumentException, IOException {
   if (verifyNotNull(source, flipType)) {
     BufferedImage sourceImage = convertToBufferedImage(source);
     BufferedImage target =
         new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), sourceImage.getType());
     AffineTransform affineTransform;
     AffineTransformOp affineTransformOp;
     if (flipType.equals(FlipType.HORIZONTAL) || flipType.equals(FlipType.BOTH)) {
       affineTransform = AffineTransform.getScaleInstance(1, -1);
       affineTransform.translate(-sourceImage.getWidth(), 0);
       affineTransformOp =
           new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
       target = affineTransformOp.filter(sourceImage, target);
     }
     if (flipType.equals(FlipType.VERTICAL) || flipType.equals(FlipType.BOTH)) {
       affineTransform = AffineTransform.getScaleInstance(1, -1);
       affineTransformOp =
           new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
       affineTransform.translate(0, -sourceImage.getHeight());
       target = affineTransformOp.filter(sourceImage, target);
     }
     return target;
   }
   throw new NullPointerException(E_OBJECT_WAS_NULL);
 }
  /**
   * Renders an image on the device
   *
   * @param graphics the image location on the screen, x coordinate
   * @param x the image location on the screen, y coordinate
   * @param y the image
   * @param image DOCUMENT ME!
   * @param rotation the image rotatation
   * @param opacity DOCUMENT ME!
   */
  private void renderImage(
      Graphics2D graphics,
      double x,
      double y,
      BufferedImage image,
      double rotation,
      float opacity) {
    if (LOGGER.isLoggable(Level.FINEST)) {
      LOGGER.finest("drawing Image @" + x + "," + y);
    }

    AffineTransform markAT = new AffineTransform();
    markAT.translate(x, y);
    markAT.rotate(rotation);
    markAT.translate(-image.getWidth() / 2.0, -image.getHeight() / 2.0);

    graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));

    Object interpolation = graphics.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
    if (interpolation == null) {
      interpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
    }
    try {
      graphics.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics.drawRenderedImage(image, markAT);
    } finally {
      graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation);
    }
  }
예제 #3
0
  public Area getCutArea1() {

    if (alpha[1] < 0.08f) {
      // 假如这部分已经基本透明,那么就把它变成空区域,并把它的位置速度变得和area部分一样,这样下次切割就不会出错。
      cutArea1 = new Area();
      x[1] = x[0];
      y[1] = y[0];
      vx[1] = vx[0];
      vy[1] = vy[0];
      asMove2.setToIdentity();
      asMove2.translate(x[1], y[1]);
      cutArea1 = new Area(asMove2.createTransformedShape(cutArea1));
    }

    if (cutArea1.isEmpty()) {
      alpha[1] = 1f;
    } else {

      alpha[1] = alpha[1] - 0.04f;
    }
    asMove2.setToIdentity();
    x[1] = x[1] + vx[1];
    y[1] = y[1] + vy[1];

    asMove2.translate(vx[1], vy[1]);
    cutArea1 = new Area(asMove2.createTransformedShape(cutArea1));

    return sinWave(cutArea1);
  }
예제 #4
0
  public Area getCutArea2() {

    if (alpha[2] < 0.08f) {
      cutArea2 = new Area();
      x[2] = x[0];
      y[2] = y[0];
      vx[2] = vx[0];
      vy[2] = vy[0];
      asMove3.setToIdentity();
      asMove3.translate(x[2], y[2]);
      cutArea2 = new Area(asMove3.createTransformedShape(cutArea2));
    }
    if (cutArea2.isEmpty()) {
      alpha[2] = 1f;

    } else {

      alpha[2] = alpha[2] - 0.04f;
    }

    asMove3.setToIdentity();
    x[2] = x[2] + vx[2];
    y[2] = y[2] + vy[2];

    asMove3.translate(vx[2], vy[2]);
    cutArea2 = new Area(asMove3.createTransformedShape(cutArea2));
    return sinWave(cutArea2);
  }
예제 #5
0
  public Area getArea() {

    if (!isPassed) {

      asMove1.setToIdentity();
      x[0] = x[0] + vx[0];
      y[0] = y[0] + vy[0];

      if ((pointList.size() - 1) % grap == 0) {
        makeSawtooth();
      }

      asMove1.translate(vx[0], vy[0]);
      area = new Area(asMove1.createTransformedShape(area));

      return sinWave(area);
    } else {
      // 生成锯齿状边缘

      cutTheArea(sawtooth);

      asMove1.setToIdentity();
      x[0] = x[0] + vx[0];
      y[0] = y[0] + vy[0];

      asMove1.translate(vx[0], vy[0]);
      area = new Area(asMove1.createTransformedShape(area));

      return sinWave(area);
    }
  }
예제 #6
0
  // TODO currently allows for collisions if same name & different filetype
  public void loadImage(String path) {
    BufferedImage readImage = null;
    try {
      readImage = ImageIO.read(new File("images/" + path));
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (readImage != null) {
      BufferedImage aImages[] = new BufferedImage[8];
      BufferedImage image =
          new BufferedImage(
              readImage.getWidth(), readImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
      Graphics g = image.getGraphics();
      g.drawImage(readImage, 0, 0, null);
      for (int i = 0; i < 8; i++) {
        AffineTransform trans = new AffineTransform();
        trans.translate(image.getWidth() / 2, image.getHeight() / 2);
        trans.rotate(Math.PI * i / 4.0);
        trans.translate(-image.getWidth() / 2, -image.getHeight() / 2);
        AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
        aImages[i] =
            new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
        op.filter(image, aImages[i]);
      }

      images.add(
          new Asset(
              path.substring(0, path.length() - 4), aImages)); // assumes standard 3 letter postfix
    }
  }
예제 #7
0
  @Override
  public void keyPressed(KeyEvent evt) {
    Figure f = getOwner();
    if (f.isTransformable()) {
      AffineTransform tx = new AffineTransform();

      switch (evt.getKeyCode()) {
        case KeyEvent.VK_UP:
          tx.translate(0, -1);
          evt.consume();
          break;
        case KeyEvent.VK_DOWN:
          tx.translate(0, +1);
          evt.consume();
          break;
        case KeyEvent.VK_LEFT:
          tx.translate(-1, 0);
          evt.consume();
          break;
        case KeyEvent.VK_RIGHT:
          tx.translate(+1, 0);
          evt.consume();
          break;
      }
      f.willChange();
      f.transform(tx);
      f.changed();
      fireUndoableEditHappened(new TransformEdit(f, tx));
    }
  }
예제 #8
0
  /** Refine segmentation with ADD/SUB regions of interests */
  private synchronized void refine() {
    if (controlPanel.status != ControlJPanel.SEGMENTATED_STATUS) return;

    if (controlPanel.addJRadioButton.isSelected()) addRoi = imp.getRoi();
    else subRoi = imp.getRoi();

    if (null != addRoi) {
      final float alpha = controlPanel.addThreshold.getValue() / 100.0f;
      final Shape shape = ShapeRoiHelper.getShape(new ShapeRoi(addRoi));
      final AffineTransform trans = new AffineTransform();
      trans.translate(addRoi.getBounds().getX(), addRoi.getBounds().getY());
      final Area area = new Area(shape);
      area.transform(trans);
      siox.subpixelRefine(area, SioxSegmentator.ADD_EDGE, alpha, (float[]) confMatrix.getPixels());
    }
    if (null != subRoi) {
      final float alpha = controlPanel.subThreshold.getValue() / 100.0f;
      final Shape shape = ShapeRoiHelper.getShape(new ShapeRoi(subRoi));
      final AffineTransform trans = new AffineTransform();
      trans.translate(subRoi.getBounds().getX(), subRoi.getBounds().getY());
      final Area area = new Area(shape);
      area.transform(trans);
      siox.subpixelRefine(area, SioxSegmentator.SUB_EDGE, alpha, (float[]) confMatrix.getPixels());
    }

    updateResult();
  }
  public void test010() {
    final float width = 3;
    final float height = 0;
    final Point2D.Float zero = new Point2D.Float(0, 0);
    final Point2D.Float ch = new Point2D.Float(0, 2);
    final Point2D.Float cb = new Point2D.Float(0, -1);
    final float h = ch.y - cb.y;
    final float sca = width / h;

    AffineTransform mat = new AffineTransform();
    mat.translate(width / 2, height / 2);
    mat.scale(sca, sca);
    mat.rotate(Math.PI / 2);
    mat.translate(0, -(ch.y + cb.y) / 2);

    final Point2D.Float cht = new Point2D.Float(0, 0);
    final Point2D.Float cbt = new Point2D.Float(0, 0);
    final Point2D.Float zerot = new Point2D.Float(0, 0);
    mat.transform(ch, cht);
    mat.transform(cb, cbt);
    mat.transform(zero, zerot);
    print("Hog :", cht);
    print("Back:", cbt);
    print("0,0 :", zerot);

    // assertEquals("", (float) 0, p.x, (float) 1e-1);
    // assertEquals("", (float) 0, p.y, (float) 1e-1);
  }
  /**
   * 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);
  }
예제 #11
0
파일: Well.java 프로젝트: RoboSquirt/java
  /**
   * Called by the dispatcher, tells its well to paint itself at the proper location.
   *
   * @param g - graphics to paint on
   * @param sF - scale factor from cm to pixels
   */
  public void paint(Graphics g, double sF, boolean isRotated) {

    // get the graphics objects
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform at = new AffineTransform();

    // draw well's outline
    at.translate(parentPlate.getTLcorner().getX() * sF, parentPlate.getTLcorner().getY() * sF);
    if (isRotated) {
      at.translate(parentPlate.getPlateSpecs().getBorderDimensions().getY() * sF, 0);
      at.rotate(Math.PI / 2);
    }
    at.translate(
        (relativeLocation.getX() - diameter / 2) * sF,
        (relativeLocation.getY() - diameter / 2) * sF);
    at.scale(sF, sF);

    g2d.setTransform(at);
    g2d.setColor(Color.BLACK);
    g2d.drawOval(0, 0, (int) diameter, (int) diameter);

    // highlight well if it is selected
    if (isSelected) {
      g2d.setColor(Color.LIGHT_GRAY);
      g2d.fillOval(0, 0, (int) diameter, (int) diameter);
    }
  }
예제 #12
0
 public AffineTransform getPixelToMapTransform() {
   AffineTransform transform = new AffineTransform();
   transform.translate(getEasting(), getNorthing());
   transform.scale(getPixelSizeX(), -getPixelSizeY());
   transform.rotate(Math.toRadians(-getOrientation()));
   transform.translate(-getPixelX(), -getPixelY());
   return transform;
 }
예제 #13
0
 // Update the current AffineTransform
 private void updateAffineTransform() {
   affineTransform.setToIdentity();
   affineTransform.translate(getWidth() * 0.5, getHeight() * 0.5);
   affineTransform.scale(scale, scale);
   affineTransform.translate(transX, transY);
   affineTransform.rotate(rotateAngle);
   affineTransform.translate(-modelCenter.x, -modelCenter.y);
 }
 private static AffineTransform createTransform(Sector source, MeshCoords destination) {
   java.awt.geom.AffineTransform transform = new java.awt.geom.AffineTransform();
   transform.translate(destination.left, destination.bottom);
   transform.scale(
       (destination.right - destination.left) / source.getDeltaLonDegrees(),
       (destination.top - destination.bottom) / source.getDeltaLatDegrees());
   transform.translate(-source.getMinLongitude().degrees, -source.getMinLatitude().degrees);
   return transform;
 }
예제 #15
0
  @Override
  public Transition2DInstruction[] getInstructions(float progress, Dimension size) {
    if (type == OUT) {
      progress = 1 - progress;
    }
    progress = (float) Math.pow(progress, .5);

    float ySize = (size.height) * .05f;
    float xSize = (size.width) * .05f;
    Vector<RectangularShape> v = new Vector<RectangularShape>();
    float angleProgress = (float) Math.pow(1 - Math.min(progress, 1), .5);
    // pop it over 1:
    float progressZ = 1.3f * progress;
    double w = xSize * progressZ;
    double h = ySize * progressZ;
    float min = (float) (Math.min(w, h));
    for (float y = 0; y < size.height; y += ySize) {
      for (float x = 0; x < size.width; x += xSize) {
        v.add(
            new RoundRectangle2D.Double(
                x + xSize / 2 - w / 2,
                y + ySize / 2 - h / 2,
                w * progress + (1 - progress) * min,
                h * progress + (1 - progress) * min,
                w * angleProgress * progress + (1 - progress) * min * angleProgress,
                h * angleProgress * progress + (1 - progress) * min * angleProgress));
      }
    }
    ImageInstruction[] instr = new ImageInstruction[v.size() + 1];
    instr[0] = new ImageInstruction(false);
    for (int a = 0; a < v.size(); a++) {
      float progress2 = progress; // (float)Math.pow(progress, .9+.2*random.nextFloat());
      RectangularShape r = v.get(a);
      Point2D p1 = new Point2D.Double(r.getCenterX(), r.getCenterY());
      Point2D p2 = new Point2D.Double(r.getCenterX(), r.getCenterY());
      AffineTransform transform = new AffineTransform();
      transform.translate(r.getCenterX(), r.getCenterY());
      transform.scale(30 * (1 - progress) + 1, 30 * (1 - progress) + 1);
      transform.translate(-r.getCenterX(), -r.getCenterY());

      transform.rotate(.3 * (1 - progress2), size.width / 3, size.height / 2);

      transform.transform(p1, p2);
      transform.setToTranslation(p1.getX() - p2.getX(), p1.getY() - p2.getY());
      Shape shape = transform.createTransformedShape(r);
      instr[a + 1] = new ImageInstruction(true, transform, shape);
    }
    if (type == IN) {
      for (int a = 0; a < instr.length; a++) {
        instr[a].isFirstFrame = !instr[a].isFirstFrame;
      }
    }

    return instr;
  }
예제 #16
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);
  }
예제 #17
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);
 }
예제 #18
0
파일: Hero.java 프로젝트: rweichler/wuigi
  private void drawAWP(Graphics g, int x, int y) {
    if (System.currentTimeMillis() < shotTime + TAWP.SHOOT_TIME) {
      // System.out.println(true);
      double multi = 1.0 * (System.currentTimeMillis() - shotTime) / TAWP.SHOOT_TIME;
      g.setColor(new Color(255, 255, 255, 255 - (int) (multi * 256)));
      g.fillRect(0, 0, Wuigi.screenWidth, Wuigi.screenHeight);
    }
    if (numBullets <= 0) return;

    BufferedImage img = TAWP.IMAGE.getBuffer();
    AffineTransform xform = new AffineTransform();
    // g2d.setPaint(new TexturePaint(figureOutDrawImage(),
    //		new Rectangle2D.Float(0, 0, 32, 32)));
    // g2d.drawImage(figureOutDrawImage(),0,0,null);
    xform.setToIdentity();
    xform.translate(x - 5, y);

    double diffY = y + height / 2 - ScreenManager.mouse.y;
    double diffX = ScreenManager.mouse.x - x - width / 2;

    double angle;

    if (diffY > 0 && diffX > 0) {
      angle = Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX > 0) {
      angle = Math.PI / 2;
    } else if (diffY < 0 && diffX > 0) {
      angle = Math.PI / 2 + Math.atan(-diffY / diffX);
    } else if (diffY < 0 && diffX == 0) {
      angle = Math.PI;
    } else if (diffY < 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX < 0) {
      angle = 3 * Math.PI / 2;
    } else if (diffY > 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 + Math.atan(-diffY / diffX);
    } else {
      angle = 0;
    }
    angle -= Math.PI / 2;

    if (angle > Math.PI / 2 && angle < 3 * Math.PI / 2) {
      xform.scale(1, -1);
      xform.translate(0, -TAWP.IMAGE.getHeight());
      angle = -angle;
    }
    // xform.scale(/*width/img.getWidth(),height/img.getHeight()*/);
    xform.rotate(angle, 27, 13);

    ((Graphics2D) g).drawImage(img, xform, null);
    ammo.setPos(x + 10, y - 20);
    ammo.draw(g);
  }
예제 #19
0
  /*
   * (non-Javadoc)
   *
   * @see controller.Command#execute()
   */
  public void execute() {
    Point anchor = getAnchorPoint(objects);

    double shx = Math.tan((angleDegrees / 360) * (2 * Math.PI));
    System.out.printf("Applying sheerx of %f%n", shx);
    for (Object shapeObj : objects) {
      Shape shape = (Shape) shapeObj;
      mt.addMememto(shape);
      AffineTransform t = shape.getAffineTransform();
      t.translate(anchor.x, anchor.y);
      t.shear(shx, 0);
      t.translate(-anchor.x, -anchor.y);
      shape.setAffineTransform(t);
    }
  }
예제 #20
0
  protected void addGeoCoding(Product product) throws IOException {
    GeoPos ulPos = getUpperLeftPosition();
    final Rectangle rect =
        new Rectangle(product.getSceneRasterWidth(), product.getSceneRasterHeight());
    AffineTransform transform = new AffineTransform();
    transform.translate(ulPos.getLon(), ulPos.getLat());
    transform.scale(PIXEL_SIZE_DEG, -PIXEL_SIZE_DEG);
    transform.translate(-PIXEL_CENTER, -PIXEL_CENTER);

    try {
      product.setGeoCoding(new CrsGeoCoding(DefaultGeographicCRS.WGS84, rect, transform));
    } catch (Exception e) {
      throw new IOException("Cannot create GeoCoding: ", e);
    }
  }
예제 #21
0
  /**
   * Synchronize the textLayout and the shape (=frame box, by calling syncFrame) with the model When
   * <code>TextLayout</code> is used, this delegates to <code>getRotation()</code> where computing
   * rotation angle is concerned, and updates the AffineTransform returned by <code>
   * getTextToModelTransform()</code>.
   */
  protected void syncShape() {
    PicText te = (PicText) element;

    //			textLayout = new TextLayout(te.getText().length()==0 ? " " : te.getText(),
    //			    textFont,
    //			    new FontRenderContext(null,false,false));

    text2ModelTr.setToIdentity(); // reset
    PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
    text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
    // the reference point of an image is the top-left one, but the refpoint of a text layout is on
    // the baseline
    if (image != null) {
      text2ModelTr.translate(te.getLeftX(), te.getTopY());
      if (te.getWidth() != 0
          && image.getWidth() != 0
          && (te.getDepth() + te.getHeight()) != 0
          && image.getHeight() != 0)
        text2ModelTr.scale(
            te.getWidth() / image.getWidth(),
            -(te.getHeight() + te.getDepth()) / image.getHeight());
    } else {
      // Hack ? Just cheating a little bit ? Ou juste ruse ?
      // we want here to use the dimensions of the textLayout instead of latex dimensions if
      // areDimensionsComputed
      // sinon on va aligner le textlayout en fonction des parametres latex, et l'Utilisateur (qui
      // est bien bete) ne va rien comprendre.
      double latexH = 0;
      double latexD = 0;
      double latexW = 0;
      if (areDimensionsComputed) { // store latex dimensions, and setDimensions to textLayout ones
        latexH = te.getHeight();
        latexD = te.getDepth();
        latexW = te.getWidth();
        te.setDimensions(
            textLayout.getBounds().getWidth(), textLayout.getAscent(), textLayout.getDescent());
      }
      text2ModelTr.translate(te.getLeftX(), te.getBaseLineY());
      if (areDimensionsComputed) { // restore latex dimensions
        te.setDimensions(latexW, latexH, latexD);
      }
      // Autre possibilite= comprimer le texte pour qu'il rentre dans la boite (evite le hack
      // ci-dessus):
      // text2ModelTr.scale(te.getWidth()/textLayout.getWidth(),-(te.getHeight()+te.getDepth())/textLayout.getHeight());
      text2ModelTr.scale(1.0, -1.0);
    }
    syncFrame();
  }
예제 #22
0
  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);
  }
예제 #23
0
 /// @pre l > 0, x >= 0, y >= 0
 /// @post La Nau:
 ///         - està viva
 ///         - té una llargada l i una amplada(a) màxima l/2
 ///         - té la punta superior a la coordenada (a/2)
 ///         - apunta cap a dalt
 ///         - esta situada al punt (x,y)
 ///         - és de color c
 NauEnemiga(int l, Color c, double x, double y) {
   super(l, c);
   double[] centre = obtenirCentreTriangle();
   AffineTransform a = new AffineTransform();
   a.translate(x - centre[0], y - centre[1]);
   triangle_.transform(a);
 }
  public DisplayPanel(DrawComponent dc) {
    super();
    this.dc = dc;
    //		setDebug(false, true);
    dc.clearBounds();
    Rectangle dcBounds = new Rectangle(dc.getBounds());
    AffineTransform at = new AffineTransform();
    at.translate(-dcBounds.x, -dcBounds.y);
    if (debugBounds) {
      logger.debug("init dcBounds " + dcBounds); // $NON-NLS-1$
      logger.debug("translateX = " + (-dcBounds.x)); // $NON-NLS-1$
      logger.debug("translateY = " + (-dcBounds.y)); // $NON-NLS-1$
    }
    dc.transform(at);
    dc.clearBounds();
    if (debugBounds) logger.debug("translated dcBounds = " + dc.getBounds()); // $NON-NLS-1$
    dcBounds = GeomUtil.translateToOriginAndAdjustSize(dc.getBounds());
    //		dcBounds = GeomUtil.translateToOrigin(dc.getBounds());
    if (debugBounds)
      logger.debug("translateToOriginAndAdjustSize dcBounds = " + dcBounds); // $NON-NLS-1$

    setBackground(bgColor);
    renderingHintsManager.setRenderMode(RenderingHintsManager.RENDER_MODE_QUALITY);
    init(dcBounds);
  }
예제 #25
0
  /**
   * Renders an image on the device
   *
   * @param tx the image location on the screen, x coordinate
   * @param ty the image location on the screen, y coordinate
   * @param img the image
   * @param rotation the image rotatation
   */
  private static void renderImage(
      Graphics2D graphics, double x, double y, Image image, double rotation, float opacity) {
    AffineTransform temp = graphics.getTransform();
    AffineTransform markAT = new AffineTransform();
    Point2D mapCentre = new java.awt.geom.Point2D.Double(x, y);
    Point2D graphicCentre = new java.awt.geom.Point2D.Double();
    temp.transform(mapCentre, graphicCentre);
    markAT.translate(graphicCentre.getX(), graphicCentre.getY());

    double shearY = temp.getShearY();
    double scaleY = temp.getScaleY();

    double originalRotation = Math.atan(shearY / scaleY);

    markAT.rotate(rotation);
    graphics.setTransform(markAT);
    graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));

    // we moved the origin to the centre of the image.
    graphics.drawImage(image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null);

    graphics.setTransform(temp);

    return;
  }
예제 #26
0
  public boolean scaleImage(
      SunGraphics2D sg, Image img, int x, int y, int width, int height, Color bgColor) {
    int imgw = img.getWidth(null);
    int imgh = img.getHeight(null);
    // Only accelerate scale if:
    //          - w/h positive values
    //          - sg transform integer translate/identity only
    //          - no bgColor in operation
    if ((width > 0) && (height > 0) && isSimpleTranslate(sg)) {
      double dx1 = x + sg.transX;
      double dy1 = y + sg.transY;
      double dx2 = dx1 + width;
      double dy2 = dy1 + height;
      if (renderImageScale(
          sg, img, bgColor, sg.interpolationType, 0, 0, imgw, imgh, dx1, dy1, dx2, dy2)) {
        return true;
      }
    }

    AffineTransform atfm = sg.transform;
    if ((x | y) != 0 || width != imgw || height != imgh) {
      atfm = new AffineTransform(atfm);
      atfm.translate(x, y);
      atfm.scale(((double) width) / imgw, ((double) height) / imgh);
    }
    transformImage(sg, img, atfm, sg.interpolationType, 0, 0, imgw, imgh, bgColor);
    return true;
  }
예제 #27
0
 public void Draw(Graphics2D gr) {
   AffineTransform transform = new AffineTransform();
   transform.rotate(Direction, x + width / 2, y + height / 2);
   transform.translate(x, y);
   switch (color) {
     case RED:
       gr.drawImage(image.getSubimage(0, 0, 50, 50), transform, null);
       break;
     case YELLOW:
       gr.drawImage(image.getSubimage(50, 0, 50, 50), transform, null);
       break;
     case PURPLE:
       gr.drawImage(image.getSubimage(100, 0, 50, 50), transform, null);
       break;
     case WHITE:
       gr.drawImage(image.getSubimage(150, 0, 50, 50), transform, null);
       break;
     case GREEN:
       gr.drawImage(image.getSubimage(200, 0, 50, 50), transform, null);
       break;
     case BLUE:
       gr.drawImage(image.getSubimage(250, 0, 50, 50), transform, null);
       break;
   }
   gun.Draw(gr);
 }
  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);
      }
    }
  }
예제 #29
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());
 }
예제 #30
0
파일: Use.java 프로젝트: uazure/josm
  protected void build() throws SVGException {
    super.build();

    StyleAttribute sty = new StyleAttribute();

    if (getPres(sty.setName("x"))) {
      x = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("y"))) {
      y = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("width"))) {
      width = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("height"))) {
      height = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("xlink:href"))) {
      URI src = sty.getURIValue(getXMLBase());
      href = src;
      //            href = diagram.getUniverse().getElement(src);
    }

    // Determine use offset/scale
    refXform = new AffineTransform();
    refXform.translate(this.x, this.y);
  }