Changeset 12966 in josm for trunk/test/functional


Ignore:
Timestamp:
2017-10-09T17:14:50+02:00 (7 years ago)
Author:
bastiK
Message:

use RenderingHelper in MapCSSRendererTest; move getBackgroundColor() from PaintColors to ElemStyles (no longer global) (see #15273)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java

    r12965 r12966  
    55import static org.junit.Assert.fail;
    66
    7 import java.awt.Graphics2D;
    87import java.awt.GraphicsEnvironment;
    98import java.awt.Point;
    10 import java.awt.RenderingHints;
    119import java.awt.image.BufferedImage;
    1210import java.io.File;
     
    1816import java.util.Arrays;
    1917import java.util.Collection;
     18import java.util.Collections;
    2019import java.util.List;
    2120import java.util.stream.Collectors;
     
    3837import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3938import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
    40 import org.openstreetmap.josm.data.preferences.sources.SourceEntry;
    41 import org.openstreetmap.josm.data.preferences.sources.SourceType;
    42 import org.openstreetmap.josm.gui.NavigatableComponent;
    43 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    4439import org.openstreetmap.josm.io.IllegalDataException;
    4540import org.openstreetmap.josm.io.OsmReader;
     
    163158        // load the data
    164159        DataSet dataSet = testConfig.getOsmDataSet();
    165 
    166         // load the style
    167         MapCSSStyleSource.STYLE_SOURCE_LOCK.writeLock().lock();
    168         try {
    169             MapPaintStyles.getStyles().clear();
    170 
    171             MapCSSStyleSource source = new MapCSSStyleSource(testConfig.getStyleSourceEntry());
    172             source.loadStyleSource();
    173             if (!source.getErrors().isEmpty()) {
    174                 fail("Failed to load style file. Errors: " + source.getErrors());
    175             }
    176             MapPaintStyles.getStyles().setStyleSources(Arrays.asList(source));
    177             MapPaintStyles.fireMapPaintSylesUpdated();
    178             MapPaintStyles.getStyles().clearCached();
    179 
    180         } finally {
    181             MapCSSStyleSource.STYLE_SOURCE_LOCK.writeLock().unlock();
    182         }
    183 
    184         // create the renderer
    185         BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_ARGB);
    186         NavigatableComponent nc = new NavigatableComponent() {
    187             {
    188                 setBounds(0, 0, IMAGE_SIZE, IMAGE_SIZE);
    189                 updateLocationState();
    190             }
    191 
    192             @Override
    193             protected boolean isVisibleOnScreen() {
    194                 return true;
    195             }
    196 
    197             @Override
    198             public Point getLocationOnScreen() {
    199                 return new Point(0, 0);
    200             }
    201         };
     160        dataSet.allPrimitives().stream().forEach(this::loadPrimitiveStyle);
     161        dataSet.setSelected(dataSet.allPrimitives().stream().filter(n -> n.isKeyTrue("selected")).collect(Collectors.toList()));
     162
    202163        ProjectionBounds pb = new ProjectionBounds();
    203164        pb.extend(Main.getProjection().latlon2eastNorth(testConfig.testArea.getMin()));
    204165        pb.extend(Main.getProjection().latlon2eastNorth(testConfig.testArea.getMax()));
    205166        double scale = (pb.maxEast - pb.minEast) / IMAGE_SIZE;
    206         nc.zoomTo(pb.getCenter(), scale);
    207 
    208         dataSet.allPrimitives().stream().forEach(this::loadPrimitiveStyle);
    209         dataSet.setSelected(dataSet.allPrimitives().stream().filter(n -> n.isKeyTrue("selected")).collect(Collectors.toList()));
    210 
    211         Graphics2D g = image.createGraphics();
    212         // Force all render hints to be defaults - do not use platform values
    213         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    214         g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    215         g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    216         g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
    217         g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    218         g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    219         g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    220         g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    221         g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    222         new StyledMapRenderer(g, nc, false).render(dataSet, false, testConfig.testArea);
     167
     168        RenderingHelper.StyleData sd = new RenderingHelper.StyleData();
     169        sd.styleUrl = testConfig.getStyleSourceUrl();
     170        RenderingHelper rh = new RenderingHelper(dataSet, testConfig.testArea, scale, Collections.singleton(sd));
     171        rh.setFillBackground(false);
     172        BufferedImage image = rh.render();
    223173
    224174        if (UPDATE_ALL) {
     
    317267        }
    318268
    319         public SourceEntry getStyleSourceEntry() {
    320             return new SourceEntry(SourceType.MAP_PAINT_STYLE, getTestDirectory() + "/style.mapcss",
    321                     "test style", "a test style", true // active
    322             );
     269        public String getStyleSourceUrl() {
     270            return getTestDirectory() + "/style.mapcss";
    323271        }
    324272
Note: See TracChangeset for help on using the changeset viewer.