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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_13;
24 public class AltosMapTile implements AltosFontListener, AltosMapStoreListener {
25 LinkedList<AltosMapTileListener> listeners = new LinkedList<AltosMapTileListener>();
26 public AltosLatLon upper_left, center;
31 private AltosMapCache cache;
32 public AltosMapStore store;
35 static public final int loaded = 0; /* loaded from file */
36 static public final int fetched = 1; /* downloaded to file */
37 static public final int fetching = 2; /* downloading from net */
38 static public final int failed = 3; /* loading from file failed */
39 static public final int bad_request = 4;/* downloading failed */
40 static public final int forbidden = 5; /* downloading failed */
42 static public String status_name(int status) {
61 public void font_size_changed(int font_size) {
64 private synchronized void notify_listeners(int status) {
66 for (AltosMapTileListener listener : listeners)
67 listener.notify_tile(this, status);
70 public void notify_store(AltosMapStore store, int status) {
71 notify_listeners(status);
74 public void notify_image(AltosImage image) {
79 notify_listeners(status);
82 public void paint(AltosMapTransform t) {
85 public AltosImage get_image() {
88 return cache.get(this);
91 public synchronized void add_listener(AltosMapTileListener listener) {
92 if (!listeners.contains(listener))
93 listeners.add(listener);
94 listener.notify_tile(this, status);
97 public synchronized void remove_listener(AltosMapTileListener listener) {
98 listeners.remove(listener);
101 public AltosMapTile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size, int scale) {
103 this.upper_left = upper_left;
105 while (center.lon < -180.0)
107 while (center.lon > 180.0)
110 this.center = center;
112 this.maptype = maptype;
113 this.px_size = px_size;
116 store = AltosMapStore.get(center, zoom, maptype, px_size, scale);
117 store.add_listener(this);