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

/**
 * Draws a sequence of connected lines defined by arrays of <i>x</i> and <i>y</i>
 * coordinates. Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines
 * a point. The figure is not closed if the first point differs from the last
 * point.//from w  w  w .j av a 2s. co  m
 * 
 * @param xPoints
 *          an array of <i>x</i> points
 * @param yPoints
 *          an array of <i>y</i> points
 * @param nPoints
 *          the total number of points
 * @see java.awt.Graphics#drawPolygon(int[], int[], int)
 * @since JDK1.1
 */
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
    if (nPoints > 0) {
        GeneralPath path = new GeneralPath();
        path.moveTo(xPoints[0], yPoints[0]);
        for (int i = 1; i < nPoints; i++)
            path.lineTo(xPoints[i], yPoints[i]);

        draw(path);
    }
}

From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java

/**
 *
 * @param f//  w w w .  jav  a 2 s. c o  m
 * @param useScanAcquisitionTime
 * @param outline
 * @param fill
 * @param valueVar
 * @return
 */
public static List<XYAnnotation> generatePeakShapes(IFileFragment f, boolean useScanAcquisitionTime,
        Color outline, Color fill, String valueVar) {
    List<XYAnnotation> l = new ArrayList<>();
    try {
        IVariableFragment peakNames = f.getChild("peak_name");
        IVariableFragment peakRT = f.getChild("peak_retention_time");
        IVariableFragment peakStartRT = f.getChild("peak_start_time");
        IVariableFragment peakStopRT = f.getChild("peak_end_time");

        int peaks = peakRT.getArray().getShape()[0];

        boolean baselineAvailable = true;

        IVariableFragment blStartRT = null;
        IVariableFragment blStopRT = null;
        IVariableFragment blStartValue = null;
        IVariableFragment blStopValue = null;

        try {
            blStartRT = f.getChild("baseline_start_time");
            blStopRT = f.getChild("baseline_stop_time");
            blStartValue = f.getChild("baseline_start_value");
            blStopValue = f.getChild("baseline_stop_value");
        } catch (ResourceNotAvailableException e) {
            baselineAvailable = false;
        }

        boolean andichromMode = valueVar.equals("ordinate_values");

        Array ordinateValues = null;
        try {
            ordinateValues = f.getChild(valueVar).getArray();
        } catch (ResourceNotAvailableException rne) {
            ordinateValues = f.getChild("total_intensity").getArray();
            andichromMode = false;
        }

        Collection<String> peaknames = ArrayTools.getStringsFromArray(peakNames.getArray());
        IndexIterator ii = peakRT.getArray().getIndexIterator();

        Iterator<String> peaknamesIter = peaknames.iterator();

        for (int i = 0; i < peaks; i++) {
            double sat = ii.getDoubleNext();
            double peakStartTime = peakStartRT.getArray().getDouble(i);
            double peakStopTime = peakStopRT.getArray().getDouble(i);
            int scan = 0;
            int startIdx, stopIdx;
            if (andichromMode) {
                double delay = f.getChild("actual_delay_time").getArray().getDouble(0);
                double samplingRate = f.getChild("actual_sampling_interval").getArray().getDouble(0);
                scan = (int) (Math.floor(((sat - delay) / samplingRate)));
                startIdx = (int) (Math.floor(((peakStartTime - delay) / samplingRate)));
                stopIdx = (int) (Math.floor(((peakStopTime - delay) / samplingRate)));
            } else {
                Array satA = f.getChild("scan_acquisition_time").getArray();
                double[] d = (double[]) satA.get1DJavaArray(double.class);
                scan = Arrays.binarySearch(d, sat);
                if (scan < 0) {
                    scan = ((-1) * (scan + 1));
                }
                startIdx = Arrays.binarySearch(d, peakStartTime);
                stopIdx = Arrays.binarySearch(d, peakStopTime);
                if (startIdx < 0) {
                    startIdx = ((-1) * (startIdx + 1));
                }
                if (stopIdx < 0) {
                    stopIdx = ((-1) * (stopIdx + 1));
                }
            }
            String name = peaknamesIter.next();
            double blStartTime, blStopTime, blStartVal, blStopVal;
            if (baselineAvailable) {
                blStartTime = blStartRT.getArray().getDouble(i);
                blStopTime = blStopRT.getArray().getDouble(i);
                blStartVal = blStartValue.getArray().getDouble(i);
                blStopVal = blStopValue.getArray().getDouble(i);
            } else {
                blStartTime = peakStartTime;
                blStopTime = peakStopTime;
                blStartVal = ordinateValues.getDouble(startIdx);
                blStopVal = ordinateValues.getDouble(stopIdx);
            }

            if (name.trim().isEmpty()) {
                name = "NN";
            }

            GeneralPath gp = new GeneralPath();
            if (useScanAcquisitionTime) {
                Array sat2 = f.getChild("scan_acquisition_time").getArray();
                gp.moveTo(peakStartTime, ordinateValues.getDouble(startIdx));
                for (int j = startIdx + 1; j <= stopIdx + 1; j++) {
                    gp.lineTo(sat2.getDouble(j), ordinateValues.getDouble(j));
                }
                gp.lineTo(Math.max(blStopTime, peakStopTime), blStopVal);
                gp.lineTo(Math.min(blStartTime, peakStartTime), blStartVal);
                gp.closePath();
                //gp.closePath();
                Rectangle2D.Double bbox = new Rectangle2D.Double(peakStartTime, 0, peakStopTime - peakStartTime,
                        ordinateValues.getDouble(scan));
                Area a = new Area(bbox);
                a.intersect(new Area(gp));
                XYShapeAnnotation xypa = new XYShapeAnnotation(a, new BasicStroke(), outline, fill);
                XYLineAnnotation xyla = new XYLineAnnotation(blStartTime, blStartVal, blStopTime, blStopVal,
                        new BasicStroke(), Color.BLACK);
                l.add(xypa);
                l.add(xyla);
                //                    XYLineAnnotation baseline = new XYLineAnnotation();
            } else {
                gp.moveTo(startIdx, ordinateValues.getDouble(startIdx));
                for (int j = startIdx + 1; j <= stopIdx + 1; j++) {
                    gp.lineTo(j, ordinateValues.getDouble(j));
                }
                gp.closePath();
                XYShapeAnnotation xypa = new XYShapeAnnotation(gp, new BasicStroke(), outline, fill);
                l.add(xypa);
            }
        }
    } catch (ResourceNotAvailableException rnae) {
        Logger.getLogger(Chromatogram1DChartProvider.class.getName()).info(rnae.getLocalizedMessage());
    }
    return l;
}

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

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;/*  w w w .  j  a  v a2s.co  m*/
    }

    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 GradientPaint) {
        itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    double x0 = bar.getMinX();
    double x1 = x0 + getXOffset();
    double x2 = bar.getMaxX();
    double x3 = x2 + getXOffset();

    double y0 = bar.getMinY() - getYOffset();
    double y1 = bar.getMinY();
    double y2 = bar.getMaxY() - getYOffset();
    double y3 = bar.getMaxY();

    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop = null;
    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) {
            g2.setPaint(((Color) itemPaint).darker());
        } else if (itemPaint instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) itemPaint;
            g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(),
                    gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()),
                    bar3dRight));
        }
        g2.fill(bar3dRight);
    }

    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1);
    bar3dTop.lineTo((float) x1, (float) y0);
    bar3dTop.lineTo((float) x3, (float) y0);
    bar3dTop.lineTo((float) x2, (float) y1);
    bar3dTop.closePath();
    g2.fill(bar3dTop);

    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:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java

@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;// ww w. j  a  v a2s. com
    }

    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 GradientPaint) {
        itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    double x0 = bar.getMinX();
    double x1 = x0 + getXOffset();
    double x2 = bar.getMaxX();
    double x3 = x2 + getXOffset();

    double y0 = bar.getMinY() - getYOffset();
    double y1 = bar.getMinY();
    double y2 = bar.getMaxY() - getYOffset();
    double y3 = bar.getMaxY();

    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop = null;
    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) {
            g2.setPaint(((Color) itemPaint).darker());
        } else if (itemPaint instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) itemPaint;
            g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(),
                    gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()),
                    bar3dRight));
        }
        g2.fill(bar3dRight);
    }

    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1);
    bar3dTop.lineTo((float) x1, (float) y0);
    bar3dTop.lineTo((float) x3, (float) y0);
    bar3dTop.lineTo((float) x2, (float) y1);
    bar3dTop.closePath();
    g2.fill(bar3dTop);

    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:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java

private static void drawArrowToDestination(final Graphics2D gfx, final Rectangle2D start,
        final Rectangle2D destination, final Stroke lineStroke, final Stroke arrowStroke,
        final float arrowSize) {

    final double startx = start.getCenterX();
    final double starty = start.getCenterY();

    final Point2D arrowPoint = Utils.findRectEdgeIntersection(destination, startx, starty);

    if (arrowPoint != null) {
        gfx.setStroke(arrowStroke);//from  www  . ja  v  a 2  s. co m

        double angle = findLineAngle(arrowPoint.getX(), arrowPoint.getY(), startx, starty);

        final double arrowAngle = Math.PI / 12.0d;

        final double x1 = arrowSize * Math.cos(angle - arrowAngle);
        final double y1 = arrowSize * Math.sin(angle - arrowAngle);
        final double x2 = arrowSize * Math.cos(angle + arrowAngle);
        final double y2 = arrowSize * Math.sin(angle + arrowAngle);

        final double cx = (arrowSize / 2.0f) * Math.cos(angle);
        final double cy = (arrowSize / 2.0f) * Math.sin(angle);

        final GeneralPath polygon = new GeneralPath();
        polygon.moveTo(arrowPoint.getX(), arrowPoint.getY());
        polygon.lineTo(arrowPoint.getX() + x1, arrowPoint.getY() + y1);
        polygon.lineTo(arrowPoint.getX() + x2, arrowPoint.getY() + y2);
        polygon.closePath();
        gfx.fill(polygon);

        gfx.setStroke(lineStroke);
        gfx.drawLine((int) startx, (int) starty, (int) (arrowPoint.getX() + cx),
                (int) (arrowPoint.getY() + cy));
    }
}

From source file:nl.b3p.kaartenbalie.core.server.b3pLayering.ConfigLayer.java

protected void drawTitledMessageBox(Graphics2D g2d, String title, String message, int x, int y, int w, int h) {
    /* Do some calculations and init variables. */
    g2d.setFont(KBConfiguration.OHD_messageBoxFont);
    FontMetrics fm = g2d.getFontMetrics();
    int labelHeight = KBConfiguration.OHD_messageBoxFont.getSize() + (KBConfiguration.OHD_padding * 2);
    int angling = labelHeight;
    Rectangle2D testRectangle = fm.getStringBounds(title, g2d);
    int labelWidth = (int) testRectangle.getWidth();

    if (w < labelWidth + (2 * angling)) {
        w = labelWidth + (2 * angling);/*from   ww w  .j  a v  a2s  .co m*/
    }
    y += labelHeight;
    /* Now draw the box...    */
    drawMessageBox(g2d, message, x, y, w, h);

    /* Draw the label background */
    g2d.setColor(KBConfiguration.OHD_labelBoxColor);
    GeneralPath label = new GeneralPath();
    label.moveTo(x, y);
    label.lineTo(x + angling, y - labelHeight);
    label.lineTo(x + angling + labelWidth, y - labelHeight);
    label.lineTo(x + (angling * 2) + labelWidth, y);
    label.closePath();
    g2d.fill(label);

    /* Draw the label Lines..  */
    g2d.setColor(KBConfiguration.OHD_borderBoxTopLeft);
    g2d.drawLine(x, y, x + angling, y - labelHeight);
    g2d.drawLine(x + angling, y - labelHeight, x + angling + labelWidth, y - labelHeight);
    g2d.setColor(KBConfiguration.OHD_borderBoxBottomRight);
    g2d.drawLine(x + angling + labelWidth, y - labelHeight, x + (angling * 2) + labelWidth, y);
    g2d.setColor(KBConfiguration.OHD_borderBoxBackground);
    g2d.drawLine(x + (angling * 2) + labelWidth, y, x, y);
    /*Then add the title... */
    g2d.setColor(KBConfiguration.OHD_labelFontBoxColor);
    g2d.drawString(title, x + angling, y - KBConfiguration.OHD_padding);

}

From source file:org.amanzi.awe.render.network.NetworkRenderer.java

/**
 * render sector element on map//from   w  ww  . ja va2  s .c om
 * 
 * @param destination
 * @param point
 * @param element
 */
private void renderSector(final Graphics2D destination, final Point point, final double azimuth,
        final double beamwidth, final IDataElement sector) {
    int size = getSize();
    int x = getSectorXCoordinate(point, size);
    int y = getSectorYCoordinate(point, size);
    destination.setColor(networkRendererStyle.changeColor(getColor(sector), networkRendererStyle.getAlpha()));
    GeneralPath path = new GeneralPath();
    path.moveTo(x, y);
    Arc2D a = createSector(point, networkRendererStyle.getLargeElementSize(), getAngle(azimuth, beamwidth),
            beamwidth);
    path.append(a.getPathIterator(null), true);
    path.closePath();
    destination.draw(path);
    destination.fill(path);
    // create border
    destination.setColor(networkRendererStyle.getBorderColor());
    destination.draw(path);
}

From source file:org.amanzi.awe.render.network.NetworkRenderer.java

/**
 * Draw black border around selected sector
 * //from  w ww .  j a v a2  s .co  m
 * @param destination
 * @param point
 * @param model
 * @param sector
 */
private void renderSelectionBorder(Graphics2D destination, Point point, ISectorElement sector, int index,
        int count) {
    Pair<Double, Double> sectorParameters = getSectorParameters(sector, index, count);
    int size = getSize();
    double azimuth = sectorParameters.getLeft();
    double beamwidth = sectorParameters.getRight();

    GeneralPath path = new GeneralPath();
    path.moveTo(getSectorXCoordinate(point, size), getSectorYCoordinate(point, size));
    Arc2D a = createSector(point, networkRendererStyle.getLargeElementSize(), getAngle(azimuth, beamwidth),
            beamwidth);
    path.append(a.getPathIterator(null), true);
    path.closePath();
    destination
            .setColor(networkRendererStyle.changeColor(SELECTED_SECTOR_COLOR, networkRendererStyle.getAlpha()));
    destination.draw(path);
    destination.drawString(sector.getName(), (int) a.getEndPoint().getX() + 10, (int) a.getEndPoint().getY());
}

From source file:org.apache.fontbox.cff.CharStringRenderer.java

/**
 * Renders the given sequence and returns the result as a GeneralPath.
 * @param sequence the given charstring sequence
 * @return the rendered GeneralPath//w w w  .j  ava 2s. c o  m
 */
public GeneralPath render(List<Object> sequence) {
    path = new GeneralPath();
    sidebearingPoint = new Point2D.Float(0, 0);
    referencePoint = null;
    setWidth(0);
    handleSequence(sequence);
    return path;
}

From source file:org.apache.fontbox.cff.Type1CharString.java

/**
 * Renders the Type 1 char string sequence to a GeneralPath.
 *///w  ww  .j a  v a 2  s.  c o m
private void render() {
    path = new GeneralPath();
    leftSideBearing = new Point2D.Float(0, 0);
    width = 0;
    CharStringHandler handler = new CharStringHandler() {
        @Override
        public List<Number> handleCommand(List<Number> numbers, CharStringCommand command) {
            return Type1CharString.this.handleCommand(numbers, command);
        }
    };
    handler.handleSequence(type1Sequence);
}