Ignore:
Timestamp:
2017-10-09T00:17:55+02:00 (7 years ago)
Author:
bastiK
Message:

applied #15414 - Redesign of SlippyMapBBoxChooser's SourceButton (patch by ris)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r12931 r12955  
    2222import java.util.concurrent.CopyOnWriteArrayList;
    2323
     24import javax.swing.ButtonModel;
     25import javax.swing.JToggleButton;
    2426import javax.swing.JOptionPane;
    2527import javax.swing.SpringLayout;
     28import javax.swing.event.ChangeListener;
     29import javax.swing.event.ChangeEvent;
    2630
    2731import org.openstreetmap.gui.jmapviewer.Coordinate;
     
    4448import org.openstreetmap.josm.data.imagery.TileLoaderFactory;
    4549import org.openstreetmap.josm.data.osm.BBox;
     50import org.openstreetmap.josm.data.preferences.BooleanProperty;
    4651import org.openstreetmap.josm.data.preferences.StringProperty;
    4752import org.openstreetmap.josm.gui.MainApplication;
     
    5661 * This panel displays a map and lets the user chose a {@link BBox}.
    5762 */
    58 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, MainLayerManager.ActiveLayerChangeListener {
     63public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, ChangeListener, MainLayerManager.ActiveLayerChangeListener {
    5964
    6065    /**
     
    121126
    122127    private static final StringProperty PROP_MAPSTYLE = new StringProperty("slippy_map_chooser.mapstyle", "Mapnik");
     128    private static final BooleanProperty PROP_SHOWDLAREA = new BooleanProperty("slippy_map_chooser.show_downloaded_area", true);
    123129    /**
    124130     * The property name used for the resize button.
     
    131137
    132138    private final SizeButton iSizeButton;
     139    private final ButtonModel showDownloadAreaButtonModel;
    133140    private final SourceButton iSourceButton;
    134141    private transient Bounds bbox;
     
    173180        List<TileSource> tileSources = getAllTileSources();
    174181
    175         iSourceButton = new SourceButton(this, tileSources);
     182        this.showDownloadAreaButtonModel = new JToggleButton.ToggleButtonModel();
     183        this.showDownloadAreaButtonModel.setSelected(PROP_SHOWDLAREA.get());
     184        this.showDownloadAreaButtonModel.addChangeListener(this);
     185        iSourceButton = new SourceButton(this, tileSources, this.showDownloadAreaButtonModel);
    176186        add(iSourceButton);
    177         springLayout.putConstraint(SpringLayout.EAST, iSourceButton, 0, SpringLayout.EAST, this);
    178         springLayout.putConstraint(SpringLayout.NORTH, iSourceButton, 30, SpringLayout.NORTH, this);
     187        springLayout.putConstraint(SpringLayout.EAST, iSourceButton, -2, SpringLayout.EAST, this);
     188        springLayout.putConstraint(SpringLayout.NORTH, iSourceButton, 2, SpringLayout.NORTH, this);
    179189
    180190        iSizeButton = new SizeButton(this);
     
    231241        // enough to make sharing code impractical)
    232242        final OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    233         if (editLayer != null && Config.getPref().getBoolean("draw.data.downloaded_area", true) && !editLayer.data.getDataSources().isEmpty()) {
     243        if (editLayer != null && this.showDownloadAreaButtonModel.isSelected() && !editLayer.data.getDataSources().isEmpty()) {
    234244            // initialize area with current viewport
    235245            Rectangle b = this.getBounds();
     
    271281    @Override
    272282    public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e) {
     283        this.repaint();
     284    }
     285
     286    @Override
     287    public void stateChanged(ChangeEvent e) {
     288        // fired for the stateChanged event of this.showDownloadAreaButtonModel
     289        PROP_SHOWDLAREA.put(this.showDownloadAreaButtonModel.isSelected());
    273290        this.repaint();
    274291    }
     
    342359        this.setTileSource(tileSource);
    343360        PROP_MAPSTYLE.put(tileSource.getName()); // TODO Is name really unique?
     361        if (this.iSourceButton.getCurrentSource() != tileSource) { // prevent infinite recursion
     362            this.iSourceButton.setCurrentMap(tileSource);
     363        }
    344364    }
    345365
Note: See TracChangeset for help on using the changeset viewer.