Changeset 4416 in josm


Ignore:
Timestamp:
Sep 12, 2011 10:15:20 PM (21 months ago)
Author:
bastiK
Message:

applied #6825 - Display imagery providers bbox in a slippy map (patch by Don-vip)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java

    r4405 r4416  
    1818import java.net.MalformedURLException; 
    1919import java.net.URL; 
     20import java.util.HashMap; 
    2021import java.util.List; 
    2122import java.util.Locale; 
     23import java.util.Map; 
    2224 
    2325import javax.swing.AbstractAction; 
     
    4850import javax.swing.table.TableColumnModel; 
    4951 
     52import org.openstreetmap.gui.jmapviewer.JMapViewer; 
     53import org.openstreetmap.gui.jmapviewer.MapRectangleImpl; 
     54import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle; 
    5055import org.openstreetmap.josm.Main; 
     56import org.openstreetmap.josm.data.Bounds; 
    5157import org.openstreetmap.josm.data.imagery.ImageryInfo; 
    5258import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 
     
    364370        private JTable listActive; 
    365371        final JTable listdef; 
     372        final JMapViewer map; 
    366373        final PreferenceTabbedPane gui; 
    367374 
     
    407414            add(scrolldef, GBC.std().insets(0, 5, 0, 0).fill(GridBagConstraints.BOTH).weight(1.0, 0.6).insets(5, 0, 0, 0)); 
    408415 
     416            // Add default item map 
     417            map = new JMapViewer(); 
     418            map.setZoomContolsVisible(false); 
     419            map.setPreferredSize(new Dimension(200, 200)); 
     420            add(map, GBC.std().insets(5, 5, 0, 0).fill(GridBagConstraints.BOTH).weight(0.333, 0.6).insets(5, 0, 0, 0)); 
     421 
     422            listdef.getSelectionModel().addListSelectionListener(new DefListSelectionListener()); 
     423 
    409424            JToolBar tb = new JToolBar(JToolBar.VERTICAL); 
    410425            tb.setFloatable(false); 
     
    429444            add(new JLabel(tr("Selected entries:")), GBC.eol().insets(5, 0, 0, 0)); 
    430445            JScrollPane scroll = new JScrollPane(listActive); 
    431             add(scroll, GBC.std().fill(GridBagConstraints.BOTH).weight(1.0, 0.4).insets(5, 0, 0, 5)); 
     446            add(scroll, GBC.std().fill(GridBagConstraints.BOTH).span(GridBagConstraints.RELATIVE).weight(1.0, 0.4).insets(5, 0, 0, 5)); 
    432447            scroll.setPreferredSize(new Dimension(200, 200)); 
    433448 
     
    441456            add(sideButtonTB, GBC.eol().anchor(GBC.NORTH).insets(0, 0, 5, 5)); 
    442457 
     458        } 
     459 
     460        // Listener of default providers list selection 
     461        private final class DefListSelectionListener implements ListSelectionListener { 
     462            // The current drawn rectangles 
     463            private final Map<Integer, MapRectangle> mapRectangles; 
     464 
     465            private DefListSelectionListener() { 
     466                this.mapRectangles = new HashMap<Integer, MapRectangle>(); 
     467            } 
     468 
     469            @Override 
     470            public void valueChanged(ListSelectionEvent e) { 
     471                // First index is set to -1 when the list is refreshed, so discard all map rectangles 
     472                if (e.getFirstIndex() == -1) { 
     473                    map.removeAllMapRectangles(); 
     474                    mapRectangles.clear(); 
     475                    // Only process complete (final) selection events 
     476                } else if (!e.getValueIsAdjusting()) { 
     477                    for (int i = e.getFirstIndex(); i<=e.getLastIndex(); i++) { 
     478                        Bounds bounds = modeldef.getRow(i).getBounds(); 
     479                        if (bounds != null) { 
     480                            if (listdef.getSelectionModel().isSelectedIndex(i)) { 
     481                                if (!mapRectangles.containsKey(i)) { 
     482                                    // Add new map rectangle 
     483                                    MapRectangle rectangle = new MapRectangleImpl(bounds); 
     484                                    mapRectangles.put(i, rectangle); 
     485                                    map.addMapRectangle(rectangle); 
     486                                } 
     487                            } else if (mapRectangles.containsKey(i)) { 
     488                                // Remove previousliy drawn map rectangle 
     489                                map.removeMapRectangle(mapRectangles.get(i)); 
     490                                mapRectangles.remove(i); 
     491                            } 
     492                        } 
     493                    } 
     494                    // If needed, adjust map to show all map rectangles 
     495                    if (!mapRectangles.isEmpty()) { 
     496                        map.setDisplayToFitMapRectangle(); 
     497                        map.zoomOut(); 
     498                    } 
     499                } 
     500            } 
    443501        } 
    444502 
Note: See TracChangeset for help on using the changeset viewer.