Changeset 27950 in osm for applications


Ignore:
Timestamp:
2012-02-27T05:13:26+01:00 (12 years ago)
Author:
clever
Message:

you can now control when it downloads tiles and open the tiles from within josm!

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  
    44import java.util.Enumeration;
    55import java.util.zip.ZipEntry;
    6 import java.util.zip.ZipException;
    76import java.util.zip.ZipFile;
    87import java.util.regex.Pattern;
     
    2423
    2524public class CanVecTile {
    26         canvec_helper plugin_self;
     25        canvec_layer layer;
     26        public boolean can_download = false;
    2727        private ArrayList<String> sub_tile_ids = new ArrayList<String>();
    2828        private boolean zip_scanned = false;
     
    3838        String cordb,cordd;
    3939        private Bounds bounds;
    40         private String tileid;
    41         public CanVecTile(String tileid,canvec_helper self) {
     40        public String tileid;
     41        public CanVecTile(String tileid,canvec_layer layer) {
    4242                String parta,partb,partc,partd;
    4343                parta = tileid.substring(0,3);
     
    4848                a = Integer.parseInt(parta);
    4949                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) {
    5656                this.index = index;
    57                 plugin_self = self;
     57                this.layer = layer;
    5858                corda = a;
    5959                cordb = b;
     
    181181        }
    182182        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);
    184184                download_path.mkdir();
    185185                MirroredInputStream tile_zip;
     
    201201                        sub_tile_ids.add(entry.getName());
    202202                        zip_scanned = true;
    203                         CanVecTile final_tile = new CanVecTile(entry.getName(),plugin_self);
     203                        CanVecTile final_tile = new CanVecTile(entry.getName(),layer);
    204204                        if (final_tile.isValid()) sub_tiles.add(final_tile);
    205205                }
    206206        }
    207         private void load_raw_osm() {
     207        public void load_raw_osm() {
    208208                ZipFile zipFile;
    209209                try {
     
    212212                        while (entries.hasMoreElements()) {
    213213                                ZipEntry entry = entries.nextElement();
    214                                 System.out.println(entry.getName());
    215                                 if (false) {
     214                                if (tileid.equals(entry.getName())) {
     215                                        debug("found myself!");
    216216                                        InputStream rawtile = zipFile.getInputStream(entry);
    217217                                        OsmImporter importer = new OsmImporter();
    218                                         System.out.println("loading raw osm");
     218                                        debug("loading raw osm");
    219219                                        OsmImporterData temp = importer.loadLayer(rawtile, null, entry.getName(), null);
    220220                                        Main.worker.submit(temp.getPostLayerTask());
     
    248248                                        buffer.add(m.group(0));
    249249                                } 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));
    251251                                        buffer = new ArrayList<String>();
    252252                                        buffer.add(m.group(0));
     
    254254                                last_cell = cell;
    255255                        }
    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));
    257257                        break;
    258258                case 2:
     
    269269                                        buffer.add(m.group(0));
    270270                                } 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));
    272272                                        buffer = new ArrayList<String>();
    273273                                        buffer.add(m.group(0));
     
    275275                                last_cell2 = cell;
    276276                        }
    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));
    278278                        break;
    279279                }
     
    283283                boolean show_sub_tiles = false;
    284284                if (!isVisible(bounds)) return;
     285                if (depth == 4) {
     286                        layer.openable.add(this);
     287                }
    285288                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                        }
    288297                } else if ((depth == 2) && (bounds.getArea() < 20)) { // its a layer2 tile
    289298                        make_sub_tiles(2);
  • applications/editors/josm/plugins/canvec_helper/src/org/openstreetmap/josm/plugins/canvec_helper/canvec_layer.java

    r27926 r27950  
    11package org.openstreetmap.josm.plugins.canvec_helper;
    22
    3 import static org.openstreetmap.josm.tools.I18n.tr;
    4 import org.openstreetmap.josm.gui.layer.Layer;
     3import java.awt.Color;
    54import java.awt.Component;
    6 import java.awt.Graphics2D;
    75import java.awt.event.ActionEvent;
    86import java.awt.event.MouseEvent;
    97import java.awt.event.MouseListener;
     8import java.awt.Graphics2D;
    109import java.awt.Point;
    11 import java.awt.Color;
    1210import java.awt.Toolkit;
    1311import java.io.BufferedReader;
    1412import java.io.InputStreamReader;
    1513import java.io.IOException;
    16 
     14import java.util.ArrayList;
     15import java.util.List;
     16import java.util.regex.Matcher;
     17import java.util.regex.Pattern;
     18import java.util.zip.ZipException;
    1719import javax.swing.AbstractAction;
    1820import javax.swing.Action;
     
    2123import javax.swing.JMenu;
    2224import javax.swing.JMenuItem;
    23 import org.openstreetmap.josm.actions.RenameLayerAction;
     25//import org.openstreetmap.josm.actions.RenameLayerAction;
    2426import org.openstreetmap.josm.data.Bounds;
    2527import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    26 import org.openstreetmap.josm.io.MirroredInputStream;
    2728import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    2829import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     30import org.openstreetmap.josm.gui.layer.Layer;
    2931import 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;
     32import org.openstreetmap.josm.io.MirroredInputStream;
     33import static org.openstreetmap.josm.tools.I18n.tr;
    3534
    3635// most of the layout was copied from the openstreetbugs plugin to get things started
    3736public class canvec_layer extends Layer implements MouseListener {
    3837        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;
    4140        private ArrayList<CanVecTile> tiles = new ArrayList<CanVecTile>();
     41        public ArrayList<CanVecTile> downloadable = new ArrayList<CanVecTile>();
     42        public ArrayList<CanVecTile> openable = new ArrayList<CanVecTile>();
    4243
    4344        public canvec_layer(String name,canvec_helper self){
     
    6566                                                list.add(m.group(0));
    6667                                        } 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);
    6869                                                if (tile.isValid()) tiles.add(tile);
    6970                                                list = new ArrayList<String>();
     
    7374                                } else System.out.print("bad line '" + line + "'\n");
    7475                        }
    75                         CanVecTile tile = new CanVecTile(last_cell,"",0,"",plugin_self,list);
     76                        CanVecTile tile = new CanVecTile(last_cell,"",0,"",this,list);
    7677                        if (tile.isValid()) tiles.add(tile);
    7778
     
    8889                        SeparatorLayerAction.INSTANCE,
    8990                        new LayerListPopup.InfoAction(this),
    90                         new MaxZoomAction(this)};
     91                        new MaxZoomAction(this),
     92                        new DownloadCanvecAction(this),
     93                        new OpenOsmAction(this)};
    9194        }
    9295        public class MaxZoomAction extends AbstractAction implements LayerAction {
     
    108111                }
    109112        }
     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        }
    110167        public void setMaxZoom(int max_zoom) {
    111168                this.max_zoom = max_zoom;
     
    124181        public Icon getIcon() { return layerIcon; }
    125182        public void paint(Graphics2D g, MapView mv, Bounds bounds) {
    126                 long start = System.currentTimeMillis();
     183                //long start = System.currentTimeMillis();
    127184                //System.out.println("painting the area covered by "+bounds.toString());
     185                downloadable = new ArrayList<CanVecTile>();
     186                openable = new ArrayList<CanVecTile>();
    128187                // loop over each canvec tile in the db and check bounds.intersects(Bounds)
    129188                g.setColor(Color.red);
Note: See TracChangeset for help on using the changeset viewer.