Changeset 4416 in josm
- Timestamp:
- 2011-09-12T22:15:20+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
r4405 r4416 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; … … 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; … … 364 370 private JTable listActive; 365 371 final JTable listdef; 372 final JMapViewer map; 366 373 final PreferenceTabbedPane gui; 367 374 … … 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); … … 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 … … 441 456 add(sideButtonTB, GBC.eol().anchor(GBC.NORTH).insets(0, 0, 5, 5)); 442 457 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 } 443 501 } 444 502
Note:
See TracChangeset
for help on using the changeset viewer.