Changeset 19640 in josm


Ignore:
Timestamp:
2026-10-06T09:35:45+02:00 (10 hours ago)
Author:
stoecker
Message:

add grid overlay and tile border display, fix #8464, patch by wangi

Location:
trunk
Files:
18 added
5 edited

Legend:

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

    r19547 r19640  
    3131import org.openstreetmap.josm.actions.AboutAction;
    3232import org.openstreetmap.josm.actions.AddNodeAction;
     33import org.openstreetmap.josm.actions.AlignGridRotationAction;
    3334import org.openstreetmap.josm.actions.AlignInCircleAction;
    3435import org.openstreetmap.josm.actions.AlignInLineAction;
    … …  
    101102import org.openstreetmap.josm.actions.SessionSaveAction;
    102103import org.openstreetmap.josm.actions.SessionSaveAsAction;
     104import org.openstreetmap.josm.actions.SetGridOriginAction;
     105import org.openstreetmap.josm.actions.ShowGridAction;
    103106import org.openstreetmap.josm.actions.ShowStatusReportAction;
    104107import org.openstreetmap.josm.actions.SimplifyWayAction;
    … …  
    136139import org.openstreetmap.josm.gui.layer.geoimage.WikimediaCommonsLoader.WikimediaCommonsLoadImagesAction;
    137140import org.openstreetmap.josm.gui.mappaint.MapPaintMenu;
     141import org.openstreetmap.josm.gui.preferences.display.GridPreference;
    138142import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
    139143import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSearchPrimitiveDialog;
    … …  
    257261    /** View / Hatch area outside download */
    258262    public final DrawBoundariesOfDownloadedDataAction drawBoundariesOfDownloadedDataAction = new DrawBoundariesOfDownloadedDataAction();
     263    /** View / Grid submenu: the grid drawn over the map and its placement */
     264    public final JMenu gridMenu = new JMenu(tr("Grid"));
     265    /** View / Grid / Show */
     266    public final ShowGridAction showGridAction = new ShowGridAction();
     267    /** View / Grid / Set origin to selection */
     268    public final SetGridOriginAction setGridOriginAction = new SetGridOriginAction();
     269    /** View / Grid / Align rotation to selection */
     270    public final AlignGridRotationAction alignGridRotationAction = new AlignGridRotationAction();
    259271    /** View / Advanced info */
    260272    public final InfoAction info = new InfoAction();
    … …  
    816828        viewMenu.add(hatchAreaOutsideDownloadMenuItem);
    817829        ExpertToggleAction.addVisibilitySwitcher(hatchAreaOutsideDownloadMenuItem);
     830        // -- Grid submenu
     831        gridMenu.setIcon(ImageProvider.get("grid", ImageProvider.ImageSizes.MENU));
     832        gridMenu.add(showGridAction.getCheckbox());
     833        add(gridMenu, setGridOriginAction);
     834        add(gridMenu, alignGridRotationAction);
     835        gridMenu.addSeparator();
     836        add(gridMenu, PreferencesAction.forPreferenceTab(tr("Grid preferences..."),
     837                tr("Click to open the grid tab in the preferences"), GridPreference.class));
     838        viewMenu.add(gridMenu);
    818839
    819840        viewMenu.add(new MapPaintMenu());
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r19384 r19640  
    7474import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog;
    7575import org.openstreetmap.josm.gui.layer.Layer;
     76import org.openstreetmap.josm.gui.layer.MapGridPaintable;
    7677import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
    7778import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
    … …  
    123124     */
    124125    public final MapView mapView;
     126    /** The grid drawn over the map view, see {@link MapGridPaintable} */
     127    private final MapGridPaintable gridOverlay = new MapGridPaintable();
    125128
    126129    /**
    … …  
    205208
    206209        mapView = new MapView(MainApplication.getLayerManager(), viewportData);
     210        mapView.addTemporaryLayer(gridOverlay);
    207211
    208212        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    … …  
    367371
    368372        statusLine.destroy();
     373        mapView.removeTemporaryLayer(gridOverlay);
     374        gridOverlay.destroy();
    369375        mapView.destroy();
    370376        keyDetector.unregister();
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r19291 r19640  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
     7import java.awt.BasicStroke;
    78import java.awt.Color;
    89import java.awt.Component;
    … …  
    1617import java.awt.Shape;
    1718import java.awt.Toolkit;
     19import java.awt.Stroke;
    1820import java.awt.event.ActionEvent;
    1921import java.awt.event.MouseAdapter;
    … …  
    9496import org.openstreetmap.josm.data.preferences.BooleanProperty;
    9597import org.openstreetmap.josm.data.preferences.IntegerProperty;
     98import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    9699import org.openstreetmap.josm.data.projection.Projection;
    97100import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    … …  
    117120import org.openstreetmap.josm.gui.layer.imagery.ReprojectionTile;
    118121import org.openstreetmap.josm.gui.layer.imagery.ShowErrorsAction;
     122import org.openstreetmap.josm.gui.layer.imagery.ShowTileBordersAction;
    119123import org.openstreetmap.josm.gui.layer.imagery.TileAnchor;
    120124import org.openstreetmap.josm.gui.layer.imagery.TileCoordinateConverter;
    … …  
    182186
    183187    private static final BooleanProperty POPUP_MENU_ENABLED = new BooleanProperty(PREFERENCE_PREFIX + ".popupmenu", true);
     188    /** Color of the border drawn around each tile if enabled, see {@link TileSourceDisplaySettings#isShowTileBorders()} */
     189    private static final NamedColorProperty TILE_BORDER_COLOR = new NamedColorProperty(marktr("imagery tile border"), new Color(0, 0, 0, 96));
     190    private static final Stroke TILE_BORDER_STROKE = new BasicStroke(1f);
    184191    private static final String ERROR_STRING = marktr("Error");
    185192
    … …  
    12271234        }
    12281235
    1229         if (Logging.isDebugEnabled()) {
     1236        if (getDisplaySettings().isShowTileBorders()) {
     1237            // draw a thin border around the tile
     1238            Color oldColor = g.getColor();
     1239            Stroke oldStroke = g.getStroke();
     1240            g.setColor(TILE_BORDER_COLOR.get());
     1241            g.setStroke(TILE_BORDER_STROKE);
     1242            g.draw(coordinateConverter.getTileShapeScreen(tile));
     1243            g.setStroke(oldStroke);
     1244            g.setColor(oldColor);
     1245        } else if (Logging.isDebugEnabled()) {
    12301246            // draw tile outline in semi-transparent red
    12311247            g.setColor(new Color(255, 0, 0, 50));
    … …  
    18541870            new AutoZoomAction(this),
    18551871            new ShowErrorsAction(this),
     1872            new ShowTileBordersAction(this),
    18561873            new IncreaseZoomAction(this),
    18571874            new DecreaseZoomAction(this),
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java

    r19629 r19640  
    4646    private static final String SHOW_ERRORS = "show-errors";
    4747
     48    private static final String SHOW_TILE_BORDERS = "show-tile-borders";
     49
    4850    private static final String DISPLACEMENT = "displacement";
    4951
    … …  
    5961     */
    6062    public static final BooleanProperty PROP_AUTO_ZOOM = new BooleanProperty(PREFERENCE_PREFIX + ".default_autozoom", true);
     63
     64    /**
     65     * The default tile borders property, remembered whenever the user toggles them, so that the choice also
     66     * applies to layers created later and after a restart
     67     * @since 19640
     68     */
     69    public static final BooleanProperty PROP_SHOW_TILE_BORDERS
     70            = new BooleanProperty(PREFERENCE_PREFIX + ".default_showtileborders", false);
    6171
    6272
    … …  
    6777    /** if layer should show errors on tiles */
    6878    private boolean showErrors;
     79    /** if layer should draw a border around each tile */
     80    private boolean showTileBorders;
    6981
    7082    private OffsetBookmark previousOffsetBookmark;
    … …  
    97109        autoLoad = getProperty(prefixes, "default_autoload", PROP_AUTO_LOAD.getDefaultValue());
    98110        showErrors = getProperty(prefixes, "default_showerrors", Boolean.TRUE);
     111        showTileBorders = getProperty(prefixes, "default_showtileborders", PROP_SHOW_TILE_BORDERS.getDefaultValue());
    99112    }
    100113
    101114    private static boolean getProperty(String[] prefixes, String name, Boolean def) {
    102         // iterate through all values to force the preferences to receive the default value.
    103         // we only support a default value of true.
    104         boolean value = true;
     115        // iterate through all values to force the preferences to receive the default value
     116        boolean value = def;
    105117        for (String p : prefixes) {
    106118            String key = p + "." + name;
    107             boolean currentValue = Config.getPref().getBoolean(key, true);
     119            boolean currentValue = Config.getPref().getBoolean(key, def);
    108120            if (!Config.getPref().get(key, def.toString()).isEmpty()) {
    109121                value = currentValue;
    … …  
    168180        this.showErrors = showErrors;
    169181        fireSettingsChange(SHOW_ERRORS);
     182    }
     183
     184    /**
     185     * If the layer should draw a thin border around each tile.
     186     * @return <code>true</code> to draw tile borders.
     187     * @since 19640
     188     */
     189    public boolean isShowTileBorders() {
     190        return showTileBorders;
     191    }
     192
     193    /**
     194     * Sets the show tile borders property. Fires a change event.
     195     * @param showTileBorders {@code true} if the layer should draw a thin border around each tile
     196     * @see #isShowTileBorders()
     197     * @since 19640
     198     */
     199    public void setShowTileBorders(boolean showTileBorders) {
     200        this.showTileBorders = showTileBorders;
     201        fireSettingsChange(SHOW_TILE_BORDERS);
    170202    }
    171203
    … …  
    290322        data.put(AUTO_ZOOM, Boolean.toString(autoZoom));
    291323        data.put(SHOW_ERRORS, Boolean.toString(showErrors));
     324        data.put(SHOW_TILE_BORDERS, Boolean.toString(showTileBorders));
    292325        return data;
    293326    }
    … …  
    317350                setShowErrors(Boolean.parseBoolean(doShowErrors));
    318351            }
     352
     353            String doShowTileBorders = data.get(SHOW_TILE_BORDERS);
     354            if (doShowTileBorders != null) {
     355                setShowTileBorders(Boolean.parseBoolean(doShowTileBorders));
     356            }
    319357        } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
    320358            throw BugReport.intercept(e).put("data", data);
    … …  
    324362    @Override
    325363    public int hashCode() {
    326         return Objects.hash(autoLoad, autoZoom, showErrors);
     364        return Objects.hash(autoLoad, autoZoom, showErrors, showTileBorders);
    327365    }
    328366
    … …  
    336374        return autoLoad == other.autoLoad
    337375            && autoZoom == other.autoZoom
    338             && showErrors == other.showErrors;
     376            && showErrors == other.showErrors
     377            && showTileBorders == other.showTileBorders;
    339378    }
    340379
    … …  
    342381    public String toString() {
    343382        return "TileSourceDisplaySettings [autoZoom=" + autoZoom + ", autoLoad=" + autoLoad + ", showErrors="
    344                 + showErrors + ']';
     383                + showErrors + ", showTileBorders=" + showTileBorders + ']';
    345384    }
    346385
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r19535 r19640  
    5252import org.openstreetmap.josm.gui.preferences.display.DrawingPreference;
    5353import org.openstreetmap.josm.gui.preferences.display.GPXPreference;
     54import org.openstreetmap.josm.gui.preferences.display.GridPreference;
    5455import org.openstreetmap.josm.gui.preferences.display.LafPreference;
    5556import org.openstreetmap.josm.gui.preferences.display.LanguagePreference;
    … …  
    611612        SETTINGS_FACTORIES.add(new ProxyPreference.Factory());
    612613        SETTINGS_FACTORIES.add(new ProjectionPreference.Factory());
     614        SETTINGS_FACTORIES.add(new GridPreference.Factory());
    613615        SETTINGS_FACTORIES.add(new MapPaintPreference.Factory());
    614616        SETTINGS_FACTORIES.add(new TaggingPresetPreference.Factory());
Note: See TracChangeset for help on using the changeset viewer.