예제 #1
0
  /**
   * returns the skew transform
   *
   * @param svgHandle a svg handle
   * @param bounds the bounds of the area to transform
   * @param firstPoint the first clicked point by the user
   * @param currentPoint the current point of the drag action by the user
   * @param item the selection item
   * @return the skew transform
   */
  protected AffineTransform getSkewTransform(
      SVGHandle svgHandle,
      Rectangle2D bounds,
      Point2D firstPoint,
      Point2D currentPoint,
      SelectionItem item) {

    // getting the skew factor
    double skewX = 0, skewY = 0;
    boolean isHorizontal =
        (item.getType() == SelectionItem.NORTH || item.getType() == SelectionItem.SOUTH);

    if (bounds.getWidth() > 0 && bounds.getHeight() > 0) {

      if (isHorizontal) {

        skewX = (currentPoint.getX() - firstPoint.getX()) / bounds.getHeight();

      } else {

        skewY = (currentPoint.getY() - firstPoint.getY()) / bounds.getWidth();
      }
    }

    // getting the center point
    Point2D centerPoint = getRotationSkewCenterPoint(svgHandle, bounds);

    // creating the affine transform
    AffineTransform af =
        AffineTransform.getTranslateInstance(-centerPoint.getX(), -centerPoint.getY());
    af.preConcatenate(AffineTransform.getShearInstance(skewX, skewY));
    af.preConcatenate(AffineTransform.getTranslateInstance(centerPoint.getX(), centerPoint.getY()));

    return af;
  }
  /**
   * Retrieves the original grid to world transformation for this {@link
   * AbstractGridCoverage2DReader}.
   *
   * @param pixInCell specifies the datum of the transformation we want.
   * @return the original grid to world transformation for this {@link
   *     AbstractGridCoverage2DReader}.
   */
  @Override
  public MathTransform getOriginalGridToWorld(String coverageName, PixelInCell pixInCell) {
    if (!checkName(coverageName)) {
      throw new IllegalArgumentException(
          "The specified coverageName " + coverageName + "is not supported");
    }
    synchronized (this) {
      if (raster2Model == null) {
        final GridToEnvelopeMapper geMapper =
            new GridToEnvelopeMapper(
                getOriginalGridRange(coverageName), getOriginalEnvelope(coverageName));
        geMapper.setPixelAnchor(PixelInCell.CELL_CENTER);
        raster2Model = geMapper.createTransform();
      }
    }

    // we do not have to change the pixel datum
    if (pixInCell == PixelInCell.CELL_CENTER) return raster2Model;

    // we do have to change the pixel datum
    if (raster2Model instanceof AffineTransform) {
      final AffineTransform tr = new AffineTransform((AffineTransform) raster2Model);
      tr.concatenate(AffineTransform.getTranslateInstance(-0.5, -0.5));
      return ProjectiveTransform.create(tr);
    }
    if (raster2Model instanceof IdentityTransform) {
      final AffineTransform tr = new AffineTransform(1, 0, 0, 1, 0, 0);
      tr.concatenate(AffineTransform.getTranslateInstance(-0.5, -0.5));
      return ProjectiveTransform.create(tr);
    }
    throw new IllegalStateException("This reader's grid to world transform is invalud!");
  }
  /**
   * Builds the circular shape and returns the result as an array of <code>Area</code>. Each <code>
   * Area</code> is one of the bars composing the shape.
   */
  private Area[] buildTicker() {
    width = this.getPreferredSize().getWidth();
    height = this.getPreferredSize().getHeight();

    Area[] ticker = new Area[barsCount];
    Point2D.Double center = new Point2D.Double((double) width / 2, (double) height / 2);
    double fixedAngle = 2.0 * Math.PI / ((double) barsCount);

    for (double i = 0.0; i < (double) barsCount; i++) {
      Area primitive = buildPrimitive();

      AffineTransform toCenter = AffineTransform.getTranslateInstance(center.getX(), center.getY());
      AffineTransform toBorder = AffineTransform.getTranslateInstance(45.0 / 8, -6.0 / 8);
      AffineTransform toCircle =
          AffineTransform.getRotateInstance(-i * fixedAngle, center.getX(), center.getY());

      AffineTransform toWheel = new AffineTransform();
      toWheel.concatenate(toCenter);
      toWheel.concatenate(toBorder);

      primitive.transform(toWheel);
      primitive.transform(toCircle);

      ticker[(int) i] = primitive;
    }

    return ticker;
  }
예제 #4
0
파일: PrintPanel.java 프로젝트: xxs/lpf
  public void drawPage(Graphics2D g2) {
    FontRenderContext context = g2.getFontRenderContext();
    Font f = new Font("Serif", Font.PLAIN, 72);
    GeneralPath clipShape = new GeneralPath();

    TextLayout layout = new TextLayout("2426打印指南", f, context);
    AffineTransform transform = AffineTransform.getTranslateInstance(0, 72);
    Shape outline = layout.getOutline(transform);
    clipShape.append(outline, false);

    layout = new TextLayout("thank you", f, context);
    transform = AffineTransform.getTranslateInstance(0, 144);
    outline = layout.getOutline(transform);
    clipShape.append(outline, false);

    g2.draw(clipShape);
    g2.clip(clipShape);

    final int NLINES = 50;
    Point2D p = new Point2D.Double(0, 0);
    for (int i = 0; i < NLINES; i++) {
      double x = (2 * getWidth() * i) / NLINES;
      double y = (2 * getHeight() * (NLINES - 1 - i)) / NLINES;
      Point2D q = new Point2D.Double(x, y);
      g2.draw(new Line2D.Double(p, q));
    }
  }
예제 #5
0
 /**
  * Perform a zooming operation centered on the given point (dx, dy) and using the given scale
  * factor. The given AffineTransform instance is preconcatenated.
  *
  * @param dx center x
  * @param dy center y
  * @param scale zoom rate
  * @param af original affinetransform
  */
 public void centerZoom(double dx, double dy, double scale, AffineTransform af) {
   af.preConcatenate(AffineTransform.getTranslateInstance(-dx, -dy));
   af.preConcatenate(AffineTransform.getScaleInstance(scale, scale));
   af.preConcatenate(AffineTransform.getTranslateInstance(dx, dy));
   transform = af;
   syncScrollBars();
 }
예제 #6
0
  static {
    ImageLayout layout = new ImageLayout();
    layout.setColorModel(ColorModel.getRGBdefault());

    RenderingHints screenHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
    screenHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    screenHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    screenHints.put(
        RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    screenHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    screenHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    screenHints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    screenHints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    screenHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);

    screenContext = new RenderContext(AffineTransform.getTranslateInstance(0.0, 0.0), screenHints);

    RenderingHints draftHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);

    draftHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    draftHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    draftHints.put(
        RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
    draftHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
    draftHints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
    draftHints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    draftHints.put(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    draftHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

    draftContext = new RenderContext(AffineTransform.getTranslateInstance(0.0, 0.0), draftHints);
  }
  /**
   * Create a image according to the current state, simple and silly ...
   *
   * @param event the report event.
   */
  public void pageStarted(final ReportEvent event) {
    final BufferedImage image = new BufferedImage(150, 50, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2 = image.createGraphics();
    final JButton bt = new JButton("A Button");
    bt.setSize(90, 20);
    final JRadioButton radio = new JRadioButton("A radio button");
    radio.setSize(100, 20);

    g2.setColor(Color.darkGray);
    bt.paint(g2);
    g2.setColor(Color.blue);
    g2.setTransform(AffineTransform.getTranslateInstance(20, 20));
    radio.paint(g2);
    g2.setTransform(AffineTransform.getTranslateInstance(0, 0));
    g2.setPaint(Color.green);
    g2.setFont(new Font("Serif", Font.PLAIN, 10));
    g2.drawString(
        "You are viewing a graphics of JFreeReport on index " + event.getState().getCurrentRow(),
        10,
        10);
    g2.dispose();
    try {
      functionValue = new DefaultImageReference(image);
    } catch (IOException e) {
      functionValue = null;
    }
  }
예제 #8
0
 private void updateFire(RenderingContext rc) {
   fireCount++;
   if (fireCount > time2updateFire) {
     fireCount = 0;
     if (curFireFrame < 2) curFireFrame++;
     else curFireFrame = 0;
   }
   Fire.get(curFireFrame).render(rc, AffineTransform.getTranslateInstance(xPos + 15, yPos + 25));
   Fire.get(curFireFrame).render(rc, AffineTransform.getTranslateInstance(xPos + 50, yPos + 25));
 }
예제 #9
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);
    }
  }
예제 #10
0
  /**
   * Creates a new output frame.
   *
   * @param title the title of the output window
   * @param universe specifies the width-to-height ratio of the output window and is needed for the
   *     transformation of data- coordinates into view coordinates
   * @param maxExtension specifies the maximum width/height(according to the width-to-height ratio)
   */
  public VisualOutput(String title, final Rectangle universe, int maxExtension) {
    super(title);

    imageStack = new Stack<Raster>();

    final double m = universe.deltas()[0] / universe.deltas()[1];
    final int width = m > 1 ? maxExtension : (int) Math.floor(maxExtension * m);
    final int height = m > 1 ? (int) Math.floor(maxExtension / m) : maxExtension;

    content = new BufferedImage(width + 1, height + 1, BufferedImage.TYPE_INT_RGB);
    graphics = (Graphics2D) content.getGraphics();

    double tX = -universe.getCorner(false).getValue(0);
    double tY = -universe.getCorner(false).getValue(1);

    double sX = width / universe.deltas()[0];
    double sY = height / universe.deltas()[1];

    transformation = new AffineTransform();
    transformation.concatenate(AffineTransform.getScaleInstance(sX, -sY));
    transformation.concatenate(AffineTransform.getTranslateInstance(tX, tY));
    transformation.concatenate(AffineTransform.getTranslateInstance(0, -universe.deltas()[1]));

    java2DConverter =
        new Java2DConverter(
            new PointConverter() {
              private double degToPixX(double d) {
                return d * (width) / universe.deltas()[0];
              }

              private double degToPixY(double d) {
                return d * (height) / universe.deltas()[1];
              }

              public java.awt.geom.Point2D toViewPoint(Coordinate c)
                  throws NoninvertibleTransformException {
                int pixX = (int) Math.floor(degToPixX(c.x - universe.getCorner(false).getValue(0)));
                int pixY =
                    (int) Math.floor(-1 * degToPixY(c.y - universe.getCorner(true).getValue(1)));
                return new java.awt.geom.Point2D.Float(pixX, pixY);
              }
            });

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    this.setSize(width + 20, height + 50);
    this.setLocation((screenSize.width - width) / 2, (screenSize.height - height) / 2);
    this.setBackground(Color.BLACK);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setResizable(false);
    this.setVisible(true);
  }
예제 #11
0
  public void render(final RenderingContext rc) {
    if (!active) {
      return;
    }

    AffineTransform at = AffineTransform.getTranslateInstance(position.getX(), position.getY());
    /*
    Manipulating the at with at.scale(x,y) will resize the sprite and i dont think we will have to worry about
    keeping track of the resize variable because colision will only happen when it is resied to a certain range
    around the size it is allocated at
     */
    // System.out.println("scaling with scal2H="+scal2H);
    at.scale(scal2H, scal2H);
    scalFactorW = scal2W;
    scalFactorH = scal2H;
    super.render(rc, at);

    if (renderMarkup) {
      imgBoundingRectangle.get(0).render(rc, at);
    }

    if (setFire) updateFire(rc);
    if (setSmoke) updateSmoke(rc);
    if (offRoad) updateOffroad(rc);
  }
예제 #12
0
파일: Bug4945.java 프로젝트: srnsw/xena
  public void paint(Graphics2D g) {
    Font origFont = g.getFont();

    g.setRenderingHint(
        java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);

    // 1) create scaled font
    Font font = origFont.deriveFont(AffineTransform.getScaleInstance(1.5, 3));
    g.setFont(font);
    g.drawString("Scaled Font", 20, 40);

    // 2) create translated font
    font = origFont.deriveFont(AffineTransform.getTranslateInstance(50, 20));
    g.setFont(font);
    g.drawString("Translated Font", 20, 80);
    g.drawLine(20, 80, 120, 80);

    // 3) create sheared font
    font = origFont.deriveFont(AffineTransform.getShearInstance(.5, .5));
    g.setFont(font);
    g.drawString("Sheared Font", 20, 120);

    // 4) create rotated font
    font = origFont.deriveFont(AffineTransform.getRotateInstance(Math.PI / 4));
    g.setFont(font);
    g.drawString("Rotated Font", 220, 120);
  }
예제 #13
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));

    if (floorPlan != null) {
      // colocando a posicao inicial na tela e pegando uma instancia do transformador
      AffineTransform at = AffineTransform.getTranslateInstance(transfPosX, transfPosY);
      // double escala = INDICE_ESCALA / 100.0;
      // double sx = ((double) floorPlan.getWidth()) * escala ;
      // double sy = ((double) floorPlan.getHeight()) * escala;
      at.scale(escala, escala);
      System.out.println("Meu teste: " + floorPlan.getWidth() + " " + floorPlan.getHeight());
      g2d.drawRenderedImage(floorPlan, at);
    }
    if (pathNormalizer != null) {
      g2d.setColor(Color.red);
      g2d.draw(pathNormalizer);
    }
    if (path != null) {
      g2d.setColor(Color.black);
      g2d.draw(path);
    }
  }
예제 #14
0
  public static BufferedImage rotateImage(BufferedImage image, double theta) {
    int degrees = (int) Math.abs(Math.toDegrees(theta));
    double xCenter = image.getWidth() / 2;
    double yCenter = image.getHeight() / 2;
    AffineTransform rotateTransform = AffineTransform.getRotateInstance(-theta, xCenter, yCenter);

    // Translation adjustments so image still centered after rotate width/height changes
    if (image.getHeight() != image.getWidth() && degrees != 180 && degrees != 0) {
      Point2D origin = new Point2D.Double(0.0, 0.0);
      origin = rotateTransform.transform(origin, null);
      double yTranslate = origin.getY();

      Point2D yMax = new Point2D.Double(0, image.getHeight());
      yMax = rotateTransform.transform(yMax, null);
      double xTranslate = yMax.getX();

      AffineTransform translationAdjustment =
          AffineTransform.getTranslateInstance(-xTranslate, -yTranslate);
      rotateTransform.preConcatenate(translationAdjustment);
    }

    AffineTransformOp op = new AffineTransformOp(rotateTransform, AffineTransformOp.TYPE_BILINEAR);
    // Have to recopy image because of JDK bug #4723021, AffineTransformationOp throwing exception
    // sometimes
    image = copyImage(image, BufferedImage.TYPE_INT_ARGB);

    // Need to create filter dest image ourselves since AffineTransformOp's own dest image creation
    // throws exceptions in some cases.
    Rectangle bounds = op.getBounds2D(image).getBounds();
    BufferedImage finalImage =
        new BufferedImage(
            (int) bounds.getWidth(), (int) bounds.getHeight(), BufferedImage.TYPE_INT_ARGB);

    return op.filter(image, finalImage);
  }
  private synchronized void initBars() {
    if (bars != null) {
      return;
    }

    bars = new Area[BAR_COUNT];

    final double fixedAngle = 2.0 * Math.PI / (double) bars.length;
    for (int i = 0; i < bars.length; ++i) {
      Area primitive = makeBar();

      Point2D.Double center = new Point2D.Double((double) DIAMETER / 2, (double) DIAMETER / 2);
      AffineTransform toCircle =
          AffineTransform.getRotateInstance(
              ((double) -i) * fixedAngle, center.getX(), center.getY());
      AffineTransform toBorder = AffineTransform.getTranslateInstance(45.0, -6.0);

      AffineTransform toScale = AffineTransform.getScaleInstance(0.1, 0.1);

      primitive.transform(toBorder);
      primitive.transform(toCircle);
      primitive.transform(toScale);

      bars[i] = primitive;
    }
  }
 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]);
   }
 }
    public void addGlyph(GlyphData gv, float x, float y) {
      AffineTransform at = AffineTransform.getTranslateInstance(x, y);
      PathIterator pi = gv.gp.getPathIterator(at);

      float[] coords = new float[6];

      while (!pi.isDone()) {
        int type = pi.currentSegment(coords);

        switch (type) {
          case PathIterator.SEG_MOVETO:
            moveTo(coords[0], coords[1]);
            break;
          case PathIterator.SEG_LINETO:
            lineTo(coords[0], coords[1]);
            break;
          case PathIterator.SEG_CUBICTO:
            curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
            break;
          case PathIterator.SEG_CLOSE:
            closePath();
            break;
          default:
            System.out.println("Unknown path type: " + type);
            break;
        }

        pi.next();
      }
    }
예제 #18
0
 static Point2d transformToGlobal(double x, double y) {
   Point2d controlCenter = FlowerPatternPanel.getControlCenter();
   double deltaX = 0.0 - controlCenter.x;
   double deltaY = 0.0 - controlCenter.y;
   AffineTransform T = AffineTransform.getTranslateInstance(deltaX, deltaY);
   return Utilities.transform(T, x, y);
 }
예제 #19
0
  private ImageData writeImageMjpeg(OutputStream os) throws IOException {

    final LimitFinder limitFinder = new LimitFinder(TextBlockUtils.getDummyStringBounder(), true);
    udrawable.drawU(limitFinder);
    final Dimension2D dim =
        new Dimension2DDouble(
            limitFinder.getMaxX() + 1 + margin1 + margin2,
            limitFinder.getMaxY() + 1 + margin1 + margin2);

    final File f = new File("c:/tmp.avi");

    final int nbframe = 100;

    final MJPEGGenerator m =
        new MJPEGGenerator(
            f, getAviImage(null).getWidth(null), getAviImage(null).getHeight(null), 12.0, nbframe);
    for (int i = 0; i < nbframe; i++) {
      // AffineTransform at = AffineTransform.getRotateInstance(1.0);
      AffineTransform at =
          AffineTransform.getTranslateInstance(dim.getWidth() / 2, dim.getHeight() / 2);
      at.rotate(90.0 * Math.PI / 180.0 * i / 100);
      at.translate(-dim.getWidth() / 2, -dim.getHeight() / 2);
      // final AffineTransform at = AffineTransform.getTranslateInstance(i, 0);
      // final ImageIcon ii = new ImageIcon(getAviImage(at));
      // m.addImage(ii.getImage());
      throw new UnsupportedOperationException();
    }
    m.finishAVI();

    FileUtils.copyToStream(f, os);

    return new ImageDataSimple(dim);
  }
예제 #20
0
  @Override
  public Shape getPointShape(PointData data) {
    Row row = data.row;
    int colLabel = getColumn();
    if (colLabel >= row.size()) {
      return null;
    }

    Comparable<?> labelValue = row.get(colLabel);
    if (labelValue == null) {
      return null;
    }

    Format format = getFormat();
    Font font = getFont();
    String text = format.format(labelValue);
    double alignment = getAlignmentX();
    Shape shape = GraphicsUtils.getOutline(text, font, 0f, alignment);

    double alignX = getAlignmentX();
    double alignY = getAlignmentY();
    Rectangle2D bounds = shape.getBounds2D();
    AffineTransform tx =
        AffineTransform.getTranslateInstance(
            -alignX * bounds.getWidth(), alignY * bounds.getHeight());
    shape = tx.createTransformedShape(shape);

    return shape;
  }
  /**
   * Method paint. Paints the rings on the graph.
   *
   * @param g Graphics - the graphics to be painted.
   */
  @Override
  public void paint(Graphics g) {
    Collection<Double> depths = getDepths();
    g.setColor(Color.gray);
    Graphics2D g2d = (Graphics2D) g;
    Point2D center = radialLayout.getCenter();

    Ellipse2D ellipse = new Ellipse2D.Double();
    for (double d : depths) {
      ellipse.setFrameFromDiagonal(
          center.getX() - d, center.getY() - d, center.getX() + d, center.getY() + d);
      AffineTransform at = AffineTransform.getTranslateInstance(0, 0);
      Shape shape = at.createTransformedShape(ellipse);
      // Shape shape =
      //	vv.getRenderContext().getMultiLayerTransformer().transform(ellipse);
      //
      //	vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).transform(ellipse);

      MutableTransformer viewTransformer =
          vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);

      if (viewTransformer instanceof MutableTransformerDecorator) {
        shape = vv.getRenderContext().getMultiLayerTransformer().transform(shape);
      } else {
        shape = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, shape);
      }
      g2d.draw(shape);
    }
  }
예제 #22
0
파일: Glyph.java 프로젝트: Squeegee/batik
  /**
   * Draws this glyph.
   *
   * @param graphics2D The Graphics2D object to draw to.
   */
  public void draw(Graphics2D graphics2D) {
    AffineTransform tr = AffineTransform.getTranslateInstance(position.getX(), position.getY());
    if (transform != null) {
      tr.concatenate(transform);
    }

    // paint the dShape first
    if ((dShape != null) && (tpi != null)) {
      Shape tShape = tr.createTransformedShape(dShape);
      if (tpi.fillPaint != null) {
        graphics2D.setPaint(tpi.fillPaint);
        graphics2D.fill(tShape);
      }

      // check if we need to draw the outline of this glyph
      if (tpi.strokeStroke != null && tpi.strokePaint != null) {
        graphics2D.setStroke(tpi.strokeStroke);
        graphics2D.setPaint(tpi.strokePaint);
        graphics2D.draw(tShape);
      }
    }

    // paint the glyph children nodes
    if (glyphChildrenNode != null) {
      glyphChildrenNode.setTransform(tr);
      glyphChildrenNode.paint(graphics2D);
    }
  }
예제 #23
0
파일: Glyph.java 프로젝트: Squeegee/batik
 /**
  * Returns the outline of this glyph. This will be positioned correctly and any glyph transforms
  * will have been applied.
  *
  * @return the outline of this glyph.
  */
 public Shape getOutline() {
   if (outline == null) {
     AffineTransform tr = AffineTransform.getTranslateInstance(position.getX(), position.getY());
     if (transform != null) {
       tr.concatenate(transform);
     }
     Shape glyphChildrenOutline = null;
     if (glyphChildrenNode != null) {
       glyphChildrenOutline = glyphChildrenNode.getOutline();
     }
     GeneralPath glyphOutline = null;
     if (dShape != null && glyphChildrenOutline != null) {
       glyphOutline = new GeneralPath(dShape);
       glyphOutline.append(glyphChildrenOutline, false);
     } else if (dShape != null && glyphChildrenOutline == null) {
       glyphOutline = new GeneralPath(dShape);
     } else if (dShape == null && glyphChildrenOutline != null) {
       glyphOutline = new GeneralPath(glyphChildrenOutline);
     } else {
       // must be a whitespace glyph, return an empty shape
       glyphOutline = new GeneralPath();
     }
     outline = tr.createTransformedShape(glyphOutline);
   }
   return outline;
 }
예제 #24
0
파일: Glyph.java 프로젝트: Squeegee/batik
  public Rectangle2D getBounds2D() {
    // Check if the TextPaintInfo has changed...
    if ((bounds != null) && TextPaintInfo.equivilent(tpi, cacheTPI)) return bounds;

    AffineTransform tr = AffineTransform.getTranslateInstance(position.getX(), position.getY());
    if (transform != null) {
      tr.concatenate(transform);
    }

    Rectangle2D bounds = null;
    if ((dShape != null) && (tpi != null)) {
      if (tpi.fillPaint != null) bounds = tr.createTransformedShape(dShape).getBounds2D();

      if ((tpi.strokeStroke != null) && (tpi.strokePaint != null)) {
        Shape s = tpi.strokeStroke.createStrokedShape(dShape);
        Rectangle2D r = tr.createTransformedShape(s).getBounds2D();
        if (bounds == null) bounds = r;
        // else                bounds = r.createUnion(bounds);
        else bounds.add(r);
      }
    }

    if (glyphChildrenNode != null) {
      Rectangle2D r = glyphChildrenNode.getTransformedBounds(tr);
      if (bounds == null) bounds = r;
      // else                bounds = r.createUnion(bounds);
      else bounds.add(r);
    }
    if (bounds == null) bounds = new Rectangle2D.Double(position.getX(), position.getY(), 0, 0);

    cacheTPI = new TextPaintInfo(tpi);
    return bounds;
  }
예제 #25
0
    public void paint(Graphics g) {
      g.setColor(Color.gray);

      Graphics2D g2d = (Graphics2D) g;

      Ellipse2D ellipse = new Ellipse2D.Double();
      for (String v : layout.getGraph().getVertices()) {
        Double radius = layout.getRadii().get(v);
        if (radius == null) {
          continue;
        }
        Point2D p = layout.transform(v);
        ellipse.setFrame(-radius, -radius, 2 * radius, 2 * radius);
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        Shape shape = at.createTransformedShape(ellipse);

        MutableTransformer viewTransformer =
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);

        if (viewTransformer instanceof MutableTransformerDecorator) {
          shape = vv.getRenderContext().getMultiLayerTransformer().transform(shape);
        } else {
          shape = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, shape);
        }

        g2d.draw(shape);
      }
    }
예제 #26
0
  /**
   * Paints the icon.
   *
   * @param c the component on which it is painted
   * @param _g the graphics context
   * @param x the x coordinate of the icon
   * @param y the y coordinate of the icon
   */
  public void paintIcon(Component c, Graphics _g, int x, int y) {
    Graphics2D g = (Graphics2D) _g;
    AffineTransform at = AffineTransform.getTranslateInstance(x + offsetX, y + offsetY);

    // save current graphics paint and clip
    Paint gPaint = g.getPaint();
    Shape gClip = g.getClip();

    // render shape(s)
    g.setPaint(color);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.clipRect(x, y, w, h);

    // paint shape, if any
    if (shape != null) {
      g.fill(at.createTransformedShape(shape));
    }

    // paint decoration, if any
    if (decoration != null) {
      g.setPaint(decoColor);
      g.fill(at.createTransformedShape(decoration));
    }
    // restore graphics paint and clip
    g.setPaint(gPaint);
    g.setClip(gClip);
  }
예제 #27
0
  public GraphicSet importSetFromFile(File inputFile, List<String> warnings)
      throws ImportException {
    Writer out = null;
    try {
      // Get a DOMImplementation
      DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
      // Create an instance of org.w3c.dom.Document
      Document document = domImpl.createDocument(null, "svg", null);
      // Create an instance of the SVG Generator
      final SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
      svgGenerator.setTransform(new AffineTransform());
      // Open input file
      PSInputFile in = new PSInputFile(inputFile.getAbsolutePath());
      Rectangle2D bb = this.getBoundingBox(inputFile);
      svgGenerator.setTransform(AffineTransform.getTranslateInstance(-bb.getX(), -bb.getY()));
      Dimension d = new Dimension((int) bb.getWidth(), (int) bb.getHeight());
      // Create processor and associate to input and output file
      Processor processor = new Processor(svgGenerator, d, false);
      processor.setData(in);

      // Process
      processor.process();
      File tmp = File.createTempFile("temp", "svg");
      tmp.deleteOnExit();
      svgGenerator.stream(new FileWriter(tmp));
      GraphicSet result = new SVGImporter().importSetFromFile(tmp, warnings);
      // Assume the EPS has been created with 72DPI (from Inkscape)
      double px2mm = Util.inch2mm(1d / 72d);
      result.setBasicTransform(AffineTransform.getScaleInstance(px2mm, px2mm));
      return result;
    } catch (Exception ex) {
      Logger.getLogger(EPSImporter.class.getName()).log(Level.SEVERE, null, ex);
      throw new ImportException(ex);
    }
  }
예제 #28
0
파일: JImage.java 프로젝트: RussTedrake/lcm
    public void mouseDragged(MouseEvent e) {
      int mods = e.getModifiersEx();
      Point dragEnd = e.getPoint();
      boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) > 0;
      boolean ctrl = (mods & MouseEvent.CTRL_DOWN_MASK) > 0;
      boolean alt = shift & ctrl;
      ctrl = ctrl & (!alt);
      shift = shift & (!alt);
      boolean nomods = !(shift | ctrl | alt);

      if (dragBegin == null) dragBegin = dragEnd;

      nodrag = false;

      if ((mods & InputEvent.BUTTON3_DOWN_MASK) > 0 || true) {
        double dx = dragEnd.getX() - dragBegin.getX();
        double dy = dragEnd.getY() - dragBegin.getY();

        synchronized (JImage.this) {
          t.preConcatenate(AffineTransform.getTranslateInstance(dx, dy));
        }

        dragBegin = dragEnd;
        repaint();
      }
    }
예제 #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);
  }
  /*
   * Test method for 'org.locationtech.udig.tools.edit.support.EditUtils.overVertex(Point, PixelCoordMap, int)'
   */
  @Test
  public void testOverVertex() {
    EditBlackboard map =
        new EditBlackboard(
            SCREEN.x, SCREEN.y, AffineTransform.getTranslateInstance(0, 0), layerToWorld);

    map.addPoint(10, 10, map.getGeoms().get(0).getShell());

    Point valueOf = Point.valueOf(10, 10);

    int snapSize = 6;
    for (int x = -snapSize; x < snapSize; x++)
      for (int y = -snapSize; y < snapSize; y++)
        assertEquals(
            "x=" + (10 - x) + ", y=" + (10 - y),
            valueOf,
            map.overVertex(Point.valueOf(10 - x, 10 - y), snapSize)); // $NON-NLS-1$  //$NON-NLS-2$

    assertNull(map.overVertex(Point.valueOf(12, 11), 1));
    assertNull(map.overVertex(Point.valueOf(10, 12), 1));
    assertNull(map.overVertex(Point.valueOf(9, 12), 1));
    assertNull(map.overVertex(Point.valueOf(12, 9), 1));
    assertNull(map.overVertex(Point.valueOf(12, 10), 1));
    assertNull(map.overVertex(Point.valueOf(12, 11), 1));
  }