Changeset 12966 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2017-10-09T17:14:50+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java
r12537 r12966 5 5 6 6 import java.awt.Color; 7 import java.util.List;8 import java.util.Optional;9 7 10 8 import org.openstreetmap.josm.data.preferences.CachingProperty; 11 9 import org.openstreetmap.josm.data.preferences.ColorProperty; 12 10 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 13 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener;14 import org.openstreetmap.josm.gui.mappaint.StyleSource;15 11 16 12 /** … … 91 87 private final CachingProperty<Color> property; 92 88 93 private static volatile Color backgroundColorCache;94 95 private static final MapPaintSylesUpdateListener STYLE_OVERRIDE_LISTENER = new MapPaintSylesUpdateListener() {96 //TODO: Listen to wireframe map mode changes.97 @Override98 public void mapPaintStylesUpdated() {99 backgroundColorCache = null;100 }101 102 @Override103 public void mapPaintStyleEntryUpdated(int idx) {104 mapPaintStylesUpdated();105 }106 };107 108 static {109 MapPaintStyles.addMapPaintSylesUpdateListener(STYLE_OVERRIDE_LISTENER);110 }111 112 89 PaintColors(String name, Color defaultColor) { 113 90 baseProperty = new ColorProperty(name, defaultColor); … … 138 115 */ 139 116 public static Color getBackgroundColor() { 140 if (backgroundColorCache != null) 141 return backgroundColorCache; 142 List<StyleSource> sources = MapPaintStyles.getStyles().getStyleSources(); 143 for (StyleSource s : sources) { 144 if (!s.active) { 145 continue; 146 } 147 Color backgroundColorOverride = s.getBackgroundColorOverride(); 148 if (backgroundColorOverride != null) { 149 backgroundColorCache = backgroundColorOverride; 150 } 151 } 152 return Optional.ofNullable(backgroundColorCache).orElseGet(BACKGROUND::get); 117 return MapPaintStyles.getStyles().getBackgroundColor(); 153 118 } 154 119 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r12964 r12966 1372 1372 super.getColors(); 1373 1373 this.highlightColorTransparent = new Color(highlightColor.getRed(), highlightColor.getGreen(), highlightColor.getBlue(), 100); 1374 this.backgroundColor = PaintColors.getBackgroundColor();1374 this.backgroundColor = styles.getBackgroundColor(); 1375 1375 } 1376 1376 -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r12881 r12966 10 10 import java.util.Map; 11 11 import java.util.Map.Entry; 12 import java.util.Optional; 12 13 13 14 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent; … … 17 18 import org.openstreetmap.josm.data.osm.Relation; 18 19 import org.openstreetmap.josm.data.osm.Way; 20 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 19 21 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; 20 22 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; … … 69 71 private final Map<String, String> preferenceCache = new HashMap<>(); 70 72 73 private static volatile Color backgroundColorCache; 74 71 75 /** 72 76 * Constructs a new {@code ElemStyles}. … … 75 79 styleSources = new ArrayList<>(); 76 80 Config.getPref().addPreferenceChangeListener(this); 81 MapPaintStyles.addMapPaintSylesUpdateListener(new MapPaintStyles.MapPaintSylesUpdateListener() { 82 //TODO: Listen to wireframe map mode changes. 83 @Override 84 public void mapPaintStylesUpdated() { 85 backgroundColorCache = null; 86 } 87 88 @Override 89 public void mapPaintStyleEntryUpdated(int idx) { 90 mapPaintStylesUpdated(); 91 } 92 }); 77 93 } 78 94 … … 94 110 public List<StyleSource> getStyleSources() { 95 111 return Collections.<StyleSource>unmodifiableList(styleSources); 112 } 113 114 public Color getBackgroundColor() { 115 if (backgroundColorCache != null) 116 return backgroundColorCache; 117 for (StyleSource s : styleSources) { 118 if (!s.active) { 119 continue; 120 } 121 Color backgroundColorOverride = s.getBackgroundColorOverride(); 122 if (backgroundColorOverride != null) { 123 backgroundColorCache = backgroundColorOverride; 124 } 125 } 126 return Optional.ofNullable(backgroundColorCache).orElseGet(PaintColors.BACKGROUND::get); 96 127 } 97 128 -
trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java
r12963 r12966 5 5 6 6 import java.awt.Dimension; 7 import java.awt.image.BufferedImage; 8 import java.io.File; 7 9 import java.io.FileInputStream; 8 10 import java.io.FileNotFoundException; … … 14 16 import java.util.function.Supplier; 15 17 import java.util.logging.Level; 18 19 import javax.imageio.ImageIO; 16 20 17 21 import org.openstreetmap.gui.jmapviewer.OsmMercator; … … 155 159 RenderingArea area = determineRenderingArea(ds); 156 160 RenderingHelper rh = new RenderingHelper(ds, area.bounds, area.scale, argStyles); 157 rh.setOutputFile(argOutput);158 161 checkPreconditions(rh); 159 rh.render(); 162 BufferedImage image = rh.render(); 163 writeImageToFile(image); 160 164 } catch (FileNotFoundException e) { 161 165 if (Logging.isDebugEnabled()) { … … 562 566 } 563 567 } 568 569 private void writeImageToFile(BufferedImage image) throws IOException { 570 String output = Optional.ofNullable(argOutput).orElse("out.png"); 571 ImageIO.write(image, "png", new File(output)); 572 } 564 573 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java
r12964 r12966 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Color; 6 7 import java.awt.Dimension; 7 8 import java.awt.Graphics2D; 8 9 import java.awt.Point; 10 import java.awt.RenderingHints; 9 11 import java.awt.image.BufferedImage; 10 import java.io.File;11 12 import java.io.IOException; 12 13 import java.util.Collection; … … 15 16 import java.util.Optional; 16 17 17 import javax.imageio.ImageIO;18 19 18 import org.openstreetmap.josm.Main; 20 19 import org.openstreetmap.josm.data.Bounds; 21 20 import org.openstreetmap.josm.data.ProjectionBounds; 22 21 import org.openstreetmap.josm.data.osm.DataSet; 23 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;24 22 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 25 23 import org.openstreetmap.josm.data.projection.Projection; … … 41 39 private final double scale; 42 40 private final Collection<StyleData> styles; 43 private String outputFile; 41 private Color backgroundColor; 42 private boolean fillBackground = true; 44 43 45 44 /** … … 73 72 74 73 /** 75 * Set the output file for rendering.74 * Set the background color to use for rendering. 76 75 * 77 * Default is {@code out.png}. 78 * @param outputFile the output file for rendering 76 * @param backgroundColor the background color to use, {@code} means 77 * to determine the background color automatically from the style 78 * @see #setFillBackground(boolean) 79 * @since 12966 79 80 */ 80 public void setOutputFile(String outputFile) { 81 this.outputFile = outputFile; 81 public void setBackgroundColor(Color backgroundColor) { 82 this.backgroundColor = backgroundColor; 83 } 84 85 /** 86 * Decide if background should be filled or left transparent. 87 * @param fillBackground true, if background should be filled 88 * @see #setBackgroundColor(java.awt.Color) 89 * @since 12966 90 */ 91 public void setFillBackground(boolean fillBackground) { 92 this.fillBackground = fillBackground; 82 93 } 83 94 … … 93 104 * Invoke the renderer. 94 105 * 106 * @return the rendered image 95 107 * @throws IOException in case of an IOException 96 108 * @throws IllegalDataException when illegal data is encountered (style has errors, etc.) 97 109 */ 98 public voidrender() throws IOException, IllegalDataException {110 public BufferedImage render() throws IOException, IllegalDataException { 99 111 // load the styles 100 112 ElemStyles elemStyles = new ElemStyles(); … … 152 164 BufferedImage image = new BufferedImage(imgDimPx.width, imgDimPx.height, BufferedImage.TYPE_INT_ARGB); 153 165 Graphics2D g = image.createGraphics(); 154 g.setColor(PaintColors.getBackgroundColor()); 155 g.fillRect(0, 0, imgDimPx.width, imgDimPx.height); 166 167 // Force all render hints to be defaults - do not use platform values 168 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 169 g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); 170 g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); 171 g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); 172 g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); 173 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 174 g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 175 g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); 176 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 177 178 if (fillBackground) { 179 g.setColor(Optional.ofNullable(backgroundColor).orElse(elemStyles.getBackgroundColor())); 180 g.fillRect(0, 0, imgDimPx.width, imgDimPx.height); 181 } 156 182 StyledMapRenderer smr = new StyledMapRenderer(g, nc, false); 157 183 smr.setStyles(elemStyles); 158 184 smr.render(ds, false, bounds); 159 160 // write to file 161 String output = Optional.ofNullable(outputFile).orElse("out.png"); 162 ImageIO.write(image, "png", new File(output)); 185 return image; 163 186 } 164 187
Note:
See TracChangeset
for help on using the changeset viewer.