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_11;
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 static public String status_name(int status) {
60 public void font_size_changed(int font_size) {
63 private synchronized void notify_listeners(int status) {
65 for (AltosMapTileListener listener : listeners)
66 listener.notify_tile(this, status);
69 public void notify_store(AltosMapStore store, int status) {
70 notify_listeners(status);
73 public void notify_image(AltosImage image) {
78 notify_listeners(status);
81 public void paint(AltosMapTransform t) {
84 public AltosImage get_image() {
87 return cache.get(this);
90 public synchronized void add_listener(AltosMapTileListener listener) {
91 if (!listeners.contains(listener))
92 listeners.add(listener);
93 listener.notify_tile(this, status);
96 public synchronized void remove_listener(AltosMapTileListener listener) {
97 listeners.remove(listener);
100 public AltosMapTile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size, int scale) {
102 this.upper_left = upper_left;
104 while (center.lon < -180.0)
106 while (center.lon > 180.0)
109 this.center = center;
111 this.maptype = maptype;
112 this.px_size = px_size;
115 store = AltosMapStore.get(center, zoom, maptype, px_size, scale);
116 store.add_listener(this);