Example usage for java.awt.geom RectangularShape getMinX

List of usage examples for java.awt.geom RectangularShape getMinX

Introduction

In this page you can find the example usage for java.awt.geom RectangularShape getMinX.

Prototype

public double getMinX() 

Source Link

Document

Returns the smallest X coordinate of the framing rectangle of the Shape in double precision.

Usage

From source file:GraphicsUtil.java

public static Point2D getPoint(RectangularShape bounds, Align align) {
    double x = 0.0;
    double y = 0.0;

    switch (align) {
    case North://from  w w  w.java2 s  .  com
        x = bounds.getCenterX();
        y = bounds.getMinY();
        break;
    case NorthEast:
        x = bounds.getMaxX();
        y = bounds.getMinY();
        break;
    case East:
        x = bounds.getMaxX();
        y = bounds.getCenterY();
        break;
    case SouthEast:
        x = bounds.getMaxX();
        y = bounds.getMaxY();
        break;
    case South:
        x = bounds.getCenterX();
        y = bounds.getMaxY();
        break;
    case SouthWest:
        x = bounds.getMinX();
        y = bounds.getMaxY();
        break;
    case West:
        x = bounds.getMinX();
        y = bounds.getCenterY();
        break;
    case NorthWest:
        x = bounds.getMinX();
        y = bounds.getMinY();
        break;
    case Center:
        x = bounds.getCenterX();
        y = bounds.getCenterY();
        break;
    }

    return new Point2D.Double(x, y);
}

From source file:it.cnr.istc.utils.gui.ReverseGradientXYBarPainter.java

/**
 * Splits a bar into subregions (elsewhere, these subregions will have
 * different gradients applied to them).
 *
 * @param bar the bar shape.// w w  w .j  a v a 2  s .  c om
 * @param a the first division.
 * @param b the second division.
 * @param c the third division.
 *
 * @return An array containing four subregions.
 */
private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a, double b, double c) {
    Rectangle2D[] result = new Rectangle2D[4];
    double x0 = bar.getMinX();
    double x1 = Math.rint(x0 + (bar.getWidth() * a));
    double x2 = Math.rint(x0 + (bar.getWidth() * b));
    double x3 = Math.rint(x0 + (bar.getWidth() * c));
    result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), x1 - x0, bar.getHeight());
    result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1, bar.getHeight());
    result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2, bar.getHeight());
    result[3] = new Rectangle2D.Double(x3, bar.getMinY(), bar.getMaxX() - x3, bar.getHeight());
    return result;
}

From source file:it.cnr.istc.utils.gui.ReverseGradientXYBarPainter.java

/**
 * Creates a shadow for the bar./*from w  w w .  j  a v  a2s.c  o m*/
 *
 * @param bar the bar shape.
 * @param xOffset the x-offset for the shadow.
 * @param yOffset the y-offset for the shadow.
 * @param base the edge that is the base of the bar.
 * @param pegShadow peg the shadow to the base?
 *
 * @return A rectangle for the shadow.
 */
private Rectangle2D createShadow(RectangularShape bar, double xOffset, double yOffset, RectangleEdge base,
        boolean pegShadow) {
    double x0 = bar.getMinX();
    double x1 = bar.getMaxX();
    double y0 = bar.getMinY();
    double y1 = bar.getMaxY();
    if (base == RectangleEdge.TOP) {
        x0 += xOffset;
        x1 += xOffset;
        if (!pegShadow) {
            y0 += yOffset;
        }
        y1 += yOffset;
    } else if (base == RectangleEdge.BOTTOM) {
        x0 += xOffset;
        x1 += xOffset;
        y0 += yOffset;
        if (!pegShadow) {
            y1 += yOffset;
        }
    } else if (base == RectangleEdge.LEFT) {
        if (!pegShadow) {
            x0 += xOffset;
        }
        x1 += xOffset;
        y0 += yOffset;
        y1 += yOffset;
    } else if (base == RectangleEdge.RIGHT) {
        x0 += xOffset;
        if (!pegShadow) {
            x1 += xOffset;
        }
        y0 += yOffset;
        y1 += yOffset;
    }
    return new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
}

From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java

public static Point2D getPoint(RectangularShape bounds, Align align) {
    double x = 0.0;
    double y = 0.0;

    switch (align) {
    case TopCenter:
        x = bounds.getCenterX();/*from   w  ww .ja  v a  2s  .  c  o  m*/
        y = bounds.getMinY();
        break;
    case TopRight:
        x = bounds.getMaxX();
        y = bounds.getMinY();
        break;
    case MiddleRight:
        x = bounds.getMaxX();
        y = bounds.getCenterY();
        break;
    case BottomRight:
        x = bounds.getMaxX();
        y = bounds.getMaxY();
        break;
    case BottomCenter:
        x = bounds.getCenterX();
        y = bounds.getMaxY();
        break;
    case BottomLeft:
        x = bounds.getMinX();
        y = bounds.getMaxY();
        break;
    case MiddleLeft:
        x = bounds.getMinX();
        y = bounds.getCenterY();
        break;
    case TopLeft:
        x = bounds.getMinX();
        y = bounds.getMinY();
        break;
    case Center:
        x = bounds.getCenterX();
        y = bounds.getCenterY();
        break;
    }

    return new Point2D.Double(x, y);
}

From source file:it.cnr.istc.utils.gui.ReverseGradientXYBarPainter.java

/**
 * Splits a bar into subregions (elsewhere, these subregions will have
 * different gradients applied to them).
 *
 * @param bar the bar shape.//ww w.  ja  v  a2s . co m
 * @param a the first division.
 * @param b the second division.
 * @param c the third division.
 *
 * @return An array containing four subregions.
 */
private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a, double b, double c) {
    Rectangle2D[] result = new Rectangle2D[4];
    double y0 = bar.getMinY();
    double y1 = Math.rint(y0 + (bar.getHeight() * a));
    double y2 = Math.rint(y0 + (bar.getHeight() * b));
    double y3 = Math.rint(y0 + (bar.getHeight() * c));
    result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), y1 - y0);
    result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(), y2 - y1);
    result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(), y3 - y2);
    result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(), bar.getMaxY() - y3);
    return result;
}

From source file:com.rapidminer.gui.plotter.charts.RapidXYBarPainter.java

@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar,
        RectangleEdge base) {/*from   ww  w.  j  a va  2  s .  c  o m*/
    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0 = null;

    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
    } else {
        c0 = SwingTools.DARK_BLUE;
    }

    // as a special case, if the bar color has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    g2.setPaint(c0);
    g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight()));

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
}

From source file:com.rapidminer.gui.plotter.charts.RapidBarPainter.java

/**
 * Paints a single bar instance.//  w  w  w  . j  a  va2  s  .c o  m
 * 
 * @param g2
 *            the graphics target.
 * @param renderer
 *            the renderer.
 * @param row
 *            the row index.
 * @param column
 *            the column index.
 * @param bar
 *            the bar
 * @param base
 *            indicates which side of the rectangle is the base of the bar.
 */
@Override
public void paintBar(final Graphics2D g2, final BarRenderer renderer, final int row, final int column,
        final RectangularShape bar, final RectangleEdge base) {
    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0 = null;

    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
    } else {
        c0 = SwingTools.DARK_BLUE;
    }

    // as a special case, if the bar color has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    g2.setPaint(c0);
    g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight()));

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

}

From source file:org.aksw.resparql.ServerMethods.java

public static String toUriPart(RectangularShape rect) {
    return rect.getMinX() + "-" + rect.getMaxX() + "/" + rect.getMinY() + "-" + rect.getMaxY();
}

From source file:org.apache.fop.fonts.type1.AFMFile.java

/**
 * Returns the FontBBox value as integer array.
 * @return the font's bounding box//from   w  w  w  .  j a  va2  s . c o  m
 */
public int[] getFontBBoxAsIntArray() {
    RectangularShape rect = getFontBBox();
    return new int[] { (int) Math.floor(rect.getMinX()), (int) Math.floor(rect.getMinY()),
            (int) Math.ceil(rect.getMaxX()), (int) Math.ceil(rect.getMaxY()) };
}

From source file:org.apache.fop.fonts.type1.Type1FontLoader.java

private void handleMetrics(AFMFile afm, PFMFile pfm) {
    // Basic metrics
    if (afm != null) {
        if (afm.getCapHeight() != null) {
            returnFont.setCapHeight(afm.getCapHeight().intValue());
        }//from  w ww. ja v a  2  s. co m
        if (afm.getXHeight() != null) {
            returnFont.setXHeight(afm.getXHeight().intValue());
        }
        if (afm.getAscender() != null) {
            returnFont.setAscender(afm.getAscender().intValue());
        }
        if (afm.getDescender() != null) {
            returnFont.setDescender(afm.getDescender().intValue());
        }

        returnFont.setFontBBox(afm.getFontBBoxAsIntArray());
        if (afm.getStdVW() != null) {
            returnFont.setStemV(afm.getStdVW().intValue());
        } else {
            returnFont.setStemV(80); // Arbitrary value
        }
        returnFont.setItalicAngle((int) afm.getWritingDirectionMetrics(0).getItalicAngle());
    } else {
        returnFont.setFontBBox(pfm.getFontBBox());
        returnFont.setStemV(pfm.getStemV());
        returnFont.setItalicAngle(pfm.getItalicAngle());
    }
    if (pfm != null) {
        // Sometimes the PFM has these metrics while the AFM doesn't (ex. Symbol)
        if (returnFont.getCapHeight() == 0) {
            returnFont.setCapHeight(pfm.getCapHeight());
        }
        if (returnFont.getXHeight(1) == 0) {
            returnFont.setXHeight(pfm.getXHeight());
        }
        if (returnFont.getAscender() == 0) {
            returnFont.setAscender(pfm.getLowerCaseAscent());
        }
        if (returnFont.getDescender() == 0) {
            returnFont.setDescender(pfm.getLowerCaseDescent());
        }
    }

    // Fallbacks when some crucial font metrics aren't available
    // (the following are all optional in AFM, but FontBBox is always available)
    if (returnFont.getXHeight(1) == 0) {
        int xHeight = 0;
        if (afm != null) {
            AFMCharMetrics chm = afm.getChar("x");
            if (chm != null) {
                RectangularShape rect = chm.getBBox();
                if (rect != null) {
                    xHeight = (int) Math.round(rect.getMinX());
                }
            }
        }
        if (xHeight == 0) {
            xHeight = Math.round(returnFont.getFontBBox()[3] * 0.6f);
        }
        returnFont.setXHeight(xHeight);
    }
    if (returnFont.getAscender() == 0) {
        int asc = 0;
        if (afm != null) {
            AFMCharMetrics chm = afm.getChar("d");
            if (chm != null) {
                RectangularShape rect = chm.getBBox();
                if (rect != null) {
                    asc = (int) Math.round(rect.getMinX());
                }
            }
        }
        if (asc == 0) {
            asc = Math.round(returnFont.getFontBBox()[3] * 0.9f);
        }
        returnFont.setAscender(asc);
    }
    if (returnFont.getDescender() == 0) {
        int desc = 0;
        if (afm != null) {
            AFMCharMetrics chm = afm.getChar("p");
            if (chm != null) {
                RectangularShape rect = chm.getBBox();
                if (rect != null) {
                    desc = (int) Math.round(rect.getMinX());
                }
            }
        }
        if (desc == 0) {
            desc = returnFont.getFontBBox()[1];
        }
        returnFont.setDescender(desc);
    }
    if (returnFont.getCapHeight() == 0) {
        returnFont.setCapHeight(returnFont.getAscender());
    }

    if (afm != null) {
        String charSet = afm.getCharacterSet();
        int flags = 0;
        if ("Special".equals(charSet)) {
            flags |= 4; // bit 3: Symbolic
        } else {
            if (singleFont.getEncoding().mapChar('A') == 'A') {
                // High likelyhood that the font is non-symbolic
                flags |= 32; // bit 6: Nonsymbolic
            } else {
                flags |= 4; // bit 3: Symbolic
            }
        }
        if (afm.getWritingDirectionMetrics(0).isFixedPitch()) {
            flags |= 1; // bit 1: FixedPitch
        }
        if (afm.getWritingDirectionMetrics(0).getItalicAngle() != 0.0) {
            flags |= 64; // bit 7: Italic
        }
        returnFont.setFlags(flags);

        returnFont.setFirstChar(afm.getFirstChar());
        returnFont.setLastChar(afm.getLastChar());
        for (AFMCharMetrics chm : afm.getCharMetrics()) {
            if (chm.hasCharCode()) {
                singleFont.setWidth(chm.getCharCode(), (int) Math.round(chm.getWidthX()));
            }
        }
        if (useKerning) {
            returnFont.replaceKerningMap(afm.createXKerningMapEncoded());
        }
    } else {
        returnFont.setFlags(pfm.getFlags());
        returnFont.setFirstChar(pfm.getFirstChar());
        returnFont.setLastChar(pfm.getLastChar());
        for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) {
            singleFont.setWidth(i, pfm.getCharWidth(i));
        }
        if (useKerning) {
            returnFont.replaceKerningMap(pfm.getKerning());
        }
    }
}