Changeset 27950 in osm for applications/editors/josm/plugins/canvec_helper
- Timestamp:
- 2012-02-27T05:13:26+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/CanVecTile.java
r27926 r27950 4 4 import java.util.Enumeration; 5 5 import java.util.zip.ZipEntry; 6 import java.util.zip.ZipException;7 6 import java.util.zip.ZipFile; 8 7 import java.util.regex.Pattern; … … 24 23 25 24 public class CanVecTile { 26 canvec_helper plugin_self; 25 canvec_layer layer; 26 public boolean can_download = false; 27 27 private ArrayList<String> sub_tile_ids = new ArrayList<String>(); 28 28 private boolean zip_scanned = false; … … 38 38 String cordb,cordd; 39 39 private Bounds bounds; 40 p rivateString tileid;41 public CanVecTile(String tileid,canvec_ helper self) {40 public String tileid; 41 public CanVecTile(String tileid,canvec_layer layer) { 42 42 String parta,partb,partc,partd; 43 43 parta = tileid.substring(0,3); … … 48 48 a = Integer.parseInt(parta); 49 49 c = Integer.parseInt(partc); 50 real_init(a,partb,c,partd, self,new ArrayList<String>());51 } 52 public CanVecTile(int a,String b,int c,String d,canvec_ helper self,ArrayList<String> index) {53 real_init(a,b,c,d, self,index);54 } 55 public void real_init(int a,String b,int c,String d,canvec_ helper self, ArrayList<String> index) {50 real_init(a,partb,c,partd,layer,new ArrayList<String>()); 51 } 52 public CanVecTile(int a,String b,int c,String d,canvec_layer layer,ArrayList<String> index) { 53 real_init(a,b,c,d,layer,index); 54 } 55 public void real_init(int a,String b,int c,String d,canvec_layer layer, ArrayList<String> index) { 56 56 this.index = index; 57 plugin_self = self;57 this.layer = layer; 58 58 corda = a; 59 59 cordb = b; … … 181 181 } 182 182 private ZipFile open_zip() throws IOException { 183 File download_path = new File( plugin_self.getPluginDir() + File.separator);183 File download_path = new File(layer.plugin_self.getPluginDir() + File.separator); 184 184 download_path.mkdir(); 185 185 MirroredInputStream tile_zip; … … 201 201 sub_tile_ids.add(entry.getName()); 202 202 zip_scanned = true; 203 CanVecTile final_tile = new CanVecTile(entry.getName(), plugin_self);203 CanVecTile final_tile = new CanVecTile(entry.getName(),layer); 204 204 if (final_tile.isValid()) sub_tiles.add(final_tile); 205 205 } 206 206 } 207 p rivatevoid load_raw_osm() {207 public void load_raw_osm() { 208 208 ZipFile zipFile; 209 209 try { … … 212 212 while (entries.hasMoreElements()) { 213 213 ZipEntry entry = entries.nextElement(); 214 System.out.println(entry.getName());215 if (false) {214 if (tileid.equals(entry.getName())) { 215 debug("found myself!"); 216 216 InputStream rawtile = zipFile.getInputStream(entry); 217 217 OsmImporter importer = new OsmImporter(); 218 System.out.println("loading raw osm");218 debug("loading raw osm"); 219 219 OsmImporterData temp = importer.loadLayer(rawtile, null, entry.getName(), null); 220 220 Main.worker.submit(temp.getPostLayerTask()); … … 248 248 buffer.add(m.group(0)); 249 249 } else { 250 sub_tiles.add(new CanVecTile(corda,last_cell,0,"", plugin_self,buffer));250 sub_tiles.add(new CanVecTile(corda,last_cell,0,"",this.layer,buffer)); 251 251 buffer = new ArrayList<String>(); 252 252 buffer.add(m.group(0)); … … 254 254 last_cell = cell; 255 255 } 256 sub_tiles.add(new CanVecTile(corda,last_cell,0,"", plugin_self,buffer));256 sub_tiles.add(new CanVecTile(corda,last_cell,0,"",this.layer,buffer)); 257 257 break; 258 258 case 2: … … 269 269 buffer.add(m.group(0)); 270 270 } else { 271 sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"", plugin_self,buffer));271 sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"",this.layer,buffer)); 272 272 buffer = new ArrayList<String>(); 273 273 buffer.add(m.group(0)); … … 275 275 last_cell2 = cell; 276 276 } 277 if (last_cell2 != -1) sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"", plugin_self,buffer));277 if (last_cell2 != -1) sub_tiles.add(new CanVecTile(corda,cordb,last_cell2,"",this.layer,buffer)); 278 278 break; 279 279 } … … 283 283 boolean show_sub_tiles = false; 284 284 if (!isVisible(bounds)) return; 285 if (depth == 4) { 286 layer.openable.add(this); 287 } 285 288 if ((depth == 3) && (bounds.getArea() < 0.5)) { // 022B01 286 if (max_zoom == 4) downloadSelf(); 287 show_sub_tiles = true; 289 if (zip_scanned) { 290 show_sub_tiles = true; 291 } else if (can_download) { 292 downloadSelf(); 293 show_sub_tiles = true; 294 } else { 295 layer.downloadable.add(this); 296 } 288 297 } else if ((depth == 2) && (bounds.getArea() < 20)) { // its a layer2 tile 289 298 make_sub_tiles(2); -
applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_layer.java
r27926 r27950 1 1 package org.openstreetmap.josm.plugins.canvec_helper; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 import org.openstreetmap.josm.gui.layer.Layer; 3 import java.awt.Color; 5 4 import java.awt.Component; 6 import java.awt.Graphics2D;7 5 import java.awt.event.ActionEvent; 8 6 import java.awt.event.MouseEvent; 9 7 import java.awt.event.MouseListener; 8 import java.awt.Graphics2D; 10 9 import java.awt.Point; 11 import java.awt.Color;12 10 import java.awt.Toolkit; 13 11 import java.io.BufferedReader; 14 12 import java.io.InputStreamReader; 15 13 import java.io.IOException; 16 14 import java.util.ArrayList; 15 import java.util.List; 16 import java.util.regex.Matcher; 17 import java.util.regex.Pattern; 18 import java.util.zip.ZipException; 17 19 import javax.swing.AbstractAction; 18 20 import javax.swing.Action; … … 21 23 import javax.swing.JMenu; 22 24 import javax.swing.JMenuItem; 23 import org.openstreetmap.josm.actions.RenameLayerAction;25 //import org.openstreetmap.josm.actions.RenameLayerAction; 24 26 import org.openstreetmap.josm.data.Bounds; 25 27 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 26 import org.openstreetmap.josm.io.MirroredInputStream;27 28 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 28 29 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 30 import org.openstreetmap.josm.gui.layer.Layer; 29 31 import org.openstreetmap.josm.gui.MapView; 30 import java.util.ArrayList; 31 import java.util.zip.ZipException; 32 import java.util.regex.Pattern; 33 import java.util.regex.Matcher; 34 import java.util.List; 32 import org.openstreetmap.josm.io.MirroredInputStream; 33 import static org.openstreetmap.josm.tools.I18n.tr; 35 34 36 35 // most of the layout was copied from the openstreetbugs plugin to get things started 37 36 public class canvec_layer extends Layer implements MouseListener { 38 37 private Icon layerIcon = null; 39 private int max_zoom = 3;40 canvec_helper plugin_self;38 private int max_zoom = 4; 39 public canvec_helper plugin_self; 41 40 private ArrayList<CanVecTile> tiles = new ArrayList<CanVecTile>(); 41 public ArrayList<CanVecTile> downloadable = new ArrayList<CanVecTile>(); 42 public ArrayList<CanVecTile> openable = new ArrayList<CanVecTile>(); 42 43 43 44 public canvec_layer(String name,canvec_helper self){ … … 65 66 list.add(m.group(0)); 66 67 } else if (last_cell != -1) { 67 CanVecTile tile = new CanVecTile(last_cell,"",0,"", plugin_self,list);68 CanVecTile tile = new CanVecTile(last_cell,"",0,"",this,list); 68 69 if (tile.isValid()) tiles.add(tile); 69 70 list = new ArrayList<String>(); … … 73 74 } else System.out.print("bad line '" + line + "'\n"); 74 75 } 75 CanVecTile tile = new CanVecTile(last_cell,"",0,"", plugin_self,list);76 CanVecTile tile = new CanVecTile(last_cell,"",0,"",this,list); 76 77 if (tile.isValid()) tiles.add(tile); 77 78 … … 88 89 SeparatorLayerAction.INSTANCE, 89 90 new LayerListPopup.InfoAction(this), 90 new MaxZoomAction(this)}; 91 new MaxZoomAction(this), 92 new DownloadCanvecAction(this), 93 new OpenOsmAction(this)}; 91 94 } 92 95 public class MaxZoomAction extends AbstractAction implements LayerAction { … … 108 111 } 109 112 } 113 private class AllowDownload extends AbstractAction { 114 CanVecTile tile; 115 public AllowDownload(CanVecTile tile) { 116 super(tile.tileid); 117 this.tile = tile; 118 } 119 public void actionPerformed(ActionEvent arg0) { 120 tile.can_download = true; 121 } 122 } 123 private class OpenOsmAction extends AbstractAction implements LayerAction { 124 private canvec_layer layer; 125 public OpenOsmAction(canvec_layer layer) { 126 this.layer = layer; 127 } 128 public void actionPerformed(ActionEvent e) {} 129 public Component createMenuComponent() { 130 JMenu OpenOsm = new JMenu("Open tile"); 131 for (int i = 0; i < layer.openable.size(); i++) { 132 OpenOsm.add(new JMenuItem(new DoOpenOsm(layer.openable.get(i)))); 133 } 134 return OpenOsm; 135 } 136 public boolean supportLayers(List<Layer> layers) { 137 return false; 138 } 139 } 140 private class DoOpenOsm extends AbstractAction { 141 CanVecTile tile; 142 public DoOpenOsm(CanVecTile tile) { 143 super(tile.tileid); 144 this.tile = tile; 145 } 146 public void actionPerformed(ActionEvent e) { 147 tile.load_raw_osm(); 148 } 149 } 150 private class DownloadCanvecAction extends AbstractAction implements LayerAction { 151 private canvec_layer parent; 152 public DownloadCanvecAction(canvec_layer parent) { 153 this.parent = parent; 154 } 155 public void actionPerformed(ActionEvent e) {} 156 public boolean supportLayers(List<Layer> layers) { 157 return false; 158 } 159 public Component createMenuComponent() { 160 JMenu downloadCanvec = new JMenu("Download zip's"); 161 for (int i = 0; i < parent.downloadable.size(); i++) { 162 downloadCanvec.add(new JMenuItem(new AllowDownload(parent.downloadable.get(i)))); 163 } 164 return downloadCanvec; 165 } 166 } 110 167 public void setMaxZoom(int max_zoom) { 111 168 this.max_zoom = max_zoom; … … 124 181 public Icon getIcon() { return layerIcon; } 125 182 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 126 long start = System.currentTimeMillis();183 //long start = System.currentTimeMillis(); 127 184 //System.out.println("painting the area covered by "+bounds.toString()); 185 downloadable = new ArrayList<CanVecTile>(); 186 openable = new ArrayList<CanVecTile>(); 128 187 // loop over each canvec tile in the db and check bounds.intersects(Bounds) 129 188 g.setColor(Color.red);
Note:
See TracChangeset
for help on using the changeset viewer.