示例#1
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);
  }
示例#2
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);
  }
示例#3
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);
    }
  }
示例#4
0
  /** @throws RuntimeException */
  private void calculateAffineTransform() {
    if (extent == null) {
      return;
    } else if (image == null || getWidth() == 0 || getHeight() == 0) {
      return;
    }

    if (adjustExtent) {
      double escalaX = getWidth() / extent.getWidth();
      double escalaY = getHeight() / extent.getHeight();

      double xCenter = extent.getMinX() + extent.getWidth() / 2.0;
      double yCenter = extent.getMinY() + extent.getHeight() / 2.0;
      adjustedExtent = new Envelope();

      double scale;
      if (escalaX < escalaY) {
        scale = escalaX;
        double newHeight = getHeight() / scale;
        double newX = xCenter - (extent.getWidth() / 2.0);
        double newY = yCenter - (newHeight / 2.0);
        adjustedExtent = new Envelope(newX, newX + extent.getWidth(), newY, newY + newHeight);
      } else {
        scale = escalaY;
        double newWidth = getWidth() / scale;
        double newX = xCenter - (newWidth / 2.0);
        double newY = yCenter - (extent.getHeight() / 2.0);
        adjustedExtent = new Envelope(newX, newX + newWidth, newY, newY + extent.getHeight());
      }

      trans.setToIdentity();
      trans.concatenate(AffineTransform.getScaleInstance(scale, -scale));
      trans.concatenate(
          AffineTransform.getTranslateInstance(
              -adjustedExtent.getMinX(), -adjustedExtent.getMinY() - adjustedExtent.getHeight()));
    } else {
      adjustedExtent = new Envelope(extent);
      trans.setToIdentity();
      double scaleX = getWidth() / extent.getWidth();
      double scaleY = getHeight() / extent.getHeight();

      /** Map Y axis grows downward but CRS grows upward => -1 */
      trans.concatenate(AffineTransform.getScaleInstance(scaleX, -scaleY));
      trans.concatenate(
          AffineTransform.getTranslateInstance(
              -extent.getMinX(), -extent.getMinY() - extent.getHeight()));
    }
    try {
      transInv = trans.createInverse();
    } catch (NoninvertibleTransformException ex) {
      transInv = null;
      throw new RuntimeException(ex);
    }
  }
示例#5
0
  private BufferedImage createGrid() {
    if (transformCells.getScaleY() < SHOW_GRID_MIN_SCALE) {
      return null;
    }

    Point2D cellSize = getCellSizeAfterScale();
    cellWidth = round(cellSize.getX());
    cellHeight = round(cellSize.getY());

    BufferedImage image =
        new BufferedImage(
            getWidth() + 2 * (cellWidth),
            getHeight() + 2 * (cellHeight),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = image.createGraphics();
    graphics2D.setColor(new Color(0, true));
    graphics2D.fillRect(0, 0, image.getWidth(), image.getHeight());

    graphics2D.setPaint(Color.YELLOW);
    graphics2D.setStroke(new BasicStroke(1));

    for (int x = 0; x < image.getWidth(); x += cellWidth) {
      graphics2D.drawLine(x, 0, x, image.getHeight());
    }
    for (int y = 0; y < image.getHeight(); y += cellHeight) {
      graphics2D.drawLine(0, y, image.getWidth(), y);
    }
    transformGrid.setToIdentity();
    calculateGridTranslation();

    graphics2D.dispose();
    return image;
  }
  public void test110_ZoomShift() {
    // final double s = 1.0 / RockLocationDisplayBase.SCALE;
    final double[] flat = new double[6];
    final Point2D dst = new Point2D.Double();
    final Point2D src = new Point2D.Double();
    final AffineTransform mat = new AffineTransform();
    final Rectangle2D wc = new Rectangle2D.Double(1, 2, 3, 4);
    Rectangle dc = new Rectangle(-1, -2, 3, 4);
    final Point2D fix = new Point2D.Double(1, 2);
    ZoomerFixPoint zom = new ZoomerFixPoint("1:1", wc, fix);

    mat.setToIdentity();
    zom.computeWc2Dc(dc, Orientation.N, true, false, mat);
    mat.getMatrix(flat);
    assertEquals("", -0.0010, flat[0], 1e-9);
    assertEquals("", 0, flat[1], 1e-9);
    assertEquals("", 0, flat[2], 1e-9);
    assertEquals("", -0.0010, flat[3], 1e-9);
    assertEquals("", 1.0, flat[4], 1e-9);
    assertEquals("", 6, flat[5], 1e-9);
    src.setLocation(fix);
    mat.transform(src, dst);
    assertEquals(new Point2D.Double(0.999, 5.998), dst);
    src.setLocation(3, 4);
    mat.transform(src, dst);
    assertEquals(new Point2D.Double(0.997, 5.996), dst);
  }
  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);
  }
  public void drawPoolOrLane(String name, int x, int y, int width, int height) {
    g.drawRect(x, y, width, height);

    // Add the name as text, vertical
    if (name != null && name.length() > 0) {
      // Include some padding
      int availableTextSpace = height - 6;

      // Create rotation for derived font
      AffineTransform transformation = new AffineTransform();
      transformation.setToIdentity();
      transformation.rotate(270 * Math.PI / 180);

      Font currentFont = g.getFont();
      Font theDerivedFont = currentFont.deriveFont(transformation);
      g.setFont(theDerivedFont);

      String truncated = fitTextToWidth(name, availableTextSpace);
      int realWidth = fontMetrics.stringWidth(truncated);

      g.drawString(
          truncated,
          x + 2 + fontMetrics.getHeight(),
          3 + y + availableTextSpace - (availableTextSpace - realWidth) / 2);
      g.setFont(currentFont);
    }
  }
示例#9
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);
 }
示例#10
0
 public JImageObject() {
   imageIcon = null;
   boundRect = null;
   totalTransform = new AffineTransform();
   totalTransform.setToIdentity();
   alpha = 1f;
   addingTransform = null;
 }
示例#11
0
 /** Creates a new instance of JImageObject */
 public JImageObject(Image img, Point2D sp) {
   imageIcon = new ImageIcon(img);
   boundRect =
       new Rectangle2D.Double(
           sp.getX(), sp.getY(), imageIcon.getIconWidth(), imageIcon.getIconHeight());
   totalTransform = new AffineTransform();
   totalTransform.setToIdentity();
   addingTransform = null;
   alpha = 1f;
 }
示例#12
0
 /** draw: draws the asteroid */
 public void draw(Graphics2D g2) {
   saveT = g2.getTransform();
   identity.setToIdentity();
   g2.setTransform(identity);
   g2.translate(x, y);
   g2.rotate(faceAngle);
   g2.setColor(color);
   g2.draw(shape);
   g2.setTransform(saveT);
 }
示例#13
0
  void createBufferedImage(final int width, final int height) {
    if (bufferedImage != null
        && bufferedImage.getWidth() == width
        && bufferedImage.getHeight() == height) {
      // just clear
      clearPlane();
      return;
    }

    bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    pixels = ((DataBufferInt) bufferedImage.getRaster().getDataBuffer()).getData();
    previewRotation = 0;

    transformCells.setToIdentity();
    transformGrid.setToIdentity();
    // center plane if needed
    if (width < getWidth()) transformCells.translate(round((getWidth() - width) / 2f), 0);
    if (height < getHeight()) transformCells.translate(0, round((getHeight() - height) / 2f));

    bufferedImageGrid = createGrid();
  }
示例#14
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);
  }
示例#15
0
 /**
  * synchronize frame shape and location (TextLayout only) ; this is called by syncShape(), so that
  * subclasser might override easily when only rectangular shapes are availables.
  */
 protected void syncFrame() {
   PicText te = (PicText) element;
   if (!te.isFramed()) {
     return;
   }
   AffineTransform tr =
       new AffineTransform(); // maps Image coordinates to Model coordinates (see paint)
   tr.setToIdentity(); // reset
   PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
   tr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
   shape = tr.createTransformedShape(te.getShapeOfFrame());
 }
示例#16
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();
  }
  public void drawDefaultSequenceFlowIndicator(Line2D.Double line) {
    double length = DEFAULT_INDICATOR_WIDTH, halfOfLength = length / 2, f = 8;
    Line2D.Double defaultIndicator = new Line2D.Double(-halfOfLength, 0, halfOfLength, 0);

    double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1);
    double dx = f * Math.cos(angle), dy = f * Math.sin(angle), x1 = line.x1 + dx, y1 = line.y1 + dy;

    AffineTransform transformation = new AffineTransform();
    transformation.setToIdentity();
    transformation.translate(x1, y1);
    transformation.rotate((angle - 3 * Math.PI / 4));

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

    g.setTransform(originalTransformation);
  }
  public void drawArrowHead(Line2D.Double line) {
    int doubleArrowWidth = 2 * ARROW_WIDTH;
    Polygon arrowHead = new Polygon();
    arrowHead.addPoint(0, 0);
    arrowHead.addPoint(-ARROW_WIDTH, -doubleArrowWidth);
    arrowHead.addPoint(ARROW_WIDTH, -doubleArrowWidth);

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

    AffineTransform originalTransformation = g.getTransform();
    g.setTransform(transformation);
    g.fill(arrowHead);
    g.setTransform(originalTransformation);
  }
示例#19
0
  public void validateCompositeState(
      Composite comp, AffineTransform xform, Paint paint, SunGraphics2D sg2d) {
    boolean updatePaint = (paint != validatedPaint) || paint == null;

    // validate composite
    if ((comp != validatedComp)) {
      if (comp != null) {
        setComposite(comp);
      } else {
        comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
        setComposite(comp);
      }
      // the paint state is dependent on the composite state, so make
      // sure we update the color below
      updatePaint = true;
      validatedComp = comp;
    }

    if (sg2d != null && validatedPixel != sg2d.pixel) {
      validatedPixel = sg2d.pixel;
      setForeground(validatedPixel);
    }

    // validate paint
    if (updatePaint) {
      if (paint != null && sg2d != null && sg2d.paintState >= SunGraphics2D.PAINT_GRADIENT) {
        XRPaints.setPaint(sg2d, paint);
      } else {
        XRResetPaint();
      }
      validatedPaint = paint;
    }

    if (src != solidSrcPict) {
      AffineTransform at = (AffineTransform) xform.clone();
      try {
        at.invert();
      } catch (NoninvertibleTransformException e) {
        at.setToIdentity();
      }
      src.validateAsSource(at, -1, -1);
    }
  }
示例#20
0
  /** Synchronizes bounding box with the model ; */
  protected void syncBounds() {
    PicText te = (PicText) element;
    // [pending] Il faut tenir compte de la rotation !

    Rectangle2D latexBB =
        null; // BB relative to latex dimensions (including rotation) (without frame)
    Rectangle2D textLayoutBB =
        null; // BB relative to textLayout dimensions (including rotation) (without frame)
    Rectangle2D textBB = null; // BB of the text (including rotation), without frame

    if (areDimensionsComputed) { // compute latexBB
      Rectangle2D nonRotated =
          new Rectangle2D.Double(
              te.getLeftX(), te.getBottomY(), te.getWidth(), te.getHeight() + te.getDepth());
      AffineTransform tr =
          new AffineTransform(); // maps Image coordinates to Model coordinates (see paint)
      tr.setToIdentity(); // reset
      PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
      tr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
      latexBB = tr.createTransformedShape(nonRotated).getBounds2D();
    }

    if (image == null) { // compute textLayoutBB
      Rectangle2D nonRotated = textLayout.getBounds();
      textLayoutBB = text2ModelTr.createTransformedShape(nonRotated).getBounds2D();
    }

    // use textLayoutBB or latexBB or their union
    if (image != null) textBB = latexBB;
    else {
      if (!areDimensionsComputed) textBB = textLayoutBB;
      else {
        textBB = latexBB.createUnion(textLayoutBB);
      }
    }

    // union with frame BB
    if (te.isFramed()) {
      super.syncBounds(); // update bounds of the frame if necessary
      Rectangle2D.union(super.bounds, textBB, this.bounds);
    } else this.bounds = textBB;
  }
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Dimension d = getSize();

    bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bi.createGraphics();

    step(d.width, d.height);

    AffineTransform at = new AffineTransform();
    at.setToIdentity();
    at.translate(x, y);
    at.rotate(Math.toRadians(rotate));
    at.scale(scale, scale);
    big.drawImage(image, at, this);

    Graphics2D g2D = (Graphics2D) g;
    g2D.drawImage(bi, 0, 0, null);

    big.dispose();
  }
示例#22
0
文件: Car.java 项目: mhcrnl/JavaCode
  @Override
  public void draw(Graphics g) {

    // FIXME : Draw the train car at the specific x and y coordinates with the current angle.

    // Compute these values in the handlers
    // and then handle the visual interpretation of them in this draw function.

    // Create an Affine transform and use it to draw the car using my scheme.

    AT.setToIdentity();

    AT.rotate(Math.toRadians(angle), x, y);

    AT.translate(x - Spr.car.getWidth() / 2, y - Spr.car.getHeight() / 2);

    Graphics2D g2 = (Graphics2D) g;

    g2.drawImage(Spr.car, AT, null);

    g2.setFont(FontManager.font_12);
    FontDrawing.drawTextCentered(g2, "" + load, x, y);
  }
示例#23
0
 public void paintObjects(LGraphics g, int minX, int minY, int maxX, int maxY) {
   if (objects == null) {
     return;
   }
   synchronized (objects) {
     int paintSeq = 0;
     boolean isListener = false;
     Iterator iter = objects.iterator();
     Actor thing = null;
     while (iter.hasNext()) {
       thing = (Actor) iter.next();
       if (!thing.isVisible()) {
         continue;
       }
       isListener = (thing.actorListener != null);
       thing.update(elapsedTime);
       if (isListener) {
         thing.actorListener.update(elapsedTime);
       }
       RectBox rect = thing.getRectBox();
       int actorX = minX + thing.getX();
       int actorY = minY + thing.getY();
       int actorWidth = rect.getWidth();
       int actorHeight = rect.getHeight();
       if (actorX + actorWidth < minX
           || actorX > maxX
           || actorY + actorHeight < minY
           || actorY > maxY) {
         continue;
       }
       LImage actorImage = thing.getImage();
       if (actorImage != null) {
         thing.setLastPaintSeqNum(paintSeq++);
         boolean isBitmapFilter = ImageFilterType.NoneFilter != thing.filterType;
         Image bitmap = actorImage.getBufferedImage();
         if (isBitmapFilter) {
           bitmap = factory.doFilter(bitmap, thing.filterType);
         }
         int rotation = thing.getRotation();
         if (thing.alpha < 1.0) {
           g.setAlpha(thing.alpha);
         }
         if (rotation != 0) {
           double halfWidth = actorImage.getWidth() / 2;
           double halfHeight = actorImage.getHeight() / 2;
           double newWidth = actorX + halfWidth;
           double newHeight = actorY + halfHeight;
           atform.setToIdentity();
           atform.scale(thing.scaleX, thing.scaleY);
           atform.translate(newWidth, newHeight);
           atform.rotate(Math.toRadians(rotation));
           atform.translate(-newWidth, -newHeight);
           atform.translate(actorX, actorY);
           g.drawImage(bitmap, atform);
         } else {
           int width = (int) (actorImage.getWidth() * thing.scaleX);
           int height = (int) (actorImage.getHeight() * thing.scaleY);
           g.drawImage(bitmap, actorX, actorY, width, height);
         }
         if (isBitmapFilter) {
           bitmap.flush();
           bitmap = null;
         }
         if (thing.alpha < 1.0) {
           g.setAlpha(1.0F);
         }
       }
       if (actorX == 0 && actorY == 0) {
         thing.draw(g);
         if (isListener) {
           thing.actorListener.draw(g);
         }
       } else {
         g.translate(actorX, actorY);
         thing.draw(g);
         if (isListener) {
           thing.actorListener.draw(g);
         }
         g.translate(-actorX, -actorY);
       }
     }
   }
 }
示例#24
0
  protected void drawMyself() {
    float ro = getStyle().getF("f.roundOff");
    Color strokeC = getStrokeColor();
    Stroke stroke = getStroke();
    float px = getStyle().getF("f.padX");
    float py = getStyle().getF("f.padY");

    roundRect.setRoundRect(x, y, width, height, ro, ro);
    Graphics2D g2 = menu.buff.g2;

    /*
     * Set the correct fill gradient
     */
    //		if (!isEnabled())
    //		{
    //			g2.setPaint(getStyle().getC("c.disabled"));
    //		} else
    if (isOpen() && parent == menu) {
      g2.setPaint(getStyle().getGradient(MenuItem.DOWN, y, y + height));
    } else if (!hasChildren() && getState() == MenuItem.DOWN) {
      g2.setPaint(getStyle().getGradient(MenuItem.DOWN, y, y + height));
    } else g2.setPaint(getStyle().getGradient(getState(), y, y + height));

    /*
     * Only perform the fill if the mood is right.
     */
    //		if (getState() != MenuItem.UP || isOpen())
    //		{
    //			if (!isEnabled())
    //			{
    //				;
    //			} else if (menu.hovered != null && menu.hovered != this
    //					&& !isAncestorOfHovered())
    //			{
    //				;
    //			} else
    //			{
    //				g2.fill(roundRect);
    //				g2.setPaint(strokeC);
    //				g2.setStroke(stroke);
    //				g2.draw(roundRect);
    //			}
    //		}
    if (shouldPerformFill()) {
      g2.fill(roundRect);
      g2.setPaint(strokeC);
      g2.setStroke(stroke);
      g2.draw(roundRect);
    }

    /*
     * Draw the text, triangle, and shortcut.
     */
    float curX = x + px;
    MenuUtils.drawLeftText(this, getName(), curX);
    curX += tWidth;
    if (shortcut != null) {
      PFont font = getStyle().getFont("font");
      float fs = getStyle().getF("f.fontSize");

      float rightX = getX() + getWidth();
      curX = rightX - shortcutWidth;
      // curX += getStyle().padX;
      float shortSize = fs * shortcutTextSize;
      float descent = UIUtils.getTextDescent(menu.buff, font, shortSize, true);
      g2.setFont(font.getFont().deriveFont(shortSize));
      g2.setPaint(strokeC.brighter(100));
      float ht = UIUtils.getTextHeight(menu.canvas.g, font, shortSize, shortcut.label, true);
      float yOffset = (height - ht) / 2f + descent;
      yOffset += ht / 2;
      g2.drawString(shortcut.label, curX, y + yOffset);
    }
    curX += shortcutWidth;
    if (drawChildrenTriangle && items.size() > 0) {
      if (layoutMode == LAYOUT_BELOW && getState() != MenuItem.UP && !isOpen()) {
        curX = x + width / 2;
        at.setToIdentity();
        at.translate(curX, y + height + py / 2);
        at.rotate(PApplet.HALF_PI);
        Area a2 = tri.createTransformedArea(at);
        g2.setPaint(strokeC);
        g2.fill(a2);
      } else if (layoutMode != LAYOUT_BELOW) {
        curX = x + width - triWidth - px;
        at.setToIdentity();
        at.translate(curX, y + height / 2);
        Area a2 = tri.createTransformedArea(at);
        g2.setPaint(strokeC);
        g2.fill(a2);
      }
    }
  }
示例#25
0
  // Thread's run method aimed at creating a bitmap asynchronously
  public void run() {
    Drawing drawing = new Drawing();
    PicText rawPicText = new PicText();
    String s = ((PicText) element).getText();
    rawPicText.setText(s);
    drawing.add(
        rawPicText); // bug fix: we must add a CLONE of the PicText, otherwise it loses it former
                     // parent... (then pb with the view )
    drawing.setNotparsedCommands(
        "\\newlength{\\jpicwidth}\\settowidth{\\jpicwidth}{"
            + s
            + "}"
            + CR_LF
            + "\\newlength{\\jpicheight}\\settoheight{\\jpicheight}{"
            + s
            + "}"
            + CR_LF
            + "\\newlength{\\jpicdepth}\\settodepth{\\jpicdepth}{"
            + s
            + "}"
            + CR_LF
            + "\\typeout{JPICEDT INFO: \\the\\jpicwidth, \\the\\jpicheight,  \\the\\jpicdepth }"
            + CR_LF);
    RunExternalCommand.Command commandToRun = RunExternalCommand.Command.BITMAP_CREATION;
    // RunExternalCommand command = new RunExternalCommand(drawing, contentType,commandToRun);
    boolean isWriteTmpTeXfile = true;
    String bitmapExt = "png"; // [pending] preferences
    String cmdLine =
        "{i}/unix/tetex/create_bitmap.sh {p} {f} "
            + bitmapExt
            + " "
            + fileDPI; // [pending] preferences
    ContentType contentType = getContainer().getContentType();
    RunExternalCommand.isGUI = false; // System.out, no dialog box // [pending] debug
    RunExternalCommand command =
        new RunExternalCommand(drawing, contentType, cmdLine, isWriteTmpTeXfile);
    command
        .run(); // synchronous in an async. thread => it's ok (anyway, we must way until the LaTeX
                // process has completed)

    if (wantToComputeLatexDimensions) {
      // load size of text:
      try {
        File logFile = new File(command.getTmpPath(), command.getTmpFilePrefix() + ".log");
        BufferedReader reader = null;
        try {
          reader = new BufferedReader(new FileReader(logFile));
        } catch (FileNotFoundException fnfe) {
          System.out.println("Cannot find log file! " + fnfe.getMessage());
          System.out.println(logFile);
        } catch (IOException ioex) {
          System.out.println("Log file IO exception");
          ioex.printStackTrace();
        } // utile ?
        System.out.println("Log file created! file=" + logFile);
        getDimensionsFromLogFile(reader, (PicText) element);
        syncStringLocation(); // update dimensions
        syncBounds();
        syncFrame();
        SwingUtilities.invokeLater(
            new Thread() {
              public void run() {
                repaint(null);
              }
            });
        // repaint(null); // now that dimensions are available, we force a repaint() [pending]
        // smart-repaint ?
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (wantToGetBitMap) {
      // load image:
      try {
        File bitmapFile =
            new File(command.getTmpPath(), command.getTmpFilePrefix() + "." + bitmapExt);
        this.image = ImageIO.read(bitmapFile);
        System.out.println(
            "Bitmap created! file="
                + bitmapFile
                + ", width="
                + image.getWidth()
                + "pixels, height="
                + image.getHeight()
                + "pixels");
        if (image == null) return;
        syncStringLocation(); // sets strx, stry, and dimensions of text
        syncBounds();
        // update the AffineTransform that will be applied to the bitmap before displaying on screen
        PicText te = (PicText) element;
        text2ModelTr.setToIdentity(); // reset
        PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
        text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
        text2ModelTr.translate(te.getLeftX(), te.getTopY());
        text2ModelTr.scale(
            te.getWidth() / image.getWidth(),
            -(te.getHeight() + te.getDepth()) / image.getHeight());
        // [pending]  should do something special to avoid dividing by 0 or setting a rescaling
        // factor to 0 [non invertible matrix] (java will throw an exception)
        syncFrame();
        SwingUtilities.invokeLater(
            new Thread() {
              public void run() {
                repaint(null);
              }
            });
        // repaint(null); // now that bitmap is available, we force a repaint() [pending]
        // smart-repaint ?
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  public void drawSequenceFlow(
      BufferedImage image, String processDefinitionId, String sequenceFlowId) {
    GetBpmnModelCmd getBpmnModelCmd = new GetBpmnModelCmd(processDefinitionId);
    BpmnModel bpmnModel = getBpmnModelCmd.execute(Context.getCommandContext());

    Graphics2D graphics = image.createGraphics();
    graphics.setPaint(HISTORY_COLOR);
    graphics.setStroke(new BasicStroke(2f));

    try {
      List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlowId);

      int[] xPoints = new int[graphicInfoList.size()];
      int[] yPoints = new int[graphicInfoList.size()];

      for (int i = 1; i < graphicInfoList.size(); i++) {
        GraphicInfo graphicInfo = graphicInfoList.get(i);
        GraphicInfo previousGraphicInfo = graphicInfoList.get(i - 1);

        if (i == 1) {
          xPoints[0] = (int) previousGraphicInfo.getX() - minX;
          yPoints[0] = (int) previousGraphicInfo.getY() - minY;
        }

        xPoints[i] = (int) graphicInfo.getX() - minX;
        yPoints[i] = (int) graphicInfo.getY() - minY;
      }

      int radius = 15;

      Path2D path = new Path2D.Double();

      for (int i = 0; i < xPoints.length; i++) {
        Integer anchorX = xPoints[i];
        Integer anchorY = yPoints[i];

        double targetX = anchorX;
        double targetY = anchorY;

        double ax = 0;
        double ay = 0;
        double bx = 0;
        double by = 0;
        double zx = 0;
        double zy = 0;

        if ((i > 0) && (i < (xPoints.length - 1))) {
          Integer cx = anchorX;
          Integer cy = anchorY;

          // pivot point of prev line
          double lineLengthY = yPoints[i] - yPoints[i - 1];

          // pivot point of prev line
          double lineLengthX = xPoints[i] - xPoints[i - 1];
          double lineLength = Math.sqrt(Math.pow(lineLengthY, 2) + Math.pow(lineLengthX, 2));
          double dx = (lineLengthX * radius) / lineLength;
          double dy = (lineLengthY * radius) / lineLength;
          targetX = targetX - dx;
          targetY = targetY - dy;

          // isDefaultConditionAvailable = isDefault && i == 1 && lineLength > 10;
          if ((lineLength < (2 * radius)) && (i > 1)) {
            targetX = xPoints[i] - (lineLengthX / 2);
            targetY = yPoints[i] - (lineLengthY / 2);
          }

          // pivot point of next line
          lineLengthY = yPoints[i + 1] - yPoints[i];
          lineLengthX = xPoints[i + 1] - xPoints[i];
          lineLength = Math.sqrt(Math.pow(lineLengthY, 2) + Math.pow(lineLengthX, 2));

          if (lineLength < radius) {
            lineLength = radius;
          }

          dx = (lineLengthX * radius) / lineLength;
          dy = (lineLengthY * radius) / lineLength;

          double nextSrcX = xPoints[i] + dx;
          double nextSrcY = yPoints[i] + dy;

          if ((lineLength < (2 * radius)) && (i < (xPoints.length - 2))) {
            nextSrcX = xPoints[i] + (lineLengthX / 2);
            nextSrcY = yPoints[i] + (lineLengthY / 2);
          }

          double dx0 = (cx - targetX) / 3;
          double dy0 = (cy - targetY) / 3;
          ax = cx - dx0;
          ay = cy - dy0;

          double dx1 = (cx - nextSrcX) / 3;
          double dy1 = (cy - nextSrcY) / 3;
          bx = cx - dx1;
          by = cy - dy1;

          zx = nextSrcX;
          zy = nextSrcY;
        }

        if (i == 0) {
          path.moveTo(targetX, targetY);
        } else {
          path.lineTo(targetX, targetY);
        }

        if ((i > 0) && (i < (xPoints.length - 1))) {
          // add curve
          path.curveTo(ax, ay, bx, by, zx, zy);
        }
      }

      graphics.draw(path);

      // draw arrow
      Line2D.Double line =
          new Line2D.Double(
              xPoints[xPoints.length - 2],
              yPoints[xPoints.length - 2],
              xPoints[xPoints.length - 1],
              yPoints[xPoints.length - 1]);

      int ARROW_WIDTH = 5;
      int doubleArrowWidth = 2 * ARROW_WIDTH;
      Polygon arrowHead = new Polygon();
      arrowHead.addPoint(0, 0);
      arrowHead.addPoint(-ARROW_WIDTH, -doubleArrowWidth);
      arrowHead.addPoint(ARROW_WIDTH, -doubleArrowWidth);

      AffineTransform transformation = new AffineTransform();
      transformation.setToIdentity();

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

      AffineTransform originalTransformation = graphics.getTransform();
      graphics.setTransform(transformation);
      graphics.fill(arrowHead);
      graphics.setTransform(originalTransformation);
    } finally {
      graphics.dispose();
    }
  }