Ticket #6825: patch.diff
| File patch.diff, 9.2 KB (added by , 14 years ago) |
|---|
-
src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
670 670 repaint(); 671 671 } 672 672 673 public void removeAllMapMarkers() { 674 mapMarkerList.clear(); 675 repaint(); 676 } 677 673 678 public void addMapRectangle(MapRectangle rectangle) { 674 679 mapRectangleList.add(rectangle); 675 680 repaint(); … … 680 685 repaint(); 681 686 } 682 687 688 public void removeAllMapRectangles() { 689 mapRectangleList.clear(); 690 repaint(); 691 } 692 683 693 public void setZoomContolsVisible(boolean visible) { 684 694 zoomSlider.setVisible(visible); 685 695 zoomInButton.setVisible(visible); -
src/org/openstreetmap/gui/jmapviewer/MapRectangleImpl.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.gui.jmapviewer; 3 4 import java.awt.Color; 5 import java.awt.Graphics; 6 import java.awt.Point; 7 8 import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle; 9 import org.openstreetmap.josm.data.Bounds; 10 11 /** 12 * @author Vincent 13 * 14 */ 15 public 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
17 17 import java.io.IOException; 18 18 import java.net.MalformedURLException; 19 19 import java.net.URL; 20 import java.util.HashMap; 20 21 import java.util.List; 21 22 import java.util.Locale; 23 import java.util.Map; 22 24 23 25 import javax.swing.AbstractAction; 24 26 import javax.swing.BorderFactory; … … 47 49 import javax.swing.table.DefaultTableModel; 48 50 import javax.swing.table.TableColumnModel; 49 51 52 import org.openstreetmap.gui.jmapviewer.JMapViewer; 53 import org.openstreetmap.gui.jmapviewer.MapRectangleImpl; 54 import org.openstreetmap.gui.jmapviewer.interfaces.MapRectangle; 50 55 import org.openstreetmap.josm.Main; 56 import org.openstreetmap.josm.data.Bounds; 51 57 import org.openstreetmap.josm.data.imagery.ImageryInfo; 52 58 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 53 59 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; … … 76 82 private Color colFadeColor; 77 83 private JButton btnFadeColor; 78 84 private JSlider fadeAmount = new JSlider(0, 100); 79 private JComboBox sharpen;85 private JComboBox<String> sharpen; 80 86 private JCheckBox useOffsetServer; 81 87 private JTextField offsetServerUrl; 82 88 83 89 // WMS Settings 84 private JComboBox browser;90 private JComboBox<String> browser; 85 91 JCheckBox overlapCheckBox; 86 92 JSpinner spinEast; 87 93 JSpinner spinNorth; … … 126 132 p.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 127 133 p.add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL)); 128 134 129 this.sharpen = new JComboBox (new String[] {135 this.sharpen = new JComboBox<String>(new String[] { 130 136 tr("None"), 131 137 tr("Soft"), 132 138 tr("Strong")}); … … 150 156 151 157 private JPanel buildWMSSettingsPanel() { 152 158 final JPanel p = new JPanel(new GridBagLayout()); 153 browser = new JComboBox (new String[] {159 browser = new JComboBox<String>(new String[] { 154 160 "webkit-image {0}", 155 161 "gnome-web-photo --mode=photo --format=png {0} /dev/stdout", 156 162 "gnome-web-photo-fixed {0}", … … 363 369 private final ImageryLayerInfo layerInfo; 364 370 private JTable listActive; 365 371 final JTable listdef; 372 final JMapViewer map; 366 373 final PreferenceTabbedPane gui; 367 374 368 375 public ImageryProvidersPanel(final PreferenceTabbedPane gui, ImageryLayerInfo layerInfo) { … … 406 413 scrolldef.setPreferredSize(new Dimension(200, 200)); 407 414 add(scrolldef, GBC.std().insets(0, 5, 0, 0).fill(GridBagConstraints.BOTH).weight(1.0, 0.6).insets(5, 0, 0, 0)); 408 415 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 409 424 JToolBar tb = new JToolBar(JToolBar.VERTICAL); 410 425 tb.setFloatable(false); 411 426 tb.setBorderPainted(false); … … 428 443 429 444 add(new JLabel(tr("Selected entries:")), GBC.eol().insets(5, 0, 0, 0)); 430 445 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)); 432 447 scroll.setPreferredSize(new Dimension(200, 200)); 433 448 434 449 JToolBar sideButtonTB = new JToolBar(JToolBar.VERTICAL); … … 442 457 443 458 } 444 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 } 501 } 502 445 503 class NewEntryAction extends AbstractAction { 446 504 public NewEntryAction() { 447 505 putValue(NAME, tr("New"));
