Changeset 30757 in osm for applications/editors/josm/plugins/canvec_helper/src
- Timestamp:
- 2014-10-21T01:19:59+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanVecTile.java
r30738 r30757 1 // License: GPL 1 2 package org.openstreetmap.josm.plugins.canvec_helper; 2 3 3 4 import java.util.ArrayList; 4 5 import java.util.Enumeration; 6 import java.util.List; 5 7 import java.util.zip.ZipEntry; 6 8 import java.util.zip.ZipFile; 7 9 import java.util.regex.Pattern; 8 10 import java.util.regex.Matcher; 11 9 12 import org.openstreetmap.josm.Main; 10 13 import org.openstreetmap.josm.data.Bounds; 14 11 15 import java.awt.Point; 16 12 17 import org.openstreetmap.josm.data.coor.LatLon; 13 18 import org.openstreetmap.josm.gui.MapView; 14 19 import org.openstreetmap.josm.io.IllegalDataException; 15 20 import org.openstreetmap.josm.io.CachedFile; 21 16 22 import java.awt.Graphics2D; 17 23 import java.awt.Polygon; … … 19 25 import java.io.IOException; 20 26 import java.io.InputStream; 27 21 28 import org.openstreetmap.josm.io.OsmImporter; 22 29 import org.openstreetmap.josm.io.OsmImporter.OsmImporterData; 23 30 24 publicclass CanVecTile {25 CanvecLayer layer;26 public boolean can_download = false;27 private ArrayList<String> sub_tile_ids = new ArrayList<>();28 private boolean zip _scanned = false;31 class CanVecTile { 32 private CanvecLayer layer; 33 boolean canDownload = false; 34 private List<String> subTileIds = new ArrayList<>(); 35 private boolean zipScanned = false; 29 36 30 private ArrayList<CanVecTile> sub_tiles = new ArrayList<>();31 private boolean sub _tiles_made = false;32 33 private ArrayList<String> index;37 private List<CanVecTile> subTiles = new ArrayList<>(); 38 private boolean subTilesMade = false; 39 40 private List<String> index; 34 41 private int depth; 35 42 36 int corda,cordc; 43 private int corda; 44 private int cordc; 37 45 private boolean valid = false; 38 String cordb,cordd; 46 private String cordb; 47 private String cordd; 39 48 private Bounds bounds; 40 publicString tileid;41 public CanVecTile(String tileid,CanvecLayer layer) {49 String tileid; 50 CanVecTile(String tileid, CanvecLayer layer) { 42 51 String parta,partb,partc,partd; 43 52 parta = tileid.substring(0,3); … … 48 57 a = Integer.parseInt(parta); 49 58 c = Integer.parseInt(partc); 50 real _init(a,partb,c,partd,layer,new ArrayList<String>());51 } 52 public CanVecTile(int a,String b,int c,String d,CanvecLayer layer,ArrayList<String> index) {53 real _init(a,b,c,d,layer,index);54 } 55 p ublic void real_init(int a,String b,int c,String d,CanvecLayer layer, ArrayList<String> index) {59 realInit(a,partb,c,partd,layer,new ArrayList<String>()); 60 } 61 CanVecTile(int a,String b,int c,String d,CanvecLayer layer, List<String> index) { 62 realInit(a,b,c,d,layer,index); 63 } 64 private void realInit(int a,String b,int c,String d,CanvecLayer layer, List<String> index) { 56 65 this.index = index; 57 66 this.layer = layer; … … 60 69 cordc = c; 61 70 cordd = d; 62 double zero _point_lat,zero_point_lon;63 double lat _span,lon_span;64 double lat2, lon2;71 double zeroPointLat, zeroPointLon; 72 double latSpan, lonSpan; 73 double lat2, lon2; 65 74 if ((a >= 0) && (a <= 119)) { // main block of tiles 66 75 int column = a / 10; … … 70 79 return; 71 80 } 72 zero _point_lat = 40 + 4 * row;73 zero _point_lon = -56 - 8 * column;81 zeroPointLat = 40 + 4 * row; 82 zeroPointLon = -56 - 8 * column; 74 83 75 84 // size of each grid 76 85 if (row <= 6) { 77 86 // each is 4x8 degrees, broken into a 4x4 grid 78 lat _span = 4;79 lon _span = 8;87 latSpan = 4; 88 lonSpan = 8; 80 89 depth = 1; 81 90 } else { … … 89 98 // map A-P to 1-16 90 99 int grid2; 91 if (b == "") grid2 = 0;100 if (b.isEmpty()) grid2 = 0; 92 101 else grid2 = b.charAt(0) - 64; 93 int rows1[]= { 0, 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3 };94 int cols1[]= { 0, 3,2,1,0, 0,1,2,3, 3,2,1,0, 0,1,2,3 };95 lat2 = zero _point_lat + (lat_span/4)*rows1[grid2];96 lon2 = zero _point_lon + (lon_span/4)*cols1[grid2];102 int[] rows1 = { 0, 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3 }; 103 int[] cols1 = { 0, 3,2,1,0, 0,1,2,3, 3,2,1,0, 0,1,2,3 }; 104 lat2 = zeroPointLat + (latSpan/4)*rows1[grid2]; 105 lon2 = zeroPointLon + (lonSpan/4)*cols1[grid2]; 97 106 98 107 if (grid2 != 0) { 99 lat _span = lat_span / 4;100 lon _span = lon_span / 4;108 latSpan = latSpan / 4; 109 lonSpan = lonSpan / 4; 101 110 depth = 2; 102 111 } 103 112 104 int rows3[]= { 0, 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3 };105 lat2 = lat2 + (lat _span/4)*rows3[c];106 int cols3[]= { 0, 3,2,1,0, 0,1,2,3, 3,2,1,0, 0,1,2,3 };107 lon2 = lon2 + (lon _span/4)*cols3[c];113 int[] rows3 = { 0, 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3 }; 114 lat2 = lat2 + (latSpan/4)*rows3[c]; 115 int[] cols3 = { 0, 3,2,1,0, 0,1,2,3, 3,2,1,0, 0,1,2,3 }; 116 lon2 = lon2 + (lonSpan/4)*cols3[c]; 108 117 109 118 if (c != 0) { 110 lat _span = lat_span / 4;111 lon _span = lon_span / 4;119 latSpan = latSpan / 4; 120 lonSpan = lonSpan / 4; 112 121 depth = 3; 113 122 } 114 123 115 if ( cordd != "") {124 if (!cordd.isEmpty()) { 116 125 depth = 4; 117 System.out.println("cordd: "+cordd); 118 String foo[] = cordd.split("\\."); 126 String[] foo = cordd.split("\\."); 119 127 for (int i = 0; i < foo.length; i++) { 120 128 int cell; 121 System.out.println(foo[i]); 122 if (foo[i] == "osm") break; 123 if (foo[i] == "") continue; 129 if ("osm".equals(foo[i])) break; 130 if (foo[i].isEmpty()) continue; 124 131 try { 125 132 cell = Integer.parseInt(foo[i]); … … 131 138 break; 132 139 case 1: 133 lat2 = lat2 + lat _span/2;140 lat2 = lat2 + latSpan/2; 134 141 break; 135 142 case 2: 136 lat2 = lat2 + lat _span/2;137 lon2 = lon2 + lon _span/2;143 lat2 = lat2 + latSpan/2; 144 lon2 = lon2 + lonSpan/2; 138 145 break; 139 146 case 3: 140 lon2 = lon2 + lon _span/2;147 lon2 = lon2 + lonSpan/2; 141 148 break; 142 149 } 143 lat _span = lat_span/2;144 lon _span = lon_span/2;145 } 146 } 147 148 bounds = new Bounds(lat2,lon2,lat2+lat _span,lon2+lon_span);149 if (cordb == "") this.tileid = String.format("%03d",corda);150 latSpan = latSpan/2; 151 lonSpan = lonSpan/2; 152 } 153 } 154 155 bounds = new Bounds(lat2,lon2,lat2+latSpan,lon2+lonSpan); 156 if (cordb.isEmpty()) this.tileid = String.format("%03d",corda); 150 157 else if (cordc == 0) this.tileid = String.format("%03d%s",corda,cordb); 151 else if (cordd == "") this.tileid = String.format("%03d%s%02d",corda,cordb,cordc);158 else if (cordd.isEmpty()) this.tileid = String.format("%03d%s%02d",corda,cordb,cordc); 152 159 else this.tileid = String.format("%03d%s%02d%s",corda,cordb,cordc,cordd); 153 160 valid = true; 154 //debug(index.toString());155 //debug("creating tileid: "+this.tileid);156 }157 public boolean isValid() { return valid;}158 publicString getTileId() {161 } 162 boolean isValid() { 163 return valid; 164 } 165 String getTileId() { 159 166 return this.tileid; 160 167 } 161 private void debug(String line) { 162 System.out.println(depth + "_" + tileid + ": " + line); 163 } 164 public boolean isVisible(Bounds view) { 168 boolean isVisible(Bounds view) { 165 169 return view.intersects(bounds); 166 170 } 167 publicPoint[] getCorners(MapView mv) {171 Point[] getCorners(MapView mv) { 168 172 LatLon min = bounds.getMin(); 169 173 LatLon max = bounds.getMax(); … … 180 184 return String.format("http://ftp2.cits.rncan.gc.ca/OSM/pub/%1$03d/%2$s/%1$03d%2$s%3$02d.zip",corda,cordb,cordc); 181 185 } 182 private ZipFile open_zip() throws IOException { 183 File download_path = new File(layer.plugin_self.getPluginDir() + File.separator); 184 download_path.mkdir(); 185 CachedFile tile_zip = new CachedFile(getDownloadUrl()).setDestDir(download_path.toString()); 186 return new ZipFile(tile_zip.getFile()); 187 } 188 public void downloadSelf() { 189 if (zip_scanned) return; 186 private ZipFile openZip() throws IOException { 187 File downloadPath = new File(layer.plugin.getPluginDir() + File.separator); 188 if (!downloadPath.mkdir() && Main.isDebugEnabled()) { 189 Main.debug("Unable to create directory: "+downloadPath); 190 } 191 CachedFile tileZip = new CachedFile(getDownloadUrl()).setDestDir(downloadPath.toString()); 192 return new ZipFile(tileZip.getFile()); 193 } 194 void downloadSelf() { 195 if (zipScanned) return; 190 196 ZipFile zipFile; 191 197 try { 192 zipFile = open _zip();198 zipFile = openZip(); 193 199 } catch (IOException e) { 194 e.printStackTrace();200 Main.error(e); 195 201 return; 196 202 } … … 198 204 while (entries.hasMoreElements()) { 199 205 ZipEntry entry = entries.nextElement(); 200 if (entry.getName().equals("Metadata.txt")) continue; 201 sub_tile_ids.add(entry.getName()); 202 zip_scanned = true; 203 CanVecTile final_tile = new CanVecTile(entry.getName(),layer); 204 if (final_tile.isValid()) sub_tiles.add(final_tile); 205 } 206 } 207 public void load_raw_osm() { 206 if ("Metadata.txt".equals(entry.getName())) continue; 207 subTileIds.add(entry.getName()); 208 zipScanned = true; 209 CanVecTile finalTile = new CanVecTile(entry.getName(),layer); 210 if (finalTile.isValid()) { 211 subTiles.add(finalTile); 212 } 213 } 214 } 215 void loadRawOsm() { 208 216 ZipFile zipFile; 209 217 try { 210 zipFile = open _zip();218 zipFile = openZip(); 211 219 Enumeration<? extends ZipEntry> entries = zipFile.entries(); 212 220 while (entries.hasMoreElements()) { 213 221 ZipEntry entry = entries.nextElement(); 214 222 if (tileid.equals(entry.getName())) { 215 debug("found myself!");216 223 InputStream rawtile = zipFile.getInputStream(entry); 217 224 OsmImporter importer = new OsmImporter(); 218 debug("loading raw osm");219 225 OsmImporterData temp = importer.loadLayer(rawtile, null, entry.getName(), null); 220 226 Main.worker.submit(temp.getPostLayerTask()); … … 223 229 } 224 230 } 225 } catch (IOException e) {226 e.printStackTrace();231 } catch (IOException | IllegalDataException e) { 232 Main.error(e); 227 233 return; 228 } catch (IllegalDataException e) { 229 e.printStackTrace(); 230 return; 231 } 232 } 233 private void make_sub_tiles(int layer) { 234 ArrayList<String> buffer = new ArrayList<>(); 234 } 235 } 236 private void makeSubTiles(int layer) { 237 List<String> buffer = new ArrayList<>(); 235 238 Pattern p; 236 if (sub _tiles_made) return;239 if (subTilesMade) return; 237 240 switch (layer) { 238 241 case 1: 239 242 p = Pattern.compile("\\d\\d\\d([A-Z]).*"); 240 String last _cell = "";243 String lastCell = ""; 241 244 for (int i = 0; i < index.size(); i++) { 242 245 Matcher m = p.matcher(index.get(i)); … … 244 247 245 248 String cell = m.group(1); 246 if (cell.equals(last _cell)) {247 buffer.add(m.group(0)); 248 } else if (last _cell == "") {249 if (cell.equals(lastCell)) { 250 buffer.add(m.group(0)); 251 } else if (lastCell.isEmpty()) { 249 252 buffer.add(m.group(0)); 250 253 } else { 251 sub _tiles.add(new CanVecTile(corda,last_cell,0,"",this.layer,buffer));254 subTiles.add(new CanVecTile(corda,lastCell,0,"",this.layer,buffer)); 252 255 buffer = new ArrayList<>(); 253 256 buffer.add(m.group(0)); 254 257 } 255 last _cell = cell;256 } 257 sub _tiles.add(new CanVecTile(corda,last_cell,0,"",this.layer,buffer));258 lastCell = cell; 259 } 260 subTiles.add(new CanVecTile(corda,lastCell,0,"",this.layer,buffer)); 258 261 break; 259 262 case 2: 260 263 p = Pattern.compile("\\d\\d\\d[A-Z](\\d\\d).*"); 261 int last _cell2 = -1;264 int lastCell2 = -1; 262 265 for (int i = 0; i < index.size(); i++) { 263 266 Matcher m = p.matcher(index.get(i)); … … 265 268 266 269 int cell = Integer.parseInt(m.group(1)); 267 if (cell == last _cell2) {268 buffer.add(m.group(0)); 269 } else if (last _cell2 == -1) {270 if (cell == lastCell2) { 271 buffer.add(m.group(0)); 272 } else if (lastCell2 == -1) { 270 273 buffer.add(m.group(0)); 271 274 } else { 272 sub _tiles.add(new CanVecTile(corda,cordb,last_cell2,"",this.layer,buffer));275 subTiles.add(new CanVecTile(corda,cordb,lastCell2,"",this.layer,buffer)); 273 276 buffer = new ArrayList<>(); 274 277 buffer.add(m.group(0)); 275 278 } 276 last _cell2 = cell;277 } 278 if (last _cell2 != -1) sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"",this.layer,buffer));279 lastCell2 = cell; 280 } 281 if (lastCell2 != -1) subTiles.add(new CanVecTile(corda,cordb,lastCell2,"",this.layer,buffer)); 279 282 break; 280 283 } 281 sub _tiles_made = true;282 } 283 public void paint(Graphics2D g, MapView mv, Bounds bounds, int max_zoom) {284 boolean show _sub_tiles = false;284 subTilesMade = true; 285 } 286 void paint(Graphics2D g, MapView mv, Bounds bounds, int maxZoom) { 287 boolean showSubTiles = false; 285 288 if (!isVisible(bounds)) return; 286 289 if (depth == 4) { … … 288 291 } 289 292 if ((depth == 3) && (bounds.getArea() < 0.5)) { // 022B01 290 if (zip _scanned) {291 show _sub_tiles = true;292 } else if (can _download) {293 if (zipScanned) { 294 showSubTiles = true; 295 } else if (canDownload) { 293 296 downloadSelf(); 294 show _sub_tiles = true;297 showSubTiles = true; 295 298 } else { 296 299 layer.downloadable.add(this); 297 300 } 298 301 } else if ((depth == 2) && (bounds.getArea() < 20)) { // its a layer2 tile 299 make _sub_tiles(2);300 show _sub_tiles = true;302 makeSubTiles(2); 303 showSubTiles = true; 301 304 } else if ((depth == 1) && (bounds.getArea() < 40)) { // its a layer1 tile and zoom too small 302 305 // draw layer2 tiles for self 303 make _sub_tiles(1);304 show _sub_tiles = true;305 } 306 if (show _sub_tiles && (depth < max_zoom)) {307 for (int i = 0; i < sub _tiles.size(); i++) {308 CanVecTile tile = sub _tiles.get(i);309 tile.paint(g,mv,bounds,max _zoom);306 makeSubTiles(1); 307 showSubTiles = true; 308 } 309 if (showSubTiles && (depth < maxZoom)) { 310 for (int i = 0; i < subTiles.size(); i++) { 311 CanVecTile tile = subTiles.get(i); 312 tile.paint(g,mv,bounds,maxZoom); 310 313 } 311 314 } else { 312 Point corners[]= getCorners(mv);313 int xs[]= { corners[0].x, corners[1].x, corners[2].x, corners[3].x };314 int ys[]= { corners[0].y, corners[1].y, corners[2].y, corners[3].y };315 Point[] corners = getCorners(mv); 316 int[] xs = { corners[0].x, corners[1].x, corners[2].x, corners[3].x }; 317 int[] ys = { corners[0].y, corners[1].y, corners[2].y, corners[3].y }; 315 318 Polygon shape = new Polygon(xs,ys,4); 316 319 g.draw(shape); -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanvecHelper.java
r30738 r30757 1 // License: GPL 1 2 package org.openstreetmap.josm.plugins.canvec_helper; 2 3 4 import org.openstreetmap.josm.Main; 3 5 import org.openstreetmap.josm.plugins.Plugin; 4 6 import org.openstreetmap.josm.plugins.PluginInformation; 5 import org.openstreetmap.josm.gui.MapFrame;6 import org.openstreetmap.josm.Main;7 7 8 /** 9 * Canvec Helper plugin. 10 */ 8 11 public class CanvecHelper extends Plugin { 9 12 13 /** 14 * Constructs a new {@code CanvecHelper} plugin. 15 * @param info plugin info 16 */ 10 17 public CanvecHelper(PluginInformation info) { 11 18 super(info); 12 19 Main.main.menu.imagerySubMenu.add(new CanvecHelperAction(this)); 13 20 } 14 15 @Override16 public void mapFrameInitialized(MapFrame old, MapFrame new1) {17 updateLayer();18 }19 20 private synchronized void updateLayer() {21 }22 21 } -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanvecHelperAction.java
r30738 r30757 1 // License: GPL 1 2 package org.openstreetmap.josm.plugins.canvec_helper; 2 3 … … 4 5 import org.openstreetmap.josm.Main; 5 6 6 publicclass CanvecHelperAction extends JosmAction {7 private CanvecHelper parent _temp;8 publicCanvecHelperAction(CanvecHelper parent) {7 class CanvecHelperAction extends JosmAction { 8 private CanvecHelper parentTemp; 9 CanvecHelperAction(CanvecHelper parent) { 9 10 super("CanVec Helper","layericon24",null,null,false); 10 parent _temp = parent;11 parentTemp = parent; 11 12 } 12 @Override 13 14 @Override 13 15 public void actionPerformed(java.awt.event.ActionEvent action) { 14 CanvecLayer layer; 15 layer = new CanvecLayer("canvec tile helper",parent_temp); 16 Main.main.addLayer(layer); 16 Main.main.addLayer(new CanvecLayer("canvec tile helper",parentTemp)); 17 17 } 18 18 } -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanvecLayer.java
r30738 r30757 1 // License: GPL 1 2 package org.openstreetmap.josm.plugins.canvec_helper; 2 3 … … 8 9 import java.awt.Toolkit; 9 10 import java.awt.event.ActionEvent; 10 import java.awt.event.MouseEvent;11 import java.awt.event.MouseListener;12 11 import java.io.BufferedReader; 13 12 import java.io.IOException; 14 13 import java.io.InputStream; 15 14 import java.io.InputStreamReader; 15 import java.nio.charset.StandardCharsets; 16 16 import java.util.ArrayList; 17 17 import java.util.List; … … 36 36 37 37 // most of the layout was copied from the openstreetbugs plugin to get things started 38 public class CanvecLayer extends Layer implements MouseListener {38 class CanvecLayer extends Layer { 39 39 private Icon layerIcon = null; 40 private int max _zoom = 4;41 public CanvecHelper plugin_self;42 private ArrayList<CanVecTile> tiles = new ArrayList<>();43 public ArrayList<CanVecTile> downloadable = new ArrayList<>();44 public ArrayList<CanVecTile> openable = new ArrayList<>();45 46 public CanvecLayer(String name,CanvecHelper self){40 private int maxZoom = 4; 41 final CanvecHelper plugin; 42 private List<CanVecTile> tiles = new ArrayList<>(); 43 List<CanVecTile> downloadable = new ArrayList<>(); 44 List<CanVecTile> openable = new ArrayList<>(); 45 46 CanvecLayer(String name, CanvecHelper self){ 47 47 super(name); 48 plugin _self= self;48 plugin = self; 49 49 this.setBackgroundLayer(true); 50 /* for (int i = 0; i < 119; i++) {51 CanVecTile tile = new CanVecTile(i,"",0,"",plugin_self);52 if (tile.isValid()) tiles.add(tile);53 }*/54 50 layerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/layericon.png"))); 55 51 long start = System.currentTimeMillis(); 56 52 try ( 57 53 InputStream index = new CachedFile("http://ftp2.cits.rncan.gc.ca/OSM/pub/ZippedOsm.txt").getInputStream(); 58 BufferedReader br = new BufferedReader(new InputStreamReader(index ));54 BufferedReader br = new BufferedReader(new InputStreamReader(index, StandardCharsets.UTF_8)); 59 55 ) { 60 56 Pattern p = Pattern.compile("(\\d\\d\\d)([A-Z]\\d\\d).*"); 61 57 String line; 62 int last _cell = -1;63 ArrayList<String> list = new ArrayList<>();58 int lastCell = -1; 59 List<String> list = new ArrayList<>(); 64 60 while ((line = br.readLine()) != null) { 65 61 Matcher m = p.matcher(line); 66 62 if (m.find()) { 67 63 int cell = Integer.parseInt(m.group(1)); 68 if (cell == last _cell) {64 if (cell == lastCell) { 69 65 list.add(m.group(0)); 70 } else if (last _cell != -1) {71 CanVecTile tile = new CanVecTile(last _cell,"",0,"",this,list);66 } else if (lastCell != -1) { 67 CanVecTile tile = new CanVecTile(lastCell,"",0,"",this,list); 72 68 if (tile.isValid()) tiles.add(tile); 73 69 list = new ArrayList<>(); 74 70 list.add(m.group(0)); 75 71 } 76 last_cell = cell; 77 } else if (line.contains("Metadata.txt")) { 78 } else { 79 System.out.print("bad line '" + line + "'\n"); 72 lastCell = cell; 73 } else if (!line.contains("Metadata.txt")) { 74 Main.warn("bad line '" + line + "'\n"); 80 75 } 81 76 } 82 CanVecTile tile = new CanVecTile(last _cell,"",0,"",this,list);77 CanVecTile tile = new CanVecTile(lastCell,"",0,"",this,list); 83 78 if (tile.isValid()) tiles.add(tile); 84 79 … … 103 98 new OpenOsmAction(this)}; 104 99 } 105 p ublic class MaxZoomAction extends AbstractAction implements LayerAction {106 private CanvecLayer parent;107 p ublicMaxZoomAction(CanvecLayer parent) {100 private static class MaxZoomAction extends AbstractAction implements LayerAction { 101 private final CanvecLayer parent; 102 private MaxZoomAction(CanvecLayer parent) { 108 103 this.parent = parent; 109 104 } 110 @Override 111 public void actionPerformed(ActionEvent e) {} 112 @Override 105 @Override 106 public void actionPerformed(ActionEvent e) { 107 // Do nothing 108 } 109 @Override 113 110 public boolean supportLayers(List<Layer> layers) { 114 111 return false; 115 112 } 116 113 @Override 117 114 public Component createMenuComponent() { 118 JMenu max _zoom= new JMenu("max zoom");119 max _zoom.add(new JMenuItem(new SetMaxZoom(parent,1)));120 max _zoom.add(new JMenuItem(new SetMaxZoom(parent,2)));121 max _zoom.add(new JMenuItem(new SetMaxZoom(parent,3)));122 max _zoom.add(new JMenuItem(new SetMaxZoom(parent,4)));123 return max _zoom;124 } 125 } 126 private class AllowDownload extends AbstractAction {127 CanVecTile tile;128 p ublicAllowDownload(CanVecTile tile) {115 JMenu maxZoomMenu = new JMenu("max zoom"); 116 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent,1))); 117 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent,2))); 118 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent,3))); 119 maxZoomMenu.add(new JMenuItem(new SetMaxZoom(parent,4))); 120 return maxZoomMenu; 121 } 122 } 123 private static class AllowDownload extends AbstractAction { 124 private final CanVecTile tile; 125 private AllowDownload(CanVecTile tile) { 129 126 super(tile.tileid); 130 127 this.tile = tile; 131 128 } 132 129 @Override 133 130 public void actionPerformed(ActionEvent arg0) { 134 tile.can _download = true;131 tile.canDownload = true; 135 132 } 136 133 } 137 134 private class OpenOsmAction extends AbstractAction implements LayerAction { 138 135 private CanvecLayer layer; 139 p ublicOpenOsmAction(CanvecLayer layer) {136 private OpenOsmAction(CanvecLayer layer) { 140 137 this.layer = layer; 141 138 } 142 @Override 143 public void actionPerformed(ActionEvent e) {} 144 @Override 139 @Override 140 public void actionPerformed(ActionEvent e) { 141 // Do nothing 142 } 143 @Override 145 144 public Component createMenuComponent() { 146 JMenu OpenOsm = new JMenu("Open tile");145 JMenu openOsm = new JMenu("Open tile"); 147 146 for (int i = 0; i < layer.openable.size(); i++) { 148 OpenOsm.add(new JMenuItem(new DoOpenOsm(layer.openable.get(i))));149 } 150 return OpenOsm;151 } 152 147 openOsm.add(new JMenuItem(new DoOpenOsm(layer.openable.get(i)))); 148 } 149 return openOsm; 150 } 151 @Override 153 152 public boolean supportLayers(List<Layer> layers) { 154 153 return false; 155 154 } 156 155 } 157 private class DoOpenOsm extends AbstractAction {158 CanVecTile tile;159 p ublicDoOpenOsm(CanVecTile tile) {156 private static class DoOpenOsm extends AbstractAction { 157 private final CanVecTile tile; 158 private DoOpenOsm(CanVecTile tile) { 160 159 super(tile.tileid); 161 160 this.tile = tile; 162 161 } 163 164 public void actionPerformed(ActionEvent e) { 165 tile.load _raw_osm();162 @Override 163 public void actionPerformed(ActionEvent e) { 164 tile.loadRawOsm(); 166 165 } 167 166 } 168 167 private class DownloadCanvecAction extends AbstractAction implements LayerAction { 169 168 private CanvecLayer parent; 170 p ublicDownloadCanvecAction(CanvecLayer parent) {169 private DownloadCanvecAction(CanvecLayer parent) { 171 170 this.parent = parent; 172 171 } 173 @Override 174 public void actionPerformed(ActionEvent e) {} 175 @Override 172 @Override 173 public void actionPerformed(ActionEvent e) { 174 // Do nothing 175 } 176 @Override 176 177 public boolean supportLayers(List<Layer> layers) { 177 178 return false; 178 179 } 179 180 @Override 180 181 public Component createMenuComponent() { 181 182 JMenu downloadCanvec = new JMenu("Download zip's"); … … 186 187 } 187 188 } 188 public void setMaxZoom(int max_zoom) {189 this.max _zoom = max_zoom;190 } 191 189 void setMaxZoom(int maxZoom) { 190 this.maxZoom = maxZoom; 191 } 192 @Override 192 193 public Object getInfoComponent() { 193 194 return getToolTipText(); 194 195 } 195 196 @Override 196 197 public String getToolTipText() { 197 198 return tr("canvec tile helper"); 198 199 } 199 @Override 200 public void visitBoundingBox(BoundingXYVisitor v) {} 201 @Override 200 @Override 201 public void visitBoundingBox(BoundingXYVisitor v) { 202 // Do nothing 203 } 204 @Override 202 205 public boolean isMergable(Layer other) { 203 206 return false; 204 207 } 205 @Override 206 public void mergeFrom(Layer from) {} 207 @Override 208 public Icon getIcon() { return layerIcon; } 209 @Override 208 @Override 209 public void mergeFrom(Layer from) { 210 // Do nothing 211 } 212 @Override 213 public Icon getIcon() { 214 return layerIcon; 215 } 216 @Override 210 217 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 211 //long start = System.currentTimeMillis();212 //System.out.println("painting the area covered by "+bounds.toString());213 218 downloadable = new ArrayList<>(); 214 219 openable = new ArrayList<>(); … … 217 222 for (int i = 0; i < tiles.size(); i++) { 218 223 CanVecTile tile = tiles.get(i); 219 tile.paint(g,mv,bounds,max_zoom); 220 } 221 //long end = System.currentTimeMillis(); 222 //System.out.println((end-start)+"ms spent"); 223 } 224 @Override 225 public void mouseExited(MouseEvent e) {} 226 @Override 227 public void mouseEntered(MouseEvent e) {} 228 @Override 229 public void mouseReleased(MouseEvent e) {} 230 @Override 231 public void mousePressed(MouseEvent e) {} 232 @Override 233 public void mouseClicked(MouseEvent e) { 234 System.out.println("click!"); 224 tile.paint(g,mv,bounds,maxZoom); 225 } 235 226 } 236 227 } -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/SetMaxZoom.java
r30738 r30757 1 // License: GPL 1 2 package org.openstreetmap.josm.plugins.canvec_helper; 2 3 … … 7 8 private CanvecLayer parent; 8 9 private int level; 9 publicSetMaxZoom(CanvecLayer parent,int level) {10 SetMaxZoom(CanvecLayer parent,int level) { 10 11 super(""+level); 11 12 this.level = level; 12 13 this.parent = parent; 13 14 } 14 15 @Override 15 16 public void actionPerformed(ActionEvent ev) { 16 17 parent.setMaxZoom(level);
Note:
See TracChangeset
for help on using the changeset viewer.