Example usage for java.awt Graphics2D getTransform

List of usage examples for java.awt Graphics2D getTransform

Introduction

In this page you can find the example usage for java.awt Graphics2D getTransform.

Prototype

public abstract AffineTransform getTransform();

Source Link

Document

Returns a copy of the current Transform in the Graphics2D context.

Usage

From source file:org.esa.nest.dat.layers.maptools.components.CompassComponent.java

public void render(final Graphics2D graphics, final ScreenPixelConverter screenPixel) {
    if (Double.isNaN(angle))
        return;/*from   w w w. j a  v a 2s . c o  m*/

    final AffineTransform transformSave = graphics.getTransform();
    try {
        final AffineTransform transform = screenPixel.getImageTransform(transformSave);

        final double scale = (marginPct * 2 * rasterWidth) / (double) image.getWidth();
        transform.translate(point1.x, point1.y);
        transform.scale(scale, scale);
        transform.rotate(angle);

        graphics.drawRenderedImage(image, transform);
    } finally {
        graphics.setTransform(transformSave);
    }
}

From source file:org.evors.rs.ui.sandpit.TrialViewer.java

@Override
public void draw() {
    if (buffer == null) {
        return;//from w  w w  .ja  v  a  2  s . co  m
    }
    Graphics2D g2 = (Graphics2D) buffer.getDrawGraphics();
    camera.setWindowSize(new Vector2D(this.getWidth(), this.getHeight()));
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, getWidth(), getHeight());
    AffineTransform prevTrans = g2.getTransform();
    g2.setTransform(camera.getTransform());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    grid.draw(g2);
    if (world != null) {
        SandpitRenderer.drawWorld(g2, world);
    }
    if (path != null) {
        path.draw(g2);
    }
    if (robot != null) {
        SandpitRenderer.drawRobot(g2, robot);
    }
    g2.setTransform(prevTrans);
    drawText(g2,
            String.format("Time: %.2f\nRobot position: {%.2f,%.2f}\nRobot heading: %.2f\nInputs:%s\nNeurons:%s",
                    time, robot.getPosition().getX(), robot.getPosition().getY(), robot.getHeading(),
                    Arrays.toString(robot.getInput()),
                    Arrays.toString(((CTRNN) controller.getController()).getNeurons())));
}

From source file:org.evors.rs.ui.sandpit.WorldViewer.java

@Override
public void draw() {
    Graphics2D g2 = (Graphics2D) getGraphics();
    camera.setWindowSize(new Vector2D(this.getWidth(), this.getHeight()));
    g2.setColor(Color.WHITE);/*  ww w  .j  a v  a 2  s . c om*/
    g2.fillRect(0, 0, getWidth(), getHeight());
    AffineTransform prevTrans = g2.getTransform();
    g2.setTransform(camera.getTransform());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    grid.draw(g2);
    if (world != null) {
        SandpitRenderer.drawWorld(g2, world);
    }
    g2.setTransform(prevTrans);
}

From source file:org.executequery.gui.erd.ErdTable.java

protected void drawTable(Graphics2D g, int offsetX, int offsetY) {

    if (parent == null) {

        return;//from   w w w.j a  va 2 s . c o  m
    }

    Font tableNameFont = parent.getTableNameFont();
    Font columnNameFont = parent.getColumnNameFont();

    // set the table value background
    g.setColor(TITLE_BAR_BG_COLOR);
    g.fillRect(offsetX, offsetY, FINAL_WIDTH - 1, TITLE_BAR_HEIGHT);

    // set the table value
    FontMetrics fm = g.getFontMetrics(tableNameFont);
    int lineHeight = fm.getHeight();
    int titleXPosn = (FINAL_WIDTH / 2) - (fm.stringWidth(tableName) / 2) + offsetX;

    g.setColor(Color.BLACK);
    g.setFont(tableNameFont);
    g.drawString(tableName, titleXPosn, lineHeight + offsetY);

    // draw the line separator
    lineHeight = TITLE_BAR_HEIGHT + offsetY - 1;
    g.drawLine(offsetX, lineHeight, offsetX + FINAL_WIDTH - 1, lineHeight);

    // fill the white background
    g.setColor(tableBackground);
    g.fillRect(offsetX, TITLE_BAR_HEIGHT + offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - TITLE_BAR_HEIGHT - 1);

    // add the column names
    fm = g.getFontMetrics(columnNameFont);
    int heightPlusSep = 1 + TITLE_BAR_HEIGHT + offsetY;
    int leftMargin = 5 + offsetX;

    lineHeight = fm.getHeight();
    g.setColor(Color.BLACK);
    g.setFont(columnNameFont);

    int drawCount = 0;
    String value = null;
    if (ArrayUtils.isNotEmpty(columns)) {

        for (int i = 0; i < columns.length; i++) {
            ColumnData column = columns[i];
            if (displayReferencedKeysOnly && !column.isKey()) {
                continue;
            }

            int y = (((drawCount++) + 1) * lineHeight) + heightPlusSep;
            int x = leftMargin;

            // draw the column value string
            value = column.getColumnName();
            g.drawString(value, x, y);

            // draw the data type and size string
            x = leftMargin + dataTypeOffset;
            value = column.getFormattedDataType();
            g.drawString(value, x, y);

            // draw the key label
            if (column.isKey()) {

                if (column.isPrimaryKey() && column.isForeignKey()) {

                    value = PRIMARY + FOREIGN;

                } else if (column.isPrimaryKey()) {

                    value = PRIMARY;

                } else if (column.isForeignKey()) {

                    value = FOREIGN;
                }

                x = leftMargin + dataTypeOffset + keyLabelOffset;
                g.drawString(value, x, y);
            }

        }

    }

    // draw the rectangle border
    double scale = g.getTransform().getScaleX();

    if (selected && scale != ErdPrintable.PRINT_SCALE) {
        g.setStroke(focusBorderStroke);
        g.setColor(Color.BLUE);
    } else {
        g.setColor(Color.BLACK);
    }

    g.drawRect(offsetX, offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - 1);
    //    g.setColor(Color.DARK_GRAY);
    //    g.draw3DRect(offsetX, offsetY, FINAL_WIDTH - 2, FINAL_HEIGHT - 2, true);
}

From source file:org.jcurl.core.swing.RockLocationDisplayBase.java

public void paintComponent(final Graphics g) {
    super.paintComponent(g);
    if (log.isDebugEnabled())
        log.debug("[" + this.getX() + ", " + this.getY() + ", " + this.getWidth() + ", " + this.getHeight()
                + "]");
    final Graphics2D g2 = (Graphics2D) g;
    final AffineTransform dc_mat = g2.getTransform();
    g2.setRenderingHints(hints);/*from  www.  j ava 2 s  . co m*/
    final int w = this.getWidth();
    final int h = this.getHeight();

    // paint WC stuff (ice and rocks)
    if (zoom.hasChanged() || oldWid != w || oldHei != h) {
        // either the wc viewport, fixpoint or dc viewport has changed:
        // re-compute the transformation
        wc_mat.setToIdentity();
        zoom.computeWctoDcTrafo(this.getBounds(), orient, true, wc_mat);
        oldWid = w;
        oldHei = h;
        // re-build the background image
        img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D gi = (Graphics2D) img.getGraphics();
        gi.setRenderingHints(hints);
        paintIceDC(gi);
    }
    g2.drawImage(img, null, 0, 0);
    paintRocksDC(g2);

    g2.setTransform(dc_mat);
}

From source file:org.jcurl.core.swing.RockLocationDisplayBase.java

/**
 * Draw one rock at it's wc position. Builds the coordinate transform and
 * calls {@link #paintRockRC(Graphics2D, boolean, int)}.
 * //from   w w w.ja va 2  s. c  o m
 * @param g
 * @param rock
 * @param isDark
 * @param idx
 * @see RockPainter#paintRockRC(Graphics2D, boolean, int)
 */
protected void paintRockWC(final Graphics2D g, final Rock rock, final boolean isDark, final int idx) {
    final AffineTransform t = g.getTransform();
    g.translate(JCurlDisplay.SCALE * rock.getX(), JCurlDisplay.SCALE * rock.getY());
    g.rotate(Math.PI + rock.getZ());
    // make the right-handed coordinate system left handed again (for
    // un-flipped text display)
    g.scale(-1, 1);
    paintRockRC(g, isDark, idx);
    g.setTransform(t);
}

From source file:org.jhotdraw.samples.svg.figures.SVGImage.java

@Override
public void draw(Graphics2D g) {
    AffineTransform t = g.getTransform();
    double scaleX = t.getScaleX();
    if (scaleX == 1.0) {
        g.drawImage(image, null, 0, 0);/*w ww.  j  a  v a 2  s.  com*/
        return;
    }
    g.scale(1 / scaleX, 1 / scaleX);
    BufferedImage scaledImage = scaledImages.get(scaleX);
    if (scaledImage == null) {
        int w = (int) (image.getWidth() * scaleX);
        int h = (int) (image.getHeight() * scaleX);
        scaledImage = new BufferedImage(w, h, image.getType());
        Graphics2D g2 = scaledImage.createGraphics();
        g2.drawImage(image, 0, 0, w, h, null);
        g2.dispose();
        scaledImages.put((Double) scaleX, scaledImage);
    }
    g.drawImage(scaledImage, null, 0, 0);
    g.setTransform(t);
}

From source file:org.springframework.cloud.stream.app.pose.estimation.processor.PoseEstimateOutputMessageBuilder.java

private void drawPartOval(Part part, int radius, Graphics2D g) {
    int partX = part.getNormalizedX();
    int partY = part.getNormalizedY();

    g.setColor(GraphicsUtils.LIMBS_COLORS[part.getPartType().getId()]);
    g.fillOval(partX - radius, partY - radius, 2 * radius, 2 * radius);

    if (this.poseProperties.isDrawPartLabels()) {
        String label = part.getPartType().getId() + ":" + part.getPartType().name();
        FontMetrics fm = g.getFontMetrics();
        int labelX = partX + 5;
        int labelY = partY - 5;
        AffineTransform t = g.getTransform();
        g.setTransform(AffineTransform.getRotateInstance(Math.toRadians(-35), labelX, labelY));

        g.drawString(label, labelX, labelY);
        g.setTransform(t);//from ww w.  j a v  a2  s.c o  m
    }

}

From source file:org.tinymediamanager.ui.components.ImageLabel.java

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (scaledImage != null) {
        int originalWidth = scaledImage.getWidth(null);
        int originalHeight = scaledImage.getHeight(null);

        // calculate new height/width
        int newWidth = 0;
        int newHeight = 0;

        int offsetX = 0;
        int offsetY = 0;

        if (drawBorder && !drawFullWidth) {
            Point size = ImageCache.calculateSize(this.getWidth() - 8, this.getHeight() - 8, originalWidth,
                    originalHeight, true);

            // calculate offsets
            if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) {
                offsetX = this.getWidth() - size.x - 8;
            }/*  w  w  w .  j  a v  a 2 s  .co  m*/

            if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) {
                offsetY = this.getHeight() - size.y - 8;
            }

            if (position == Position.CENTER) {
                offsetX = (this.getWidth() - size.x - 8) / 2;
                offsetY = (this.getHeight() - size.y - 8) / 2;
            }

            newWidth = size.x;
            newHeight = size.y;

            // when the image size differs too much - reload and rescale the original image
            recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight);

            g.setColor(Color.BLACK);
            g.drawRect(offsetX, offsetY, size.x + 7, size.y + 7);
            g.setColor(Color.WHITE);
            g.fillRect(offsetX + 1, offsetY + 1, size.x + 6, size.y + 6);
            // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX + 4, offsetY + 4, newWidth, newHeight, this);
            g.drawImage(scaledImage, offsetX + 4, offsetY + 4, newWidth, newHeight, this);
        } else {
            Point size = null;
            if (drawFullWidth) {
                size = new Point(this.getWidth(), this.getWidth() * originalHeight / originalWidth);
            } else {
                size = ImageCache.calculateSize(this.getWidth(), this.getHeight(), originalWidth,
                        originalHeight, true);
            }

            // calculate offsets
            if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) {
                offsetX = this.getWidth() - size.x;
            }

            if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) {
                offsetY = this.getHeight() - size.y;
            }

            if (position == Position.CENTER) {
                offsetX = (this.getWidth() - size.x) / 2;
                offsetY = (this.getHeight() - size.y) / 2;
            }

            newWidth = size.x;
            newHeight = size.y;

            // when the image size differs too much - reload and rescale the original image
            recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight);

            // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX, offsetY, newWidth, newHeight, this);
            g.drawImage(scaledImage, offsetX, offsetY, newWidth, newHeight, this);
        }
    } else {
        // draw border and background
        if (drawBorder) {
            g.setColor(Color.BLACK);
            g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
            if (getParent().isOpaque()) {
                g.setColor(getParent().getBackground());
                g.fillRect(1, 1, this.getWidth() - 2, this.getHeight() - 2);
            }
        }

        // calculate diagonal
        int diagonalSize = (int) Math
                .sqrt(this.getWidth() * this.getWidth() + this.getHeight() * this.getHeight());

        // draw text
        String text = "";
        if (alternativeText != null) {
            text = alternativeText;
        } else {
            text = BUNDLE.getString("image.nonefound"); //$NON-NLS-1$
        }
        if (!getParent().isOpaque()) {
            text = "";
        }
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        AffineTransform orig = g2.getTransform();
        AffineTransform at = new AffineTransform(orig);
        at.translate(0, this.getHeight());
        at.rotate(this.getWidth(), -this.getHeight());
        g2.setTransform(at);
        g2.setColor(Color.BLACK);
        g2.setFont(FONT);

        FontMetrics fm = g2.getFontMetrics();
        int x = (diagonalSize - fm.stringWidth(text)) / 2;
        int y = (fm.getAscent() - fm.getDescent()) / 2;

        g2.drawString(text, x, y);
        // g2.drawLine(0, 0, diagonalSize, 0);
        at.translate(0, -this.getHeight());
        g2.setTransform(orig);
    }
}

From source file:org.tros.logo.swing.LogoPanel.java

/**
 * Paint./*  www  . j  av a  2 s. c o  m*/
 *
 * @param g
 */
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;

    turtleState.width = getWidth();
    turtleState.height = getHeight();

    draw(g2d, turtleState);

    if (turtleState.showTurtle && turtle != null) {
        double x = turtleState.penX - (turtle.getWidth() / 2.0);
        double y = turtleState.penY - (turtle.getHeight() / 2.0);
        AffineTransform translateInstance = AffineTransform
                .getRotateInstance(turtleState.angle + (Math.PI / 2.0), turtleState.penX, turtleState.penY);
        AffineTransform saveXform = g2d.getTransform();
        g2d.transform(translateInstance);
        g2d.drawImage(turtle, (int) x, (int) y, null);
        g2d.setTransform(saveXform);
    }
}