Example usage for java.awt.geom Rectangle2D getY

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

Introduction

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

Prototype

public abstract double getY();

Source Link

Document

Returns the Y coordinate of the upper-left corner of the framing rectangle in double precision.

Usage

From source file:org.squidy.designer.zoom.impl.PortShape.java

public PortShape() {
    setBounds(Constants.DEFAULT_PORT_BOUNDS);

    addInputEventListener(new PBasicInputEventHandler() {

        /*//from   w  w  w  . j  a  v a  2 s. c  o m
         * (non-Javadoc)
         * 
         * @see
         * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mousePressed
         * (edu.umd.cs.piccolo .event.PInputEvent)
         */
        @Override
        public void mousePressed(PInputEvent event) {
            super.mousePressed(event);

            if (!event.isHandled()) {
                isCreatingEdge = true;
                Rectangle2D bounds = localToGlobal(getBounds());
                startX = bounds.getX() + bounds.getWidth() / 2;// .getCenterX();
                startY = bounds.getY() + bounds.getWidth() / 2;// .getCenterY();
                currentX = startX;
                currentY = startY;

                // moveToFront();

                event.setHandled(true);
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see
         * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseReleased
         * (edu.umd.cs.piccolo.event.PInputEvent)
         */
        @Override
        public void mouseReleased(PInputEvent event) {
            super.mouseReleased(event);

            isCreatingEdge = false;

            ConnectionManager connectionManager = ShapeUtils.getConnectionManager(PortShape.this);

            Point2D point = event.getPosition();

            if (connectionManager.hasConnectionAtDifferentNodeAtPoint(PortShape.this, point)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Connection port found at " + point);
                }

                ConnectorShape<?, ?> source = (ConnectorShape<?, ?>) getParent();
                ConnectorShape<?, ?> target = (ConnectorShape<?, ?>) connectionManager
                        .getConnectionAtPoint(point).getParent();

                if (!source.getParent().equals(target.getParent())) {
                    //                  ConnectorShape<?, ?> tmp = source;
                    //                  source = target;
                    //                  target = tmp;
                }

                PipeShape pipeShape;
                try {
                    pipeShape = PipeShape.create(source, target);
                } catch (Exception e) {
                    publishNotification(new TemporaryNotification(e.getMessage()));
                    return;
                }

                VisualShape<VisualShape<?>> parentShape;
                if (!source.getParent().equals(target.getParent())) {
                    if (target.getParent().equals(source)) {
                        parentShape = (VisualShape<VisualShape<?>>) source;
                    } else {
                        parentShape = (VisualShape<VisualShape<?>>) target;
                    }
                } else {
                    parentShape = (VisualShape<VisualShape<?>>) source.getParent();
                }

                parentShape.addVisualShape(pipeShape);
                pipeShape.invalidateFullBounds();
            } else {
                // TODO [RR]: Repaint from bounds (do not repaint full node bounds)
                getParent().getParent().invalidatePaint();
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see
         * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseDragged
         * (edu.umd.cs.piccolo.event.PInputEvent)
         */
        @Override
        public void mouseDragged(PInputEvent event) {
            super.mouseDragged(event);

            Point2D point = event.getPosition();

            currentX = point.getX();
            currentY = point.getY();

            event.getCamera().invalidatePaint();

            event.setHandled(true);
        }

        /*
         * (non-Javadoc)
         * 
         * @see
         * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseEntered
         * (edu.umd.cs.piccolo.event.PInputEvent)
         */
        @Override
        public void mouseEntered(PInputEvent event) {
            super.mouseEntered(event);

            innerColor = Color.GRAY;
        }

        /*
         * (non-Javadoc)
         * 
         * @see
         * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseExited(
         * edu.umd.cs.piccolo.event.PInputEvent)
         */
        @Override
        public void mouseExited(PInputEvent event) {
            super.mouseExited(event);

            innerColor = Color.LIGHT_GRAY;
        }
    });
}

From source file:net.sourceforge.processdash.ui.lib.chart.DiscPlot.java

private Rectangle2D getDataArea(Rectangle2D plotArea) {
    double hGap = plotArea.getWidth() * this.interiorGap;
    double vGap = plotArea.getHeight() * this.interiorGap;

    return new Rectangle2D.Double(plotArea.getX() + hGap, plotArea.getY() + vGap,
            plotArea.getWidth() - 2 * hGap, plotArea.getHeight() - 2 * vGap);
}

From source file:org.jfree.chart.demo.CylinderRenderer.java

public void drawItem(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate,
        Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis,
        CategoryDataset categorydataset, int i, int j, int k) {
    Number number = categorydataset.getValue(i, j);
    if (number == null)
        return;//ww  w.  j  a va2s . c om
    double d = number.doubleValue();
    java.awt.geom.Rectangle2D.Double double1 = new java.awt.geom.Rectangle2D.Double(rectangle2d.getX(),
            rectangle2d.getY() + getYOffset(), rectangle2d.getWidth() - getXOffset(),
            rectangle2d.getHeight() - getYOffset());
    PlotOrientation plotorientation = categoryplot.getOrientation();
    double d1 = calculateBarW0(categoryplot, plotorientation, double1, categoryaxis, categoryitemrendererstate,
            i, j);
    double ad[] = calculateBarL0L1(d);
    if (ad == null)
        return;
    RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge();
    float f = (float) valueaxis.valueToJava2D(ad[0], double1, rectangleedge);
    float f1 = (float) valueaxis.valueToJava2D(ad[1], double1, rectangleedge);
    float f2 = Math.min(f, f1);
    float f3 = Math.abs(f1 - f);
    GeneralPath generalpath = new GeneralPath();
    java.awt.geom.Ellipse2D.Double double2 = null;
    if (plotorientation == PlotOrientation.HORIZONTAL) {
        generalpath.moveTo((float) ((double) f2 + getXOffset() / 2D), (float) d1);
        generalpath.lineTo((float) ((double) (f2 + f3) + getXOffset() / 2D), (float) d1);
        java.awt.geom.Arc2D.Double double3 = new java.awt.geom.Arc2D.Double(f2 + f3, d1, getXOffset(),
                categoryitemrendererstate.getBarWidth(), 90D, 180D, 0);
        generalpath.append(double3, true);
        generalpath.lineTo((float) ((double) f2 + getXOffset() / 2D),
                (float) (d1 + categoryitemrendererstate.getBarWidth()));
        double3 = new java.awt.geom.Arc2D.Double(f2, d1, getXOffset(), categoryitemrendererstate.getBarWidth(),
                270D, -180D, 0);
        generalpath.append(double3, true);
        generalpath.closePath();
        double2 = new java.awt.geom.Ellipse2D.Double(f2 + f3, d1, getXOffset(),
                categoryitemrendererstate.getBarWidth());
    } else {
        generalpath.moveTo((float) d1, (float) ((double) f2 - getYOffset() / 2D));
        generalpath.lineTo((float) d1, (float) ((double) (f2 + f3) - getYOffset() / 2D));
        java.awt.geom.Arc2D.Double double4 = new java.awt.geom.Arc2D.Double(d1,
                (double) (f2 + f3) - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset(), 180D,
                180D, 0);
        generalpath.append(double4, true);
        generalpath.lineTo((float) (d1 + categoryitemrendererstate.getBarWidth()),
                (float) ((double) f2 - getYOffset() / 2D));
        double4 = new java.awt.geom.Arc2D.Double(d1, (double) f2 - getYOffset(),
                categoryitemrendererstate.getBarWidth(), getYOffset(), 0.0D, -180D, 0);
        generalpath.append(double4, true);
        generalpath.closePath();
        double2 = new java.awt.geom.Ellipse2D.Double(d1, (double) f2 - getYOffset(),
                categoryitemrendererstate.getBarWidth(), getYOffset());
    }
    Object obj = getItemPaint(i, j);
    if (getGradientPaintTransformer() != null && (obj instanceof GradientPaint)) {
        GradientPaint gradientpaint = (GradientPaint) obj;
        obj = getGradientPaintTransformer().transform(gradientpaint, generalpath);
    }
    graphics2d.setPaint(((java.awt.Paint) (obj)));
    graphics2d.fill(generalpath);
    if (obj instanceof GradientPaint) {
        graphics2d.setPaint(((GradientPaint) obj).getColor2());
    }
    if (double2 != null) {
        graphics2d.fill(double2);
    }
    if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) {
        graphics2d.setStroke(getItemOutlineStroke(i, j));
        graphics2d.setPaint(getItemOutlinePaint(i, j));
        graphics2d.draw(generalpath);
        if (double2 != null)
            graphics2d.draw(double2);
    }
    CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j);
    if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j))
        drawItemLabel(graphics2d, categorydataset, i, j, categoryplot, categoryitemlabelgenerator,
                generalpath.getBounds2D(), d < 0.0D);
    if (categoryitemrendererstate.getInfo() != null) {
        EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection();
        if (entitycollection != null) {
            String s = null;
            CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j);
            if (categorytooltipgenerator != null)
                s = categorytooltipgenerator.generateToolTip(categorydataset, i, j);
            String s1 = null;
            if (getItemURLGenerator(i, j) != null)
                s1 = getItemURLGenerator(i, j).generateURL(categorydataset, i, j);
            CategoryItemEntity categoryitementity = new CategoryItemEntity(generalpath.getBounds2D(), s, s1,
                    categorydataset, categorydataset.getRowKey(i), categorydataset.getColumnKey(j));
            entitycollection.add(categoryitementity);
        }
    }
}

From source file:com.hexidec.ekit.component.UnicodeDialog.java

public void init(int startIndex) {
    String customFont = Translatrix.getTranslationString("UnicodeDialogButtonFont");
    if (customFont != null && customFont.length() > 0) {
        buttonFont = new Font(Translatrix.getTranslationString("UnicodeDialogButtonFont"), Font.PLAIN, 12);
    } else {//from   w  w  w  .  j a  v a2  s .co m
        buttonFont = new Font("Monospaced", Font.PLAIN, 12);
    }

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new GridLayout(0, 17, 0, 0));
    buttonGroup = new ButtonGroup();

    int prefButtonWidth = 32;
    int prefButtonHeight = 32;

    centerPanel.add(new JLabel(""));
    for (int labelLoop = 0; labelLoop < 16; labelLoop++) {
        JLabel jlblMarker = new JLabel(
                "x" + (labelLoop > 9 ? "" + (char) (65 + (labelLoop - 10)) : "" + labelLoop));
        jlblMarker.setHorizontalAlignment(SwingConstants.CENTER);
        jlblMarker.setVerticalAlignment(SwingConstants.CENTER);
        jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f));
        centerPanel.add(jlblMarker);
    }

    int labelcount = 0;
    for (int counter = 0; counter < UNICODEBLOCKSIZE; counter++) {
        if ((counter % 16) == 0) {
            JLabel jlblMarker = new JLabel(
                    (labelcount > 9 ? "" + (char) (65 + (labelcount - 10)) : "" + labelcount) + "x");
            jlblMarker.setHorizontalAlignment(SwingConstants.CENTER);
            jlblMarker.setVerticalAlignment(SwingConstants.CENTER);
            jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f));
            centerPanel.add(jlblMarker);
            labelcount++;
        }
        buttonArray[counter] = new JToggleButton(" ");
        buttonArray[counter].getModel().setActionCommand("");
        buttonArray[counter].setFont(buttonFont);
        buttonArray[counter].setBorder(
                javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED));
        buttonArray[counter].addActionListener(this);
        if (counter == 0) {
            FontRenderContext frcLocal = ((java.awt.Graphics2D) (parentEkit.getGraphics()))
                    .getFontRenderContext();
            Rectangle2D fontBounds = buttonFont.getMaxCharBounds(frcLocal);
            int maxCharWidth = (int) (Math.abs(fontBounds.getX())) + (int) (Math.abs(fontBounds.getWidth()));
            int maxCharHeight = (int) (Math.abs(fontBounds.getY())) + (int) (Math.abs(fontBounds.getHeight()));
            Insets buttonInsets = buttonArray[counter].getBorder().getBorderInsets(buttonArray[counter]);
            prefButtonWidth = maxCharWidth + buttonInsets.left + buttonInsets.right;
            prefButtonHeight = maxCharHeight + buttonInsets.top + buttonInsets.bottom;
        }
        buttonArray[counter].setPreferredSize(new Dimension(prefButtonWidth, prefButtonHeight));
        centerPanel.add(buttonArray[counter]);
        buttonGroup.add(buttonArray[counter]);
    }

    JPanel selectorPanel = new JPanel();

    jcmbBlockSelector = new JComboBox(unicodeBlocks);
    jcmbBlockSelector.setSelectedIndex(startIndex);
    jcmbBlockSelector.setActionCommand(CMDCHANGEBLOCK);
    jcmbBlockSelector.addActionListener(this);

    String[] sPages = { "1" };
    jcmbPageSelector = new JComboBox(sPages);
    jcmbPageSelector.setSelectedIndex(0);
    jcmbPageSelector.setActionCommand(CMDCHANGEBLOCK);
    jcmbPageSelector.addActionListener(this);

    selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodeBlock")));
    selectorPanel.add(jcmbBlockSelector);
    selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodePage")));
    selectorPanel.add(jcmbPageSelector);

    JPanel buttonPanel = new JPanel();

    JButton closeButton = new JButton(Translatrix.getTranslationString("DialogClose"));
    closeButton.setActionCommand("close");
    closeButton.addActionListener(this);
    buttonPanel.add(closeButton);

    contentPane.add(centerPanel, BorderLayout.CENTER);
    contentPane.add(selectorPanel, BorderLayout.NORTH);
    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    this.pack();

    populateButtons(startIndex, 0);

    this.setVisible(true);
}

From source file:net.sf.mzmine.modules.visualization.twod.TwoDXYPlot.java

public boolean render(final Graphics2D g2, final Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    // if this is not TwoDDataSet
    if (index != 0)
        return super.render(g2, dataArea, index, info, crosshairState);

    // prepare some necessary constants
    final int x = (int) dataArea.getX();
    final int y = (int) dataArea.getY();
    final int width = (int) dataArea.getWidth();
    final int height = (int) dataArea.getHeight();

    final double imageRTMin = (double) getDomainAxis().getRange().getLowerBound();
    final double imageRTMax = (double) getDomainAxis().getRange().getUpperBound();
    final double imageRTStep = (imageRTMax - imageRTMin) / width;
    final double imageMZMin = (double) getRangeAxis().getRange().getLowerBound();
    final double imageMZMax = (double) getRangeAxis().getRange().getUpperBound();
    final double imageMZStep = (imageMZMax - imageMZMin) / height;

    if ((zoomOutBitmap != null) && (imageRTMin == totalRTRange.getMin())
            && (imageRTMax == totalRTRange.getMax()) && (imageMZMin == totalMZRange.getMin())
            && (imageMZMax == totalMZRange.getMax()) && (zoomOutBitmap.getWidth() == width)
            && (zoomOutBitmap.getHeight() == height)) {
        g2.drawImage(zoomOutBitmap, x, y, null);
        return true;
    }/*w w w.j a v a2  s . com*/

    // Save current time
    Date renderStartTime = new Date();

    // prepare a double array of summed intensities
    double values[][] = new double[width][height];
    maxValue = 0; // now this is an instance variable
    Random r = new Random();

    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {

            double pointRTMin = imageRTMin + (i * imageRTStep);
            double pointRTMax = pointRTMin + imageRTStep;
            double pointMZMin = imageMZMin + (j * imageMZStep);
            double pointMZMax = pointMZMin + imageMZStep;

            double lv = dataset.getMaxIntensity(new Range(pointRTMin, pointRTMax),
                    new Range(pointMZMin, pointMZMax), plotMode);

            if (logScale) {
                lv = Math.log10(lv);
                if (lv < 0 || Double.isInfinite(lv))
                    lv = 0;
                values[i][j] = lv;
                //values[r.nextInt(width)][r.nextInt(height)] = lv;
            } else {
                values[i][j] = lv;
            }

            if (lv > maxValue)
                maxValue = lv;

        }

    // This should never happen, but just for correctness
    if (maxValue == 0)
        return false;

    // Normalize all values
    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            values[i][j] /= maxValue;
        }

    // prepare a bitmap of required size
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    // draw image points
    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            Color pointColor = paletteType.getColor(values[i][j]);
            image.setRGB(i, height - j - 1, pointColor.getRGB());
        }

    // if we are zoomed out, save the values
    if ((imageRTMin == totalRTRange.getMin()) && (imageRTMax == totalRTRange.getMax())
            && (imageMZMin == totalMZRange.getMin()) && (imageMZMax == totalMZRange.getMax())) {
        zoomOutBitmap = image;
    }

    // Paint image
    g2.drawImage(image, x, y, null);

    Date renderFinishTime = new Date();

    logger.finest("Finished rendering 2D visualizer, "
            + (renderFinishTime.getTime() - renderStartTime.getTime()) + " ms");

    return true;

}

From source file:MWC.GUI.JFreeChart.StepperXYPlot.java

/**
 * draw the new stepper line into the plot
 * /*  w w  w. ja v a 2s . c  o  m*/
 * @param g2
 * @param linePosition
 * @param dataArea
 */
protected void plotStepperLine(final Graphics2D g2, final double linePosition, final Rectangle2D dataArea) {
    // prepare to draw
    final Stroke oldStroke = g2.getStroke();
    g2.setXORMode(Color.darkGray);

    // thicken up the line
    g2.setStroke(new BasicStroke(3));

    if (this.getOrientation() == PlotOrientation.VERTICAL) {
        // draw the line
        g2.drawLine((int) linePosition - 1, (int) dataArea.getY() + 1, (int) linePosition - 1,
                (int) dataArea.getY() + (int) dataArea.getHeight() - 1);
    } else {
        // draw the line
        g2.drawLine((int) dataArea.getY() + 1, (int) linePosition - 1,
                (int) dataArea.getY() + (int) dataArea.getHeight() - 1, (int) linePosition - 1);

    }

    // and restore everything
    g2.setStroke(oldStroke);
    g2.setPaintMode();
}

From source file:org.pentaho.reporting.libraries.pixie.wmf.WmfFile.java

public synchronized void draw(final Graphics2D graphics, final Rectangle2D bounds) {

    // this adjusts imageWidth and imageHeight
    scaleToFit((float) bounds.getWidth(), (float) bounds.getHeight());
    // adjust translation if needed ...
    graphics.translate(bounds.getX(), bounds.getY());
    // adjust to the image origin
    graphics.translate(-imageX, -imageY);

    this.graphics = graphics;

    for (int i = 0; i < records.size(); i++) {
        try {//from  w  ww .ja v  a 2  s  .c o m
            final MfCmd command = (MfCmd) records.get(i);
            command.setScale((float) imageWidth / (float) maxWidth, (float) imageHeight / (float) maxHeight);
            command.replay(this);
        } catch (Exception e) {
            logger.warn("Error while processing image record #" + i, e);
        }
    }
    resetStates();
}

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 ww .  j av  a  2s  .  c  om*/
        } 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:ImageLabel.java

public void paint(Graphics g) {

    /*//from w w  w  .  j  a  va 2s . c o  m
     * Draw the image stretched to exactly cover the size of the drawing area.
     */
    Dimension size = getSize();
    g.drawImage(img, 0, 0, size.width, size.height, 0, 0, img.getWidth(null), img.getHeight(null), null);

    /*
     * Fill a rounded rectangle centered in the drawing area. Calculate the size
     * of the rectangle from the size of the text
     */
    g.setFont(font);
    FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
    Rectangle2D bounds = font.getStringBounds(text, frc);

    int wText = (int) bounds.getWidth();
    int hText = (int) bounds.getHeight();

    int rX = (size.width - wText) / 2;
    int rY = (size.height - hText) / 2;
    g.setColor(Color.yellow);
    g.fillRoundRect(rX, rY, wText, hText, hText / 2, hText / 2);

    /*
     * Draw text positioned in the rectangle. Since the rectangle is sized based
     * on the bounds of the String we can position it using those bounds.
     */
    int xText = rX - (int) bounds.getX();
    int yText = rY - (int) bounds.getY();
    g.setColor(Color.black);
    g.setFont(font);
    g.drawString(text, xText, yText);
}

From source file:org.tsho.dmc2.core.chart.BasinRenderer.java

public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) {
    basinComponent.setDataobject(null);/*from w w w  . j  a  v  a 2 s  .c o m*/
    attractorsSamplePoints = new Vector();

    state = STATE_RUNNING;

    gridWidth = (int) dataArea.getWidth();
    gridHeight = (int) dataArea.getHeight();

    this.imageX = (int) dataArea.getX() + 1;
    this.imageY = (int) dataArea.getY();

    this.image = new BufferedImage(gridWidth, gridHeight, BufferedImage.TYPE_INT_RGB);
    this.g2 = g2;
    WritableRaster raster = image.getRaster();

    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis = plot.getRangeAxis();

    double maxCoordinate = Math.abs(domainAxis.getUpperBound());
    if (Math.abs(domainAxis.getLowerBound()) > maxCoordinate)
        maxCoordinate = Math.abs(domainAxis.getLowerBound());
    if (Math.abs(rangeAxis.getLowerBound()) > maxCoordinate)
        maxCoordinate = Math.abs(rangeAxis.getLowerBound());
    if (Math.abs(rangeAxis.getUpperBound()) > maxCoordinate)
        maxCoordinate = Math.abs(rangeAxis.getUpperBound());
    if (infinity < maxCoordinate)
        infinity = maxCoordinate + 1;

    grid = new Grid(new double[] { domainAxis.getLowerBound(), domainAxis.getUpperBound(),
            rangeAxis.getLowerBound(), rangeAxis.getUpperBound() }, gridHeight, gridWidth);
    imageData = ((DataBufferInt) raster.getDataBuffer()).getData();
    rate = gridHeight * gridWidth / 100;
    attractorsSamplePoints = new Vector();

    BasinsAlgorithm bA = null;
    if (type == FAST_ALGORITHM)
        bA = new FastBasinsAlgorithm(this);
    else if (type == SLOW_ALGORITHM)
        bA = new SlowBasinsAlgorithm(this);
    bA.run();

    /** Now that grid is computed, pass it to the BasinComponent for possible storing */
    int[] tmp = grid.getData();
    grid.setData((int[]) tmp.clone());//from now on, grid data is disconnected from image data
    basinComponent.setDataobject(grid);

    drawImage();
    state = STATE_FINISHED;
}