Ignore:
Timestamp:
2009-05-17T13:19:29+02:00 (16 years ago)
Author:
stoecker
Message:

close #2589, #2310

Location:
applications/editors/josm/plugins/wmsplugin/src/wmsplugin
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Cache.java

    r13927 r15091  
    88import java.util.Date;
    99import java.util.Iterator;
     10import java.util.Random;
    1011import java.util.Set;
    1112import java.util.TreeMap;
    1213import javax.imageio.*;
    13 
    1414
    1515import org.openstreetmap.josm.Main;
     
    2424    // If the cache is full, we don't want to delete just one file
    2525    private final int cleanUpThreshold = 20;
     26    // After how many file-writes do we want to check if the cache needs emptying?
     27    private final int cleanUpInterval = 5;
    2628
    2729    Cache() {
     
    7375        }
    7476
    75         // Clean up must be called manually
     77        checkCleanUp();
    7678    }
    7779
     
    7981        saveImg(ident, image);
    8082        return image;
     83    }
     84
     85    public void checkCleanUp() {
     86        // The Cache class isn't persistent in its current implementation,
     87        // therefore clean up on random intervals, but not every write
     88        if(new Random().nextInt(cleanUpInterval) == 0)
     89            cleanUp();
    8190    }
    8291
     
    112121    }
    113122
     123    public void deleteSmallFiles(int size) {
     124        if(disabled) return;
     125        for(File f : getFiles()) {
     126            if(f.length() < size)
     127                f.delete();
     128        }
     129    }
     130
    114131    private long getDirSize() {
     132        if(disabled) return -1;
    115133        long dirsize = 0;
    116134
     
    121139
    122140    private File[] getFiles() {
     141        if(disabled) return null;
    123142        return dir.listFiles(
    124143            new FileFilter() {
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java

    r13741 r15091  
    11package wmsplugin;
    22
     3import java.awt.Color;
    34import java.awt.Dimension;
    45import java.awt.Graphics;
     
    8081        // Zooming is still slow because the images need to be resized
    8182        if(diffx >= 0 && diffx <= 2 && diffy >= 0 && diffy <= 2 && reImg != null) {
     83            /*g.setColor(Color.RED);
     84              g.drawRect(minPt.x, minPt.y-height, width, height);*/
    8285            g.drawImage(reImg, minPt.x, maxPt.y, null);
    8386            return true;
     
    120123
    121124                reImgHash.setSize(width, height);
     125                /*g.setColor(Color.RED);
     126                  g.drawRect(minPt.x, minPt.y-height, width, height);*/
    122127                g.drawImage(reImg, minPt.x, maxPt.y, null);
    123128            }
     
    153158
    154159    private Image clearAlpha(Image img) {
    155                 ImageProducer ip = img.getSource();
    156                 RGBImageFilter filter = new RGBImageFilter() {
    157                         public int filterRGB(int x, int y, int rgb) {
    158                                 return rgb | 0xff000000;
    159                         }
    160                 };
    161                 ImageProducer filt_ip = new FilteredImageSource(ip, filter);
    162                 Image out_img = Toolkit.getDefaultToolkit().createImage(filt_ip);
     160        ImageProducer ip = img.getSource();
     161        RGBImageFilter filter = new RGBImageFilter() {
     162            public int filterRGB(int x, int y, int rgb) {
     163                return rgb | 0xff000000;
     164            }
     165        };
     166        ImageProducer filt_ip = new FilteredImageSource(ip, filter);
     167        Image out_img = Toolkit.getDefaultToolkit().createImage(filt_ip);
    163168
    164                 return out_img;
    165         }
     169        return out_img;
     170    }
    166171
    167172    public void flushedResizedCachedInstance() {
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Grabber.java

    r13673 r15091  
    1212import java.awt.Font;
    1313import javax.swing.JOptionPane;
     14import org.openstreetmap.josm.data.coor.LatLon;
    1415
    1516abstract public class Grabber implements Runnable {
     
    2122    protected GeorefImage image;
    2223
    23     Grabber(Bounds b, Projection proj,
    24             double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
    25         this.b = b;
     24    Grabber(Bounds b, Projection proj, double pixelPerDegree, GeorefImage image,
     25    MapView mv, WMSLayer layer)
     26    {
     27        if (b.min != null && b.max != null && WMSPlugin.doOverlap)
     28        {
     29            double latCent = (b.min.lat() + b.max.lat()) / 2;
     30            double lonCent = (b.min.lon() + b.max.lon()) / 2;
     31
     32            double latSize =  b.max.lat() - b.min.lat();
     33            double lonSize =  b.max.lon() - b.min.lon();
     34
     35            double latCoef = (100.0 + WMSPlugin.overlapLat) / 100.0 / 2.0;
     36            double lonCoef = (100.0 + WMSPlugin.overlapLon) / 100.0 / 2.0;
     37
     38            this.b = new Bounds( new LatLon(latCent - latCoef * latSize,
     39                                            lonCent - lonCoef * lonSize),
     40                                 new LatLon(latCent + latCoef * latSize,
     41                                            lonCent + lonCoef * lonSize));
     42        }
     43        else
     44            this.b = b;
     45
    2646        this.proj = proj;
    2747        this.pixelPerDegree = pixelPerDegree;
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r13796 r15091  
    4242 */
    4343public class WMSLayer extends Layer {
    44 
    4544    protected static final Icon icon =
    4645        new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png")));
     
    8079        mv = Main.map.mapView;
    8180        getPPD();
    82        
     81
    8382        executor = Executors.newFixedThreadPool(3);
    8483    }
    85    
     84
     85    @Override
    8686    public void destroy() {
    87         try { 
    88             executor.shutdown(); 
     87        try {
     88            executor.shutdown();
    8989        // Might not be initalized, so catch NullPointer as well
    9090        } catch(Exception x) {}
     
    172172            return;
    173173        }
    174        
     174
    175175        for(int x = bminx; x<bmaxx; ++x)
    176176            for(int y = bminy; y<bmaxy; ++y){
    177177                GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
     178                g.drawRect(x, y, dax, bminy);
    178179                if(!img.paint(g, mv, dx, dy) && !img.downloadingStarted){
    179180                    img.downloadingStarted = true;
     
    184185            }
    185186        }
    186 
    187         new wmsplugin.Cache().cleanUp();
    188187    }
    189188
     
    248247        }
    249248    }
    250    
     249
    251250    public class reloadErrorTilesAction extends AbstractAction {
    252251        public reloadErrorTilesAction() {
     
    254253        }
    255254        public void actionPerformed(ActionEvent ev) {
     255            // Delete small files, because they're probably blank tiles.
     256            // See https://josm.openstreetmap.de/ticket/2307
     257            new wmsplugin.Cache().deleteSmallFiles(2048);
     258
    256259            for (int x = 0; x < dax; ++x) {
    257260                for (int y = 0; y < day; ++y) {
     
    266269        }
    267270    }
    268    
     271
    269272    public class ToggleAlphaAction extends AbstractAction {
    270273        public ToggleAlphaAction() {
     
    275278            boolean alphaChannel = checkbox.isSelected();
    276279            Main.pref.put("wmsplugin.alpha_channel", alphaChannel);
    277            
     280
    278281            // clear all resized cached instances and repaint the layer
    279282            for (int x = 0; x < dax; ++x) {
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java

    r14120 r15091  
    3737    static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>();
    3838    static TreeMap<String,String> wmsListDefault = new TreeMap<String,String>();
     39
     40    static boolean doOverlap = false;
     41    static int overlapLat = 4;
     42    static int overlapLon = 14;
    3943
    4044    // remember state of menu item to restore on changed preferences
     
    7781
    7882        TreeSet<String> keys = new TreeSet<String>(prefs.keySet());
     83
     84        // Here we load the settings for "overlap" checkbox and spinboxes.
     85
     86        try {
     87            doOverlap = Boolean.valueOf(prefs.get("wmsplugin.url.overlap"));
     88        } catch (Exception e) {} // If sth fails, we drop to default settings.
     89
     90        try {
     91            overlapLat = Integer.valueOf(prefs.get("wmsplugin.url.overlapLat"));
     92        } catch (Exception e) {} // If sth fails, we drop to default settings.
     93
     94        try {
     95            overlapLon = Integer.valueOf(prefs.get("wmsplugin.url.overlapLon"));
     96        } catch (Exception e) {} // If sth fails, we drop to default settings.
     97
     98        // And then the names+urls of WMS servers
    7999        int prefid = 0;
    80100        String name = null;
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java

    r13497 r15091  
    11package wmsplugin;
    22
     3import java.awt.BorderLayout;
     4import java.awt.FlowLayout;
     5import javax.swing.JCheckBox;
     6import javax.swing.JSpinner;
     7import javax.swing.SpinnerNumberModel;
     8import org.openstreetmap.josm.Main;
    39import static org.openstreetmap.josm.tools.I18n.tr;
    410
     
    915import java.util.HashMap;
    1016import java.util.Map;
    11 
    1217
    1318import javax.swing.Box;
     
    2126import javax.swing.table.DefaultTableModel;
    2227
    23 
    2428import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
    2529import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
     
    2731
    2832public class WMSPreferenceEditor implements PreferenceSetting {
    29 
    3033    private Map<String,String> orig;
    3134    private DefaultTableModel model;
    3235    private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>();
     36
     37    JCheckBox overlapCheckBox;
     38    JSpinner spinLat;
     39    JSpinner spinLon;
    3340
    3441    public void addGui(final PreferenceDialog gui) {
     
    5966        }
    6067
     68        JPanel buttonPanel = new JPanel(new FlowLayout());
     69
    6170        JButton add = new JButton(tr("Add"));
    62         p.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
    63         p.add(add, GBC.std().insets(0,5,0,0));
     71        buttonPanel.add(add, GBC.std().insets(0,5,0,0));
    6472        add.addActionListener(new ActionListener(){
    6573            public void actionPerformed(ActionEvent e) {
     
    7987
    8088        JButton delete = new JButton(tr("Delete"));
    81         p.add(delete, GBC.std().insets(0,5,0,0));
     89        buttonPanel.add(delete, GBC.std().insets(0,5,0,0));
    8290        delete.addActionListener(new ActionListener(){
    8391            public void actionPerformed(ActionEvent e) {
     
    94102
    95103        JButton copy = new JButton(tr("Copy Default"));
    96         p.add(copy, GBC.std().insets(0,5,0,0));
     104        buttonPanel.add(copy, GBC.std().insets(0,5,0,0));
    97105        copy.addActionListener(new ActionListener(){
    98106            public void actionPerformed(ActionEvent e) {
     
    107115            }
    108116        });
     117
     118        p.add(buttonPanel);
     119        p.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
     120
     121        overlapCheckBox = new JCheckBox(tr("Overlap tiles"), WMSPlugin.doOverlap );
     122        JLabel labelLat = new JLabel(tr("% of lat:"));
     123        JLabel labelLon = new JLabel(tr("% of lon:"));
     124        spinLat = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapLat, 1, 50, 1));
     125        spinLon = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapLon, 1, 50, 1));
     126
     127        JPanel overlapPanel = new JPanel(new FlowLayout());
     128        overlapPanel.add(overlapCheckBox);
     129        overlapPanel.add(labelLat);
     130        overlapPanel.add(spinLat);
     131        overlapPanel.add(labelLon);
     132        overlapPanel.add(spinLon);
     133
     134        p.add(overlapPanel);
    109135    }
    110136
     
    145171
    146172        if (change) WMSPlugin.refreshMenu();
     173
     174        WMSPlugin.doOverlap = overlapCheckBox.getModel().isSelected();
     175        WMSPlugin.overlapLat = (Integer) spinLat.getModel().getValue();
     176        WMSPlugin.overlapLon = (Integer) spinLon.getModel().getValue();
     177
     178        Main.pref.put("wmsplugin.url.overlap",    String.valueOf(WMSPlugin.doOverlap));
     179        Main.pref.put("wmsplugin.url.overlapLat", String.valueOf(WMSPlugin.overlapLat));
     180        Main.pref.put("wmsplugin.url.overlapLon", String.valueOf(WMSPlugin.overlapLon));
     181
    147182        return false;
    148183    }
Note: See TracChangeset for help on using the changeset viewer.