Ticket #6825: patch.diff

File patch.diff, 9.2 KB (added by Don-vip, 14 years ago)
  • src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

     
    670670        repaint();
    671671    }
    672672
     673    public void removeAllMapMarkers() {
     674        mapMarkerList.clear();
     675        repaint();
     676    }
     677
    673678    public void addMapRectangle(MapRectangle rectangle) {
    674679        mapRectangleList.add(rectangle);
    675680        repaint();
     
    680685        repaint();
    681686    }
    682687
     688    public void removeAllMapRectangles() {
     689        mapRectangleList.clear();
     690        repaint();
     691    }
     692
    683693    public void setZoomContolsVisible(boolean visible) {
    684694        zoomSlider.setVisible(visible);
    685695        zoomInButton.setVisible(visible);
  • src/org/openstreetmap/gui/jmapviewer/MapRectangleImpl.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.gui.jmapviewer;
     3
     4import java.awt.Color;
     5import java.awt.Graphics;
     6import java.awt.Point;
     7
     8import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle;
     9import org.openstreetmap.josm.data.Bounds;
     10
     11/**
     12 * @author Vincent
     13 *
     14 */
     15public class MapRectangleImpl implements MapRectangle {
     16
     17    private Coordinate topLeft;
     18    private Coordinate bottomRight;
     19    Color color;
     20
     21    public MapRectangleImpl(Bounds bounds) {
     22        this(bounds, Color.BLUE);
     23    }
     24
     25    public MapRectangleImpl(Bounds bounds, Color color) {
     26        this.topLeft = new Coordinate(bounds.getMax().lat(), bounds.getMin().lon());
     27        this.bottomRight = new Coordinate(bounds.getMin().lat(), bounds.getMax().lon());
     28        this.color = color;
     29    }
     30
     31    /* (non-Javadoc)
     32     * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#getTopLeft()
     33     */
     34    @Override
     35    public Coordinate getTopLeft() {
     36        return topLeft;
     37    }
     38
     39    /* (non-Javadoc)
     40     * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#getBottomRight()
     41     */
     42    @Override
     43    public Coordinate getBottomRight() {
     44        return bottomRight;
     45    }
     46
     47    /* (non-Javadoc)
     48     * @see org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle#paint(java.awt.Graphics, java.awt.Point, java.awt.Point)
     49     */
     50    @Override
     51    public void paint(Graphics g, Point topLeft, Point bottomRight) {
     52        g.setColor(color);
     53        g.drawRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
     54    }
     55
     56    @Override
     57    public String toString() {
     58        return "MapRectangle from " + topLeft + " to " + bottomRight;
     59    }
     60}
  • src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java

     
    1717import java.io.IOException;
    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;
    2426import javax.swing.BorderFactory;
     
    4749import javax.swing.table.DefaultTableModel;
    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;
    5359import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
     
    7682    private Color colFadeColor;
    7783    private JButton btnFadeColor;
    7884    private JSlider fadeAmount = new JSlider(0, 100);
    79     private JComboBox sharpen;
     85    private JComboBox<String> sharpen;
    8086    private JCheckBox useOffsetServer;
    8187    private JTextField offsetServerUrl;
    8288
    8389    // WMS Settings
    84     private JComboBox browser;
     90    private JComboBox<String> browser;
    8591    JCheckBox overlapCheckBox;
    8692    JSpinner spinEast;
    8793    JSpinner spinNorth;
     
    126132        p.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
    127133        p.add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL));
    128134
    129         this.sharpen = new JComboBox(new String[] {
     135        this.sharpen = new JComboBox<String>(new String[] {
    130136                tr("None"),
    131137                tr("Soft"),
    132138                tr("Strong")});
     
    150156
    151157    private JPanel buildWMSSettingsPanel() {
    152158        final JPanel p = new JPanel(new GridBagLayout());
    153         browser = new JComboBox(new String[] {
     159        browser = new JComboBox<String>(new String[] {
    154160                "webkit-image {0}",
    155161                "gnome-web-photo --mode=photo --format=png {0} /dev/stdout",
    156162                "gnome-web-photo-fixed {0}",
     
    363369        private final ImageryLayerInfo layerInfo;
    364370        private JTable listActive;
    365371        final JTable listdef;
     372        final JMapViewer map;
    366373        final PreferenceTabbedPane gui;
    367374
    368375        public ImageryProvidersPanel(final PreferenceTabbedPane gui, ImageryLayerInfo layerInfo) {
     
    406413            scrolldef.setPreferredSize(new Dimension(200, 200));
    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);
    411426            tb.setBorderPainted(false);
     
    428443
    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
    434449            JToolBar sideButtonTB = new JToolBar(JToolBar.VERTICAL);
     
    442457
    443458        }
    444459
     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            }
     501        }
     502
    445503        class NewEntryAction extends AbstractAction {
    446504            public NewEntryAction() {
    447505                putValue(NAME, tr("New"));