Changeset 34668 in osm for applications/editors/josm/plugins
- Timestamp:
- 2018-09-22T15:26:51+02:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionBoundaries.java
r34458 r34668 2 2 package org.openstreetmap.josm.plugins.fr.cadastre.actions; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 … … 13 14 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer; 14 15 16 /** 17 * Extract commune boundary 18 */ 15 19 public class MenuActionBoundaries extends JosmAction { 16 20 17 p ublicstatic final String NAME = "Administrative boundary";21 private static final String NAME = marktr("Administrative boundary"); 18 22 19 23 private static final long serialVersionUID = 1L; -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionCancelGrab.java
r33638 r34668 10 10 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer; 11 11 12 @SuppressWarnings("serial") 12 /** 13 * Cancel current grab (only vector images) 14 */ 13 15 public class MenuActionCancelGrab extends JosmAction { 14 16 15 p ublicstatic final String NAME = marktr("Cancel current grab");17 private static final String NAME = marktr("Cancel current grab"); 16 18 17 19 private WMSLayer wmsLayer; -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrab.java
r33640 r34668 20 20 public class MenuActionGrab extends JosmAction { 21 21 22 p ublicstatic final String NAME = marktr("Cadastre grab");22 private static final String NAME = marktr("Cadastre grab"); 23 23 24 24 /** -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java
r34458 r34668 18 18 import org.openstreetmap.josm.spi.preferences.Config; 19 19 20 /** 21 * Grab non-georeferenced image 22 */ 20 23 public class MenuActionGrabPlanImage extends JosmAction implements Runnable { 21 24 -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionLoadFromCache.java
r34458 r34668 22 22 import org.openstreetmap.josm.tools.Logging; 23 23 24 /** 25 * Load location from cache (only if cache is enabled) 26 */ 24 27 public class MenuActionLoadFromCache extends JosmAction { 25 28 private static final long serialVersionUID = 1L; 26 29 27 p ublicstatic final String name = marktr("Load layer from cache");30 private static final String name = marktr("Load layer from cache"); 28 31 29 32 /** … … 49 52 String ext = (filename.lastIndexOf('.') == -1) ? "" : filename.substring(filename.lastIndexOf('.')+1, filename.length()); 50 53 if ((ext.length() == 3 && ext.substring(0, CacheControl.C_LAMBERT_CC_9Z.length()).equals(CacheControl.C_LAMBERT_CC_9Z) && 51 ! (CadastrePlugin.isLambert_cc9()))54 !CadastrePlugin.isLambert_cc9()) 52 55 || (ext.length() == 4 && ext.substring(0, CacheControl.C_UTM20N.length()).equals(CacheControl.C_UTM20N) && 53 56 !(CadastrePlugin.isUtm_france_dom())) 54 || (ext.length() == 1 ) && !(CadastrePlugin.isLambert())) {57 || (ext.length() == 1 && !CadastrePlugin.isLambert())) { 55 58 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 56 59 tr("{0} not allowed with the current projection", filename), -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionNewLocation.java
r34458 r34668 24 24 import org.openstreetmap.josm.tools.Logging; 25 25 26 /** 27 * Set a new location for the next request 28 */ 26 29 public class MenuActionNewLocation extends JosmAction { 27 30 … … 59 62 // CHECKSTYLE.ON: LineLength 60 63 64 /** 65 * Constructs a new {@code MenuActionNewLocation}. 66 */ 61 67 public MenuActionNewLocation() { 62 68 super(tr("Change location"), "cadastre_small", tr("Set a new location for the next request"), null, false, -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionOpenPreferences.java
r34458 r34668 12 12 import org.openstreetmap.josm.plugins.fr.cadastre.preferences.CadastrePreferenceSetting; 13 13 14 /** 15 * Open Cadastre Preferences 16 */ 14 17 public class MenuActionOpenPreferences extends JosmAction { 15 private static final long serialVersionUID = 1L;16 18 17 p ublicstatic final String NAME = marktr("Preferences");19 private static final String NAME = marktr("Preferences"); 18 20 19 21 /** -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java
r33640 r34668 13 13 import org.openstreetmap.josm.tools.Logging; 14 14 15 /** 16 * Improve georeferencing (only raster images) 17 */ 15 18 public class MenuActionRefineGeoRef extends JosmAction { 16 19 17 p ublicstatic final String NAME = marktr("Refine georeferencing");20 private static final String NAME = marktr("Refine georeferencing"); 18 21 19 22 private WMSLayer wmsLayer; -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionResetCookie.java
r33638 r34668 8 8 import org.openstreetmap.josm.actions.JosmAction; 9 9 10 /** 11 * Get a new cookie (session timeout) 12 */ 10 13 public class MenuActionResetCookie extends JosmAction { 11 14 12 15 /** 13 * 16 * Constructs a new {@code MenuActionResetCookie} 14 17 */ 15 private static final long serialVersionUID = 1L;16 17 18 public MenuActionResetCookie() { 18 19 super(tr("Reset cookie"), "cadastre_small", tr("Get a new cookie (session timeout)"), null, false); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java
r34495 r34668 30 30 import org.openstreetmap.josm.tools.Logging; 31 31 32 /** 33 * Export image (only raster images) 34 */ 32 35 public class MenuActionSaveRasterAs extends JosmAction { 33 36 34 public static final String NAME = marktr("Save image as..."); 35 36 private static final long serialVersionUID = 1L; 37 private static final String NAME = marktr("Save image as..."); 37 38 38 39 private WMSLayer wmsLayer; 39 40 40 publicstatic class FiltrePng extends FileFilter {41 static class FiltrePng extends FileFilter { 41 42 @Override 42 43 public boolean accept(File file) { … … 53 54 } 54 55 55 publicstatic class FiltreTiff extends FileFilter {56 static class FiltreTiff extends FileFilter { 56 57 @Override 57 58 public boolean accept(File file) { … … 96 97 try { 97 98 ImageIO.write(bi, "png", file); 98 /*99 FileOutputStream flux = new FileOutputStream(file);100 BufferedOutputStream fluxBuf = new BufferedOutputStream(flux);101 JPEGImageEncoder codec = JPEGCodec.createJPEGEncoder(fluxBuf, JPEGCodec.getDefaultJPEGEncodeParam(bi));102 codec.encode(bi);103 fluxBuf.close();104 */105 99 } catch (IOException e) { 106 100 Logging.error(e); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoRecord.java
r33653 r34668 10 10 * Edigeo record. 11 11 */ 12 class EdigeoRecord { 12 final class EdigeoRecord { 13 13 14 14 enum Nature { -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheControl.java
r34458 r34668 64 64 public boolean isCachePipeEmpty() { 65 65 imagesLock.lock(); 66 boolean ret = imagesToSave.isEmpty(); 67 imagesLock.unlock(); 68 return ret; 66 try { 67 return imagesToSave.isEmpty(); 68 } finally { 69 imagesLock.unlock(); 70 } 69 71 } 70 72 … … 159 161 ObjectInputStream ois = new ObjectInputStream(fis); 160 162 ) { 161 successfulRead = wmsLayer.read(file, ois, currentLambertZone); 163 wmsLayer.setAssociatedFile(file); 164 successfulRead = wmsLayer.read(ois, currentLambertZone); 162 165 } catch (IOException | ClassNotFoundException ex) { 163 166 Logging.error(ex); … … 176 179 public synchronized void saveCache(GeorefImage image) { 177 180 imagesLock.lock(); 178 this.imagesToSave.add(image); 179 this.notifyAll(); 180 imagesLock.unlock(); 181 try { 182 this.imagesToSave.add(image); 183 this.notifyAll(); 184 } finally { 185 imagesLock.unlock(); 186 } 181 187 } 182 188 … … 203 209 try (ObjectOutputStream oos = new ObjectOutputStream( 204 210 new BufferedOutputStream(new FileOutputStream(file)))) { 205 wmsLayer.write(file, oos); 211 wmsLayer.setAssociatedFile(file); 212 wmsLayer.write(oos); 206 213 for (int i = 0; i < size; i++) { 207 214 oos.writeObject(imagesToSave.get(i)); … … 213 220 } 214 221 imagesLock.lock(); 215 for (int i = 0; i < size; i++) { 216 imagesToSave.remove(0); 217 } 218 imagesLock.unlock(); 222 try { 223 for (int i = 0; i < size; i++) { 224 imagesToSave.remove(0); 225 } 226 } finally { 227 imagesLock.unlock(); 228 } 219 229 } 220 230 try { -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java
r34458 r34668 536 536 if (MainApplication.getMap() != null) { 537 537 for (Layer l : MainApplication.getLayerManager().getLayers()) { 538 if (l instanceof WMSLayer && l.getName().equals(wmsLayer.getName()) && (!l.equals(wmsLayer))) {538 if (l instanceof WMSLayer && l.getName().equals(wmsLayer.getName()) && !l.equals(wmsLayer)) { 539 539 Logging.info("Try to grab into a new layer when "+wmsLayer.getName()+" is already opened."); 540 540 // remove the duplicated layer -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/GrabThread.java
r34223 r34668 40 40 void addImages(ArrayList<EastNorthBound> moreImages) { 41 41 lockImagesToGrag.lock(); 42 imagesToGrab.addAll(moreImages); 43 lockImagesToGrag.unlock(); 42 try { 43 imagesToGrab.addAll(moreImages); 44 } finally { 45 lockImagesToGrag.unlock(); 46 } 44 47 synchronized (this) { 45 48 this.notify(); … … 53 56 public int getImagesToGrabSize() { 54 57 lockImagesToGrag.lock(); 55 int size = imagesToGrab.size(); 56 lockImagesToGrag.unlock(); 57 return size; 58 try { 59 return imagesToGrab.size(); 60 } finally { 61 lockImagesToGrag.unlock(); 62 } 58 63 } 59 64 … … 61 66 ArrayList<EastNorthBound> copyList = new ArrayList<>(); 62 67 lockImagesToGrag.lock(); 63 for (EastNorthBound img : imagesToGrab) { 64 EastNorthBound imgCpy = new EastNorthBound(img.min, img.max); 65 copyList.add(imgCpy); 66 } 67 lockImagesToGrag.unlock(); 68 try { 69 for (EastNorthBound img : imagesToGrab) { 70 EastNorthBound imgCpy = new EastNorthBound(img.min, img.max); 71 copyList.add(imgCpy); 72 } 73 } finally { 74 lockImagesToGrag.unlock(); 75 } 68 76 return copyList; 69 77 } … … 71 79 void clearImagesToGrab() { 72 80 lockImagesToGrag.lock(); 73 imagesToGrab.clear(); 74 lockImagesToGrag.unlock(); 81 try { 82 imagesToGrab.clear(); 83 } finally { 84 lockImagesToGrag.unlock(); 85 } 75 86 } 76 87 … … 109 120 if (CadastrePlugin.backgroundTransparent) { 110 121 wmsLayer.imagesLock.lock(); 111 for (GeorefImage img : wmsLayer.getImages()) { 112 if (img.overlap(newImage)) 113 // mask overlapping zone in already grabbed image 114 img.withdraw(newImage); 115 else 116 // mask overlapping zone in new image only when new image covers completely the 117 // existing image 118 newImage.withdraw(img); 122 try { 123 for (GeorefImage img : wmsLayer.getImages()) { 124 if (img.overlap(newImage)) 125 // mask overlapping zone in already grabbed image 126 img.withdraw(newImage); 127 else 128 // mask overlapping zone in new image only when new image covers completely the 129 // existing image 130 newImage.withdraw(img); 131 } 132 } finally { 133 wmsLayer.imagesLock.unlock(); 119 134 } 120 wmsLayer.imagesLock.unlock();121 135 } 122 136 wmsLayer.addImage(newImage); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/WMSLayer.java
r34458 r34668 15 15 import java.awt.image.ImageObserver; 16 16 import java.io.EOFException; 17 import java.io.File;18 17 import java.io.IOException; 19 18 import java.io.ObjectInputStream; … … 61 60 private int lambertZone = -1; 62 61 63 publicCadastreGrabber grabber = new CadastreGrabber();62 CadastreGrabber grabber = new CadastreGrabber(); 64 63 65 64 protected static final Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage( … … 68 67 private Vector<GeorefImage> images = new Vector<>(); 69 68 70 publicLock imagesLock = new ReentrantLock();69 Lock imagesLock = new ReentrantLock(); 71 70 72 71 /** … … 77 76 protected final int serializeFormatVersion = 4; 78 77 79 publicstatic int currentFormat;78 static int currentFormat; 80 79 81 80 private ArrayList<EastNorthBound> dividedBbox = new ArrayList<>(); … … 87 86 private String codeCommune = ""; 88 87 89 publicEastNorthBound communeBBox = new EastNorthBound(new EastNorth(0, 0), new EastNorth(0, 0));88 EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0, 0), new EastNorth(0, 0)); 90 89 91 90 private boolean isRaster; 92 91 private boolean isAlreadyGeoreferenced; 93 publicdouble X0, Y0, angle, fX, fY;92 double X0, Y0, angle, fX, fY; 94 93 95 94 // bbox of the georeferenced raster image (the nice horizontal and vertical box) … … 99 98 100 99 // offset for vector images temporarily shifted (correcting Cadastre artifacts), in pixels 101 publicdouble deltaEast;102 publicdouble deltaNorth;100 double deltaEast; 101 double deltaNorth; 103 102 104 103 private Action saveAsPng; … … 300 299 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); 301 300 imagesLock.lock(); 302 for (GeorefImage img : images) { 303 img.paint(g, mv, CadastrePlugin.backgroundTransparent, 304 CadastrePlugin.transparency, CadastrePlugin.drawBoundaries); 305 } 306 imagesLock.unlock(); 301 try { 302 for (GeorefImage img : images) { 303 img.paint(g, mv, CadastrePlugin.backgroundTransparent, 304 CadastrePlugin.transparency, CadastrePlugin.drawBoundaries); 305 } 306 } finally { 307 imagesLock.unlock(); 308 } 307 309 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, savedInterpolation); 308 310 } … … 378 380 * The original raster size is [0,0,12286,8730] where 0,0 is the upper left corner and 379 381 * 12286,8730 is the approx. raster max size. 382 * @param min min east/north 383 * @param max max east/north 380 384 * @return the raster coordinates for the wms server request URL (minX,minY,maxX,maxY) 381 385 */ … … 456 460 * Called by CacheControl when a new cache file is created on disk. 457 461 * Save only primitives to keep cache independent of software changes. 458 */ 459 public void write(File associatedFile, ObjectOutputStream oos) throws IOException { 462 * @param oos output stream 463 * @throws IOException if any I/O error occurs 464 */ 465 public void write(ObjectOutputStream oos) throws IOException { 460 466 currentFormat = this.serializeFormatVersion; 461 setAssociatedFile(associatedFile);462 467 oos.writeInt(this.serializeFormatVersion); 463 468 oos.writeObject(this.location); // String … … 482 487 * Called by CacheControl when a cache file is read from disk. 483 488 * Cache uses only primitives to stay independent of software changes. 484 */ 485 public boolean read(File associatedFile, ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException { 486 currentFormat = ois.readInt();; 489 * @param ois input stream 490 * @param currentLambertZone current Lambert zone 491 * @return {@code true} for success 492 * @throws IOException if any I/O error occurs 493 * @throws ClassNotFoundException if class of a serialized object cannot be found 494 */ 495 public boolean read(ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException { 496 currentFormat = ois.readInt(); 487 497 if (currentFormat < 2) { 488 498 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), … … 495 505 this.lambertZone = ois.readInt(); 496 506 this.setRaster(ois.readBoolean()); 497 setAssociatedFile(associatedFile);498 507 if (currentFormat >= 4) 499 508 ois.readBoolean(); … … 587 596 * Works only for raster image layer (only one image in collection). 588 597 * Updates layer georeferences. 598 * @param en1 first east/north 599 * @param en2 second east/north 589 600 */ 590 601 public void cropImage(EastNorth en1, EastNorth en2) { … … 700 711 public GeorefImage getImage(int index) { 701 712 imagesLock.lock(); 702 GeorefImage img = null;703 713 try { 704 img = this.images.get(index);714 return images.get(index); 705 715 } catch (ArrayIndexOutOfBoundsException e) { 706 716 Logging.error(e); 707 } 708 imagesLock.unlock(); 709 return img; 717 return null; 718 } finally { 719 imagesLock.unlock(); 720 } 710 721 } 711 722 712 723 public Vector<GeorefImage> getImages() { 713 return this.images;724 return images; 714 725 } 715 726 … … 720 731 public void addImage(GeorefImage img) { 721 732 imagesLock.lock(); 722 this.images.add(img); 723 imagesLock.unlock(); 733 try { 734 images.add(img); 735 } finally { 736 imagesLock.unlock(); 737 } 724 738 } 725 739 726 740 public void setImages(Vector<GeorefImage> images) { 727 741 imagesLock.lock(); 728 this.images = images; 729 imagesLock.unlock(); 742 try { 743 this.images = images; 744 } finally { 745 imagesLock.unlock(); 746 } 730 747 } 731 748 732 749 public void clearImages() { 733 750 imagesLock.lock(); 734 this.images.clear(); 735 imagesLock.unlock(); 751 try { 752 images.clear(); 753 } finally { 754 imagesLock.unlock(); 755 } 736 756 } 737 757 }
Note:
See TracChangeset
for help on using the changeset viewer.