Ticket #24678: patch-24678.diff

File patch-24678.diff, 20.6 KB (added by zkir, 27 hours ago)
  • src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintSettings.java

    diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintSettings.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintSettings.java
    index a5111b2b24..3708debda4 100644
    a b public final class MapPaintSettings implements PreferenceChangedListener {  
    7171        Config.getPref().addPreferenceChangeListener(this);
    7272    }
    7373
     74    /**
     75     * Constructs new MapPaintSettings with custom values. Used for rendering where preferences should not be used.
     76     * @param useRealWidth if true, real width of ways should be used
     77     * @param showDirectionArrow if true, directional arrows should be displayed
     78     * @param showOnewayArrow if true, arrows for oneways should be displayed
     79     * @param defaultSegmentWidth default width for ways segments
     80     * @param showOrderNumber if true, segment numbers of ways should be displayed
     81     * @param showOrderNumberOnSelectedWay if true, segment numbers of ways should be displayed on selected way
     82     * @param showHeadArrowOnly if true, only the last arrow of a way should be displayed
     83     * @param showNamesDistance the distance at which names should be drawn
     84     * @param useStrokesDistance the distance at which strokes should be used
     85     * @param showIconsDistance the distance at which icons should be drawn
     86     * @param selectedNodeSize the size of selected nodes
     87     * @param connectionNodeSize the size of multiply connected nodes
     88     * @param unselectedNodeSize the size of unselected nodes
     89     * @param taggedNodeSize the size of tagged nodes
     90     * @param fillSelectedNode if true, selected nodes should be filled
     91     * @param fillUnselectedNode if true, unselected nodes should be filled
     92     * @param fillTaggedNode if true, tagged nodes should be filled
     93     * @param fillConnectionNode if true, multiply connected nodes should be filled
     94     * @param outlineOnly if true, only the data area outline should be drawn
     95     * @param selectedColor color for selected objects
     96     * @param relationSelectedColor color for selected relations
     97     * @param highlightColor color for highlighted objects
     98     * @param inactiveColor color for inactive objects
     99     * @param nodeColor color for nodes
     100     * @param taggedColor color for tagged nodes
     101     * @param connectionColor color for multiply connected nodes
     102     * @param taggedConnectionColor color for tagged and multiply connected nodes
     103     */
     104    public MapPaintSettings(boolean useRealWidth, boolean showDirectionArrow, boolean showOnewayArrow,
     105                            int defaultSegmentWidth, boolean showOrderNumber, boolean showOrderNumberOnSelectedWay,
     106                            boolean showHeadArrowOnly, int showNamesDistance, int useStrokesDistance,
     107                            int showIconsDistance, int selectedNodeSize, int connectionNodeSize,
     108                            int unselectedNodeSize, int taggedNodeSize, boolean fillSelectedNode,
     109                            boolean fillUnselectedNode, boolean fillTaggedNode, boolean fillConnectionNode,
     110                            boolean outlineOnly, Color selectedColor, Color relationSelectedColor,
     111                            Color highlightColor, Color inactiveColor, Color nodeColor, Color taggedColor,
     112                            Color connectionColor, Color taggedConnectionColor) {
     113        this.useRealWidth = useRealWidth;
     114        this.showDirectionArrow = showDirectionArrow;
     115        this.showOnewayArrow = showOnewayArrow;
     116        this.defaultSegmentWidth = defaultSegmentWidth;
     117        this.showOrderNumber = showOrderNumber;
     118        this.showOrderNumberOnSelectedWay = showOrderNumberOnSelectedWay;
     119        this.showHeadArrowOnly = showHeadArrowOnly;
     120        this.showNamesDistance = showNamesDistance;
     121        this.useStrokesDistance = useStrokesDistance;
     122        this.showIconsDistance = showIconsDistance;
     123        this.selectedNodeSize = selectedNodeSize;
     124        this.connectionNodeSize = connectionNodeSize;
     125        this.unselectedNodeSize = unselectedNodeSize;
     126        this.taggedNodeSize = taggedNodeSize;
     127        this.fillSelectedNode = fillSelectedNode;
     128        this.fillUnselectedNode = fillUnselectedNode;
     129        this.fillTaggedNode = fillTaggedNode;
     130        this.fillConnectionNode = fillConnectionNode;
     131        this.outlineOnly = outlineOnly;
     132        this.selectedColor = selectedColor;
     133        this.relationSelectedColor = relationSelectedColor;
     134        this.highlightColor = highlightColor;
     135        this.inactiveColor = inactiveColor;
     136        this.nodeColor = nodeColor;
     137        this.taggedColor = taggedColor;
     138        this.connectionColor = connectionColor;
     139        this.taggedConnectionColor = taggedConnectionColor;
     140    }
     141
     142    /**
     143     * Creates MapPaintSettings with most neutral settings, that do not override MapCSS.
     144     * Useful for MapCSS CLI/Plugin rendering, via {@link org.openstreetmap.josm.gui.mappaint.RenderingHelper}
     145     * @return a new MapPaintSettings instance with neutral values.
     146     */
     147    public static MapPaintSettings createNeutralSettings() {
     148        // Use current INSTANCE to get default colors and other non-arrow-related settings
     149        MapPaintSettings instance = MapPaintSettings.INSTANCE;
     150        return new MapPaintSettings(
     151                false, // Real width is not used (at least currently)
     152                false, // Direction arrows are turned off
     153                false, // One way arrows are disabled
     154                instance.getDefaultSegmentWidth(),
     155                false, // Segment numbers are disabled
     156                false, // Segment numbers are disabled on selected ways
     157                false, // Direction arrows are turned off on way head
     158                0, // Forced labels are disabled
     159                instance.getUseStrokesDistance(),
     160                instance.getShowIconsDistance(),
     161                instance.getSelectedNodeSize(),
     162                instance.getConnectionNodeSize(),
     163                instance.getUnselectedNodeSize(),
     164                instance.getTaggedNodeSize(),
     165                instance.isFillSelectedNode(),
     166                instance.isFillUnselectedNode(),
     167                instance.isFillTaggedNode(),
     168                instance.isFillConnectionNode(),
     169                false, //Polygons are filled as per MapCSS style,
     170                instance.getSelectedColor(),
     171                instance.getRelationSelectedColor(),
     172                instance.getHighlightColor(),
     173                instance.getInactiveColor(),
     174                instance.getNodeColor(),
     175                instance.getTaggedColor(),
     176                instance.getConnectionColor(),
     177                instance.getTaggedConnectionColor()
     178        );
     179    }
     180
    74181    private void load() {
    75182        showDirectionArrow = Config.getPref().getBoolean("draw.segment.direction", false);
    76183        showOnewayArrow = Config.getPref().getBoolean("draw.oneway", true);
  • src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
    index f49eb1e332..47909742c1 100644
    a b public class StyledMapRenderer extends AbstractMapRenderer {  
    382382        this.styles = MapPaintStyles.getStyles();
    383383    }
    384384
     385    /**
     386     * Constructs a new {@code StyledMapRenderer} with custom map paint settings.
     387     *
     388     * @param g the graphics context. Must not be null.
     389     * @param nc the map viewport. Must not be null.
     390     * @param isInactiveMode if true, the paint visitor shall render OSM objects such that they
     391     * look inactive. Example: rendering of data in an inactive layer using light gray as color only.
     392     * @param paintSettings the map paint settings to use. Must not be null.
     393     * @throws IllegalArgumentException if {@code g} is null
     394     * @throws IllegalArgumentException if {@code nc} is null
     395     * @throws IllegalArgumentException if {@code paintSettings} is null
     396     */
     397    public StyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode, MapPaintSettings paintSettings) {
     398        this(g, nc, isInactiveMode);
     399        this.paintSettings = paintSettings;
     400    }
     401
    385402    /**
    386403     * Set the {@link ElemStyles} instance to use for this renderer.
    387404     * @param styles the {@code ElemStyles} instance to use
    public class StyledMapRenderer extends AbstractMapRenderer {  
    14101427    @Override
    14111428    public void getSettings(boolean virtual) {
    14121429        super.getSettings(virtual);
    1413         paintSettings = MapPaintSettings.INSTANCE;
     1430        if (paintSettings == null) {
     1431            paintSettings = MapPaintSettings.INSTANCE;
     1432        }
    14141433
    14151434        circum = nc.getDist100Pixel();
    14161435        scale = nc.getScale();
  • src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java

    diff --git a/src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java b/src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java
    index 93f524a944..c8fab26cae 100644
    a b import org.openstreetmap.josm.data.projection.ProjectionRegistry;  
    2626import org.openstreetmap.josm.gui.NavigatableComponent;
    2727import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    2828import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
     29import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
    2930import org.openstreetmap.josm.io.IllegalDataException;
    3031import org.openstreetmap.josm.tools.CheckParameterUtil;
    3132import org.openstreetmap.josm.tools.Logging;
    public class RenderingHelper {  
    183184            g.setColor(Optional.ofNullable(backgroundColor).orElse(elemStyles.getBackgroundColor()));
    184185            g.fillRect(0, 0, imgDimPx.width, imgDimPx.height);
    185186        }
    186         StyledMapRenderer smr = new StyledMapRenderer(g, nc, false);
     187        StyledMapRenderer smr = new StyledMapRenderer(g, nc, false, MapPaintSettings.createNeutralSettings());
    187188        smr.setStyles(elemStyles);
    188189        smr.render(ds, false, bounds);
    189190