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.*;
27 import java.awt.RenderingHints.*;
28 import org.altusmetrum.altoslib_4.*;
34 AltosPoint(Point2D.Double pt, int state) {
40 public class AltosSiteMapTile extends JComponent {
46 Point2D.Double landed;
48 LinkedList<AltosPoint> points;
50 public synchronized void queue_repaint() {
51 SwingUtilities.invokeLater(new Runnable() {
58 public void load_map(File pngFile) {
63 private Font font = null;
65 public void set_font(Font font) {
67 this.status = AltosSiteMapCache.success;
71 public void set_status(int status) {
77 public void clearMap() {
82 status = AltosSiteMapCache.success;
86 static Color stateColors[] = {
87 Color.WHITE, // startup
92 Color.YELLOW, // coast
98 private void draw_circle(Graphics g, Point2D.Double pt) {
99 g.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10);
100 g.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40);
101 g.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70);
104 public void set_boost(Point2D.Double boost) {
109 public void paint(Graphics g) {
110 Graphics2D g2d = (Graphics2D) g;
111 AltosPoint prev = null;
115 img = AltosSiteMapCache.get_image(this, file, px_size, px_size);
118 g2d.drawImage(img, 0, 0, null);
120 g2d.setColor(Color.GRAY);
121 g2d.fillRect(0, 0, getWidth(), getHeight());
122 String message = null;
124 case AltosSiteMapCache.loading:
125 message = "Loading...";
127 case AltosSiteMapCache.bad_request:
128 message = "Internal error";
130 case AltosSiteMapCache.failed:
131 message = "Network error, check connection";
133 case AltosSiteMapCache.forbidden:
134 message = "Too many requests, try later";
137 if (message != null && font != null) {
139 g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
141 bounds = font.getStringBounds(message, g2d.getFontRenderContext());
143 float x = getWidth() / 2.0f;
144 float y = getHeight() / 2.0f;
145 x = x - (float) bounds.getWidth() / 2.0f;
146 y = y - (float) bounds.getHeight() / 2.0f;
147 g2d.setColor(Color.BLACK);
148 g2d.drawString(message, x, y);
152 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
153 RenderingHints.VALUE_ANTIALIAS_ON);
154 g2d.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
156 if (points != null) {
157 for (AltosPoint point : points) {
159 if (0 <= point.state && point.state < stateColors.length)
160 g2d.setColor(stateColors[point.state]);
161 g2d.draw(new Line2D.Double(prev.pt, point.pt));
167 g2d.setColor(Color.RED);
168 draw_circle(g2d, boost);
170 if (landed != null) {
171 g2d.setColor(Color.BLACK);
172 draw_circle(g2d, landed);
176 public synchronized void show(int state, Point2D.Double last_pt, Point2D.Double pt)
179 points = new LinkedList<AltosPoint>();
181 points.add(new AltosPoint(pt, state));
183 if (state == AltosLib.ao_flight_boost && boost == null)
185 if (state == AltosLib.ao_flight_landed && landed == null)
190 public AltosSiteMapTile(int in_px_size) {
191 px_size = in_px_size;
192 setPreferredSize(new Dimension(px_size, px_size));