Example usage for java.awt.geom Rectangle2D.Double setFrameFromCenter

List of usage examples for java.awt.geom Rectangle2D.Double setFrameFromCenter

Introduction

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

Prototype

public void setFrameFromCenter(double centerX, double centerY, double cornerX, double cornerY) 

Source Link

Document

Sets the framing rectangle of this Shape based on the specified center point coordinates and corner point coordinates.

Usage

From source file:gov.nih.nci.rembrandt.web.plots.RBTPrincipalComponentAnalysisPlot.java

/**
 * This chart uses the XYAnnotation as a glyph to represent
 * a single pca data point. Glyph shape is determined by survival time.
 * Survival of more than 10 months is represented by a circle. 10 months or less
 * is represented by a square. Component1 values are represented by X 
 * Component2 values are represented by Y
 *//*from  ww  w .  ja va 2 s .c  om*/
protected void createGlyphsAndAddToPlot(XYPlot plot) {

    //for RBT, if its non_tumor, show a diamond meaning "N/A for survival"

    XYShapeAnnotation glyph;
    Shape glyphShape;
    Color glyphColor;

    PrincipalComponentAnalysisDataPoint pcaPoint;
    double x, y;
    for (Iterator i = dataPoints.iterator(); i.hasNext();) {
        pcaPoint = (PrincipalComponentAnalysisDataPoint) i.next();

        x = pcaPoint.getComponentValue(component1);
        y = pcaPoint.getComponentValue(component2);
        double survival = pcaPoint.getSurvivalInMonths();
        String diseaseName = pcaPoint.getDiseaseName();

        if (this.colorBy.equals(PCAcolorByType.NONE)) {
            Ellipse2D.Double circle = new Ellipse2D.Double();
            circle.setFrameFromCenter(x, y, x + 2, y + 2);
            glyphShape = circle;
        } else if (diseaseName.equals(RembrandtConstants.NON_TUMOR) || diseaseName.equals("CELL_LINE")) {
            //glyphShape = ShapeUtilities.createDiamond(new Float(x));
            Rectangle2D.Double rect = new Rectangle2D.Double();
            rect.setFrameFromCenter(x, y, x + 2, y + 2);
            glyphShape = rect;
            Shape gShape = ShapeUtilities.rotateShape(glyphShape, new Double(0.785398163), new Float(x),
                    new Float(y));
            glyphShape = gShape;
        } else if ((survival > 0) && (survival < 10.0)) {
            Rectangle2D.Double rect = new Rectangle2D.Double();
            rect.setFrameFromCenter(x, y, x + 2, y + 2);
            glyphShape = rect;
        } else if ((survival > 0) && (survival >= 10.0)) {
            Ellipse2D.Double circle = new Ellipse2D.Double();
            circle.setFrameFromCenter(x, y, x + 2, y + 2);
            glyphShape = circle;
        } else {
            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;
            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf + 3.0f, yf - 3.0f);
            gp.lineTo(xf - 3.0f, yf - 3.0f);
            gp.closePath();
            glyphShape = gp;
        }

        glyphColor = getColorForDataPoint(pcaPoint);
        glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor);
        String tooltip = "";
        if (pcaPoint.getSurvivalInMonths() <= 0.0) {
            tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName();
        } else {
            tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName() + " survivalMonths="
                    + nf.format(pcaPoint.getSurvivalInMonths());
        }
        glyph.setToolTipText(tooltip);
        plot.addAnnotation(glyph);
    }

}

From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java

/**
 * This chart uses the XYAnnotation as a glyph to represent
 * a single pca data point. Glyph shape is determined by survival time.
 * Survival of more than 10 months is represented by a circle. 10 months or less
 * is represented by a square. Component1 values are represented by X 
 * Component2 values are represented by Y
 *///from  w  w w  .ja  v a 2s. c o m
protected void createGlyphsAndAddToPlot(XYPlot plot) {
    XYShapeAnnotation glyph;
    Shape glyphShape;
    Color glyphColor;

    PrincipalComponentAnalysisDataPoint pcaPoint;
    double x, y;
    for (Iterator i = dataPoints.iterator(); i.hasNext();) {
        pcaPoint = (PrincipalComponentAnalysisDataPoint) i.next();

        x = pcaPoint.getComponentValue(component1);
        y = pcaPoint.getComponentValue(component2);
        double survival = pcaPoint.getSurvivalInMonths();
        if ((survival > 0) && (survival < 10.0)) {
            Rectangle2D.Double rect = new Rectangle2D.Double();
            rect.setFrameFromCenter(x, y, x + 2, y + 2);
            glyphShape = rect;
        } else if ((survival > 0) && (survival >= 10.0)) {
            Ellipse2D.Double circle = new Ellipse2D.Double();
            circle.setFrameFromCenter(x, y, x + 2, y + 2);
            glyphShape = circle;
        } else {
            //Rectangle2D.Double rect = new Rectangle2D.Double();
            //rect.setFrameFromCenter(x,y, x+2,y+2);
            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;
            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf + 3.0f, yf - 3.0f);
            gp.lineTo(xf - 3.0f, yf - 3.0f);
            gp.closePath();
            glyphShape = gp;
        }

        glyphColor = getColorForDataPoint(pcaPoint);
        glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor);
        String tooltip = "";
        if (pcaPoint.getSurvivalInMonths() <= 0.0) {
            tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName();
        } else {
            tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName() + " survivalMonths="
                    + nf.format(pcaPoint.getSurvivalInMonths());
        }
        glyph.setToolTipText(tooltip);
        plot.addAnnotation(glyph);
    }

}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYPrincipalComponentAnalysisPlot.java

/**
 * This chart uses the XYAnnotation as a glyph to represent
 * a single pca data point. Glyph shape is determined by survival time.
 * Survival of more than 10 months is represented by a circle. 10 months or less
 * is represented by a square. Component1 values are represented by X 
 * Component2 values are represented by Y
 *///from w  ww.  ja v a2  s. c o m
private void createGlyphsAndAddToPlot(XYPlot plot, double glyphScaleFactor) {
    XYShapeAnnotation glyph;
    Shape glyphShape = null;
    Color glyphColor;

    double glyphSize = 8.0; //pixels

    double glyphIncrement = (glyphSize * glyphScaleFactor) / 2.0;
    float gi = (float) glyphIncrement;

    ISPYPCADataPoint pcaPoint;
    double x, y;
    for (Iterator i = dataPoints.iterator(); i.hasNext();) {
        pcaPoint = (ISPYPCADataPoint) i.next();

        x = pcaPoint.getComponentValue(component1);
        y = pcaPoint.getComponentValue(component2);

        Double mriPctChange = pcaPoint.getTumorMRIpctChange();

        if (mriPctChange == null) {
            //data is missing
            Rectangle2D.Double rect = new Rectangle2D.Double();
            //rect.setFrameFromCenter(x,y, x+1.25,y+1.25);
            rect.setFrameFromCenter(x, y, x + glyphIncrement, y + glyphIncrement);
            glyphShape = rect;
        } else if (mriPctChange <= -30.0) {

            //tumor shrank by more than 30% (down arrow)
            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;

            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf - gi, yf + gi);
            gp.lineTo(xf + gi, yf + gi);
            gp.closePath();
            glyphShape = gp;
        } else if (mriPctChange > 0.0) {
            //tumor size increased (up arrow)

            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;
            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf + gi, yf - gi);
            gp.lineTo(xf - gi, yf - gi);
            gp.closePath();
            glyphShape = gp;

            //         Ellipse2D.Double circle = new Ellipse2D.Double();
            //         circle.setFrameFromCenter(x,y, x+2, y+2);

        } else if ((mriPctChange > -30.0) && (mriPctChange <= 0.0)) {
            //no change or reduction in tumor size but less than 30% reduction
            Ellipse2D.Double circle = new Ellipse2D.Double();
            //circle.setFrameFromCenter(x,y,x+1.25,y+1.25);
            circle.setFrameFromCenter(x, y, x + gi, y + gi);
            glyphShape = circle;

        }

        glyphColor = getColorForDataPoint(pcaPoint);
        glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor);

        String tooltip = pcaPoint.toString();

        glyph.setToolTipText(tooltip);
        plot.addAnnotation(glyph);
    }

}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java

private void createGlyphsAndAddToPlot(XYPlot plot, double xScale, double yScale) {
    XYShapeAnnotation glyph;/*from  w w w .j  a v a  2 s . c  om*/
    Shape glyphShape = null;
    Color glyphColor;

    //double glyphSize = 8.0;   //pixels

    double glyphIncrementX = (glyphSize * xScale) / 2.0;
    double glyphIncrementY = (glyphSize * yScale) / 2.0;
    float gi_x = (float) glyphIncrementX;
    float gi_y = (float) glyphIncrementY;

    PatientData pd;

    double x, y;
    Double mriPctChange = null;
    for (ISPYPlotPoint corrPoint : dataPoints) {

        x = corrPoint.getX();
        y = corrPoint.getY();

        mriPctChange = corrPoint.getMRITumorPctChange();

        if (mriPctChange == null) {
            //data is missing
            Rectangle2D.Double rect = new Rectangle2D.Double();
            //rect.setFrameFromCenter(x,y, x+1.25,y+1.25);
            rect.setFrameFromCenter(x, y, x + glyphIncrementX, y + glyphIncrementY);
            glyphShape = rect;
        } else if (mriPctChange <= -30.0) {

            //tumor shrank by more than 30% (down arrow)
            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;

            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf - gi_x, yf + gi_y);
            gp.lineTo(xf + gi_x, yf + gi_y);
            gp.closePath();
            glyphShape = gp;
        } else if (mriPctChange > 0.0) {
            //tumor size increased (up arrow)

            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;
            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf + gi_x, yf - gi_y);
            gp.lineTo(xf - gi_x, yf - gi_y);
            gp.closePath();
            glyphShape = gp;

            //            Ellipse2D.Double circle = new Ellipse2D.Double();
            //            circle.setFrameFromCenter(x,y, x+2, y+2);

        } else if ((mriPctChange > -30.0) && (mriPctChange <= 0.0)) {
            //no change or reduction in tumor size but less than 30% reduction
            Ellipse2D.Double circle = new Ellipse2D.Double();
            //circle.setFrameFromCenter(x,y,x+1.25,y+1.25);
            circle.setFrameFromCenter(x, y, x + gi_x, y + gi_y);
            glyphShape = circle;

        }

        //glyphColor = Color.BLUE; 
        //later can set color based on 
        glyphColor = getColorForDataPoint(corrPoint);

        glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor);

        String tooltip = corrPoint.getTag();

        glyph.setToolTipText(tooltip);
        plot.addAnnotation(glyph);
    }

}