Example usage for org.jfree.chart.annotations XYPolygonAnnotation XYPolygonAnnotation

List of usage examples for org.jfree.chart.annotations XYPolygonAnnotation XYPolygonAnnotation

Introduction

In this page you can find the example usage for org.jfree.chart.annotations XYPolygonAnnotation XYPolygonAnnotation.

Prototype

public XYPolygonAnnotation(double[] polygon) 

Source Link

Document

Creates a new annotation (where, by default, the polygon is drawn with a black outline).

Usage

From source file:fr.crnan.videso3d.trajectography.Track2DView.java

public Track2DView(VidesoTrack track) {
    if (track instanceof LPLNTrack) {
        XYSeries dataset = new XYSeries(track.getName());
        List<ValueMarker> markers = new LinkedList<ValueMarker>();
        double distance = 0;
        LPLNTrackPoint last = null;//w w  w  .j ava 2  s .  c o  m
        for (LPLNTrackPoint p : ((LPLNTrack) track).getTrackPoints()) {
            if (last != null) {
                distance += Position.ellipsoidalDistance(last.getPosition(), p.getPosition(),
                        Earth.WGS84_EQUATORIAL_RADIUS, Earth.WGS84_POLAR_RADIUS) / LatLonCautra.NM;
            }
            dataset.add(distance, p.getElevation() / 30.48);
            ValueMarker marker = new ValueMarker(distance);
            marker.setLabel(p.getName());
            marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
            marker.setLabelTextAnchor(TextAnchor.TOP_CENTER);
            markers.add(marker);
            last = p;
        }
        JFreeChart chart = ChartFactory.createXYLineChart("Coupe 2D", "NM", "FL",
                new XYSeriesCollection(dataset), PlotOrientation.VERTICAL, false, false, false);
        for (ValueMarker m : markers) {
            chart.getXYPlot().addDomainMarker(m);
        }
        //ajout des secteurs AIP avec des XYPolygonAnnotation
        Collection<Object> secteurs;
        AIPController controller = (AIPController) DatasManager.getController(DatasManager.Type.AIP);
        secteurs = controller.getObjects(AIP.CTL);
        for (int i = 0; i <= 600; i += 10) {
            last = null;
            Secteur3D lastSecteur = null;
            double lastBoundary = 0.0;
            for (LPLNTrackPoint point : ((LPLNTrack) track).getTrackPoints()) {
                Position p = new Position(point.getPosition(), i * 30.48);
                //calcul du secteur contenant le point en cours
                Iterator<Object> iterator = secteurs.iterator();
                boolean contain = false;
                Secteur3D secteur = null;
                while (iterator.hasNext() && !contain) {
                    Secteur3D temp = (Secteur3D) iterator.next();
                    if (temp.contains(p)) {
                        contain = true;
                        secteur = temp;
                    }
                }

                //si premier point, on enregistre simplement le secteur trouv
                if (last == null) {
                    lastSecteur = secteur;
                } else {
                    if (lastSecteur != secteur) {
                        //si le secteur a chang, on dessine le secteur prcdent
                        //sauf si ce dernier n'existait pas
                        if (lastSecteur != null) {
                            //dans ce cas, on calcule le point d'intersection entre le secteur et le segment form par les deux points
                            //lastSecteur != null => last !=null
                            Set<Point2D> intersects = lastSecteur
                                    .getIntersections(new Line2D.Double(last.getLatitude(), last.getLongitude(),
                                            p.getLatitude().degrees, p.getLongitude().degrees), true);
                            if (!intersects.isEmpty()) {
                                Point2D intersect = intersects.iterator().next();
                                distance = Position.ellipsoidalDistance(
                                        new LatLonCautra(intersect.getX(), intersect.getY()),
                                        last.getPosition(), Earth.WGS84_EQUATORIAL_RADIUS,
                                        Earth.WGS84_POLAR_RADIUS) / LatLonCautra.NM;
                                //et ajout de l'annotation
                                XYPolygonAnnotation annotation = new XYPolygonAnnotation(
                                        new double[] { lastBoundary, i, lastBoundary + distance, i,
                                                lastBoundary + distance, i + 10, lastBoundary, i + 10 });
                                chart.getXYPlot().addAnnotation(annotation);
                                lastBoundary += distance;
                            }
                        }
                        lastSecteur = secteur;
                    }
                }
                last = point;
            }
        }
        //espace en haut pour les marqueurs
        chart.getXYPlot().getRangeAxis().setUpperMargin(0.05);
        ChartPanel chartPanel = new ChartPanel(chart);
        this.setContentPane(chartPanel);
        this.pack();
    }
}