Example usage for java.awt.geom GeneralPath GeneralPath

List of usage examples for java.awt.geom GeneralPath GeneralPath

Introduction

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

Prototype

public GeneralPath() 

Source Link

Document

Constructs a new empty single precision GeneralPath object with a default winding rule of #WIND_NON_ZERO .

Usage

From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartSvgRenderer.java

byte[] renderJFreeChart(JFreeChart chart, float width, float height, boolean naked, Date fromDate, Date toDate)
        throws IOException {
    String svgNamespaceUri = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document doc = SVGDOMImplementation.getDOMImplementation().createDocument(svgNamespaceUri, "svg", null);

    String generatedText = "Generated "
            + DateUtils.formatAsStringToLong(new Date(), UserContext.getCurrentLocale()) + " by "
            + MessageAccess.getStringOrNull("global.applicationname", UserContext.getCurrentLocale()) + " "
            + properties.getBuildId();//from   w  w w  . ja v  a  2 s. co m
    String drawingInfo = MessageAccess.getStringOrNull("graphicalExport.timeline.drawInfo",
            UserContext.getCurrentLocale()) + ": "
            + DateUtils.formatAsString(fromDate, UserContext.getCurrentLocale()) + " -> "
            + DateUtils.formatAsString(toDate, UserContext.getCurrentLocale());

    SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc);
    ctx.setComment(generatedText);
    SVGGraphics2D svgGraphics = new SVGGraphics2D(ctx, false);

    if (!naked) {
        //Render the chart to the SVG graphics object
        chart.draw(svgGraphics, new Rectangle(20, 20, Math.round(width - MARGIN), Math.round(height - MARGIN)));

        //Add logo and generated text
        int widthIntForLogo = Math.round(width + 40 - MARGIN);
        int heightIntForLogo = Math.round(height - MARGIN + 20);

        int xLogoUpperRightCorner[] = { widthIntForLogo - 40, widthIntForLogo, widthIntForLogo,
                widthIntForLogo - 8, widthIntForLogo - 8, widthIntForLogo - 40 };
        int yLogoUpperRightCorner[] = { MARGIN_TOP, MARGIN_TOP, MARGIN_TOP + 40, MARGIN_TOP + 40,
                MARGIN_TOP + 8, MARGIN_TOP + 8 };

        GeneralPath logoUpperRightCorner = new GeneralPath();
        logoUpperRightCorner.moveTo(xLogoUpperRightCorner[0], yLogoUpperRightCorner[0]);
        for (int i = 1; i < xLogoUpperRightCorner.length; i++) {
            logoUpperRightCorner.lineTo(xLogoUpperRightCorner[i], yLogoUpperRightCorner[i]);
        }
        logoUpperRightCorner.closePath();
        svgGraphics.setColor(Color.decode(COLOR_LOGO));
        svgGraphics.fill(logoUpperRightCorner);
        svgGraphics.draw(logoUpperRightCorner);

        int xLogoLowerLeftCorner[] = { MARGIN_LEFT, MARGIN_LEFT + 8, MARGIN_LEFT + 8, MARGIN_LEFT + 40,
                MARGIN_LEFT + 40, MARGIN_LEFT };
        int yLogoLowerLeftCorner[] = { heightIntForLogo, heightIntForLogo, heightIntForLogo + 32,
                heightIntForLogo + 32, heightIntForLogo + 40, heightIntForLogo + 40 };

        GeneralPath logoLowerLeftCorner = new GeneralPath();
        logoLowerLeftCorner.moveTo(xLogoLowerLeftCorner[0], yLogoLowerLeftCorner[0]);
        for (int i = 1; i < xLogoLowerLeftCorner.length; i++) {
            logoLowerLeftCorner.lineTo(xLogoLowerLeftCorner[i], yLogoLowerLeftCorner[i]);
        }
        logoLowerLeftCorner.closePath();
        svgGraphics.setColor(Color.BLACK);
        svgGraphics.fill(logoLowerLeftCorner);
        svgGraphics.draw(logoLowerLeftCorner);

        Font f = new Font(null, Font.ITALIC, 12);
        svgGraphics.setFont(f);
        FontMetrics fontMetrics = svgGraphics.getFontMetrics(f);
        int charsWidthInfo = fontMetrics.stringWidth(drawingInfo);
        svgGraphics.drawString(drawingInfo, width - MARGIN - charsWidthInfo,
                height - MARGIN + MARGIN_DOWN_GENERATED_TEXT);
        int charsWidth = fontMetrics.stringWidth(generatedText);
        svgGraphics.drawString(generatedText, width - MARGIN - charsWidth,
                height - MARGIN + MARGIN_DOWN_GENERATED_TEXT + 20);

    } else {
        chart.draw(svgGraphics,
                new Rectangle(20, 20, Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN),
                        Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN)));
    }

    svgGraphics.setSVGCanvasSize(new Dimension((int) width, (int) height));

    //Convert the SVGGraphics2D object to SVG XML 
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer out = new OutputStreamWriter(baos, "UTF-8");
    svgGraphics.stream(out, true);
    byte[] originalSvgXml = baos.toByteArray();

    //    return originalSvgXml;
    return addAdditionalAttributes(originalSvgXml);
}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialPointer.java

/**
 * Draws the pointer./*ww w .j a  va2  s  .  c o  m*/
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    g2.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius());
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius());
    double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale);
    DialScale scale = plot.getScaleForDataset(this.getDatasetIndex());
    double angle = scale.valueToAngle(value);

    Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
    Point2D pt1 = arc1.getEndPoint();
    Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN);
    Point2D pt2 = arc2.getStartPoint();
    Point2D pt3 = arc2.getEndPoint();
    Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN);
    Point2D pt4 = arc3.getStartPoint();

    GeneralPath gp = new GeneralPath();
    gp.moveTo((float) pt1.getX(), (float) pt1.getY());
    gp.lineTo((float) pt2.getX(), (float) pt2.getY());
    gp.lineTo((float) pt4.getX(), (float) pt4.getY());
    gp.lineTo((float) pt3.getX(), (float) pt3.getY());
    gp.closePath();
    g2.setPaint(this.fillPaint);
    g2.fill(gp);

    g2.setPaint(this.getOutlinePaint());
    Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY());
    //      g2.draw(line);

    line.setLine(pt2, pt3);
    g2.draw(line);

    line.setLine(pt3, pt1);
    g2.draw(line);

    line.setLine(pt2, pt1);
    g2.draw(line);

    line.setLine(pt2, pt4);
    g2.draw(line);

    line.setLine(pt3, pt4);
    g2.draw(line);
}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialPointer.java

/**
 * Draws the pointer./*w  w  w  . j ava2  s .com*/
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    g2.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius());
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius());
    double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale);
    DialScale scale = plot.getScaleForDataset(this.getDatasetIndex());
    double angle = scale.valueToAngle(value);

    Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
    Point2D pt1 = arc1.getEndPoint();
    Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN);
    Point2D pt2 = arc2.getStartPoint();
    Point2D pt3 = arc2.getEndPoint();
    Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN);
    Point2D pt4 = arc3.getStartPoint();

    GeneralPath gp = new GeneralPath();
    gp.moveTo((float) pt1.getX(), (float) pt1.getY());
    gp.lineTo((float) pt2.getX(), (float) pt2.getY());
    gp.lineTo((float) pt4.getX(), (float) pt4.getY());
    gp.lineTo((float) pt3.getX(), (float) pt3.getY());
    gp.closePath();
    g2.setPaint(this.fillPaint);
    g2.fill(gp);

    g2.setPaint(this.getOutlinePaint());
    Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY());
    //      g2.draw(line);

    line.setLine(pt2, pt3);
    g2.draw(line);

    line.setLine(pt3, pt1);
    g2.draw(line);

    line.setLine(pt2, pt1);
    g2.draw(line);

    line.setLine(pt2, pt4);
    g2.draw(line);

    line.setLine(pt3, pt4);
    g2.draw(line);
}

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

private void createGlyphsAndAddToPlot(XYPlot plot) {
    XYShapeAnnotation glyph;//  ww  w  .j a v  a  2s  . co  m
    Shape glyphShape;
    Color glyphColor;

    ClinicalDataPoint clinicalPoint;
    String survivalLenStr;
    double x, y;
    for (Iterator i = dataPoints.iterator(); i.hasNext();) {
        clinicalPoint = (ClinicalDataPoint) i.next();

        x = clinicalPoint.getFactorValue(factor1);
        y = clinicalPoint.getFactorValue(factor2);

        if ((x != ClinicalDataPoint.MISSING_CLINICAL_FACTOR_VALUE)
                && (y != ClinicalDataPoint.MISSING_CLINICAL_FACTOR_VALUE)) {

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

            //Rectangle2D.Double rect = new Rectangle2D.Double();
            //rect.setFrameFromCenter(x,y, x+1,y+1);
            //glyphShape = rect;
            glyphColor = getColorForDataPoint(clinicalPoint);
            glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor);

            if (clinicalPoint.getSurvivalInMonths() >= 0.0) {
                survivalLenStr = nf.format(clinicalPoint.getSurvivalInMonths());
            } else {
                survivalLenStr = "";
            }

            String tooltip = clinicalPoint.getPatientId() + " " + clinicalPoint.getDiseaseName()
                    + " survivalMonths=" + survivalLenStr;
            glyph.setToolTipText(tooltip);
            plot.addAnnotation(glyph);
        }
    }

}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

/**<!====== drawItem ======================================================>
   Draws a 3D bar to represent one data item.
   <!      Name       Description>
   @param  g2         the graphics device.
   @param  state      the renderer state.
   @param  dataArea   the area for plotting the data.
   @param  plot       the plot./*www. j ava2s .c  o  m*/
   @param  domainAxis the domain axis.
   @param  rangeAxis  the range axis.
   @param  dataset    the dataset.
   @param  row        the row index (zero-based).
   @param  column     the column index (zero-based).
   @param  pass       the pass index.
<!=======================================================================>*/
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    g2.setStroke(new BasicStroke(1));
    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint itemPaint = getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color endColor = getFrontDark((Color) itemPaint);
        Color startColor = (Color) itemPaint;
        Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor,
                (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor);
        g2.setPaint(paint);
    }
    g2.fill(bar);

    double x0 = bar.getMinX(); // left
    double x1 = x0 + getXOffset(); // offset left
    double x2 = bar.getMaxX(); // right
    double x3 = x2 + getXOffset(); // offset right

    double y0 = bar.getMinY() - getYOffset(); // offset top
    double y1 = bar.getMinY(); // bar top
    double y2 = bar.getMaxY() - getYOffset(); // offset bottom
    double y3 = bar.getMaxY(); // bottom

    //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight());

    Line2D.Double line = new Line2D.Double(x2, y1, x2, y3);
    g2.draw(line);

    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop = null;
    g2.setPaint(itemPaint);

    // Draw the right side
    if (barLength > 0.0) {
        bar3dRight = new GeneralPath();
        bar3dRight.moveTo((float) x2, (float) y3);
        bar3dRight.lineTo((float) x2, (float) y1);
        bar3dRight.lineTo((float) x3, (float) y0);
        bar3dRight.lineTo((float) x3, (float) y2);
        bar3dRight.closePath();

        if (itemPaint instanceof Color) {
            Color startColor = getSideLight((Color) itemPaint);
            Color endColor = getSideDark((Color) itemPaint);
            Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3,
                    endColor);
            g2.setPaint(paint);
        }
        g2.fill(bar3dRight);
    }

    // Draw the top
    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1); // bottom left
    bar3dTop.lineTo((float) x1, (float) y0); // top left
    bar3dTop.lineTo((float) x3, (float) y0); // top right
    bar3dTop.lineTo((float) x2, (float) y1); // bottom right
    bar3dTop.closePath();
    if (itemPaint instanceof Color) {
        Color endColor = getTopDark((Color) itemPaint);
        Color startColor = getTopLight((Color) itemPaint);
        //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor);
        Point2D.Double topRight = new Point2D.Double(x3, y0);
        Point2D.Double bottomLeft = new Point2D.Double(x0, y1);
        //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2)));
        Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2)));
        Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor,
                (float) darkEnd.getX(), (float) darkEnd.getY(), endColor);
        g2.setPaint(paint);
        //drawMarker(topRight, g2, startColor);
    }
    g2.fill(bar3dTop);
    g2.setPaint(itemPaint);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dRight != null) {
            g2.draw(bar3dRight);
        }
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        GeneralPath barOutline = new GeneralPath();
        barOutline.moveTo((float) x0, (float) y3);
        barOutline.lineTo((float) x0, (float) y1);
        barOutline.lineTo((float) x1, (float) y0);
        barOutline.lineTo((float) x3, (float) y0);
        barOutline.lineTo((float) x3, (float) y2);
        barOutline.lineTo((float) x2, (float) y3);
        barOutline.closePath();
        addItemEntity(entities, dataset, row, column, barOutline);
    }

}

From source file:ucar.unidata.idv.control.chart.MyScatterPlot.java

/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the
 * screen or a printer)./* w w w  . java  2  s . co  m*/
 * a
 * @param g2  the graphics device.
 * @param dataArea the data area
 * @param index which data set
 * @param info  collects chart drawing information (<code>null</code>
 *              permitted).
 * @param crosshairState crosshairState
 *
 * @return did something
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    if (index >= series.size()) {
        return false;
    }
    XYDataset dataset = getDataset(index);
    g2.setStroke(new BasicStroke());
    //                   getRendererForDataset(dataset).getSeriesStroke(0));
    ScatterPlotChartWrapper.MyRenderer renderer = (ScatterPlotChartWrapper.MyRenderer) getRendererForDataset(
            dataset);
    g2.setPaint(renderer.getSeriesPaint(0));
    int shape = renderer.shape;

    PlotOrientation orientation = getOrientation();
    int seenCnt = 0;

    int xx = (int) dataArea.getMinX();
    int ww = (int) dataArea.getWidth();
    int yy = (int) dataArea.getMaxY();
    int hh = (int) dataArea.getHeight();
    ValueAxis rangeAxis = getRangeAxisForDataset(index);
    ValueAxis domainAxis = getDomainAxisForDataset(index);
    double domainMin = domainAxis.getLowerBound();
    double domainLength = domainAxis.getUpperBound() - domainMin;
    double rangeMin = rangeAxis.getLowerBound();
    double rangeLength = rangeAxis.getUpperBound() - rangeMin;
    int boxWidth = 6;

    double[][] data = (double[][]) series.get(index);

    double[] d1 = data[0];
    double[] d2 = data[1];
    int size = d1.length;

    Hashtable seen = new Hashtable();
    int lastX = 0;
    int lastY = 0;
    //TODO: Check for clipping
    //TODO: Try to create a GeneralPath with the points
    //and cal g2.draw just once
    GeneralPath path = new GeneralPath();
    long t1 = System.currentTimeMillis();

    for (int i = 0; i < size; i++) {
        int transX = (int) (xx + ww * (d1[i] - domainMin) / domainLength);
        int transY = (int) (yy - hh * (d2[i] - rangeMin) / rangeLength);
        Object key = transX + "_" + transY;
        if (seen.get(key) != null) {
            seenCnt++;
            continue;
        }
        seen.put(key, key);
        if (crosshairState != null) {
            crosshairState.updateCrosshairPoint(d1[i], d2[i], transX, transY, orientation);
        }

        switch (shape) {

        case LineState.SHAPE_VLINE:
            if (i > 1) {
                g2.drawLine(lastX, lastY, transX, transY);
            }
            lastX = transX;
            lastY = transY;

        case LineState.SHAPE_POINT:
            path.append(new Rectangle((int) transX, (int) transY, 1, 1), false);
            break;

        case LineState.SHAPE_LARGEPOINT:
            path.append(new Rectangle((int) transX, (int) transY, 2, 2), false);
            break;

        case LineState.SHAPE_RECTANGLE:
            path.append(
                    new Rectangle((int) transX - boxWidth / 2, (int) transY - boxWidth / 2, boxWidth, boxWidth),
                    false);
            break;

        case LineState.SHAPE_X:
            g2.drawLine(transX - boxWidth / 2, transY - boxWidth / 2, transX + boxWidth - boxWidth / 2,
                    transY + boxWidth - boxWidth / 2);
            g2.drawLine(transX + boxWidth - boxWidth / 2, transY - boxWidth / 2, transX - boxWidth / 2,
                    transY + boxWidth - boxWidth / 2);
            break;

        case LineState.SHAPE_PLUS:
            g2.drawLine(transX + boxWidth / 2, transY, transX + boxWidth / 2, transY + boxWidth);
            g2.drawLine(transX, transY + boxWidth / 2, transX + boxWidth, transY + boxWidth / 2);
            break;

        }
    }
    g2.fill(path);
    long t2 = System.currentTimeMillis();
    //        System.out.println ("time:" + (t2-t1));
    return true;
}

From source file:io.github.dsheirer.spectrum.SpectrumPanel.java

/**
 * Draws the current fft spectrum with a line and a gradient fill.
 *///  w w w  .  j a va  2s  .c  o m
private void drawSpectrum(Graphics2D graphics) {
    Dimension size = getSize();

    //Draw the background
    Rectangle background = new Rectangle(0, 0, size.width, size.height);
    graphics.setColor(mColorSpectrumBackground);
    graphics.draw(background);
    graphics.fill(background);

    //Define the gradient
    GradientPaint gradient = new GradientPaint(0, (getSize().height - mSpectrumInset) / 2,
            mColorSpectrumGradientTop, 0, getSize().height, mColorSpectrumGradientBottom);

    graphics.setBackground(mColorSpectrumBackground);

    GeneralPath spectrumShape = new GeneralPath();

    //Start at the lower right inset point
    spectrumShape.moveTo(size.getWidth(), size.getHeight() - mSpectrumInset);

    //Draw to the lower left
    spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset);

    float[] bins = getBins();

    //If we have FFT data to display ...
    if (bins != null) {
        float insideHeight = size.height - mSpectrumInset;

        float scalor = insideHeight / -mDBScale;

        /* Calculate based on bin size - 1, since bin 0 is rendered at zero
           * and the last bin is rendered at the width */
        float binSize = (float) size.width / ((float) (bins.length));

        for (int x = 0; x < bins.length; x++) {
            float height;

            height = bins[x] * scalor;

            if (height > insideHeight) {
                height = insideHeight;
            }

            if (height < 0) {
                height = 0;
            }

            float xAxis = (float) x * binSize;

            spectrumShape.lineTo(xAxis, height);
        }
    }
    //Otherwise show an empty spectrum
    else {
        //Draw Left Size
        graphics.setPaint(gradient);
        spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset);
        //Draw Middle
        spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset);
    }

    //Draw Right Side
    spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset);

    graphics.setPaint(gradient);
    graphics.draw(spectrumShape);
    graphics.fill(spectrumShape);

    graphics.setPaint(mColorSpectrumLine);

    //Draw the bottom line under the spectrum
    graphics.draw(new Line2D.Float(0, size.height - mSpectrumInset, size.width, size.height - mSpectrumInset));
}

From source file:StrokeTest.java

public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    GeneralPath path = new GeneralPath();
    path.moveTo((float) points[0].getX(), (float) points[0].getY());
    for (int i = 1; i < points.length; i++)
        path.lineTo((float) points[i].getX(), (float) points[i].getY());
    BasicStroke stroke;// w  ww.  j av  a 2  s.  c  o m
    if (dash) {
        float miterLimit = 10.0F;
        float[] dashPattern = { 10F, 10F, 10F, 10F, 10F, 10F, 30F, 10F, 30F, 10F, 30F, 10F, 10F, 10F, 10F, 10F,
                10F, 30F };
        float dashPhase = 0;
        stroke = new BasicStroke(width, cap, join, miterLimit, dashPattern, dashPhase);
    } else
        stroke = new BasicStroke(width, cap, join);
    g2.setStroke(stroke);
    g2.draw(path);
}

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

/**
 * Build the legend//from w  w w. ja va2  s  .co m
 *
 */
protected void buildLegend() {

    LegendTitle legend = pcaChart.getLegend();
    LegendItemSource[] sources = new LegendItemSource[1];
    PcaLegendItemSource legendSrc = new PcaLegendItemSource();
    LegendItem item = null;

    //Rect=survival less than 10 months
    item = new LegendItem("Survival less than 10 months", null, null, null, new Rectangle2D.Double(0, 0, 8, 8),
            Color.BLACK);
    legendSrc.addLegendItem(item);

    //Circle=survival 10 months or more
    item = new LegendItem("Survival over 10 months", null, null, null, new Ellipse2D.Double(0, 0, 8, 8),
            Color.BLACK);
    legendSrc.addLegendItem(item);

    //Triangle if data if survival data is missing
    GeneralPath triangle = new GeneralPath();
    //     triangle.moveTo(1.0f,0.0f);
    //     triangle.moveTo(0.0f,1.0f);
    //     triangle.moveTo(1.0f,1.0f);
    triangle.moveTo(0.0f, -4.0f);
    triangle.lineTo(4.0f, 4.0f);
    triangle.lineTo(-4.0f, 4.0f);
    triangle.closePath();
    //triangle.closePath();
    item = new LegendItem("Survival Unknown", null, null, null, triangle, Color.BLACK);
    legendSrc.addLegendItem(item);

    //Diamond=survival N/A, for non_tumor/normal
    Shape r = new Rectangle2D.Double(0, 0, 8, 8);
    Shape d = ShapeUtilities.rotateShape(r, new Double(0.785398163), new Float(0), new Float(0));
    item = new LegendItem("Survival N/A", null, null, null, d, Color.BLACK);
    legendSrc.addLegendItem(item);

    if (colorBy == PCAcolorByType.Disease) {
        //go through the disease color map and add legend items
        String diseaseName = null;
        Color diseaseColor = null;
        DiseaseType[] diseases = DiseaseType.values();
        for (int i = 0; i < diseases.length; i++) {
            diseaseName = diseases[i].name();
            if (diseases[i].equals(DiseaseType.UNCLASSIFIED)) {
                continue; //remove unclassified from the legend
            }
            diseaseColor = diseases[i].getColor();
            item = new LegendItem(diseaseName, null, null, null, new Line2D.Double(0, 0, 6, 6),
                    new BasicStroke(3.0f), diseaseColor);
            //item = new LegendItem(diseaseName, null, null, null, new Rectangle2D.Double(0,0,6,6), diseaseColor);
            legendSrc.addLegendItem(item);
        }
        //      item = new LegendItem("Unknown", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.GRAY);
        //      legendSrc.addLegendItem(item);
    } else if (colorBy == PCAcolorByType.Gender) {
        String genderName = null;
        Color genderColor = null;
        GenderType[] genderTypes = GenderType.values();
        for (int i = 0; i < genderTypes.length; i++) {
            genderName = genderTypes[i].toString();
            genderColor = genderTypes[i].getColor();
            item = new LegendItem(genderName, null, null, null, new Line2D.Double(0, 0, 6, 6),
                    new BasicStroke(3.0f), genderColor);
            legendSrc.addLegendItem(item);
        }
        //        item = new LegendItem("Male", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.BLUE);
        //        legendSrc.addLegendItem(item);
        //        item = new LegendItem("Female", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.PINK);
        //        legendSrc.addLegendItem(item);
        //        item = new LegendItem("Unknown", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f),Color.GRAY);
        //        legendSrc.addLegendItem(item);
    }

    sources[0] = legendSrc;
    legend.setSources(sources);
}

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

/**
 * Build the legend/*w  w w .  j  a v a2  s .  c om*/
 *
 */
private void buildLegend() {

    LegendTitle legend = pcaChart.getLegend();
    LegendItemSource[] sources = new LegendItemSource[1];
    PcaLegendItemSource legendSrc = new PcaLegendItemSource();
    LegendItem item = null;

    //Rect=survival less than 10 months
    item = new LegendItem("Tumor size change (MRI): Unknown", null, null, null,
            new Rectangle2D.Double(0, 0, 8, 8), Color.BLACK);
    legendSrc.addLegendItem(item);

    GeneralPath downtriangle = new GeneralPath();
    downtriangle.moveTo(-4.0f, -4.0f);
    downtriangle.lineTo(4.0f, -4.0f);
    downtriangle.lineTo(0.0f, 4.0f);
    downtriangle.closePath();
    item = new LegendItem("Tumor size reduced by 30% or more (MRI)", null, null, null, downtriangle,
            Color.BLACK);
    legendSrc.addLegendItem(item);

    item = new LegendItem("Tumor size reduced less than 30% or no change (MRI)", null, null, null,
            new Ellipse2D.Double(0, 0, 8, 8), Color.BLACK);
    legendSrc.addLegendItem(item);

    GeneralPath uptriangle = new GeneralPath();
    uptriangle.moveTo(0.0f, -4.0f);
    uptriangle.lineTo(4.0f, 4.0f);
    uptriangle.lineTo(-4.0f, 4.0f);
    uptriangle.closePath();
    item = new LegendItem("Tumor size increased (MRI)", null, null, null, uptriangle, Color.BLACK);
    legendSrc.addLegendItem(item);

    if (colorBy == ColorByType.CLINICALRESPONSE) {

        for (ClinicalResponseType cr : ClinicalResponseType.values()) {
            item = new LegendItem(cr.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                    new BasicStroke(3.0f), cr.getColor());
            legendSrc.addLegendItem(item);
        }

    } else if (colorBy == ColorByType.DISEASESTAGE) {

        for (ClinicalStageType ds : ClinicalStageType.values()) {
            if (!ds.name().endsWith("ALL")) {
                item = new LegendItem(ds.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ds.getColor());
                legendSrc.addLegendItem(item);
            }
        }
    } else if (colorBy == ColorByType.TIMEPOINT) {
        for (TimepointType tp : TimepointType.values()) {
            item = new LegendItem(tp.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                    new BasicStroke(3.0f), tp.getColor());
            legendSrc.addLegendItem(item);
        }
    }

    sources[0] = legendSrc;
    legend.setSources(sources);
}