Example usage for java.awt Polygon Polygon

List of usage examples for java.awt Polygon Polygon

Introduction

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

Prototype

public Polygon() 

Source Link

Document

Creates an empty polygon.

Usage

From source file:MessagePopup.java

private void initPolygon() {
    poly = new Polygon();
    int halfWidth = width / 2;
    int halfHeight = height / 2;
    poly.addPoint(0, halfHeight);// www  .  j a v a  2 s  . c o m
    poly.addPoint(halfWidth, 0);
    poly.addPoint(width, halfHeight);
    poly.addPoint(halfWidth, height);
}

From source file:de.biomedical_imaging.ij.nanotrackj.Track.java

/**
 * @return Track as Polygon/*from  w w w .ja  v a  2 s .  com*/
 */
public Polygon getTrackAsPolygon() {
    trackAsPolygon = new Polygon();
    for (int i = 0; i < this.size(); i++) {
        trackAsPolygon.addPoint((int) this.get(i).getX(), (int) this.get(i).getY());
    }
    return trackAsPolygon;
}

From source file:de.biomedical_imaging.ij.nanotrackj.Track.java

/**
 * @return Track as Polygon up to a slice number
 *///from  ww  w.ja v  a 2s .  c  o  m
public Polygon getTrackAsPolygon(int slicenumber) {
    trackAsPolygon = new Polygon();
    int i = 0;
    while (this.get(i).getFrameIndex() < slicenumber) {
        trackAsPolygon.addPoint((int) this.get(i).getX(), (int) this.get(i).getY());
        i++;
    }
    return trackAsPolygon;
}

From source file:oct.analysis.application.OCTSelection.java

protected void drawSelectButton(Graphics g, int imageOffsetX, int imageOffsetY) {
    Polygon buttonOutline = getSelectionButtonShape();
    buttonOutline.translate(imageOffsetX, imageOffsetY);
    g.setColor(Color.lightGray);//from   ww w  . j ava2s .com
    g.drawPolygon(buttonOutline);
    g.fillPolygon(buttonOutline);
    Polygon button = new Polygon();
    button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY);
    button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY + 15);
    button.addPoint(imageOffsetX + xPositionOnOct, imageOffsetY + 20);
    button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY + 15);
    button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY);
    g.setColor(Color.DARK_GRAY);
    g.drawPolygon(button);
}

From source file:hudson.util.StackedAreaRenderer2.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) {

    // plot non-null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;//from  w w  w  .ja v  a 2 s.  com
    }

    double value = dataValue.doubleValue();

    // leave the y values (y1, y0) untranslated as it is going to be be
    // stacked up later by previous series values, after this it will be
    // translated.
    double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    double previousHeightx1 = getPreviousHeight(dataset, row, column);
    double y1 = value + previousHeightx1;
    RectangleEdge location = plot.getRangeAxisEdge();
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location);

    g2.setPaint(getItemPaint(row, column));
    g2.setStroke(getItemStroke(row, column));

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();

    // in column zero, the only job to do is draw any visible item labels
    // and this is done in the second pass...
    if (column == 0) {
        if (pass == 1) {
            // draw item labels, if visible
            if (isItemLabelVisible(row, column)) {
                drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
            }
        }
    } else {
        Number previousValue = dataset.getValue(row, column - 1);
        if (previousValue != null) {

            double xx0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                    plot.getDomainAxisEdge());
            double y0 = previousValue.doubleValue();

            // Get the previous height, but this will be different for both
            // y0 and y1 as the previous series values could differ.
            double previousHeightx0 = getPreviousHeight(dataset, row, column - 1);

            // Now stack the current y values on top of the previous values.
            y0 += previousHeightx0;

            // Now translate the previous heights
            double previousHeightxx0 = rangeAxis.valueToJava2D(previousHeightx0, dataArea, location);
            double previousHeightxx1 = rangeAxis.valueToJava2D(previousHeightx1, dataArea, location);

            // Now translate the current y values.
            double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location);

            if (pass == 0) {
                // left half
                Polygon p = new Polygon();
                p.addPoint((int) xx0, (int) yy0);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
                p.addPoint((int) xx0, (int) previousHeightxx0);

                g2.setPaint(getItemPaint(row, column - 1));
                g2.setStroke(getItemStroke(row, column - 1));
                g2.fill(p);

                if (entities != null)
                    addItemEntity(entities, dataset, row, column - 1, p);

                // right half
                p = new Polygon();
                p.addPoint((int) xx1, (int) yy1);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
                p.addPoint((int) xx1, (int) previousHeightxx1);

                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.fill(p);

                if (entities != null)
                    addItemEntity(entities, dataset, row, column, p);
            } else {
                if (isItemLabelVisible(row, column)) {
                    drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
                }
            }
        }
    }
}

From source file:oct.analysis.application.OCTSelection.java

public Polygon getSelectionButtonShape() {
    Polygon buttonOutline = new Polygon();
    buttonOutline.addPoint(xPositionOnOct - 6, -1);
    buttonOutline.addPoint(xPositionOnOct - 6, 16);
    buttonOutline.addPoint(xPositionOnOct, 22);
    buttonOutline.addPoint(xPositionOnOct + 6, 16);
    buttonOutline.addPoint(xPositionOnOct + 6, -1);
    return buttonOutline;
}

From source file:de.hdm.uls.loadtests.ui.XYLineAndAreaRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.//from   w w w  .j av  a 2 s.c o m
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color information
 *              etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    if (!getItemVisible(series, item)) {
        return;
    }
    XYAreaRendererState areaState = (XYAreaRendererState) state;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1)) {
        y1 = 0.0;
    }
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());

    // get the previous point and the next point so we can calculate a
    // "hot spot" for the area (used by the chart entity)...
    int itemCount = dataset.getItemCount(series);
    double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
    double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
    if (Double.isNaN(y0)) {
        y0 = 0.0;
    }
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());

    double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
    double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
    if (Double.isNaN(y2)) {
        y2 = 0.0;
    }
    double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge());
    double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge());

    double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
    Polygon hotspot = null;
    if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        hotspot = new Polygon();
        hotspot.addPoint((int) transZero, (int) ((transX0 + transX1) / 2.0));
        hotspot.addPoint((int) ((transY0 + transY1) / 2.0), (int) ((transX0 + transX1) / 2.0));
        hotspot.addPoint((int) transY1, (int) transX1);
        hotspot.addPoint((int) ((transY1 + transY2) / 2.0), (int) ((transX1 + transX2) / 2.0));
        hotspot.addPoint((int) transZero, (int) ((transX1 + transX2) / 2.0));
    } else { // vertical orientation
        hotspot = new Polygon();
        hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) transZero);
        hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) ((transY0 + transY1) / 2.0));
        hotspot.addPoint((int) transX1, (int) transY1);
        hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) ((transY1 + transY2) / 2.0));
        hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) transZero);
    }

    if (item == 0) { // create a new area polygon for the series
        areaState.area = new Polygon();
        // the first point is (x, 0)
        double zero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
        if (plot.getOrientation() == PlotOrientation.VERTICAL) {
            areaState.area.addPoint((int) transX1, (int) zero);
        } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            areaState.area.addPoint((int) zero, (int) transX1);
        }
    }

    // Add each point to Area (x, y)
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        areaState.area.addPoint((int) transX1, (int) transY1);
    } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        areaState.area.addPoint((int) transY1, (int) transX1);
    }

    PlotOrientation orientation = plot.getOrientation();
    Paint paint = getItemPaint(series, item);
    Stroke stroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(stroke);

    Shape shape = null;
    if (getPlotShapes()) {
        shape = getItemShape(series, item);
        if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        }
        g2.draw(shape);
    }

    if (getPlotLines()) {
        if (item > 0) {
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                areaState.line.setLine(transX0, transY0, transX1, transY1);
            } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
                areaState.line.setLine(transY0, transX0, transY1, transX1);
            }
            g2.draw(areaState.line);
        }
    }

    // Check if the item is the last item for the series.
    // and number of items > 0.  We can't draw an area for a single point.
    if (getPlotArea() && item > 0 && item == (itemCount - 1)) {

        if (orientation == PlotOrientation.VERTICAL) {
            // Add the last point (x,0)
            areaState.area.addPoint((int) transX1, (int) transZero);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            // Add the last point (x,0)
            areaState.area.addPoint((int) transZero, (int) transX1);
        }

        Paint fillPaint = getItemFillPaint(series, item);
        if (fillPaint instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) fillPaint;
            GradientPaintTransformer t = new StandardGradientPaintTransformer();
            fillPaint = t.transform(gp, areaState.area.getBounds());
        }
        g2.setPaint(fillPaint);
        g2.fill(areaState.area);

        // draw an outline around the Area.
        if (isOutline()) {
            g2.setStroke(getItemOutlineStroke(series, item));
            g2.setPaint(getItemOutlinePaint(series, item));
            g2.draw(areaState.area);
        }
    }

    updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation);

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null && hotspot != null) {
            String tip = null;
            XYToolTipGenerator generator = getToolTipGenerator(series, item);
            if (generator != null) {
                tip = generator.generateToolTip(dataset, series, item);
            }
            String url = null;
            if (getURLGenerator() != null) {
                url = getURLGenerator().generateURL(dataset, series, item);
            }
            XYItemEntity entity = new XYItemEntity(hotspot, dataset, series, item, tip, url);
            entities.add(entity);
        }
    }

}

From source file:net.sourceforge.processdash.ev.ui.chart.RangeXYItemRenderer.java

private void drawItemRangeGradient(Graphics2D g2, Line2D line, Paint paint, Stroke stroke, double x2, double y2,
        double x3, double y3) {
    Line2D edge1, edge2, mainLine;
    Polygon fillArea;/*from w  w  w . j a  v  a2s .  c  o  m*/
    Stroke mainLineStroke, edgeLineStroke;
    Paint mainLinePaint, edgeLinePaint, fillPaint;

    double x0 = line.getX1();
    double y0 = line.getY1();
    double x1 = line.getX2();
    double y1 = line.getY2();

    mainLine = new Line2D.Double(x0, y0, x1, y1);
    edge1 = new Line2D.Double(x0, y0, x2, y2);
    edge2 = new Line2D.Double(x0, y0, x3, y3);
    fillArea = new Polygon();
    fillArea.addPoint((int) Math.round(x0), (int) Math.round(y0));
    fillArea.addPoint((int) Math.round(x2), (int) Math.round(y2));
    fillArea.addPoint((int) Math.round(x3), (int) Math.round(y3));

    mainLinePaint = paint;
    if (mainLinePaint instanceof Color) {
        Color c = (Color) mainLinePaint;
        Color dark = transp(c, calcAlpha(c));
        Color light = transp(c, 0.01);
        edgeLinePaint = fillPaint = c;
        try {
            fillPaint = new GradientPaint(gradientStart(x0, y0, x1, y1, x2, y2, x3, y3), light,
                    new Point2D.Double(x1, y1), dark, true);
        } catch (Exception e) {
        }
    } else {
        edgeLinePaint = fillPaint = mainLinePaint;
    }

    if (stroke instanceof BasicStroke) {
        float lineWidth = ((BasicStroke) stroke).getLineWidth();
        edgeLineStroke = new BasicStroke(lineWidth / 4);
        mainLineStroke = new BasicStroke(lineWidth * 2);
    } else {
        mainLineStroke = edgeLineStroke = stroke;
    }

    g2.setPaint(fillPaint);
    g2.fill(fillArea);
    g2.fill(fillArea);

    g2.setStroke(edgeLineStroke);
    g2.setPaint(edgeLinePaint);
    g2.draw(edge1);
    g2.draw(edge2);

    g2.setStroke(mainLineStroke);
    g2.setPaint(mainLinePaint);
    g2.draw(mainLine);
}

From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java

private void initializeRendererState(LineFillItemRendererState rendererState) {
    rendererState.setLines(new ArrayList<Line2D>());
    rendererState.setAreaPolygon(new Polygon());
}

From source file:at.tuwien.ifs.somtoolbox.visualization.thematicmap.SOMRegion.java

public void fillRegion(Graphics2D g, boolean chessboard) {
    if (!resolved) {
        fillcolor = getColor(mainClass.classIndex);
        Color c = repairColor(fillcolor);
        g.setColor(c);/*from w w w .ja v a2  s  .  c  o  m*/
        if (segments.isEmpty()) {
            return;
        }
        g.fillPolygon(this);
    } else {
        if (chessboard) {
            if (polygons == null) { // calculate polygons
                polygons = new ArrayList<Polygon>();

                Rectangle2D rect = getBounds2D();
                double w = rect.getWidth();

                double h = rect.getHeight();

                if (h > 200 || w > 200) {
                    Logger.getLogger("at.tuwien.ifs.somtoolbox").info("ERROR: h>200 || w>200");
                    return;
                }

                int x = (int) rect.getX();
                int y = (int) rect.getY();

                int xSteps = (int) (w / (int) Grid.SIZE);
                int ySteps = (int) (h / (int) Grid.SIZE);
                // int n = classes.size();
                for (int i = 0; i < xSteps; i++) {
                    for (int j = 0; j < ySteps; j++) {
                        Polygon p = new Polygon();
                        p.addPoint((int) (x + i * Grid.SIZE), (int) (y + j * Grid.SIZE));
                        p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE), (int) (y + j * Grid.SIZE));
                        p.addPoint((int) (x + i * Grid.SIZE + Grid.SIZE),
                                (int) (y + Grid.SIZE + j * Grid.SIZE));
                        p.addPoint((int) (x + i * Grid.SIZE), (int) (y + Grid.SIZE + j * Grid.SIZE));
                        if (!this.contains(p.getBounds())) {
                            continue;
                        }
                        SOMClass clss = indexGenerator.getNextIndex();
                        g.setColor(getColor(clss.classIndex));
                        g.fillPolygon(p);
                        polygons.add(p);
                    }
                }
            } else { // use pre-calculated polygons
                for (int i = 0; i < polygons.size(); i++) {
                    SOMClass clss = indexGenerator.getNextIndex();
                    g.setColor(getColor(clss.classIndex));
                    Polygon p = polygons.get(i);
                    g.fillPolygon(p);
                }
            }
        } else {
            for (int i = 0; i < grids.size(); i++) {
                Grid grid = grids.get(i);
                if (grid.clss == null) {
                    continue;
                }
                g.setColor(getColor(grid.clss.classIndex));
                g.fillRect((int) grid.topLeft.coord(0), (int) grid.topLeft.coord(1), (int) Grid.SIZE,
                        (int) Grid.SIZE);
            }
        }
    }
}