Search in sources :

Example 1 with RectangularShape

use of java.awt.geom.RectangularShape in project zxing by zxing.

the class AbstractBlackBoxTestCase method rotateImage.

protected static BufferedImage rotateImage(BufferedImage original, float degrees) {
    if (degrees == 0.0f) {
        return original;
    }
    switch(original.getType()) {
        case BufferedImage.TYPE_BYTE_INDEXED:
        case BufferedImage.TYPE_BYTE_BINARY:
            BufferedImage argb = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB);
            Graphics g = argb.createGraphics();
            g.drawImage(original, 0, 0, null);
            g.dispose();
            original = argb;
            break;
    }
    double radians = Math.toRadians(degrees);
    // Transform simply to find out the new bounding box (don't actually run the image through it)
    AffineTransform at = new AffineTransform();
    at.rotate(radians, original.getWidth() / 2.0, original.getHeight() / 2.0);
    BufferedImageOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
    RectangularShape r = op.getBounds2D(original);
    int width = (int) Math.ceil(r.getWidth());
    int height = (int) Math.ceil(r.getHeight());
    // Real transform, now that we know the size of the new image and how to translate after we rotate
    // to keep it centered
    at = new AffineTransform();
    at.rotate(radians, width / 2.0, height / 2.0);
    at.translate((width - original.getWidth()) / 2.0, (height - original.getHeight()) / 2.0);
    op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
    return op.filter(original, new BufferedImage(width, height, original.getType()));
}
Also used : Graphics(java.awt.Graphics) BufferedImageOp(java.awt.image.BufferedImageOp) RectangularShape(java.awt.geom.RectangularShape) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 2 with RectangularShape

use of java.awt.geom.RectangularShape in project adempiere by adempiere.

the class CompiereUtils method paint3Deffect.

//  paint3Deffect
/**
	 *  Paint 3D effect in (lighten in upper half, darken in lowerhalf)
	 *  (called from paint methods)
	 *
	 *  @param g2D Graphics
	 *  @param c Component
	 *  @param round paint round corners
	 *  @param out paint sticking out (not pressed)
	 */
public static void paint3Deffect(Graphics2D g2D, JComponent c, boolean round, boolean out) {
    // paint upper gradient
    GradientPaint topPaint = null;
    if (out)
        topPaint = new GradientPaint(0, 0, COL_1TOP, 0, c.getHeight() / 2, COL_1END);
    else
        topPaint = new GradientPaint(0, 0, COL_2END, 0, c.getHeight() / 2, COL_2TOP);
    g2D.setPaint(topPaint);
    //
    RectangularShape topRec = null;
    if (round)
        topRec = new RoundRectangle2D.Float(0, 0, c.getWidth(), c.getHeight() / 2, 15, 15);
    else
        topRec = new Rectangle(0, 0, c.getWidth(), c.getHeight() / 2);
    g2D.fill(topRec);
    // paint lower gradient
    GradientPaint endPaint = null;
    if (out)
        endPaint = new GradientPaint(0, c.getHeight() / 2, COL_2TOP, 0, c.getHeight(), COL_2END);
    else
        endPaint = new GradientPaint(0, c.getHeight() / 2, COL_1END, 0, c.getHeight(), COL_1TOP);
    g2D.setPaint(endPaint);
    //
    RectangularShape endRec = null;
    if (round)
        endRec = new RoundRectangle2D.Float(0, c.getHeight() / 2, c.getWidth(), c.getHeight() / 2, 15, 15);
    else
        endRec = new Rectangle(0, c.getHeight() / 2, c.getWidth(), c.getHeight() / 2);
    g2D.fill(endRec);
}
Also used : RectangularShape(java.awt.geom.RectangularShape) Rectangle(java.awt.Rectangle) GradientPaint(java.awt.GradientPaint)

Example 3 with RectangularShape

use of java.awt.geom.RectangularShape in project adempiere by adempiere.

the class CompiereUtils method fillRectange.

/**
	 *  Fill Background with Color.
	 *  (Ususlly called from update methods)
	 *
	 *  @param g2D  Graphics
	 *  @param c    Component
	 *  @param round paint round corners
	 */
public static void fillRectange(Graphics2D g2D, JComponent c, boolean round) {
    //  Paint in AdempiereColor?
    CompiereColor cc = null;
    boolean stdCC = c.getClientProperty(CompiereLookAndFeel.BACKGROUND_FILL) != null;
    try {
        cc = (CompiereColor) c.getClientProperty(CompiereLookAndFeel.BACKGROUND);
    } catch (Exception e) {
        stdCC = true;
    }
    if (stdCC)
        cc = CompiereColor.getDefaultBackground();
    //  Paint AdempiereColor
    if (cc != null) {
        //  bounds is often not within Panel bouunds
        cc.paint(g2D, c);
    } else //  Paint Flat Color
    {
        Paint paint = c.getBackground();
        g2D.setPaint(paint);
        //
        RectangularShape rec = null;
        if (round)
            rec = new RoundRectangle2D.Float(0, 0, c.getWidth(), c.getHeight(), 15, 15);
        else
            rec = new Rectangle(0, 0, c.getWidth(), c.getHeight());
        g2D.fill(rec);
    }
}
Also used : RectangularShape(java.awt.geom.RectangularShape) Rectangle(java.awt.Rectangle) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 4 with RectangularShape

use of java.awt.geom.RectangularShape in project adempiere by adempiere.

the class CompiereUtils method paint3Deffect.

/**
	 *  Paint 3D effect in (lighten in upper half, darken in lowerhalf)
	 *  (called from paint methods)
	 *
	 *  @param g2D Graphics
	 *  @param r Ractangle
	 *  @param round paint round corners
	 *  @param out paint sticking out (not pressed)
	 */
public static void paint3Deffect(Graphics2D g2D, Rectangle r, boolean round, boolean out) {
    // paint upper gradient
    GradientPaint topPaint = null;
    if (out)
        topPaint = new GradientPaint(r.x, r.y, COL_1TOP, r.x, r.y + r.height / 2, COL_1END);
    else
        topPaint = new GradientPaint(r.x, r.y, COL_2END, r.x, r.y + r.height / 2, COL_2TOP);
    g2D.setPaint(topPaint);
    //
    RectangularShape topRec = null;
    if (round)
        topRec = new RoundRectangle2D.Float(r.x, r.y, r.width, r.height / 2, 15, 15);
    else
        topRec = new Rectangle(r.x, r.y, r.width, r.height / 2);
    g2D.fill(topRec);
    // paint lower gradient
    //	upper left corner to lower left
    GradientPaint endPaint = null;
    if (out)
        endPaint = new GradientPaint(r.x, r.y + r.height / 2, COL_2TOP, r.x, r.y + r.height, COL_2END);
    else
        endPaint = new GradientPaint(r.x, r.y + r.height / 2, COL_1END, r.x, r.y + r.height, COL_1TOP);
    g2D.setPaint(endPaint);
    //
    RectangularShape endRec = null;
    if (round)
        endRec = new RoundRectangle2D.Float(r.x, r.y + r.height / 2, r.width, r.height / 2, 15, 15);
    else
        endRec = new Rectangle(r.x, r.y + r.height / 2, r.width, r.height / 2);
    g2D.fill(endRec);
}
Also used : RectangularShape(java.awt.geom.RectangularShape) Rectangle(java.awt.Rectangle) GradientPaint(java.awt.GradientPaint)

Example 5 with RectangularShape

use of java.awt.geom.RectangularShape in project jo-client-platform by jo-source.

the class NodeRenderer method render.

@Override
public void render(final Graphics2D g, final VisualItem item) {
    final RectangularShape shape = (RectangularShape) getShape(item);
    gradientColor = new GradientPaint(shape.getBounds().x + shape.getBounds().width / 2, shape.getBounds().y, lightenFillColor(item.getFillColor()), shape.getBounds().x + shape.getBounds().width / 2, shape.getBounds().y + shape.getBounds().height / 2, ColorLib.getColor(item.getFillColor()), false);
    g.setPaint(gradientColor);
    g.fill(shape);
    if ((Boolean) item.get("marked")) {
        g.setStroke(new BasicStroke(2));
        g.setPaint(Color.DARK_GRAY);
        g.draw(shape);
    }
    final String text = m_text;
    final Image img = getImage(item);
    if (text == null && img == null) {
        return;
    }
    final double size = item.getSize();
    final boolean useInt = 1.5 > Math.max(g.getTransform().getScaleX(), g.getTransform().getScaleY());
    double x = shape.getMinX() + size * m_horizBorder;
    double y = shape.getMinY() + size * m_vertBorder;
    // render image
    renderImage(g, useInt, img, size, x, y, shape);
    if (img != null) {
        final double w = size * img.getWidth(null);
        final double h = size * img.getHeight(null);
        double ix = x;
        double iy = y;
        // determine one co-ordinate based on the image position
        switch(m_imagePos) {
            case Constants.LEFT:
                x += w + size * m_imageMargin;
                break;
            case Constants.RIGHT:
                ix = shape.getMaxX() - size * m_horizBorder - w;
                break;
            case Constants.TOP:
                y += h + size * m_imageMargin;
                break;
            case Constants.BOTTOM:
                iy = shape.getMaxY() - size * m_vertBorder - h;
                break;
            default:
                throw new IllegalStateException("Unrecognized image alignment setting.");
        }
        // determine the other coordinate based on image alignment
        switch(m_imagePos) {
            case Constants.LEFT:
            case Constants.RIGHT:
                // need to set image y-coordinate
                switch(m_vImageAlign) {
                    case Constants.TOP:
                        break;
                    case Constants.BOTTOM:
                        iy = shape.getMaxY() - size * m_vertBorder - h;
                        break;
                    case Constants.CENTER:
                        iy = shape.getCenterY() - h / 2;
                        break;
                    default:
                        break;
                }
                break;
            case Constants.TOP:
            case Constants.BOTTOM:
                // need to set image x-coordinate
                switch(m_hImageAlign) {
                    case Constants.LEFT:
                        break;
                    case Constants.RIGHT:
                        ix = shape.getMaxX() - size * m_horizBorder - w;
                        break;
                    case Constants.CENTER:
                        ix = shape.getCenterX() - w / 2;
                        break;
                    default:
                        break;
                }
                break;
            default:
                break;
        }
        if (useInt && size == 1.0) {
            // if possible, use integer precision
            // results in faster, flicker-free image rendering
            g.drawImage(img, (int) ix, (int) iy, null);
        } else {
            transform.setTransform(size, 0, 0, size, ix, iy);
            g.drawImage(img, transform, null);
        }
    }
    // render text
    final int textColor = item.getTextColor();
    if (text != null && ColorLib.alpha(textColor) > 0) {
        g.setPaint(ColorLib.getColor(textColor));
        g.setFont(m_font);
        final FontMetrics fm = DEFAULT_GRAPHICS.getFontMetrics(m_font);
        // compute available width
        final double tw;
        switch(m_imagePos) {
            case Constants.TOP:
            case Constants.BOTTOM:
                tw = shape.getWidth() - 2 * size * m_horizBorder;
                break;
            default:
                tw = m_textDim.width;
        }
        // compute available height
        final double th;
        switch(m_imagePos) {
            case Constants.LEFT:
            case Constants.RIGHT:
                th = shape.getHeight() - 2 * size * m_vertBorder;
                break;
            default:
                th = m_textDim.height;
        }
        // compute starting y-coordinate
        y += fm.getAscent();
        switch(m_vTextAlign) {
            case Constants.TOP:
                break;
            case Constants.BOTTOM:
                y += th - m_textDim.height;
                break;
            case Constants.CENTER:
                y += (th - m_textDim.height) / 2;
                break;
            default:
                break;
        }
        // render each line of text
        // the line height
        final int lh = fm.getHeight();
        int start = 0;
        int end = text.indexOf(m_delim);
        for (; end >= 0; y += lh) {
            drawString(g, fm, text.substring(start, end), useInt, x, y, tw);
            start = end + 1;
            end = text.indexOf(m_delim, start);
        }
        drawString(g, fm, text.substring(start), useInt, x, y, tw);
    }
    // render (+) or (-) if isParent and expanded
    if ((Boolean) item.get("isParent") && item.get("expanded") == Expand.NOT) {
        renderImage(g, useInt, expandedIcon, size, shape.getX(), shape.getY(), shape);
    } else if ((Boolean) item.get("isParent") && item.get("expanded") == Expand.FULL) {
        renderImage(g, useInt, notExpandedIcon, size, shape.getX(), shape.getY(), shape);
    } else if ((Boolean) item.get("isParent") && item.get("expanded") == Expand.PARTIALLY) {
        renderImage(g, useInt, notExpandedIcon, size, shape.getX(), shape.getY(), shape);
        renderImage(g, useInt, expandedIcon, size, shape.getX() + 16, shape.getY(), shape);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) FontMetrics(java.awt.FontMetrics) RectangularShape(java.awt.geom.RectangularShape) GradientPaint(java.awt.GradientPaint) Image(java.awt.Image) GradientPaint(java.awt.GradientPaint)

Aggregations

RectangularShape (java.awt.geom.RectangularShape)7 GradientPaint (java.awt.GradientPaint)5 Rectangle (java.awt.Rectangle)3 BasicStroke (java.awt.BasicStroke)2 Paint (java.awt.Paint)2 Color (java.awt.Color)1 Font (java.awt.Font)1 FontMetrics (java.awt.FontMetrics)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 Stroke (java.awt.Stroke)1 AffineTransform (java.awt.geom.AffineTransform)1 Area (java.awt.geom.Area)1 Path2D (java.awt.geom.Path2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 AffineTransformOp (java.awt.image.AffineTransformOp)1 BufferedImage (java.awt.image.BufferedImage)1 BufferedImageOp (java.awt.image.BufferedImageOp)1 IOException (java.io.IOException)1