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.event.*;
24 import java.lang.Math;
25 import java.awt.geom.*;
27 import java.util.concurrent.*;
28 import org.altusmetrum.altoslib_4.*;
30 public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosUIMapZoomListener {
32 static final int px_size = 512;
34 static final int maptype_hybrid = 0;
35 static final int maptype_roadmap = 1;
36 static final int maptype_satellite = 2;
37 static final int maptype_terrain = 3;
38 static final int maptype_default = maptype_hybrid;
40 static final String[] maptype_names = {
47 public static final String[] maptype_labels = {
54 public static final Color stateColors[] = {
55 Color.WHITE, // startup
60 Color.YELLOW, // coast
63 Color.BLACK, // landed
64 Color.BLACK, // invalid
65 Color.CYAN, // stateless
72 public void font_size_changed(int font_size) {
76 public void units_changed(boolean imperial_units) {
82 private void set_zoom_label() {
83 zoom_label.setText(String.format("Zoom %d", view.zoom() - view.default_zoom));
86 public void zoom_changed(int zoom) {
90 public void set_zoom(int zoom) {
94 public int get_zoom() {
98 public void set_maptype(int type) {
99 view.set_maptype(type);
100 maptype_combo.setSelectedIndex(type);
103 public void show(AltosState state, AltosListenerState listener_state) {
104 view.show(state, listener_state);
107 public void centre(double lat, double lon) {
108 view.centre(lat, lon);
111 public void centre(AltosState state) {
112 if (!state.gps.locked && state.gps.nsat < 4)
114 centre(state.gps.lat, state.gps.lon);
117 public void add_mark(double lat, double lon, int state) {
118 view.add_mark(lat, lon, state);
121 public void clear_marks() {
127 private GridBagLayout layout = new GridBagLayout();
129 JComboBox<String> maptype_combo;
131 public void set_load_params(double lat, double lon, int radius, AltosUIMapTileListener listener) {
132 view.set_load_params(lat, lon, radius, listener);
135 public boolean all_fetched() {
136 return view.all_fetched();
139 public static void prefetch_maps(double lat, double lon) {
142 public String getName() {
146 public AltosUIMap() {
148 view = new AltosUIMapView();
150 view.setPreferredSize(new Dimension(500,500));
151 view.setVisible(true);
152 view.setEnabled(true);
153 view.add_zoom_listener(this);
155 GridBagLayout my_layout = new GridBagLayout();
157 setLayout(my_layout);
159 GridBagConstraints c = new GridBagConstraints();
160 c.anchor = GridBagConstraints.CENTER;
161 c.fill = GridBagConstraints.BOTH;
172 zoom_label = new JLabel("", JLabel.CENTER);
175 c = new GridBagConstraints();
176 c.anchor = GridBagConstraints.CENTER;
177 c.fill = GridBagConstraints.HORIZONTAL;
184 JButton zoom_reset = new JButton("0");
185 zoom_reset.addActionListener(new ActionListener() {
186 public void actionPerformed(ActionEvent e) {
187 set_zoom(view.default_zoom);
191 c = new GridBagConstraints();
192 c.anchor = GridBagConstraints.CENTER;
193 c.fill = GridBagConstraints.HORIZONTAL;
200 JButton zoom_in = new JButton("+");
201 zoom_in.addActionListener(new ActionListener() {
202 public void actionPerformed(ActionEvent e) {
203 set_zoom(get_zoom() + 1);
207 c = new GridBagConstraints();
208 c.anchor = GridBagConstraints.CENTER;
209 c.fill = GridBagConstraints.HORIZONTAL;
216 JButton zoom_out = new JButton("-");
217 zoom_out.addActionListener(new ActionListener() {
218 public void actionPerformed(ActionEvent e) {
219 set_zoom(get_zoom() - 1);
222 c = new GridBagConstraints();
223 c.anchor = GridBagConstraints.CENTER;
224 c.fill = GridBagConstraints.HORIZONTAL;
231 maptype_combo = new JComboBox<String>(maptype_labels);
233 maptype_combo.setEditable(false);
234 maptype_combo.setMaximumRowCount(maptype_combo.getItemCount());
235 maptype_combo.addItemListener(new ItemListener() {
236 public void itemStateChanged(ItemEvent e) {
237 view.set_maptype(maptype_combo.getSelectedIndex());
241 c = new GridBagConstraints();
242 c.anchor = GridBagConstraints.CENTER;
243 c.fill = GridBagConstraints.HORIZONTAL;
248 add(maptype_combo, c);