2 * Copyright © 2014 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altosuilib_3;
21 import java.awt.event.*;
24 import java.lang.Math;
25 import java.awt.geom.*;
27 import java.util.concurrent.*;
28 import org.altusmetrum.altoslib_5.*;
31 AltosUILatLon lat_lon;
34 public PathPoint(AltosUILatLon lat_lon, int state) {
35 this.lat_lon = lat_lon;
39 public boolean equals(PathPoint other) {
43 return lat_lon.equals(other.lat_lon) && state == other.state;
47 public class AltosUIMapPath {
49 LinkedList<PathPoint> points = new LinkedList<PathPoint>();
50 PathPoint last_point = null;
52 static public int stroke_width = 6;
54 public void paint(Graphics2D g, AltosUIMapTransform t) {
55 Point2D.Double prev = null;
57 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
58 RenderingHints.VALUE_ANTIALIAS_ON);
59 g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
61 for (PathPoint point : points) {
62 Point2D.Double cur = t.screen(point.lat_lon);
64 Line2D.Double line = new Line2D.Double (prev, cur);
65 Rectangle bounds = line.getBounds();
67 if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) {
68 if (0 <= point.state && point.state < AltosUIMap.stateColors.length)
69 g.setColor(AltosUIMap.stateColors[point.state]);
71 g.setColor(AltosUIMap.stateColors[AltosLib.ao_flight_invalid]);
80 public AltosUIMapRectangle add(double lat, double lon, int state) {
81 PathPoint point = new PathPoint(new AltosUILatLon (lat, lon), state);
82 AltosUIMapRectangle rect = null;
84 if (!point.equals(last_point)) {
85 if (last_point != null)
86 rect = new AltosUIMapRectangle(last_point.lat_lon, point.lat_lon);
93 public void clear () {
94 points = new LinkedList<PathPoint>();