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 AltosUIMap() {
144 view = new AltosUIMapView();
146 view.setPreferredSize(new Dimension(500,500));
147 view.setVisible(true);
148 view.setEnabled(true);
149 view.add_zoom_listener(this);
151 GridBagLayout my_layout = new GridBagLayout();
153 setLayout(my_layout);
155 GridBagConstraints c = new GridBagConstraints();
156 c.anchor = GridBagConstraints.CENTER;
157 c.fill = GridBagConstraints.BOTH;
168 zoom_label = new JLabel("", JLabel.CENTER);
171 c = new GridBagConstraints();
172 c.anchor = GridBagConstraints.CENTER;
173 c.fill = GridBagConstraints.HORIZONTAL;
180 JButton zoom_reset = new JButton("0");
181 zoom_reset.addActionListener(new ActionListener() {
182 public void actionPerformed(ActionEvent e) {
183 set_zoom(view.default_zoom);
187 c = new GridBagConstraints();
188 c.anchor = GridBagConstraints.CENTER;
189 c.fill = GridBagConstraints.HORIZONTAL;
196 JButton zoom_in = new JButton("+");
197 zoom_in.addActionListener(new ActionListener() {
198 public void actionPerformed(ActionEvent e) {
199 set_zoom(get_zoom() + 1);
203 c = new GridBagConstraints();
204 c.anchor = GridBagConstraints.CENTER;
205 c.fill = GridBagConstraints.HORIZONTAL;
212 JButton zoom_out = new JButton("-");
213 zoom_out.addActionListener(new ActionListener() {
214 public void actionPerformed(ActionEvent e) {
215 set_zoom(get_zoom() - 1);
218 c = new GridBagConstraints();
219 c.anchor = GridBagConstraints.CENTER;
220 c.fill = GridBagConstraints.HORIZONTAL;
227 maptype_combo = new JComboBox<String>(maptype_labels);
229 maptype_combo.setEditable(false);
230 maptype_combo.setMaximumRowCount(maptype_combo.getItemCount());
231 maptype_combo.addItemListener(new ItemListener() {
232 public void itemStateChanged(ItemEvent e) {
233 view.set_maptype(maptype_combo.getSelectedIndex());
237 c = new GridBagConstraints();
238 c.anchor = GridBagConstraints.CENTER;
239 c.fill = GridBagConstraints.HORIZONTAL;
244 add(maptype_combo, c);