Changeset 5391 in josm


Ignore:
Timestamp:
2012-08-04T16:33:49+02:00 (12 years ago)
Author:
bastiK
Message:

add session support for imagery layers

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r5382 r5391  
    372372            layer.addPropertyChangeListener(LayerListDialog.getInstance().getModel());
    373373        }
     374        layer.hookUpMapView();
    374375        map.mapView.addLayer(layer);
    375376    }
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r5358 r5391  
    12881288    }
    12891289
    1290     private <T> Map<String,String> serializeStruct(T struct, Class<T> klass) {
     1290    public static <T> Map<String,String> serializeStruct(T struct, Class<T> klass) {
    12911291        T structPrototype;
    12921292        try {
     
    13211321    }
    13221322
    1323     private <T> T deserializeStruct(Map<String,String> hash, Class<T> klass) {
     1323    public static <T> T deserializeStruct(Map<String,String> hash, Class<T> klass) {
    13241324        T struct = null;
    13251325        try {
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r5369 r5391  
    33
    44import java.awt.Image;
     5import java.util.ArrayList;
    56import java.util.Arrays;
    6 import java.util.ArrayList;
    77import java.util.Collection;
    88import java.util.Collections;
     
    1313import javax.swing.ImageIcon;
    1414
     15import org.openstreetmap.gui.jmapviewer.Coordinate;
     16import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
     17import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTileSource;
     18import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource.Mapnik;
    1519import org.openstreetmap.josm.Main;
    1620import org.openstreetmap.josm.data.Bounds;
     
    1923import org.openstreetmap.josm.tools.CheckParameterUtil;
    2024import org.openstreetmap.josm.tools.ImageProvider;
    21 import org.openstreetmap.gui.jmapviewer.Coordinate;
    22 import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
    23 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource.Mapnik;
    24 import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTileSource;
    25 import org.openstreetmap.josm.tools.CheckParameterUtil;
    2625
    2726/**
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r5390 r5391  
    8383            icon = new ImageProvider(info.getIcon()).setOptional(true).
    8484                    setMaxHeight(ICON_SIZE).setMaxWidth(ICON_SIZE).get();
    85             if (icon == null) {
    86                 icon = ImageProvider.get("imagery_small");
    87             }
     85        }
     86        if (icon == null) {
     87            icon = ImageProvider.get("imagery_small");
    8888        }
    8989        this.sharpenLevel = PROP_SHARPEN_LEVEL.get();
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r5390 r5391  
    126126
    127127    /**
     128     * Initialization code, that depends on Main.map.mapView.
     129     *
     130     * It is always called in the event dispatching thread.
     131     * Note that Main.map is null as long as no layer has been added, so do
     132     * not execute code in the constructor, that assumes Main.map.mapView is
     133     * not null. Instead override this method.
     134     */
     135    public void hookUpMapView() {
     136    }
     137
     138    /**
    128139     * Paint the dataset using the engine set.
    129140     * @param mv The object that can translate GeoPoints to screen coordinates.
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r5357 r5391  
    3838import javax.swing.JOptionPane;
    3939import javax.swing.JPopupMenu;
    40 import javax.swing.SwingUtilities;
    4140
    4241import org.openstreetmap.gui.jmapviewer.AttributionSupport;
     
    471470            throw new IllegalStateException("Cannot create TMSLayer with non-TMS ImageryInfo");
    472471        initTileSource(source);
    473 
     472    }
     473
     474    /**
     475     * Adds a context menu to the mapView.
     476     */
     477    @Override
     478    public void hookUpMapView() {
    474479        tileOptionMenu = new JPopupMenu();
    475480
     
    521526            @Override
    522527            public void actionPerformed(ActionEvent ae) {
    523                 //Main.debug("info tile: " + clickedTile);
    524528                if (clickedTile != null) {
    525529                    showMetadataTile = clickedTile;
     
    559563
    560564        // increase and decrease commands
    561         tileOptionMenu.add(new JMenuItem(
    562                 new AbstractAction(tr("Increase zoom")) {
     565        tileOptionMenu.add(new JMenuItem(new AbstractAction(
     566                tr("Increase zoom")) {
     567            @Override
     568            public void actionPerformed(ActionEvent ae) {
     569                increaseZoomLevel();
     570                redraw();
     571            }
     572        }));
     573
     574        tileOptionMenu.add(new JMenuItem(new AbstractAction(
     575                tr("Decrease zoom")) {
     576            @Override
     577            public void actionPerformed(ActionEvent ae) {
     578                decreaseZoomLevel();
     579                redraw();
     580            }
     581        }));
     582
     583        tileOptionMenu.add(new JMenuItem(new AbstractAction(
     584                tr("Snap to tile size")) {
     585            @Override
     586            public void actionPerformed(ActionEvent ae) {
     587                double new_factor = Math.sqrt(getScaleFactor(currentZoomLevel));
     588                Main.map.mapView.zoomToFactor(new_factor);
     589                redraw();
     590            }
     591        }));
     592
     593        tileOptionMenu.add(new JMenuItem(new AbstractAction(
     594                tr("Flush Tile Cache")) {
     595            @Override
     596            public void actionPerformed(ActionEvent ae) {
     597                new PleaseWaitRunnable(tr("Flush Tile Cache")) {
    563598                    @Override
    564                     public void actionPerformed(ActionEvent ae) {
    565                         increaseZoomLevel();
    566                         redraw();
     599                    protected void realRun() throws SAXException, IOException,
     600                            OsmTransferException {
     601                        clearTileCache(getProgressMonitor());
    567602                    }
    568                 }));
    569 
    570         tileOptionMenu.add(new JMenuItem(
    571                 new AbstractAction(tr("Decrease zoom")) {
     603
    572604                    @Override
    573                     public void actionPerformed(ActionEvent ae) {
    574                         decreaseZoomLevel();
    575                         redraw();
     605                    protected void finish() {
    576606                    }
    577                 }));
    578 
    579         // FIXME: currently ran in errors
    580 
    581         tileOptionMenu.add(new JMenuItem(
    582                 new AbstractAction(tr("Snap to tile size")) {
     607
    583608                    @Override
    584                     public void actionPerformed(ActionEvent ae) {
    585                         double new_factor = Math.sqrt(getScaleFactor(currentZoomLevel));
    586                         Main.map.mapView.zoomToFactor(new_factor);
    587                         redraw();
     609                    protected void cancel() {
    588610                    }
    589                 }));
     611                }.run();
     612            }
     613        }));
    590614        // end of adding menu commands
    591615
    592         tileOptionMenu.add(new JMenuItem(
    593                 new AbstractAction(tr("Flush Tile Cache")) {
    594                     @Override
    595                     public void actionPerformed(ActionEvent ae) {
    596                         new PleaseWaitRunnable(tr("Flush Tile Cache")) {
    597                            
    598                             @Override
    599                             protected void realRun() throws SAXException, IOException,
    600                                     OsmTransferException {
    601                                 clearTileCache(getProgressMonitor());
    602                             }
    603                            
    604                             @Override
    605                             protected void finish() {
    606                             }
    607                            
    608                             @Override
    609                             protected void cancel() {
    610                             }
    611                         }.run();
    612                        
    613                     }
    614                 }));
    615         // end of adding menu commands
    616 
    617         SwingUtilities.invokeLater(new Runnable() {
    618             @Override
    619             public void run() {
    620                 final MouseAdapter adapter = new MouseAdapter() {
    621                     @Override
    622                     public void mouseClicked(MouseEvent e) {
    623                         if (!isVisible()) return;
    624                         if (e.getButton() == MouseEvent.BUTTON3) {
    625                             clickedTile = getTileForPixelpos(e.getX(), e.getY());
    626                             tileOptionMenu.show(e.getComponent(), e.getX(), e.getY());
    627                         } else if (e.getButton() == MouseEvent.BUTTON1) {
    628                             attribution.handleAttribution(e.getPoint(), true);
    629                         }
    630                     }
    631                 };
    632                 Main.map.mapView.addMouseListener(adapter);
    633 
    634                 MapView.addLayerChangeListener(new LayerChangeListener() {
    635                     @Override
    636                     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    637                         //
    638                     }
    639 
    640                     @Override
    641                     public void layerAdded(Layer newLayer) {
    642                         //
    643                     }
    644 
    645                     @Override
    646                     public void layerRemoved(Layer oldLayer) {
    647                         if (oldLayer == TMSLayer.this) {
    648                             Main.map.mapView.removeMouseListener(adapter);
    649                             MapView.removeLayerChangeListener(this);
    650                         }
    651                     }
    652                 });
     616        final MouseAdapter adapter = new MouseAdapter() {
     617            @Override
     618            public void mouseClicked(MouseEvent e) {
     619                if (!isVisible()) return;
     620                if (e.getButton() == MouseEvent.BUTTON3) {
     621                    clickedTile = getTileForPixelpos(e.getX(), e.getY());
     622                    tileOptionMenu.show(e.getComponent(), e.getX(), e.getY());
     623                } else if (e.getButton() == MouseEvent.BUTTON1) {
     624                    attribution.handleAttribution(e.getPoint(), true);
     625                }
     626            }
     627        };
     628        Main.map.mapView.addMouseListener(adapter);
     629
     630        MapView.addLayerChangeListener(new LayerChangeListener() {
     631            @Override
     632            public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     633                //
     634            }
     635
     636            @Override
     637            public void layerAdded(Layer newLayer) {
     638                //
     639            }
     640
     641            @Override
     642            public void layerRemoved(Layer oldLayer) {
     643                if (oldLayer == TMSLayer.this) {
     644                    Main.map.mapView.removeMouseListener(adapter);
     645                    MapView.removeLayerChangeListener(this);
     646                }
    653647            }
    654648        });
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r5389 r5391  
    121121    protected boolean settingsChanged;
    122122    protected ImageryInfo info;
    123     protected final MapView mv;
     123    protected MapView mv;
    124124    public WmsCache cache;
    125125    private AttributionSupport attribution = new AttributionSupport();
     
    160160        super(info);
    161161        imageSize = PROP_IMAGE_SIZE.get();
    162         mv = Main.map.mapView;
    163162        setBackgroundLayer(true); /* set global background variable */
    164163        initializeImages();
     164        this.info = new ImageryInfo(info);
     165
     166        attribution.initialize(this.info);
     167
     168        if(info.getUrl() != null) {
     169            startGrabberThreads();
     170        }
     171       
     172        Main.pref.addPreferenceChangeListener(this);
     173    }
     174
     175    @Override
     176    public void hookUpMapView() {
     177        mv = Main.map.mapView;
    165178        if (info.getUrl() != null) {
    166179            for (WMSLayer layer: Main.map.mapView.getLayersOfType(WMSLayer.class)) {
     
    175188            }
    176189        }
    177         this.info = new ImageryInfo(info);
    178190        if(this.info.getPixelPerDegree() == 0.0) {
    179191            this.info.setPixelPerDegree(getPPD());
     
    181193        resolution = mv.getDist100PixelText();
    182194
    183         attribution.initialize(this.info);
    184 
    185         if(info.getUrl() != null) {
    186             startGrabberThreads();
    187         }
    188 
    189 
    190         Main.pref.addPreferenceChangeListener(this);
    191 
    192         SwingUtilities.invokeLater(new Runnable() {
     195        final MouseAdapter adapter = new MouseAdapter() {
    193196            @Override
    194             public void run() {
    195                 final MouseAdapter adapter = new MouseAdapter() {
    196                     @Override
    197                     public void mouseClicked(MouseEvent e) {
    198                         if (!isVisible()) return;
    199                         if (e.getButton() == MouseEvent.BUTTON1) {
    200                             attribution.handleAttribution(e.getPoint(), true);
    201                         }
    202                     }
    203                 };
    204                 Main.map.mapView.addMouseListener(adapter);
    205 
    206                 MapView.addLayerChangeListener(new LayerChangeListener() {
    207                     @Override
    208                     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    209                         //
    210                     }
    211 
    212                     @Override
    213                     public void layerAdded(Layer newLayer) {
    214                         //
    215                     }
    216 
    217                     @Override
    218                     public void layerRemoved(Layer oldLayer) {
    219                         if (oldLayer == WMSLayer.this) {
    220                             Main.map.mapView.removeMouseListener(adapter);
    221                             MapView.removeLayerChangeListener(this);
    222                         }
    223                     }
    224                 });
     197            public void mouseClicked(MouseEvent e) {
     198                if (!isVisible()) return;
     199                if (e.getButton() == MouseEvent.BUTTON1) {
     200                    attribution.handleAttribution(e.getPoint(), true);
     201                }
     202            }
     203        };
     204        Main.map.mapView.addMouseListener(adapter);
     205
     206        MapView.addLayerChangeListener(new LayerChangeListener() {
     207            @Override
     208            public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     209                //
     210            }
     211
     212            @Override
     213            public void layerAdded(Layer newLayer) {
     214                //
     215            }
     216
     217            @Override
     218            public void layerRemoved(Layer oldLayer) {
     219                if (oldLayer == WMSLayer.this) {
     220                    Main.map.mapView.removeMouseListener(adapter);
     221                    MapView.removeLayerChangeListener(this);
     222                }
    225223            }
    226224        });
  • trunk/src/org/openstreetmap/josm/io/session/SessionLayerExporter.java

    r4685 r5391  
    4242
    4343    /**
    44      * Save meta data to the .jos file. Return a <layer> element.
    45      * Use support to save files in the zip archive as needed.
     44     * Save meta data to the .jos file. Return a layer XML element.
     45     * Use <code>support</code> to save files in the zip archive as needed.
    4646     */
    4747    Element export(ExportSupport support) throws IOException;
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r4874 r5391  
    5656    static {
    5757        registerSessionLayerImporter("osm-data", OsmDataSessionImporter.class);
     58        registerSessionLayerImporter("imagery", ImagerySessionImporter.class);
    5859    }
    5960
     
    166167
    167168        /**
    168          * Return a File for a URI from a .jos file.
     169         * Return a File for a URI from a .jos/.joz file.
    169170         *
    170171         * Returns null if the URI points to a file inside the zip archive.
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r4685 r5391  
    3434import org.openstreetmap.josm.gui.layer.Layer;
    3535import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     36import org.openstreetmap.josm.gui.layer.TMSLayer;
     37import org.openstreetmap.josm.gui.layer.WMSLayer;
    3638import org.openstreetmap.josm.tools.MultiMap;
    3739import org.openstreetmap.josm.tools.Utils;
     
    4345    static {
    4446        registerSessionLayerExporter(OsmDataLayer.class , OsmDataSessionExporter.class);
     47        registerSessionLayerExporter(TMSLayer.class , ImagerySessionExporter.class);
     48        registerSessionLayerExporter(WMSLayer.class , ImagerySessionExporter.class);
    4549    }
    4650
Note: See TracChangeset for help on using the changeset viewer.