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(int[] xpoints, int[] ypoints, int npoints) 

Source Link

Document

Constructs and initializes a Polygon from the specified parameters.

Usage

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

private void updateBottomLineMarker() {
    int leftEdge = getSelectionLeftEdgeCoordinate();
    int rightEdge = getSelectionRightEdgeCoordinate();
    bottomLine = new Polygon(new int[] { leftEdge, leftEdge, rightEdge, rightEdge },
            new int[] { this.yPositionOnOct + this.height - 2, this.yPositionOnOct + this.height + 2,
                    this.yPositionOnOct + this.height + 2, this.yPositionOnOct + this.height - 2 },
            4);/*ww w .j  a  v  a 2s.  c  om*/
}

From source file:net.sf.jasperreports.customizers.shape.AbstractShapeCustomizer.java

/**
 * Builds a polygon shape.//from w  w w.  j a  va2s.c o  m
 * 
 * @param shapePoints the points of the polygon
 * @return the polygon or null if it can't be build from the current configuration
 */
protected Shape buildPolygon(ShapePoints shapePoints) {
    Polygon polygon = null;
    List<Point> points = shapePoints.getPoints();
    if (points != null && !points.isEmpty()) {
        float scaleFactorX = 1.0f;
        float scaleFactorY = 1.0f;

        Rectangle2D bounds = getBounds(shapePoints);
        Integer width = getWidth();
        Integer height = getHeight();
        if (width != null) {
            scaleFactorX = (float) width / (float) bounds.getWidth();
        }
        if (height != null) {
            scaleFactorY = (float) height / (float) bounds.getHeight();
        }

        Point offset = getOffset(bounds);

        int[] pointsX = new int[points.size()];
        int[] pointsY = new int[points.size()];

        for (int i = 0; i < points.size(); i++) {
            Point point = points.get(i);
            pointsX[i] = Math.round((point.getX() - offset.getX()) * scaleFactorX);
            pointsY[i] = Math.round((point.getY() - offset.getY()) * scaleFactorY);
        }

        polygon = new Polygon(pointsX, pointsY, points.size());
    }
    return polygon;
}

From source file:fr.fg.server.core.TerritoryManager.java

private static BufferedImage createTerritoryMap(int idSector) {
    List<Area> areas = new ArrayList<Area>(DataAccess.getAreasBySector(idSector));

    float[][] points = new float[areas.size()][2];
    int[] dominatingAllies = new int[areas.size()];
    int i = 0;/*from  ww  w.  j  ava 2  s.  com*/
    for (Area area : areas) {
        points[i][0] = area.getX() * MAP_SCALE;
        points[i][1] = area.getY() * MAP_SCALE;
        dominatingAllies[i] = area.getIdDominatingAlly();
        i++;
    }

    Hull hull = new Hull(points);
    MPolygon hullPolygon = hull.getRegion();
    float[][] newPoints = new float[points.length + hullPolygon.count()][2];
    System.arraycopy(points, 0, newPoints, 0, points.length);

    float[][] hullCoords = hullPolygon.getCoords();

    for (i = 0; i < hullPolygon.count(); i++) {
        double angle = Math.atan2(hullCoords[i][1], hullCoords[i][0]);
        double length = Math.sqrt(hullCoords[i][0] * hullCoords[i][0] + hullCoords[i][1] * hullCoords[i][1]);

        newPoints[i + points.length][0] = (float) (Math.cos(angle) * (length + 8 * MAP_SCALE));
        newPoints[i + points.length][1] = (float) (Math.sin(angle) * (length + 8 * MAP_SCALE));
    }

    points = newPoints;

    Voronoi voronoi = new Voronoi(points);
    Delaunay delaunay = new Delaunay(points);

    // Dcoupage en rgions
    MPolygon[] regions = voronoi.getRegions();

    // Calcule le rayon de la galaxie
    int radius = 0;

    for (Area area : areas) {
        radius = Math.max(radius, area.getX() * area.getX() + area.getY() * area.getY());
    }

    radius = (int) Math.floor(Math.sqrt(radius) * MAP_SCALE) + 10 * MAP_SCALE;
    int diameter = 2 * radius + 1;

    // Construit l'image avec les quadrants
    BufferedImage territoriesImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = (Graphics2D) territoriesImage.getGraphics();

    // Affecte une couleur  chaque alliance
    HashMap<Integer, Color> alliesColors = new HashMap<Integer, Color>();

    for (Area area : areas) {
        int idDominatingAlly = area.getIdDominatingAlly();
        if (idDominatingAlly != 0)
            alliesColors.put(idDominatingAlly,
                    Ally.TERRITORY_COLORS[DataAccess.getAllyById(idDominatingAlly).getColor()]);
    }

    Polygon[] polygons = new Polygon[regions.length];
    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] != 0) {
            polygons[i] = createPolygon(regions[i].getCoords(), radius + 1, 3);
        }
    }

    // Dessine tous les secteurs
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0)
            continue;

        Polygon p = polygons[i];

        // Dessine le polygone
        g.setColor(alliesColors.get(dominatingAllies[i]));
        g.fill(p);

        // Rempli les espaces entre les polygones adjacents qui
        // correspondent au territoire d'une mme alliance
        int[] linkedRegions = delaunay.getLinked(i);
        for (int j = 0; j < linkedRegions.length; j++) {
            int linkedRegion = linkedRegions[j];

            if (linkedRegion >= areas.size())
                continue;

            if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                if (linkedRegion <= i)
                    continue;

                float[][] coords1 = regions[i].getCoords();
                float[][] coords2 = regions[linkedRegion].getCoords();

                int junctionIndex = 0;
                int[][] junctions = new int[2][2];

                search: for (int k = 0; k < coords1.length; k++) {
                    for (int l = 0; l < coords2.length; l++) {
                        if (coords1[k][0] == coords2[l][0] && coords1[k][1] == coords2[l][1]) {
                            junctions[junctionIndex][0] = k;
                            junctions[junctionIndex][1] = l;

                            junctionIndex++;

                            if (junctionIndex == 2) {
                                int[] xpts = new int[] { polygons[i].xpoints[junctions[0][0]],
                                        polygons[linkedRegion].xpoints[junctions[0][1]],
                                        polygons[linkedRegion].xpoints[junctions[1][1]],
                                        polygons[i].xpoints[junctions[1][0]], };
                                int[] ypts = new int[] { polygons[i].ypoints[junctions[0][0]],
                                        polygons[linkedRegion].ypoints[junctions[0][1]],
                                        polygons[linkedRegion].ypoints[junctions[1][1]],
                                        polygons[i].ypoints[junctions[1][0]], };

                                Polygon border = new Polygon(xpts, ypts, 4);
                                g.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
                                g.fill(border);
                                g.draw(border);
                                break search;
                            }
                            break;
                        }
                    }
                }
            }
        }
    }

    // Dessine des lignes de contours des territoires
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0)
            continue;

        g.setStroke(new BasicStroke(1.5f));
        g.setColor(alliesColors.get(dominatingAllies[i]).brighter().brighter());

        float[][] coords1 = regions[i].getCoords();

        lines: for (int j = 0; j < coords1.length; j++) {
            int[] linkedRegions = delaunay.getLinked(i);
            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size())
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                    float[][] coords2 = regions[linkedRegion].getCoords();

                    for (int m = 0; m < coords2.length; m++) {
                        if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1]
                                && ((coords1[(j + 1) % coords1.length][0] == coords2[(m + 1)
                                        % coords2.length][0]
                                        && coords1[(j + 1) % coords1.length][1] == coords2[(m + 1)
                                                % coords2.length][1])
                                        || (coords1[(j + 1)
                                                % coords1.length][0] == coords2[(m - 1 + coords2.length)
                                                        % coords2.length][0]
                                                && coords1[(j + 1)
                                                        % coords1.length][1] == coords2[(m - 1 + coords2.length)
                                                                % coords2.length][1]))) {
                            continue lines;
                        }
                    }
                }
            }

            g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]),
                    Math.round(polygons[i].xpoints[(j + 1) % coords1.length]),
                    Math.round(polygons[i].ypoints[(j + 1) % coords1.length]));
        }

        for (int j = 0; j < coords1.length; j++) {
            int neighbours = 0;
            int lastNeighbourRegion = -1;
            int neighbourCoordsIndex = -1;

            int[] linkedRegions = delaunay.getLinked(i);
            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size())
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                    float[][] coords2 = regions[linkedRegion].getCoords();

                    for (int m = 0; m < coords2.length; m++) {
                        if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1]) {
                            neighbours++;
                            lastNeighbourRegion = linkedRegion;
                            neighbourCoordsIndex = m;
                            break;
                        }
                    }
                }
            }

            if (neighbours == 1) {
                g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]),
                        Math.round(polygons[lastNeighbourRegion].xpoints[neighbourCoordsIndex]),
                        Math.round(polygons[lastNeighbourRegion].ypoints[neighbourCoordsIndex]));
            }
        }
    }

    BufferedImage finalImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);

    g = (Graphics2D) finalImage.getGraphics();

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .15f));
    g.drawImage(territoriesImage, 0, 0, null);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .5f));

    // Charge la police pour afficher le nom des alliances
    try {
        Font textFont = Font.createFont(Font.TRUETYPE_FONT,
                Action.class.getClassLoader().getResourceAsStream("fr/fg/server/resources/TinDog.ttf"));
        textFont = textFont.deriveFont(12f).deriveFont(Font.BOLD);
        g.setFont(textFont);
    } catch (Exception e) {
        LoggingSystem.getServerLogger().warn("Could not load quadrant map font.", e);
    }
    FontMetrics fm = g.getFontMetrics();

    ArrayList<Integer> closedRegions = new ArrayList<Integer>();

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0 || closedRegions.contains(i))
            continue;

        ArrayList<Integer> allyRegions = new ArrayList<Integer>();
        ArrayList<Integer> openRegions = new ArrayList<Integer>();

        openRegions.add(i);

        while (openRegions.size() > 0) {
            int currentRegion = openRegions.remove(0);
            allyRegions.add(currentRegion);
            closedRegions.add(currentRegion);

            int[] linkedRegions = delaunay.getLinked(currentRegion);

            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size() || openRegions.contains(linkedRegion)
                        || allyRegions.contains(linkedRegion))
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion])
                    openRegions.add(linkedRegion);
            }
        }

        Area area = areas.get(i);
        long xsum = 0;
        long ysum = 0;

        for (int k = 0; k < allyRegions.size(); k++) {
            int allyRegion = allyRegions.get(k);
            area = areas.get(allyRegion);

            xsum += area.getX();
            ysum += area.getY();
        }

        int x = (int) (xsum / allyRegions.size()) * MAP_SCALE + radius + 1;
        int y = (int) (-ysum / allyRegions.size()) * MAP_SCALE + radius + 1;
        ;

        Point point = new Point(x, y);
        boolean validLocation = false;
        for (int k = 0; k < allyRegions.size(); k++) {
            int allyRegion = allyRegions.get(k);

            if (polygons[allyRegion].contains(point)) {
                validLocation = true;
                break;
            }
        }

        if (validLocation) {
            if (allyRegions.size() == 1)
                y -= 14;
        } else {
            int xmid = (int) (xsum / allyRegions.size());
            int ymid = (int) (ysum / allyRegions.size());

            area = areas.get(i);
            int dx = area.getX() - xmid;
            int dy = area.getY() - ymid;
            int distance = dx * dx + dy * dy;

            int nearestAreaIndex = i;
            int nearestDistance = distance;

            for (int k = 0; k < allyRegions.size(); k++) {
                int allyRegion = allyRegions.get(k);

                area = areas.get(allyRegion);
                dx = area.getX() - xmid;
                dy = area.getY() - ymid;
                distance = dx * dx + dy * dy;

                if (distance < nearestDistance) {
                    nearestAreaIndex = allyRegion;
                    nearestDistance = distance;
                }
            }

            area = areas.get(nearestAreaIndex);
            x = area.getX() * MAP_SCALE + radius + 1;
            y = -area.getY() * MAP_SCALE + radius - 13;
        }

        // Dessine le tag de l'alliance
        String allyTag = "[ " + DataAccess.getAllyById(dominatingAllies[i]).getTag() + " ]";
        g.setColor(Color.BLACK);
        g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2 + 1, y);
        g.setColor(alliesColors.get(dominatingAllies[i]));
        g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2, y);
    }

    return finalImage;
}

From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo5.java

protected JFreeChart createLegend(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//from   www  .  j a v a2s .com

    chart.setBackgroundPaint(Color.white);

    Shape[] shapes = new Shape[3];
    int[] xpoints;
    int[] ypoints;

    // right-pointing triangle
    xpoints = new int[] { -3, 3, -3 };
    ypoints = new int[] { -3, 0, 3 };
    shapes[0] = new Polygon(xpoints, ypoints, 3);

    // vertical rectangle
    shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);

    // left-pointing triangle
    xpoints = new int[] { -3, 3, 3 };
    ypoints = new int[] { 0, -3, 3 };
    shapes[2] = new Polygon(xpoints, ypoints, 3);

    DrawingSupplier supplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, shapes);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDrawingSupplier(supplier);

    // set the stroke for each series...
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 10.0f, 6.0f }, 0.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 6.0f, 6.0f }, 0.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 2.0f, 6.0f }, 0.0f));

    // customise the renderer...
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    return chart;

}

From source file:Polygon2D.java

public Polygon getPolygon() {
    int[] _xpoints = new int[npoints];
    int[] _ypoints = new int[npoints];
    for (int i = 0; i < npoints; i++) {
        _xpoints[i] = (int) xpoints[i]; // todo maybe rounding is better ?
        _ypoints[i] = (int) ypoints[i];
    }/*from   w ww  . jav  a  2 s .  co m*/

    return new Polygon(_xpoints, _ypoints, npoints);
}

From source file:com.aurel.track.report.gantt.data.TrackGanttRenderer.java

/**
 * Draws a single task./*  w  w w .  j  av  a 2s. com*/
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
protected void drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, TrackTaskSeriesCollection dataset, int row, int column,
        int pass) {

    log.debug("Working on item at position - column: " + column + " row: " + row);

    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();

    RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();

    // Y0
    Number value0 = dataset.getEndValue(row, column);
    if (value0 == null) {
        return;
    }
    double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);

    // Y1
    Number value1 = dataset.getStartValue(row, column);
    if (value1 == null) {
        return;
    }
    double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);

    if (java2dValue1 < java2dValue0) {
        double temp = java2dValue1;
        java2dValue1 = java2dValue0;
        java2dValue0 = temp;
        Number tempNum = value1;
        value1 = value0;
        value0 = tempNum;
    }

    double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation);

    // BREADTH
    double rectBreadth = state.getBarWidth();

    // BAR HEIGHT
    double rectLength = Math.abs(java2dValue1 - java2dValue0);

    Rectangle2D bar = null;

    if (seriesCount > 1) {
        double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1));
        rectStart = rectStart + row * (state.getBarWidth() + seriesGap);
    } else {
        rectStart = rectStart + row * state.getBarWidth();
    }

    // correct the start/stop Bars point
    if (startBars > (int) (java2dValue1 - rectLength)) {
        this.startBars = (int) (java2dValue1 - rectLength);
    }

    if (stopBars < (int) java2dValue1) {
        stopBars = (int) java2dValue1;
    }

    // The coordinates for the bar labels
    int startLabelX = 0;
    int startLabelY = 0;

    int endLabelX = 0;
    int endLabelY = 0;

    int barLabelX = 0;
    int barLabelY = 0;

    Polygon outer = null;
    Polygon inner = null;

    boolean isMilestone = dataset.isMilestone(column, row);
    boolean isSupertask = dataset.isSupertask(column, row);

    if (isMilestone) {

        // The start point for the end date label
        endLabelX = (int) (java2dValue1 + rectBreadth / 2);
        endLabelY = (int) (rectStart + (3 * rectBreadth / 4));

        barLabelX = (int) (java2dValue1 - rectBreadth / 2);
        barLabelY = (int) (rectStart + (3 * rectBreadth / 4));

        int breadth = (int) rectBreadth;

        int centerX = (int) java2dValue1;

        int centerY = (int) (rectStart + rectBreadth / 2);

        int[] xPoints = { centerX, centerX - breadth / 2, centerX, centerX + breadth / 2 };
        int[] yPoints = { centerY - breadth / 2, centerY, centerY + breadth / 2, centerY };

        outer = new Polygon(xPoints, yPoints, 4);

        //calculate the difference from the ratio
        int diff = (int) (rectBreadth / (2 * msInfo.getRatio()));

        int[] xPointsI = { centerX, centerX - breadth / 2 + diff, centerX, centerX + breadth / 2 - diff };
        int[] yPointsI = { centerY - breadth / 2 + diff, centerY, centerY + breadth / 2 - diff, centerY };

        inner = new Polygon(xPointsI, yPointsI, 4);

    }

    else if (isSupertask) {

        // The start point for the end date label
        startLabelX = (int) (java2dValue1 - rectLength - rectBreadth / 2);
        startLabelY = (int) (rectStart + rectBreadth * 3 / 4);

        endLabelX = (int) (java2dValue1 + rectBreadth / 2);
        endLabelY = (int) (rectStart + rectBreadth * 3 / 4);

        barLabelX = (int) (java2dValue1 - rectLength + rectBreadth / 3);
        barLabelY = (int) (rectStart + rectBreadth);

        int breadth = (int) rectBreadth;
        int length = (int) rectLength;

        int startX = (int) (java2dValue1 - rectLength);
        int startY = (int) rectStart;

        int[] xPoints = { startX - breadth / 2, startX + length + breadth / 2, startX + length + breadth / 2,
                startX + length, startX + length - breadth / 2, startX + breadth / 2, startX,
                startX - breadth / 2 };
        int[] yPoints = { startY, startY, startY + breadth / 2, startY + breadth, startY + breadth / 2,
                startY + breadth / 2, startY + breadth, startY + breadth / 2 };

        outer = new Polygon(xPoints, yPoints, 8);

        //calculate the difference from the ratio
        int diff = (int) (rectBreadth / (2 * stInfo.getRatio()));

        int[] xPointsI = { startX - breadth / 2 + diff, startX + length + breadth / 2 - diff,
                startX + length + breadth / 2 - diff, startX + length, startX + length - breadth / 2 + diff,
                startX + length - breadth / 2 + diff, startX + breadth / 2 - diff, startX + breadth / 2 - diff,
                startX, startX - breadth / 2 + diff };
        int[] yPointsI = { startY + diff, startY + diff, startY + breadth / 2, startY + breadth / 2 + diff,
                startY + breadth / 2, startY + breadth / 2 - diff, startY + breadth / 2 - diff,
                startY + breadth / 2, startY + breadth / 2 + diff, startY + breadth / 2 };

        inner = new Polygon(xPointsI, yPointsI, 10);
    } else {

        rectBreadth = rectBreadth / 2.0;
        // The start point for the end date label
        startLabelX = (int) (java2dValue1 - rectLength);
        startLabelY = (int) (rectStart + rectBreadth * 3 / 4);

        endLabelX = (int) java2dValue1;
        endLabelY = (int) (rectStart + rectBreadth * 3 / 4);

        barLabelX = (int) (java2dValue1 - rectLength);
        barLabelY = (int) (rectStart); //+ rectBreadth * 4 / 3 );

        bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth);
        // percent complete could be obtained in the 
        // ReportBeans, set in the ReportBean and set in the Item by the GanttGenerator
        // currently this is not relevant.
        Rectangle2D completeBar = null;
        Rectangle2D incompleteBar = null;
        Number percent = dataset.getPercentComplete(row, column);
        double start = getStartPercent();
        double end = getEndPercent();
        if (percent != null) {
            double p = percent.doubleValue();
            completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p,
                    rectBreadth * (end - start));
            incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p,
                    rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start));
        }

        /** This is for displaying e.g. (german Soll und Ist Termine). This implementation is designed to display only one Series.
         * If you need Soll und Ist, you can generate two gantt charts.
         * --->> Paint seriesPaint = getItemPaint (row, column);
         */

        Paint seriesPaint = tsInfo.getInnerColor();

        g2.setPaint(seriesPaint);
        g2.fill(bar);

        if (tsInfo.isDisplayIDLabel() && (!tsInfo.isDisplaySynopsis())) {
            // draw the tasks ID
            drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY,
                    tsInfo.getLabelFontID(), false, (int) rectLength);
        }

        else if (tsInfo.isDisplaySynopsis()) {
            if (tsInfo.isDisplayDateLabel()) {

                // format start date to the requested format using the current locale
                String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale))
                        .format(dataset.getItem(column, row).getStart());

                label = dataset.getItem(column, row).getDescription() + " - " + label;
                drawLabel(label, g2, barLabelX, barLabelY, tsInfo.getLabelFont(), true);

                // format end date to the requested format using the current locale
                label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale))
                        .format(dataset.getItem(column, row).getStop());

                // draw the supertasks end date
                drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false);

            } else {
                drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY,
                        tsInfo.getLabelFont(), true);
            }
        }

        if (tsInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) {

            // format start date to the requested format using the current locale
            String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStart());

            // draw the tasks start date
            drawLabel(label, g2, startLabelX, startLabelY, tsInfo.getLabelFont(), true);

            // format end date to the requested format using the current locale
            label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStop());
            // draw the tasks end date
            drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false);
        }

        if (completeBar != null) {
            g2.setPaint(getCompletePaint());
            g2.fill(completeBar);
        }
        if (incompleteBar != null) {
            g2.setPaint(getIncompletePaint());
            g2.fill(incompleteBar);
        }

        // draw the outline...
        if (state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {

            Stroke stroke = getItemOutlineStroke(row, column);
            Paint paint = getItemOutlinePaint(row, column);
            if (stroke != null && paint != null) {
                g2.setStroke(stroke);
                g2.setPaint(paint);

                g2.draw(bar);
            }
        }
    }

    // Draw milestone or Supertask
    if (isMilestone) {

        g2.setPaint(msInfo.getOuterColor());
        g2.fill(outer);
        g2.draw(outer);

        g2.setPaint(msInfo.getInnerColor());
        g2.fill(inner);
        g2.draw(inner);

        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(outer);
        }

        // draw the milestones due date
        if (msInfo.isDisplayDateLabel()) {

            // format milestone date to the requested format using the current locale
            String label = (new SimpleDateFormat(msInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStart());

            drawLabel(label, g2, endLabelX, endLabelY, msInfo.getLabelFont(), false);
        }

        if (msInfo.isDisplayIDLabel() && (!msInfo.isDisplaySynopsis())) {
            // for milestones the ID is aligned at the left side.
            drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY,
                    msInfo.getLabelFontID(), true, (int) rectLength);
        } else if (msInfo.isDisplaySynopsis()) {
            drawLabel(dataset.getItem(column, row).getDescription(), g2, barLabelX, barLabelY,
                    msInfo.getLabelFont(), true, (int) rectLength);
        }

    } else if (isSupertask) {

        g2.setPaint(stInfo.getOuterColor());
        g2.fill(outer);
        g2.draw(outer);

        g2.setPaint(stInfo.getInnerColor());
        g2.fill(inner);
        g2.draw(inner);

        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(outer);
        }

        // draw the supertasks ID
        if (stInfo.isDisplayIDLabel() && (!stInfo.isDisplaySynopsis())) {
            drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY,
                    stInfo.getLabelFontID(), false, (int) rectLength);
        } else if (stInfo.isDisplaySynopsis()) {
            if (stInfo.isDisplayDateLabel()) {

                // format start date to the requested format using the current locale
                String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale))
                        .format(dataset.getItem(column, row).getStart());

                label = dataset.getItem(column, row).getDescription() + " - " + label;
                drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true);

                // format end date to the requested format using the current locale
                label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale))
                        .format(dataset.getItem(column, row).getStop());

                // draw the supertasks end date
                drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false);

            } else {
                drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY,
                        stInfo.getLabelFont(), true);
            }
        }
        if (stInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) {

            // format start date to the requested format using the current locale
            String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStart());

            // draw the supertasks start date
            drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true);

            // format end date to the requested format using the current locale
            label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale))
                    .format(dataset.getItem(column, row).getStop());

            // draw the supertasks end date
            drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false);
        }
    }
}

From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.ExtendedBoxAndWhiskerRenderer.java

/**
 * Creates a triangle to indicate the presence of far-out values when the
 * plot orientation is vertical.//from   ww  w  .j a v a  2s  . com
 *
 * @param foRadius the far-out radius.
 * @param point the location.
 */
private Shape createTriangleVertical(Point2D point, double foRadius) {
    double side = foRadius * 2;
    double x = point.getX();
    double y = point.getY();

    int[] xpoints = { (int) (x), (int) (x + side), (int) (x + (side / 2.0)) };
    int[] ypoints = { (int) (y), (int) (y), (int) (y + side) };

    return new Polygon(xpoints, ypoints, 3);
}

From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java

private void drawLegendLine(Graphics2D g2, int verticalOffset, double horizontalNumberOffset, Color col,
        String txt, String numberText, boolean textIsPlural, boolean withSubSegment, String subSegmentText,
        String subNumberText, boolean subTextIsPlural) {
    int left = 620;
    // col == null --> total --> kein Rechteck
    if (col != null) {
        g2.drawImage(keyShadow.getImage(), left, 30 + verticalOffset, keyShadow.getImageObserver());
        g2.setColor(col);/*from   www  . j  a  va2 s  .  c om*/
        g2.fillRect(left + 13, 37 + verticalOffset, 45, 45);
        if (withSubSegment) {
            Polygon p = new Polygon(new int[] { left + 13 + 45, left + 13 + 45, left + 13 },
                    new int[] { verticalOffset + 37, verticalOffset + 37 + 45, verticalOffset + 37 + 45 }, 3);
            g2.setColor(col.darker());
            g2.fillPolygon(p);
        }
    }
    g2.setColor(Color.BLACK);
    StringBuffer sb = new StringBuffer(numberText);
    sb.append("  ").append(plural(textIsPlural, txt));
    if (withSubSegment) {
        sb.append(" with ");
        sb.append(subNumberText);
        sb.append(" ");
        sb.append(plural(subTextIsPlural, subSegmentText));
    }
    g2.drawString(sb.toString(), (int) (left + 80 + horizontalNumberOffset), 30 + 41 + verticalOffset);

}

From source file:com.google.gwt.benchmarks.viewer.server.ReportImageServer.java

private DrawingSupplier getDrawingSupplier() {
    Color[] colors = new Color[] { new Color(176, 29, 29, 175), // dark red
            new Color(10, 130, 86, 175), // dark green
            new Color(8, 26, 203, 175), // dark blue
            new Color(145, 162, 66, 175), // light pea green
            new Color(196, 140, 6, 175), // sienna
    };//from  ww w  .  j  a va 2s  .  c om

    float size = 8;
    float offset = size / 2;

    int iOffset = (int) offset;

    Shape square = new Rectangle2D.Double(-offset, -offset, size, size);
    Shape circle = new Ellipse2D.Double(-offset, -offset, size, size);
    Shape triangle = new Polygon(new int[] { 0, iOffset, -iOffset }, new int[] { -iOffset, iOffset, iOffset },
            3);
    Shape diamond = new Polygon(new int[] { 0, iOffset, 0, -iOffset }, new int[] { -iOffset, 0, iOffset, 0 },
            4);
    Shape ellipse = new Ellipse2D.Double(-offset, -offset / 2, size, size / 2);

    return new DefaultDrawingSupplier(colors, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            new Shape[] { circle, square, triangle, diamond, ellipse });
}

From source file:org.pentaho.di.core.gui.SwingDirectGC.java

private Polygon getSwingPolygon(int[] polygon) {
    int nPoints = polygon.length / 2;
    int[] xPoints = new int[polygon.length / 2];
    int[] yPoints = new int[polygon.length / 2];
    for (int i = 0; i < nPoints; i++) {
        xPoints[i] = polygon[2 * i + 0] + xOffset;
        yPoints[i] = polygon[2 * i + 1] + yOffset;
    }//from w  w  w  .  j  a  v a2s .  c o  m

    return new Polygon(xPoints, yPoints, nPoints);
}