Example usage for java.awt.geom GeneralPath moveTo

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

Introduction

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

Prototype

public abstract void moveTo(double x, double y);

Source Link

Document

Adds a point to the path by moving to the specified coordinates specified in double precision.

Usage

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

@Override
public void drawBackground(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(getXOffset());
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(getXOffset());

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(getYOffset());
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(getYOffset());

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);
    clip.lineTo(x0, y2);//from  ww w.  j a  v a  2 s .c o  m
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getBackgroundAlpha()));

    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX() + getXOffset(), dataArea.getY(),
                dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }

    g2.setComposite(originalComposite);

}

From source file:com.bdaum.zoom.report.internal.jfree.custom.CylinderRenderer.java

/**
 * Draws a cylinder to represent one data item.
 *
 * @param g2  the graphics device./*from ww w.  j a  v  a2  s  .  c o m*/
 * @param state  the renderer state.
 * @param dataArea  the area for plotting the data.
 * @param plot  the plot.
 * @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.
 */
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;
    }

    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();
    float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    float barL0 = Math.min(transL0, transL1);
    float barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    GeneralPath bar = new GeneralPath();
    Shape top = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar.moveTo((float) (barL0 + getXOffset() / 2), (float) barW0);
        bar.lineTo((float) (barL0 + barLength + getXOffset() / 2), (float) barW0);
        Arc2D arc = new Arc2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth(), 90, 180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barL0 + getXOffset() / 2), (float) (barW0 + state.getBarWidth()));
        arc = new Arc2D.Double(barL0, barW0, getXOffset(), state.getBarWidth(), 270, -180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();
        top = new Ellipse2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth());

    } else {
        bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2));
        bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2));
        Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(),
                getYOffset(), 180, 180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2));
        arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();

        top = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset());
    }
    Paint itemPaint = getItemPaint(row, column);
    if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        itemPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    if (itemPaint instanceof GradientPaint) {
        g2.setPaint(((GradientPaint) itemPaint).getColor2());
    } else {
        g2.setPaint(PaintAlpha.darker(itemPaint)); // bd
    }
    if (top != null) {
        g2.fill(top);
    }

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

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

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset,
                    dataset.getRowKey(row), dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}

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

private void createGlyphsAndAddToPlot(XYPlot plot) {
    XYShapeAnnotation glyph;/*from ww  w .  j a  va 2s.  c  o  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.gargoylesoftware.htmlunit.html.HtmlArea.java

private GeneralPath parsePoly() {
    final String[] coords = StringUtils.split(getCoordsAttribute(), ',');
    final GeneralPath path = new GeneralPath();
    for (int i = 0; i + 1 < coords.length; i += 2) {
        if (i == 0) {
            path.moveTo(Float.parseFloat(coords[i]), Float.parseFloat(coords[i + 1]));
        } else {//  ww w  .j  a  v  a2 s.  c o m
            path.lineTo(Float.parseFloat(coords[i]), Float.parseFloat(coords[i + 1]));
        }
    }
    path.closePath();
    return path;
}

From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private VisualPeakAnnotation generateTriangle(double startX, double startY, double apexX, double apexY,
        double stopX, double stopY) {
    GeneralPath path = new GeneralPath();
    path.moveTo(startX, startY);
    path.lineTo(apexX, apexY);/*from  www .  ja  v  a  2s  .c o  m*/
    path.lineTo(stopX, stopY);
    path.closePath();
    Rectangle2D r = path.getBounds2D();
    return new VisualPeakAnnotation(path, new Point2D.Double(r.getCenterX(), r.getMaxY()),
            PeakAnnotationType.POINTER);
}

From source file:longMethod.jfreechart.draw.XYPolygonAnnotation.java

/**
 * Draws the annotation.  This method is usually called by the
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.//from  w  ww . j a v a 2 s . c o  m
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
        int rendererIndex, PlotRenderingInfo info) {

    // if we don't have at least 2 (x, y) coordinates, just return
    if (this.polygon.length < 4) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);

    GeneralPath area = new GeneralPath();
    double x = domainAxis.valueToJava2D(this.polygon[0], dataArea, domainEdge);
    double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        area.moveTo((float) y, (float) x);
        for (int i = 2; i < this.polygon.length; i += 2) {
            x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge);
            y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge);
            area.lineTo((float) y, (float) x);
        }
        area.closePath();
    } else if (orientation == PlotOrientation.VERTICAL) {
        area.moveTo((float) x, (float) y);
        for (int i = 2; i < this.polygon.length; i += 2) {
            x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge);
            y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge);
            area.lineTo((float) x, (float) y);
        }
        area.closePath();
    }

    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(area);
    }

    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(area);
    }
    addEntity(info, area, rendererIndex, getToolTipText(), getURL());

}

From source file:net.sf.maltcms.chromaui.charts.events.XYAnnotationAdder.java

/**
 *
 * @param x//from  ww  w.  j a va 2  s  . co  m
 * @param y
 * @param w
 * @param h
 * @return
 */
public Shape getCrosshairShape(double x, double y, double w, double h) {
    // draw GeneralPath (polyline)
    //we draw two lines, one from
    //x-5,y to x+5,y and one from
    //x,y-5 to x,y+5
    double x2Points[] = { x - w, x + w, x, x };
    double y2Points[] = { y, y, y - h, y + h };
    GeneralPath crosshair = new GeneralPath(GeneralPath.WIND_EVEN_ODD, x2Points.length);

    crosshair.moveTo(x2Points[0], y2Points[0]);
    crosshair.lineTo(x2Points[1], y2Points[1]);
    crosshair.moveTo(x2Points[2], y2Points[2]);
    crosshair.lineTo(x2Points[3], y2Points[3]);

    return crosshair;

}

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

/**
 * Build the legend/*  www.  j  a v  a 2 s.c  o  m*/
 *
 */
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);
}

From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private VisualPeakAnnotation generateOutline(IChromatogramDescriptor chromatogram,
        IPeakAnnotationDescriptor peakDescr, ADataset1D<IChromatogram1D, IScan> dataset, int seriesIndex) {
    boolean baselineAvailable = false;
    if (!(Double.isNaN(peakDescr.getBaselineStartIntensity())
            && Double.isNaN(peakDescr.getBaselineStopIntensity())
            && Double.isNaN(peakDescr.getBaselineStartTime())
            && Double.isNaN(peakDescr.getBaselineStopTime()))) {
        Logger.getLogger(getClass().getName()).warning("Using baseline for peak outline");
        baselineAvailable = true;/*  w  w w .  ja  v  a  2 s.  c  o m*/
    }
    double sat = peakDescr.getApexTime();
    double peakStartTime = peakDescr.getStartTime();
    double peakStopTime = peakDescr.getStopTime();
    if (Double.isNaN(peakStartTime) || Double.isNaN(peakStopTime)) {
        return null;
    }
    int scan = chromatogram.getChromatogram().getIndexFor(sat);
    int startIdx = chromatogram.getChromatogram().getIndexFor(peakStartTime);
    int stopIdx = chromatogram.getChromatogram().getIndexFor(peakStopTime);
    double peakStartValue = peakDescr.getStartIntensity();
    double peakStopValue = peakDescr.getStopIntensity();
    double blStartTime, blStopTime, blStartVal, blStopVal;
    if (baselineAvailable) {
        blStartTime = peakDescr.getBaselineStartTime();
        blStopTime = peakDescr.getBaselineStopTime();
        blStartVal = peakDescr.getBaselineStartIntensity();
        blStopVal = peakDescr.getBaselineStopIntensity();
    } else {
        blStartTime = peakStartTime;
        blStopTime = peakStopTime;
        //FIXME baseline is not correctly shown
        if (Double.isNaN(peakDescr.getStartIntensity()) || Double.isNaN(peakDescr.getStopIntensity())) {
            blStartVal = dataset.getYValue(seriesIndex, startIdx);
            blStopVal = dataset.getYValue(seriesIndex, stopIdx);
        } else {
            blStartVal = dataset.getYValue(seriesIndex, startIdx);
            blStopVal = dataset.getYValue(seriesIndex, stopIdx);
        }
    }
    peakStartValue = dataset.getYValue(seriesIndex, startIdx);
    peakStopValue = dataset.getYValue(seriesIndex, stopIdx);
    double peakApexValue = dataset.getYValue(seriesIndex, scan);

    GeneralPath gp = new GeneralPath();
    gp.moveTo(blStartTime, dataset.getYValue(seriesIndex, startIdx) + blStartVal);
    gp.lineTo(peakStartTime, peakStartValue);
    for (int j = startIdx + 1; j <= stopIdx; j++) {
        gp.lineTo(dataset.getXValue(seriesIndex, j), dataset.getYValue(seriesIndex, j));
    }
    gp.lineTo(blStopTime, dataset.getYValue(seriesIndex, stopIdx) + blStopVal);
    gp.closePath();
    Logger.getLogger(getClass().getName()).log(Level.WARNING,
            "Generating peak outline: ({0};{1})({2};{3}" + ")" + "({4};{5})",
            new Object[] { peakStartTime, peakStartValue, sat, peakApexValue, peakStopTime, peakStopValue });
    VisualPeakAnnotation vpa = new VisualPeakAnnotation(gp,
            new Point2D.Double(sat, Math.min(peakStartValue, Math.min(peakApexValue, peakStopValue))),
            PeakAnnotationType.OUTLINE);//generate(peakStartTime, peakStartValue, sat, peakApexValue, peakStopTime, peakStopValue);
    return vpa;
}

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

/**
 * Returns the shape for the window for this dial.  Some dial layers will
 * request that their drawing be clipped within this window.
 *
 * @param frame  the reference frame (<code>null</code> not permitted).
 *
 * @return The shape of the dial's window.
 *//*  www .  j a v  a2  s. c  o m*/
public Shape getWindow(Rectangle2D frame) {

    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius, this.innerRadius);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius, this.outerRadius);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle, this.extent, Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + this.extent, -this.extent, Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;

}