2 * Copyright © 2010 Anthony Towns <aj@erisian.com.au>
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_2;
21 import java.awt.image.*;
23 import javax.imageio.*;
24 import java.awt.geom.Point2D;
25 import java.awt.geom.Line2D;
28 import org.altusmetrum.altoslib_4.*;
34 AltosPoint(Point2D.Double pt, int state) {
40 public class AltosSiteMapTile extends JComponent {
45 Point2D.Double landed;
47 LinkedList<AltosPoint> points;
49 public void loadMap(File pngFile) {
54 public void clearMap() {
61 static Color stateColors[] = {
62 Color.WHITE, // startup
67 Color.YELLOW, // coast
73 private void draw_circle(Graphics g, Point2D.Double pt) {
74 g.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10);
75 g.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40);
76 g.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70);
79 public void set_boost(Point2D.Double boost) {
84 public void paint(Graphics g) {
85 Graphics2D g2d = (Graphics2D) g;
86 AltosPoint prev = null;
90 img = AltosSiteMapCache.get_image(this, file, px_size, px_size);
93 g2d.drawImage(img, 0, 0, null);
95 g2d.setColor(Color.GRAY);
96 g2d.fillRect(0, 0, getWidth(), getHeight());
99 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
100 RenderingHints.VALUE_ANTIALIAS_ON);
101 g2d.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
103 if (points != null) {
104 for (AltosPoint point : points) {
106 if (0 <= point.state && point.state < stateColors.length)
107 g2d.setColor(stateColors[point.state]);
108 g2d.draw(new Line2D.Double(prev.pt, point.pt));
114 g2d.setColor(Color.RED);
115 draw_circle(g2d, boost);
117 if (landed != null) {
118 g2d.setColor(Color.BLACK);
119 draw_circle(g2d, landed);
123 public synchronized void show(AltosState state, AltosListenerState listener_state,
124 Point2D.Double last_pt, Point2D.Double pt)
127 points = new LinkedList<AltosPoint>();
129 points.add(new AltosPoint(pt, state.state));
131 if (state.state == AltosLib.ao_flight_boost && boost == null)
133 if (state.state == AltosLib.ao_flight_landed && landed == null)
138 public AltosSiteMapTile(int in_px_size) {
139 px_size = in_px_size;
140 setPreferredSize(new Dimension(px_size, px_size));