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_6;
21 import javax.imageio.ImageIO;
22 import java.awt.image.*;
27 public class AltosUIMapImage implements AltosUIMapStoreListener {
28 static final long google_maps_ratelimit_ms = 1200;
29 // Google limits static map queries to 50 per minute per IP, so
30 // each query should take at least 1.2 seconds.
32 static final int success = 0;
33 static final int loading = 1;
34 static final int failed = 2;
35 static final int bad_request = 3;
36 static final int forbidden = 4;
38 static long forbidden_time;
39 static boolean forbidden_set = false;
40 static final long forbidden_interval = 60l * 1000l * 1000l * 1000l;
42 AltosUIMapTile tile; /* Notify when image has been loaded */
44 AltosUIMapStore store;
47 class loader implements Runnable {
50 tile.notify_image(image);
52 image = ImageIO.read(store.file);
53 } catch (Exception ex) {
56 tile.set_status(failed);
58 tile.set_status(success);
59 tile.notify_image(image);
64 loader l = new loader();
65 Thread lt = new Thread(l);
76 public boolean has_map() {
77 return store.status() == AltosUIMapStore.success;
80 public synchronized void notify_store(AltosUIMapStore store, int status) {
82 case AltosUIMapStore.loading:
84 case AltosUIMapStore.success:
88 tile.set_status(status);
89 tile.notify_image(null);
93 public AltosUIMapImage(AltosUIMapTile tile, AltosUIMapStore store) throws IOException {
99 int status = store.status();
101 case AltosUIMapStore.loading:
102 store.add_listener(this);
104 case AltosUIMapStore.success:
108 tile.set_status(status);
109 tile.notify_image(null);