Ignore:
Timestamp:
2009-01-28T21:44:10+01:00 (16 years ago)
Author:
pieren
Message:

add municipality bbox in grab and cache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java

    r13382 r13426  
    99import java.awt.event.ActionEvent;
    1010import java.awt.image.BufferedImage;
     11import java.io.EOFException;
    1112import java.io.File;
    1213import java.io.FileInputStream;
     
    4546public class WMSLayer extends Layer {
    4647
    47     public class EastNorthBound {
    48         public EastNorth min, max;
    49         public EastNorthBound(EastNorth min, EastNorth max) {
    50             this.min = min;
    51             this.max = max;
    52         }
    53         @Override public String toString() {
    54             return "EastNorthBound[" + min.east() + "," + min.north() + "," + max.east() + "," + max.north() + "]";
    55         }
    56     }
    57    
    5848    Component[] component = null; 
    5949
     
    6555    protected ArrayList<GeorefImage> images = new ArrayList<GeorefImage>();
    6656   
    67     protected final int serializeFormatVersion = 1;
     57    protected final int serializeFormatVersion = 2;
    6858   
    6959    private ArrayList<EastNorthBound> dividedBbox = new ArrayList<EastNorthBound>();
     
    7464
    7565    private String codeCommune = "";
     66   
     67    private EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0,0), new EastNorth(0,0));
    7668   
    7769    private boolean isRaster = false;
     
    492484        }
    493485    }
     486   
     487    /**
     488     * Called by CacheControl when a new cache file is created on disk
     489     * @param oos
     490     * @throws IOException
     491     */
     492    public void write(ObjectOutputStream oos, ArrayList<GeorefImage> imgs) throws IOException {
     493        oos.writeInt(this.serializeFormatVersion);
     494        oos.writeObject(this.location);
     495        oos.writeObject(this.codeCommune);
     496        oos.writeInt(this.lambertZone);
     497        oos.writeBoolean(this.isRaster);
     498        if (this.isRaster) {
     499            oos.writeObject(this.rasterMin);
     500            oos.writeObject(this.rasterCenter);
     501            oos.writeDouble(this.rasterRatio);
     502        } else {
     503            oos.writeObject(this.communeBBox);
     504        }
     505        for (GeorefImage img : imgs) {
     506            oos.writeObject(img);
     507        }
     508    }
     509   
     510    /**
     511     * Called by CacheControl when a cache file is read from disk
     512     * @param ois
     513     * @throws IOException
     514     * @throws ClassNotFoundException
     515     */
     516    public boolean read(ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException {
     517        int sfv = ois.readInt();
     518        if (sfv != this.serializeFormatVersion) {
     519            JOptionPane.showMessageDialog(Main.parent, tr("Unsupported cache file version; found {0}, expected {1}\nCreate a new one.",
     520                    sfv, this.serializeFormatVersion), tr("Cache Format Error"), JOptionPane.ERROR_MESSAGE);
     521            return false;
     522        }
     523        this.setLocation((String) ois.readObject());
     524        this.setCodeCommune((String) ois.readObject());
     525        this.lambertZone = ois.readInt();
     526        this.isRaster = ois.readBoolean();
     527        if (this.isRaster) {
     528            this.rasterMin = (EastNorth) ois.readObject();
     529            this.rasterCenter = (EastNorth) ois.readObject();
     530            this.rasterRatio = ois.readDouble();
     531        } else {
     532            this.communeBBox = (EastNorthBound) ois.readObject();
     533        }
     534        if (this.lambertZone != currentLambertZone) {
     535            JOptionPane.showMessageDialog(Main.parent, tr("Lambert zone {0} in cache "+
     536                    " incompatible with current Lambert zone {1}",
     537                    this.lambertZone+1, currentLambertZone), tr("Cache Lambert Zone Error"), JOptionPane.ERROR_MESSAGE);
     538            return false;
     539        }
     540        boolean EOF = false;
     541        try {
     542            while (!EOF) {
     543                GeorefImage newImage = (GeorefImage) ois.readObject();
     544                for (GeorefImage img : this.images) {
     545                    if (CadastrePlugin.backgroundTransparent) {
     546                        if (img.overlap(newImage))
     547                            // mask overlapping zone in already grabbed image
     548                            img.withdraw(newImage);
     549                        else
     550                            // mask overlapping zone in new image only when
     551                            // new image covers completely the existing image
     552                            newImage.withdraw(img);
     553                    }
     554                }
     555                this.images.add(newImage);
     556            }
     557        } catch (EOFException ex) {
     558            // expected exception when all images are read
     559        }
     560        return true;
     561    }
    494562
    495563    public double getRasterRatio() {
     
    509577    }
    510578
     579    public EastNorthBound getCommuneBBox() {
     580        return communeBBox;
     581    }
     582
     583    public void setCommuneBBox(EastNorthBound entireCommune) {
     584        this.communeBBox = entireCommune;
     585    }
     586
    511587}
Note: See TracChangeset for help on using the changeset viewer.