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.
21 import java.awt.image.*;
22 import java.awt.event.*;
24 import javax.imageio.ImageIO;
25 import javax.swing.table.*;
29 import java.util.prefs.*;
30 import java.lang.Math;
31 import java.awt.geom.Point2D;
32 import java.awt.geom.Line2D;
34 public class AltosSiteMapTile extends JLayeredPane {
39 public void loadMap(ImageIcon icn) {
40 mapLabel.setIcon(icn);
43 static Color stateColors[] = {
44 Color.WHITE, // startup
49 Color.YELLOW, // coast
55 private boolean drawn_landed_circle = false;
56 private boolean drawn_boost_circle = false;
57 public synchronized void show(AltosState state, int crc_errors,
58 Point2D.Double last_pt, Point2D.Double pt)
60 if (0 <= state.state && state.state < stateColors.length) {
61 g2d.setColor(stateColors[state.state]);
63 g2d.draw(new Line2D.Double(last_pt, pt));
65 if (state.state == 3 && !drawn_boost_circle) {
66 drawn_boost_circle = true;
67 g2d.setColor(Color.RED);
68 g2d.drawOval((int)last_pt.x-5, (int)last_pt.y-5, 10, 10);
69 g2d.drawOval((int)last_pt.x-20, (int)last_pt.y-20, 40, 40);
70 g2d.drawOval((int)last_pt.x-35, (int)last_pt.y-35, 70, 70);
72 if (state.state == 8 && !drawn_landed_circle) {
73 drawn_landed_circle = true;
74 g2d.setColor(Color.BLACK);
75 g2d.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10);
76 g2d.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40);
77 g2d.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70);
83 public static Graphics2D fillLabel(JLabel l, Color c, int px_size) {
84 BufferedImage img = new BufferedImage(px_size, px_size,
85 BufferedImage.TYPE_INT_ARGB);
86 Graphics2D g = img.createGraphics();
88 g.fillRect(0, 0, px_size, px_size);
89 l.setIcon(new ImageIcon(img));
93 public AltosSiteMapTile(int px_size) {
94 setPreferredSize(new Dimension(px_size, px_size));
96 mapLabel = new JLabel();
97 fillLabel(mapLabel, Color.GRAY, px_size);
98 mapLabel.setOpaque(true);
99 mapLabel.setBounds(0, 0, px_size, px_size);
100 add(mapLabel, new Integer(0));
103 g2d = fillLabel(draw, new Color(127, 127, 127, 0), px_size);
104 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
105 RenderingHints.VALUE_ANTIALIAS_ON);
106 g2d.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
107 draw.setBounds(0, 0, px_size, px_size);
108 draw.setOpaque(false);
110 add(draw, new Integer(1));