Changeset 17397 in osm for applications


Ignore:
Timestamp:
2009-08-31T09:48:53+02:00 (15 years ago)
Author:
guggis
Message:

fixed saving/loading wms layer
improved file filter defaults for .wms files

Location:
applications/editors/josm/plugins/wmsplugin
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/build.xml

    r17390 r17397  
    3232    <property name="ant.build.javac.target" value="1.5"/>
    3333        <property name="commit.message"         value="fixing JOSM issue #3186" />
    34         <property name="josm.reference.release" value="2012" />
     34        <property name="josm.reference.release" value="2020" />
    3535       
    3636    <target name="init">
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java

    r16872 r17397  
    144144        max = (EastNorth) in.readObject();
    145145        min = (EastNorth) in.readObject();
    146         image = (BufferedImage) ImageIO.read(ImageIO.createImageInputStream(in));
     146        boolean hasImage = in.readBoolean();
     147        if (hasImage)
     148                image = (BufferedImage) ImageIO.read(ImageIO.createImageInputStream(in));
     149        else {
     150                in.readObject(); // read null from input stream
     151                image = null;
     152        }
    147153    }
    148154
     
    150156        out.writeObject(max);
    151157        out.writeObject(min);
    152         if(image == null)
     158        if(image == null) {
     159                out.writeBoolean(false);
    153160            out.writeObject(null);
    154         else
     161        } else {
     162                out.writeBoolean(true);
    155163            ImageIO.write(image, "png", ImageIO.createImageOutputStream(out));
     164        }
    156165    }
    157166
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r17390 r17397  
    11package wmsplugin;
    22
    3 import org.openstreetmap.josm.io.CacheFiles;
    43import static org.openstreetmap.josm.tools.I18n.tr;
    54
     
    3534import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    3635import org.openstreetmap.josm.gui.layer.Layer;
     36import org.openstreetmap.josm.io.CacheFiles;
    3737import org.openstreetmap.josm.tools.ImageProvider;
    3838
     
    6161        protected String baseURL;
    6262        protected String cookies;
    63         protected final int serializeFormatVersion = 4;
     63        protected final int serializeFormatVersion = 5;
    6464
    6565        private ExecutorService executor = null;
     
    212212                                startstop,
    213213                                alphaChannel,
    214                                 new JMenuItem(new changeResolutionAction()),
    215                                 new JMenuItem(new reloadErrorTilesAction()),
    216                                 new JMenuItem(new downloadAction()),
     214                                new JMenuItem(new ChangeResolutionAction()),
     215                                new JMenuItem(new ReloadErrorTilesAction()),
     216                                new JMenuItem(new DownloadAction()),
    217217                                new JSeparator(),
    218218                                new JMenuItem(new LayerListPopup.InfoAction(this))
     
    230230        }
    231231
    232         public class downloadAction extends AbstractAction {
    233                 public downloadAction() {
     232        public class DownloadAction extends AbstractAction {
     233                public DownloadAction() {
    234234                        super(tr("Download visible tiles"));
    235235                }
     
    239239        }
    240240
    241         public class changeResolutionAction extends AbstractAction {
    242                 public changeResolutionAction() {
     241        public class ChangeResolutionAction extends AbstractAction {
     242                public ChangeResolutionAction() {
    243243                        super(tr("Change resolution"));
    244244                }
     
    251251        }
    252252
    253         public class reloadErrorTilesAction extends AbstractAction {
    254                 public reloadErrorTilesAction() {
     253        public class ReloadErrorTilesAction extends AbstractAction {
     254                public ReloadErrorTilesAction() {
    255255                        super(tr("Reload erroneous tiles"));
    256256                }
     
    294294                }
    295295        }
    296 
     296       
    297297        public class SaveWmsAction extends AbstractAction {
    298298                public SaveWmsAction() {
     
    302302                        File f = SaveActionBase.createAndOpenSaveFileChooser(
    303303                                        tr("Save WMS layer"), ".wms");
    304                         try
    305                         {
    306                                 FileOutputStream fos = new FileOutputStream(f);
    307                                 ObjectOutputStream oos = new ObjectOutputStream(fos);
    308                                 oos.writeInt(serializeFormatVersion);
    309                                 oos.writeInt(dax);
    310                                 oos.writeInt(day);
    311                                 oos.writeInt(ImageSize);
    312                                 oos.writeDouble(pixelPerDegree);
    313                                 oos.writeObject(getName());
    314                                 oos.writeObject(baseURL);
    315                                 oos.writeObject(images);
    316                                 oos.close();
    317                                 fos.close();
    318                         }
    319                         catch (Exception ex) {
     304                        try {
     305                                if (f != null) {
     306                                        ObjectOutputStream oos = new ObjectOutputStream(
     307                                                        new FileOutputStream(f)
     308                                        );
     309                                        oos.writeInt(serializeFormatVersion);
     310                                        oos.writeInt(dax);
     311                                        oos.writeInt(day);
     312                                        oos.writeInt(ImageSize);
     313                                        oos.writeDouble(pixelPerDegree);
     314                                        oos.writeObject(getName());
     315                                        oos.writeObject(baseURL);
     316                                        oos.writeObject(images);
     317                                        oos.close();
     318                                }
     319                        } catch (Exception ex) {
    320320                                ex.printStackTrace(System.out);
    321321                        }
     
    329329                public void actionPerformed(ActionEvent ev) {
    330330                        JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true,
    331                                         false, tr("Load WMS layer"));
     331                                        false, tr("Load WMS layer"), "wms");
    332332                        if(fc == null) return;
    333333                        File f = fc.getSelectedFile();
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java

    r17340 r17397  
    2424
    2525import org.openstreetmap.josm.Main;
     26import org.openstreetmap.josm.actions.ExtensionFileFilter;
    2627import org.openstreetmap.josm.actions.JosmAction;
    2728import org.openstreetmap.josm.data.ProjectionBounds;
     
    3536import org.openstreetmap.josm.plugins.Plugin;
    3637
     38import wmsplugin.io.WMSLayerExporter;
     39import wmsplugin.io.WMSLayerImporter;
     40
    3741public class WMSPlugin extends Plugin {
    3842    static CacheFiles cache = new CacheFiles("wmsplugin");
     
    4650    // remember state of menu item to restore on changed preferences
    4751    static private boolean menuEnabled = false;
     52   
     53    protected void initExporterAndImporter() {
     54        ExtensionFileFilter.exporters.add(new WMSLayerExporter());
     55        ExtensionFileFilter.importers.add(new WMSLayerImporter());
     56    }
    4857
    4958    public WMSPlugin() {
     
    5160        cache.setExpire(CacheFiles.EXPIRE_MONTHLY, false);
    5261        cache.setMaxSize(70, false);
     62        initExporterAndImporter();
    5363    }
    5464
Note: See TracChangeset for help on using the changeset viewer.