Changeset 12964 in josm


Ignore:
Timestamp:
2017-10-09T15:22:45+02:00 (2 months ago)
Author:
bastiK
Message:

see #15273 - more straightforward way to set up the styles for rendering

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/ComputeStyleListWorker.java

    r12846 r12964  
    3636    private final transient List<StyleRecord> output;
    3737
    38     private final transient ElemStyles styles = MapPaintStyles.getStyles();
     38    private final transient ElemStyles styles;
    3939    private final int directExecutionTaskSize;
    4040    private final double circum;
     
    5555    ComputeStyleListWorker(double circum, NavigatableComponent nc,
    5656            final List<? extends OsmPrimitive> input, List<StyleRecord> output, int directExecutionTaskSize) {
     57        this(circum, nc, input, output, directExecutionTaskSize, MapPaintStyles.getStyles());
     58    }
     59
     60    /**
     61     * Constructs a new {@code ComputeStyleListWorker}.
     62     * @param circum distance on the map in meters that 100 screen pixels represent
     63     * @param nc navigatable component
     64     * @param input the primitives to process
     65     * @param output the list of styles to which styles will be added
     66     * @param directExecutionTaskSize the threshold deciding whether to subdivide the tasks
     67     * @param styles the {@link ElemStyles} instance used to generate primitive {@link StyleElement}s.
     68     * @since 12964
     69     */
     70    ComputeStyleListWorker(double circum, NavigatableComponent nc,
     71            final List<? extends OsmPrimitive> input, List<StyleRecord> output, int directExecutionTaskSize,
     72            ElemStyles styles) {
    5773        this.circum = circum;
    5874        this.nc = nc;
     
    6076        this.output = output;
    6177        this.directExecutionTaskSize = directExecutionTaskSize;
     78        this.styles = styles;
    6279        this.drawArea = circum <= Config.getPref().getInt("mappaint.fillareas", 10_000_000);
    6380        this.drawMultipolygon = drawArea && Config.getPref().getBoolean("mappaint.multipolygon", true);
     
    7592                final int toIndex = Math.min(fromIndex + directExecutionTaskSize, input.size());
    7693                tasks.add(new ComputeStyleListWorker(circum, nc, input.subList(fromIndex, toIndex),
    77                         new ArrayList<>(directExecutionTaskSize), directExecutionTaskSize).fork());
     94                        new ArrayList<>(directExecutionTaskSize), directExecutionTaskSize, styles).fork());
    7895            }
    7996            for (ForkJoinTask<List<StyleRecord>> task : tasks) {
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r12876 r12964  
    6565import org.openstreetmap.josm.gui.draw.MapViewPath;
    6666import org.openstreetmap.josm.gui.draw.MapViewPositionAndRotation;
     67import org.openstreetmap.josm.gui.mappaint.ElemStyles;
     68import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    6769import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement;
    6870import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.HorizontalTextAlignment;
     
    261263
    262264    private MapPaintSettings paintSettings;
     265    private ElemStyles styles;
    263266
    264267    private Color highlightColorTransparent;
     
    345348        Component focusOwner = FocusManager.getCurrentManager().getFocusOwner();
    346349        useWiderHighlight = !(focusOwner instanceof AbstractButton || focusOwner == nc);
     350        this.styles = MapPaintStyles.getStyles();
     351    }
     352
     353    /**
     354     * Set the {@link ElemStyles} instance to use for this renderer.
     355     * @param styles the {@code ElemStyles} instance to use
     356     */
     357    public void setStyles(ElemStyles styles) {
     358        this.styles = styles;
    347359    }
    348360
     
    16261638            // (Could be synchronized, but try to avoid this for performance reasons.)
    16271639            THREAD_POOL.invoke(new ComputeStyleListWorker(circum, nc, relations, allStyleElems,
    1628                     Math.max(20, relations.size() / THREAD_POOL.getParallelism() / 3)));
     1640                    Math.max(20, relations.size() / THREAD_POOL.getParallelism() / 3), styles));
    16291641            THREAD_POOL.invoke(new ComputeStyleListWorker(circum, nc, new CompositeList<>(nodes, ways), allStyleElems,
    1630                     Math.max(100, (nodes.size() + ways.size()) / THREAD_POOL.getParallelism() / 3)));
     1642                    Math.max(100, (nodes.size() + ways.size()) / THREAD_POOL.getParallelism() / 3), styles));
    16311643
    16321644            if (!benchmark.renderSort()) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java

    r12963 r12964  
    2323import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    2424import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
    25 import org.openstreetmap.josm.data.preferences.sources.SourceEntry;
    26 import org.openstreetmap.josm.data.preferences.sources.SourceType;
    2725import org.openstreetmap.josm.data.projection.Projection;
    2826import org.openstreetmap.josm.gui.NavigatableComponent;
     
    10098    public void render() throws IOException, IllegalDataException {
    10199        // load the styles
     100        ElemStyles elemStyles = new ElemStyles();
    102101        MapCSSStyleSource.STYLE_SOURCE_LOCK.writeLock().lock();
    103102        try {
    104             MapPaintStyles.getStyles().clear();
    105103            for (StyleData sd : styles) {
    106                 SourceEntry se = new SourceEntry(SourceType.MAP_PAINT_STYLE, sd.styleUrl,
    107                             "cliRenderingStyle", "cli rendering style '" + sd.styleUrl + "'", true /* active */);
    108                 StyleSource source = MapPaintStyles.addStyle(se);
     104                MapCSSStyleSource source = new MapCSSStyleSource(sd.styleUrl, "cliRenderingStyle", "cli rendering style '" + sd.styleUrl + "'");
     105                source.loadStyleSource();
     106                elemStyles.add(source);
    109107                if (!source.getErrors().isEmpty()) {
    110108                    throw new IllegalDataException("Failed to load style file. Errors: " + source.getErrors());
     
    156154        g.setColor(PaintColors.getBackgroundColor());
    157155        g.fillRect(0, 0, imgDimPx.width, imgDimPx.height);
    158         new StyledMapRenderer(g, nc, false).render(ds, false, bounds);
     156        StyledMapRenderer smr = new StyledMapRenderer(g, nc, false);
     157        smr.setStyles(elemStyles);
     158        smr.render(ds, false, bounds);
    159159
    160160        // write to file
Note: See TracChangeset for help on using the changeset viewer.