Example usage for java.awt.geom Rectangle2D getWidth

List of usage examples for java.awt.geom Rectangle2D getWidth

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getWidth.

Prototype

public abstract double getWidth();

Source Link

Document

Returns the width of the framing rectangle in double precision.

Usage

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Updates the point-related properties of a plot.
 * /*from  ww  w.ja  va  2 s  .co m*/
 * @param aPlot
 *            Plot to be updated.
 * @param aScatter
 *            Visual settings to be applied.
 */
private static void updateScatter(XYPlot aPlot, ScatterSettings aScatter) {
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) aPlot.getRenderer();
    renderer.setSeriesPaint(0, aScatter.getPointColor());
    final Rectangle2D ds = AbstractRenderer.DEFAULT_SHAPE.getBounds2D();
    final double x = ds.getX();
    final double y = ds.getY();
    final double w = ds.getWidth();
    final double h = ds.getHeight();
    Shape shape = null;
    switch (aScatter.getPointShape()) {
    case POINT:
        shape = new Rectangle2D.Double(x + w / 2, y + h / 2, 1, 1);
        renderer.setBaseShapesFilled(true);
        break;
    case CIRCLE:
        shape = new Ellipse2D.Double(x, y, w, h);
        renderer.setBaseShapesFilled(false);
        break;
    case FILLED_CIRCLE:
        shape = new Ellipse2D.Double(x, y, w, h);
        renderer.setBaseShapesFilled(true);
        break;
    case SQUARE:
        shape = new Rectangle2D.Double(x, y, w, h);
        renderer.setBaseShapesFilled(false);
        break;
    case FILLED_SQUARE:
        shape = new Rectangle2D.Double(x, y, w, h);
        renderer.setBaseShapesFilled(true);
        break;
    case CROSS:
        shape = new Cross(x, y, w, h);
        renderer.setBaseShapesFilled(false);
    }
    renderer.setSeriesShape(0, shape);
}

From source file:ShapeTransform.java

/**
 * Clips the given shape to the given bounds. If the shape is a Line2D, manual
 * clipping is performed, as the built in Area does not handle lines.
 * //from   ww w . ja va 2  s.c  om
 * @param s
 *          the shape to be clipped
 * @param bounds
 *          the bounds to which the shape should be clipped
 * @return the clipped shape.
 */
public static Shape performCliping(final Shape s, final Rectangle2D bounds) {
    if (s instanceof Line2D) {
        final Line2D line = (Line2D) s;
        final Point2D[] clipped = getClipped(line.getX1(), line.getY1(), line.getX2(), line.getY2(), -DELTA,
                DELTA + bounds.getWidth(), -DELTA, DELTA + bounds.getHeight());
        if (clipped == null) {
            return new GeneralPath();
        }
        return new Line2D.Float(clipped[0], clipped[1]);
    }

    final Rectangle2D boundsCorrected = bounds.getBounds2D();
    boundsCorrected.setRect(-DELTA, -DELTA, DELTA + boundsCorrected.getWidth(),
            DELTA + boundsCorrected.getHeight());
    final Area a = new Area(boundsCorrected);
    if (a.isEmpty()) {
        // don't clip ... Area does not like lines
        // operations with lines always result in an empty Bounds:(0,0,0,0) area
        return new GeneralPath();
    }

    final Area clipArea = new Area(s);
    a.intersect(clipArea);
    return a;

}

From source file:org.uva.itast.blended.omr.OMRUtils.java

private static void searchMarkSquare(OMRProcessor omr, PageImage pageImage, Field field, boolean medianfilter) {
    Rectangle2D bbox = field.getBBox();// milimeters

    // leemos la anchura de las marcas en milmetros
    double markWidth = Math.max(1, bbox.getWidth());
    double markHeight = Math.max(1, bbox.getHeight());
    SolidSquareMarkScanner markScanner = new SolidSquareMarkScanner(omr, pageImage, markWidth, markHeight,
            medianfilter);/*from w w w.j a  va2 s  .  co m*/

    if (logger.isDebugEnabled()) {
        logger.debug("searchMarkCircle - field name=" + field.getName() + " at position:" + field.getBBox()); //$NON-NLS-1$
    }
    searchMark(pageImage, field, markScanner);
}

From source file:org.uva.itast.blended.omr.OMRUtils.java

/**
 * Mtodo que busca marcas de tipo circle en un objeto tipo Gray8Image
 * //from ww  w.j a v a  2s. c  om
 * @param i
 * 
 * @param field
 * @param markedImage
 * @param mark
 * @param markedImage
 * @param field
 * @param medianfilter
 */
private static void searchMarkCircle(OMRProcessor omr, PageImage pageImage, Field field, boolean medianfilter) {
    Rectangle2D bbox = field.getBBox();// milimeters

    // leemos la anchura de las marcas en milmetros
    double markWidth = Math.max(1, bbox.getWidth());
    double markHeight = Math.max(1, bbox.getHeight());
    SolidCircleMarkScanner markScanner = new SolidCircleMarkScanner(omr, pageImage, markWidth, markHeight,
            medianfilter);

    if (logger.isDebugEnabled()) {
        logger.debug(
                "START searchMarkCircle - field name=" + field.getName() + " at position:" + field.getBBox()); //$NON-NLS-1$
    }
    searchMark(pageImage, field, markScanner);
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * /*from   w ww  .  j a v a  2  s  .  c o  m*/
 * Domain and Range axes need to share the same unit (e.g. mm)
 * 
 * @param myChart
 * @return
 */
public static double calcWidthToHeight(ChartViewer myChart, double chartHeight) {
    makeChartResizable(myChart);

    myChart.getCanvas().draw();

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;

    return width;
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * //from w  w  w . j  a va  2  s .co  m
 * Domain and Range axes need to share the same unit (e.g. mm)
 * 
 * @param myChart
 * @return
 */
public static double calcWidthToHeight(ChartPanel myChart, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    JPanel parent = (JPanel) myChart.getParent();
    JPanel p = new JPanel();
    p.removeAll();
    p.add(myChart, BorderLayout.CENTER);
    p.setBounds(myChart.getBounds());
    myChart.paintImmediately(myChart.getBounds());
    p.removeAll();
    parent.add(myChart);

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;

    return width;
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * Returns dimensions for limiting factor width or height
 * //from   ww  w .  j  a  va2  s .  c  o m
 * @param myChart
 * @return
 */
public static Dimension calcMaxSize(ChartViewer myChart, double chartWidth, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    myChart.getCanvas().draw();

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calculatig width for max height

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;
    // if width is higher than given chartWidth then calc height for chartWidth
    if (width > chartWidth) {
        // calc right plot size with axis dim.
        // real plot width is given by factor;
        realPW = chartWidth - titleWidth;

        // real plot height can be calculated by
        realPH = realPW / x.getLength() * y.getLength();

        double height = realPH + titleHeight;
        // Return size
        return new Dimension((int) chartWidth, (int) height);
    } else {
        // Return size
        return new Dimension((int) width, (int) chartHeight);
    }
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * Returns dimensions for limiting factor width or height
 * /*from  w  w w. j  a va  2 s  . c  o m*/
 * @param myChart
 * @return
 */
public static Dimension calcMaxSize(ChartPanel myChart, double chartWidth, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    JPanel parent = (JPanel) myChart.getParent();
    JPanel p = new JPanel();
    p.removeAll();
    p.add(myChart, BorderLayout.CENTER);
    p.setBounds(myChart.getBounds());
    myChart.paintImmediately(myChart.getBounds());
    p.removeAll();
    parent.add(myChart);

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calculatig width for max height

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;
    // if width is higher than given chartWidth then calc height for chartWidth
    if (width > chartWidth) {
        // calc right plot size with axis dim.
        // real plot width is given by factor;
        realPW = chartWidth - titleWidth;

        // real plot height can be calculated by
        realPH = realPW / x.getLength() * y.getLength();

        double height = realPH + titleHeight;
        // Return size
        return new Dimension((int) chartWidth, (int) height);
    } else {
        // Return size
        return new Dimension((int) width, (int) chartHeight);
    }
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * calculates the correct height with multiple iterations Domain and Range axes need to share the
 * same unit (e.g. mm)/*from   ww w  .j  a v a2 s .  c  o  m*/
 * 
 * @param myChart
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcHeightToWidth(ChartViewer myChart, double chartWidth, double estimatedHeight,
        int iterations) {
    // if(myChart.getChartRenderingInfo()==null ||
    // myChart.getChartRenderingInfo().getChartArea()==null ||
    // myChart.getChartRenderingInfo().getChartArea().getWidth()==0)
    // result
    double height = estimatedHeight;
    double lastH = height;

    makeChartResizable(myChart);

    try {
        for (int i = 0; i < iterations; i++) {
            // paint on ghost panel with estimated height (if copy panel==true)
            myChart.getCanvas().setWidth((int) chartWidth);
            myChart.getCanvas().setHeight((int) estimatedHeight);
            myChart.getCanvas().draw();

            XYPlot plot = (XYPlot) myChart.getChart().getPlot();
            ChartRenderingInfo info = myChart.getRenderingInfo();
            Rectangle2D dataArea = info.getPlotInfo().getDataArea();
            Rectangle2D chartArea = info.getChartArea();

            // calc title space: will be added later to the right plot size
            double titleWidth = chartArea.getWidth() - dataArea.getWidth();
            double titleHeight = chartArea.getHeight() - dataArea.getHeight();

            // calc right plot size with axis dim.
            // real plot width is given by factor;
            double realPW = chartWidth - titleWidth;

            // ranges
            ValueAxis domainAxis = plot.getDomainAxis();
            org.jfree.data.Range x = domainAxis.getRange();
            ValueAxis rangeAxis = plot.getRangeAxis();
            org.jfree.data.Range y = rangeAxis.getRange();

            // real plot height can be calculated by
            double realPH = realPW / x.getLength() * y.getLength();

            // the real height
            height = realPH + titleHeight;

            // for next iteration
            estimatedHeight = height;
            if ((int) lastH == (int) height)
                break;
            else
                lastH = height;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return height;
}

From source file:org.apache.xmlgraphics.ps.PSImageUtils.java

/**
 * Generates commands to modify the current transformation matrix so an image fits
 * into a given rectangle.//from w w  w  .java 2 s  .  com
 * @param gen the PostScript generator
 * @param imageDimensions the image's dimensions
 * @param targetRect the target rectangle
 * @throws IOException if an I/O error occurs
 */
public static void translateAndScale(PSGenerator gen, Dimension2D imageDimensions, Rectangle2D targetRect)
        throws IOException {
    gen.writeln(gen.formatDouble(targetRect.getX()) + " " + gen.formatDouble(targetRect.getY()) + " translate");
    if (imageDimensions == null) {
        imageDimensions = new Dimension(1, 1);
    }
    double sx = targetRect.getWidth() / imageDimensions.getWidth();
    double sy = targetRect.getHeight() / imageDimensions.getHeight();
    if (sx != 1 || sy != 1) {
        gen.writeln(gen.formatDouble(sx) + " " + gen.formatDouble(sy) + " scale");
    }
}