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.altoslib_10;
23 public class AltosMapTile implements AltosFontListener, AltosMapStoreListener {
24 LinkedList<AltosMapTileListener> listeners = new LinkedList<AltosMapTileListener>();
25 public AltosLatLon upper_left, center;
30 private AltosMapCache cache;
31 public AltosMapStore store;
34 static public final int loaded = 0; /* loaded from file */
35 static public final int fetched = 1; /* downloaded to file */
36 static public final int fetching = 2; /* downloading from net */
37 static public final int failed = 3; /* loading from file failed */
38 static public final int bad_request = 4;/* downloading failed */
39 static public final int forbidden = 5; /* downloading failed */
41 public void font_size_changed(int font_size) {
44 private synchronized void notify_listeners(int status) {
46 for (AltosMapTileListener listener : listeners)
47 listener.notify_tile(this, status);
50 public void notify_store(AltosMapStore store, int status) {
51 notify_listeners(status);
54 public void notify_image(AltosImage image) {
59 notify_listeners(status);
62 public void paint(AltosMapTransform t) {
65 public AltosImage get_image() {
68 return cache.get(this);
71 public synchronized void add_listener(AltosMapTileListener listener) {
72 if (!listeners.contains(listener))
73 listeners.add(listener);
74 listener.notify_tile(this, status);
77 public synchronized void remove_listener(AltosMapTileListener listener) {
78 listeners.remove(listener);
81 public AltosMapTile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size, int scale) {
83 this.upper_left = upper_left;
85 while (center.lon < -180.0)
87 while (center.lon > 180.0)
92 this.maptype = maptype;
93 this.px_size = px_size;
96 store = AltosMapStore.get(center, zoom, maptype, px_size, scale);
97 store.add_listener(this);
100 public AltosMapTile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) {
101 this(cache, upper_left, center, zoom, maptype, px_size, 1);