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:XMLWriteTest.java

/**
 * Writers an SVG document of the current drawing.
 * @param writer the document destination
 *///from   w  ww  .j  av a2 s  . co m
public void writeDocument(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartDocument();
    writer.writeDTD("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20000802//EN\" "
            + "\"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd\">");
    writer.writeStartElement("svg");
    writer.writeAttribute("width", "" + getWidth());
    writer.writeAttribute("height", "" + getHeight());
    for (int i = 0; i < rects.size(); i++) {
        Color c = colors.get(i);
        Rectangle2D r = rects.get(i);
        writer.writeEmptyElement("rect");
        writer.writeAttribute("x", "" + r.getX());
        writer.writeAttribute("y", "" + r.getY());
        writer.writeAttribute("width", "" + r.getWidth());
        writer.writeAttribute("height", "" + r.getHeight());
        writer.writeAttribute("fill", colorToString(c));
    }
    writer.writeEndDocument(); // closes svg element
}

From source file:BookTest.java

/**
 * Gets the page count of this section./*from   w  ww . j  a v  a  2 s .  c  o  m*/
 * @param g2 the graphics context
 * @param pf the page format
 * @return the number of pages needed
 */
public int getPageCount(Graphics2D g2, PageFormat pf) {
    if (message.equals(""))
        return 0;
    FontRenderContext context = g2.getFontRenderContext();
    Font f = new Font("Serif", Font.PLAIN, 72);
    Rectangle2D bounds = f.getStringBounds(message, context);
    scale = pf.getImageableHeight() / bounds.getHeight();
    double width = scale * bounds.getWidth();
    int pages = (int) Math.ceil(width / pf.getImageableWidth());
    return pages;
}

From source file:org.jfree.experimental.chart.plot.dial.SimpleDialFrame.java

/**
 * Draws the frame.  This method is called by the {@link DialPlot} class,
 * you shouldn't need to call it directly.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param frame  the frame (<code>null</code> not permitted).
 * @param view  the view (<code>null</code> not permitted).
 *///ww  w.j a v  a  2 s  . c  o m
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Shape window = getWindow(frame);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, this.radius + 0.02);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight());

    Area area = new Area(e);
    Area area2 = new Area(window);
    area.subtract(area2);
    g2.setPaint(this.backgroundPaint);
    g2.fill(area);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(e);
}

From source file:com.epiq.bitshark.ui.IVQPanel.java

public IVQPanel() {

    initComponents();/*from www  .j a  v  a2 s . co  m*/

    initGraph();

    JPanel holderPanel = new JPanel() {

        @Override
        public void paint(Graphics g) {

            Range newDomain = null; // x
            Range newRange = null; // y

            Range currentDomainRange = plot.getDomainAxis().getRange();
            Range currentRangeRange = plot.getRangeAxis().getRange();

            if (plot.getDomainAxis().isAutoRange()) {
                plot.getDomainAxis().setAutoRange(false);
            }

            if (plot.getRangeAxis().isAutoRange()) {
                plot.getRangeAxis().setAutoRange(false);
            }

            Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            double width = dataArea.getWidth();
            double height = dataArea.getHeight();

            double domainScale = 1;
            double rangeScale = 1;

            // scale the domain values up to match the pixels
            if (width > height) {
                domainScale = width / height;
                double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound();
                newDomain = new Range(-(extent * domainScale) / 2, (extent * domainScale) / 2);

            } else if (height > width) {
                rangeScale = height / width;
                double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound();
                newRange = new Range(-(extent * rangeScale) / 2, (extent * rangeScale) / 2);
            }

            if (newDomain == null) {
                double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound();
                newDomain = new Range(-(extent) / 2, (extent) / 2);
            }

            if (newRange == null) {
                double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound();
                newRange = new Range(-(extent) / 2, (extent) / 2);
            }

            if (newDomain != null) {
                plot.getDomainAxis().setRange(newDomain, true, false);
            }

            if (newRange != null) {
                plot.getRangeAxis().setRange(newRange, true, false);
            }

            Graphics2D g2 = (Graphics2D) g.create();
            super.paint(g2);

            g2.dispose();
        }
    };

    holderPanel.setLayout(new BorderLayout());
    holderPanel.add(chartPanel, BorderLayout.CENTER);
    mainPanel.add(holderPanel, BorderLayout.CENTER);

    headerPanel.setBackgroundPainter(Common.getHeaderPainter());

    chartLabel.setUI(new BasicLabelUI());
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java

private AbstractImageMapEntry createMapEntry(final Shape area, final Rectangle2D dataArea) {
    if (buggyDrawArea) {
        if (area instanceof Ellipse2D) {
            final Ellipse2D ellipse2D = (Ellipse2D) area;
            if (ellipse2D.getWidth() == ellipse2D.getHeight()) {
                return new CircleImageMapEntry((float) (ellipse2D.getCenterX() + dataArea.getX()),
                        (float) (ellipse2D.getCenterY() + dataArea.getY()), (float) (ellipse2D.getWidth() / 2));
            }//from   w  w w.j a va2  s  .co  m
        } else if (area instanceof Rectangle2D) {
            final Rectangle2D rect = (Rectangle2D) area;
            return (new RectangleImageMapEntry((float) (rect.getX() + dataArea.getX()),
                    (float) (rect.getY() + dataArea.getY()), (float) (rect.getX() + rect.getWidth()),
                    (float) (rect.getY() + rect.getHeight())));
        }
    } else {
        if (area instanceof Ellipse2D) {
            final Ellipse2D ellipse2D = (Ellipse2D) area;
            if (ellipse2D.getWidth() == ellipse2D.getHeight()) {
                return new CircleImageMapEntry((float) (ellipse2D.getCenterX()),
                        (float) (ellipse2D.getCenterY()), (float) (ellipse2D.getWidth() / 2));
            }
        } else if (area instanceof Rectangle2D) {
            final Rectangle2D rect = (Rectangle2D) area;
            return (new RectangleImageMapEntry((float) (rect.getX()), (float) (rect.getY()),
                    (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight())));
        }
    }

    final Area a = new Area(area);
    if (buggyDrawArea) {
        a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY()));
    }
    if (dataArea.isEmpty() == false) {
        a.intersect(new Area(dataArea));
    }
    final PathIterator pathIterator = a.getPathIterator(null, 2);
    final FloatList floats = new FloatList(100);
    final float[] coords = new float[6];
    while (pathIterator.isDone() == false) {
        final int retval = pathIterator.currentSegment(coords);
        if (retval == PathIterator.SEG_MOVETO || retval == PathIterator.SEG_LINETO) {
            floats.add(coords[0]);
            floats.add(coords[1]);
        }
        pathIterator.next();
    }

    if (floats.size() == 0) {
        return null;
    }
    return (new PolygonImageMapEntry(floats.toArray()));
}

From source file:XMLWriteTest.java

/**
 * Creates an SVG document of the current drawing.
 * @return the DOM tree of the SVG document
 *///w  w w  . j av a 2  s. c  o m
public Document buildDocument() {
    Document doc = builder.newDocument();
    Element svgElement = doc.createElement("svg");
    doc.appendChild(svgElement);
    svgElement.setAttribute("width", "" + getWidth());
    svgElement.setAttribute("height", "" + getHeight());
    for (int i = 0; i < rects.size(); i++) {
        Color c = colors.get(i);
        Rectangle2D r = rects.get(i);
        Element rectElement = doc.createElement("rect");
        rectElement.setAttribute("x", "" + r.getX());
        rectElement.setAttribute("y", "" + r.getY());
        rectElement.setAttribute("width", "" + r.getWidth());
        rectElement.setAttribute("height", "" + r.getHeight());
        rectElement.setAttribute("fill", colorToString(c));
        svgElement.appendChild(rectElement);
    }
    return doc;
}

From source file:org.jfree.eastwood.GXYPlot.java

/**
 * Draws the background for the plot.//  w w w  .  j  a  va  2  s. c  o  m
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
public void drawBackground(Graphics2D g2, Rectangle2D area) {
    Paint p = getBackgroundPaint();
    if (p instanceof GradientPaint) {
        // do the transformation directly
        GradientPaint gp = (GradientPaint) p;
        double r = (this.f1 - this.f0) * area.getWidth();
        Point2D p0 = new Point2D.Double(area.getMinX() + this.f0 * area.getWidth(), area.getMaxY());
        Point2D p1 = new Point2D.Double(p0.getX() + r * Math.cos(this.angle),
                p0.getY() - r * Math.sin(this.angle));
        p = new GradientPaint(p0, gp.getColor1(), p1, gp.getColor2());
    }
    g2.setPaint(p);
    g2.fill(area);
}

From source file:gda.plots.BlockWrapper.java

/**
 * JFreeChart will actually call this from its drawTitle method expecting the Block to draw itself at this point.
 * Our JComponent will already have been drawn as a consequence of being a simple child of the ChartPanel (which
 * extends JPanel). However we can use the information passed to the Block here to get the JComponents bounds set
 * correctly./*from   ww w.  j  ava  2  s. co m*/
 * 
 * @param g2
 *            the Graphics2D into which to draw (not used here)
 * @param area
 *            the Rectangle2D into which the object should draw itself)
 * @param params
 *            some parameters not yet understood
 * @return an Object else null
 */
@Override
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
    logger.debug("BW area is " + area);
    logger.debug("BW params is " + params);
    logger.debug("BW g2 is " + g2);
    logger.debug("BW g2.transform is " + g2.getTransform());
    jc.setBounds((int) Math.round(area.getX()), (int) Math.round(area.getY()),
            (int) Math.round(area.getWidth()), (int) Math.round(area.getHeight()));

    return null;
}

From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java

public void mouseClicked(MouseEvent e) {
    if (e.getSource() instanceof ChartPanel && ((e.getButton() == MouseEvent.BUTTON2)
            || (e.getButton() == MouseEvent.BUTTON1) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0))) {
        CenterZoomNumberAxis czna = (CenterZoomNumberAxis) _cp.getChart().getXYPlot().getDomainAxis();
        NumberAxis range = (NumberAxis) _cp.getChart().getXYPlot().getRangeAxis();
        Rectangle2D screenDataArea = _cp.getScreenDataArea(e.getX(), e.getY());
        double y1 = czna.getLowerBound();
        double y2 = czna.getUpperBound();
        double x1 = screenDataArea.getX();
        double x2 = x1 + screenDataArea.getWidth();
        double transformedx = (((y2 - y1) / (x2 - x1)) * (e.getX() - x1)) + y1;
        MRMDialog mrmd = (MRMDialog) MRMAncestor();
        PeaksTableModel model = (PeaksTableModel) mrmd.peaksTable.getModel();
        MRMTransition mrt = mrmd.transitionOnPlot;
        mrt.setCalcXatMaxYAllDaughters(transformedx);
        mrt.setCalcMaxYAllDaughters(/*from ww w .j a v a 2  s. c o m*/
                range.getLowerBound() + 0.95 * (range.getUpperBound() - range.getLowerBound()));
        model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), mrt.getTableRow(),
                MRMDialog.peaksData.MidTime.colno);
        for (MRMDaughter d : mrt.getDaughters().values()) {
            model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), d.getElutionDataTableRow(),
                    MRMDialog.peaksData.MidTime.colno);
        }
        mrmd.updateChartsAndFields(false);
    }
    if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) {
        _cp.mouseClicked(e);
    } else {
        _cp.mouseClicked(e);
    }
}

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

/**Render default view if there is no timeframe yet*/
private void renderNoInfoView(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setPaint(new TexturePaint(STROKED, new Rectangle(0, 0, 3, 3)));
    g2d.fillRect(0, 0, getWidth(), getHeight());
    Font f = g2d.getFont().deriveFont(Font.BOLD, 14.0f);
    g2d.setFont(f);/* www.j  a  v a 2 s  .c  o m*/
    Rectangle2D bounds = g2d.getFontMetrics().getStringBounds("Kein Zeitfenster aktiv", g);
    int dx = 10;
    if (getWidth() > bounds.getWidth()) {
        dx = (int) Math.rint((getWidth() - bounds.getWidth()) / 2);
    }

    int dy = 10;
    if (getHeight() > bounds.getHeight()) {
        dy = (int) Math.rint((getHeight() - bounds.getHeight()) / 2);
    }
    g2d.setColor(Color.black);
    g2d.drawString("Kein Zeitfenster aktiv", dx, dy);
}