Changeset 15091 in osm for applications/editors
- Timestamp:
- 2009-05-17T13:19:29+02:00 (15 years ago)
- 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 8 8 import java.util.Date; 9 9 import java.util.Iterator; 10 import java.util.Random; 10 11 import java.util.Set; 11 12 import java.util.TreeMap; 12 13 import javax.imageio.*; 13 14 14 15 15 import org.openstreetmap.josm.Main; … … 24 24 // If the cache is full, we don't want to delete just one file 25 25 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; 26 28 27 29 Cache() { … … 73 75 } 74 76 75 // Clean up must be called manually77 checkCleanUp(); 76 78 } 77 79 … … 79 81 saveImg(ident, image); 80 82 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(); 81 90 } 82 91 … … 112 121 } 113 122 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 114 131 private long getDirSize() { 132 if(disabled) return -1; 115 133 long dirsize = 0; 116 134 … … 121 139 122 140 private File[] getFiles() { 141 if(disabled) return null; 123 142 return dir.listFiles( 124 143 new FileFilter() { -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java
r13741 r15091 1 1 package wmsplugin; 2 2 3 import java.awt.Color; 3 4 import java.awt.Dimension; 4 5 import java.awt.Graphics; … … 80 81 // Zooming is still slow because the images need to be resized 81 82 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);*/ 82 85 g.drawImage(reImg, minPt.x, maxPt.y, null); 83 86 return true; … … 120 123 121 124 reImgHash.setSize(width, height); 125 /*g.setColor(Color.RED); 126 g.drawRect(minPt.x, minPt.y-height, width, height);*/ 122 127 g.drawImage(reImg, minPt.x, maxPt.y, null); 123 128 } … … 153 158 154 159 private Image clearAlpha(Image img) { 155 156 157 158 159 160 161 162 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); 163 168 164 165 169 return out_img; 170 } 166 171 167 172 public void flushedResizedCachedInstance() { -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Grabber.java
r13673 r15091 12 12 import java.awt.Font; 13 13 import javax.swing.JOptionPane; 14 import org.openstreetmap.josm.data.coor.LatLon; 14 15 15 16 abstract public class Grabber implements Runnable { … … 21 22 protected GeorefImage image; 22 23 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 26 46 this.proj = proj; 27 47 this.pixelPerDegree = pixelPerDegree; -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java
r13796 r15091 42 42 */ 43 43 public class WMSLayer extends Layer { 44 45 44 protected static final Icon icon = 46 45 new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png"))); … … 80 79 mv = Main.map.mapView; 81 80 getPPD(); 82 81 83 82 executor = Executors.newFixedThreadPool(3); 84 83 } 85 84 85 @Override 86 86 public void destroy() { 87 try { 88 executor.shutdown(); 87 try { 88 executor.shutdown(); 89 89 // Might not be initalized, so catch NullPointer as well 90 90 } catch(Exception x) {} … … 172 172 return; 173 173 } 174 174 175 175 for(int x = bminx; x<bmaxx; ++x) 176 176 for(int y = bminy; y<bmaxy; ++y){ 177 177 GeorefImage img = images[modulo(x,dax)][modulo(y,day)]; 178 g.drawRect(x, y, dax, bminy); 178 179 if(!img.paint(g, mv, dx, dy) && !img.downloadingStarted){ 179 180 img.downloadingStarted = true; … … 184 185 } 185 186 } 186 187 new wmsplugin.Cache().cleanUp();188 187 } 189 188 … … 248 247 } 249 248 } 250 249 251 250 public class reloadErrorTilesAction extends AbstractAction { 252 251 public reloadErrorTilesAction() { … … 254 253 } 255 254 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 256 259 for (int x = 0; x < dax; ++x) { 257 260 for (int y = 0; y < day; ++y) { … … 266 269 } 267 270 } 268 271 269 272 public class ToggleAlphaAction extends AbstractAction { 270 273 public ToggleAlphaAction() { … … 275 278 boolean alphaChannel = checkbox.isSelected(); 276 279 Main.pref.put("wmsplugin.alpha_channel", alphaChannel); 277 280 278 281 // clear all resized cached instances and repaint the layer 279 282 for (int x = 0; x < dax; ++x) { -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java
r14120 r15091 37 37 static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>(); 38 38 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; 39 43 40 44 // remember state of menu item to restore on changed preferences … … 77 81 78 82 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 79 99 int prefid = 0; 80 100 String name = null; -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java
r13497 r15091 1 1 package wmsplugin; 2 2 3 import java.awt.BorderLayout; 4 import java.awt.FlowLayout; 5 import javax.swing.JCheckBox; 6 import javax.swing.JSpinner; 7 import javax.swing.SpinnerNumberModel; 8 import org.openstreetmap.josm.Main; 3 9 import static org.openstreetmap.josm.tools.I18n.tr; 4 10 … … 9 15 import java.util.HashMap; 10 16 import java.util.Map; 11 12 17 13 18 import javax.swing.Box; … … 21 26 import javax.swing.table.DefaultTableModel; 22 27 23 24 28 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 25 29 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; … … 27 31 28 32 public class WMSPreferenceEditor implements PreferenceSetting { 29 30 33 private Map<String,String> orig; 31 34 private DefaultTableModel model; 32 35 private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>(); 36 37 JCheckBox overlapCheckBox; 38 JSpinner spinLat; 39 JSpinner spinLon; 33 40 34 41 public void addGui(final PreferenceDialog gui) { … … 59 66 } 60 67 68 JPanel buttonPanel = new JPanel(new FlowLayout()); 69 61 70 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)); 64 72 add.addActionListener(new ActionListener(){ 65 73 public void actionPerformed(ActionEvent e) { … … 79 87 80 88 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)); 82 90 delete.addActionListener(new ActionListener(){ 83 91 public void actionPerformed(ActionEvent e) { … … 94 102 95 103 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)); 97 105 copy.addActionListener(new ActionListener(){ 98 106 public void actionPerformed(ActionEvent e) { … … 107 115 } 108 116 }); 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); 109 135 } 110 136 … … 145 171 146 172 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 147 182 return false; 148 183 }
Note:
See TracChangeset
for help on using the changeset viewer.