- Timestamp:
- 2011-02-07T11:42:34+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r3862 r3865 2 2 package org.openstreetmap.josm.data.osm.visitor.paint; 3 3 4 import java.awt.AlphaComposite; 4 5 import java.awt.BasicStroke; 5 6 import java.awt.Color; … … 31 32 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData; 32 33 import org.openstreetmap.josm.gui.NavigatableComponent; 34 import org.openstreetmap.josm.gui.mappaint.ElemStyle; 33 35 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle; 36 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.Symbol; 34 37 import org.openstreetmap.josm.tools.ImageProvider; 35 38 import org.openstreetmap.josm.tools.LanguageInfo; … … 54 57 55 58 private final Font orderFont; 56 private final int fillAlpha;57 59 private final int virtualNodeSize; 58 60 private final int virtualNodeSpace; … … 89 91 90 92 this.orderFont = new Font(Main.pref.get("mappaint.font", "Helvetica"), Font.PLAIN, Main.pref.getInteger("mappaint.fontsize", 8)); 91 this.fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));92 93 this.virtualNodeSize = virtual ? Main.pref.getInteger("mappaint.node.virtual-size", 8) / 2 : 0; 93 94 this.virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70); … … 187 188 } 188 189 189 public void drawNodeIcon(Node n, ImageIcon icon, boolean selected, boolean member, String name) {190 public void drawNodeIcon(Node n, ImageIcon icon, float iconAlpha, boolean selected, boolean member, String name) { 190 191 Point p = nc.getPoint(n); 191 192 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 192 193 193 194 int w = icon.getIconWidth(), h=icon.getIconHeight(); 195 if (iconAlpha != 1f) { 196 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, iconAlpha)); 197 } 194 198 icon.paintIcon ( nc, g, p.x-w/2, p.y-h/2 ); 199 g.setPaintMode(); 195 200 if(name != null) { 196 201 if (inactive || n.isDisabled()) { … … 208 213 g.setColor(selected? selectedColor : relationSelectedColor); 209 214 g.drawRect(p.x-w/2-2, p.y-h/2-2, w+4, h+4); 215 } 216 } 217 218 public void drawNodeSymbol(Node n, Symbol s, boolean selected, boolean member, String name) { 219 Point p = nc.getPoint(n); 220 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 221 int radius = (int) (s.size / 2); 222 223 if (s.fillColor != null) { 224 g.setColor(s.fillColor); 225 switch (s.symbol) { 226 case CIRCLE: 227 g.fillOval(p.x - radius, p.y - radius, (int) s.size, (int) s.size); 228 break; 229 case SQUARE: 230 g.fillRect(p.x - radius, p.y - radius, (int) s.size, (int) s.size); 231 break; 232 } 233 } 234 if (s.stroke != null) { 235 g.setStroke(s.stroke); 236 g.setColor(s.strokeColor); 237 switch (s.symbol) { 238 case CIRCLE: 239 g.drawOval(p.x - radius, p.y - radius, (int) s.size - 1, (int) s.size - 1); 240 break; 241 case SQUARE: 242 g.drawRect(p.x - radius, p.y - radius, (int) s.size - 1, (int) s.size - 1); 243 break; 244 } 245 g.setStroke(new BasicStroke()); 210 246 } 211 247 } … … 271 307 TexturePaint texture = new TexturePaint(fillImage, 272 308 new Rectangle(polygon.xpoints[0], polygon.ypoints[0], fillImage.getWidth(), fillImage.getHeight())); 273 274 309 g.setPaint(texture); 310 if (color.getAlpha() != 255) { 311 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, ElemStyle.color_int2float(color.getAlpha()))); 312 } 275 313 g.fill(polygon); 314 g.setPaintMode(); 276 315 } 277 316 -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r3862 r3865 3 3 4 4 import java.awt.Color; 5 import java.awt.Rectangle;6 import java.awt.TexturePaint;7 5 import java.awt.image.BufferedImage; 8 6 … … 17 15 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 18 16 import org.openstreetmap.josm.tools.Utils; 19 20 17 21 18 public class AreaElemStyle extends ElemStyle … … 33 30 BufferedImage fillImage = null; 34 31 IconReference iconRef = c.get("fill-image", null, IconReference.class); 32 Integer fillImageAlpha = null; 33 35 34 if (iconRef != null) { 36 35 ImageIcon icon = MapPaintStyles.getIcon(iconRef, false); … … 42 41 throw new RuntimeException(); 43 42 fillImage = (BufferedImage) icon.getImage(); 43 44 fillImageAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255)))); 45 Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class)); 46 if (pAlpha != null) { 47 fillImageAlpha = pAlpha; 48 } 44 49 } 45 50 } … … 48 53 if (color != null) { 49 54 50 int alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 51 Integer pAlpha = color_float2int(c.get("fill-opacity", null, float.class)); 52 if (pAlpha != null) { 53 alpha = pAlpha; 55 int alpha; 56 if (fillImageAlpha != null) { 57 alpha = fillImageAlpha; 58 } else { 59 alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 60 Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class)); 61 if (pAlpha != null) { 62 alpha = pAlpha; 63 } 54 64 } 55 65 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); 56 66 } 57 67 58 if (fillImage != null || color != null) 68 if (fillImage != null || color != null) { 69 if (color == null) { 70 color = new Color(0, 0, 0, fillImageAlpha); 71 } 59 72 return new AreaElemStyle(c, color, fillImage); 73 } 60 74 else 61 75 return null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
r3860 r3865 15 15 public class Cascade implements Cloneable { 16 16 17 public static final Cascade EMPTY_CASCADE = new Cascade( );17 public static final Cascade EMPTY_CASCADE = new Cascade(false); 18 18 19 19 protected Map<String, Object> prop = new HashMap<String, Object>(); 20 21 /** 22 * constructor 23 * @param isModifier Everything that is not on the default layer is assumed to 24 * be a modifier. Can be overridden in style definition. 25 */ 26 public Cascade(boolean isModifier) { 27 if (isModifier) { 28 put("modifier", true); 29 } 30 } 31 32 private Cascade() { 33 } 20 34 21 35 public <T> T get(String key, T def, Class<T> klass) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r3858 r3865 7 7 8 8 abstract public class ElemStyle { 9 9 10 10 public float z_index; 11 11 public float object_z_index; 12 public boolean isModifier; // false, if style can serve as main style for the 13 // primitive; true, if it is a highlight or modifier 12 14 13 public ElemStyle(float z_index, float object_z_index ) {15 public ElemStyle(float z_index, float object_z_index, boolean isModifier) { 14 16 this.z_index = z_index; 15 17 this.object_z_index = object_z_index; 18 this.isModifier = isModifier; 16 19 } 17 20 … … 19 22 z_index = c.get("z-index", 0f, Float.class); 20 23 object_z_index = c.get("object-z-index", 0f, Float.class); 24 isModifier = c.get("modifier", false, Boolean.class); 21 25 } 22 26 … … 28 32 return false; 29 33 ElemStyle s = (ElemStyle) o; 30 return z_index == s.z_index && object_z_index == s.object_z_index ;34 return z_index == s.z_index && object_z_index == s.object_z_index && isModifier == s.isModifier; 31 35 } 32 36 … … 36 40 hash = 41 * hash + Float.floatToIntBits(this.z_index); 37 41 hash = 41 * hash + Float.floatToIntBits(this.object_z_index); 42 hash = 41 * hash + (isModifier ? 1 : 0); 38 43 return hash; 39 44 } … … 42 47 public String toString() { 43 48 if (z_index != 0f || object_z_index != 0f) 44 return String.format("z_idx=%s/%s ", z_index, object_z_index) ;49 return String.format("z_idx=%s/%s ", z_index, object_z_index) + (isModifier ? "modifier " : ""); 45 50 return ""; 46 51 } 47 48 public static Integer color_float2int(Float val) {49 if (val == null || val < 0 || val > 1)50 return null;51 return (int) (255f * val + 0.5f);52 }53 54 public static Float color_int2float(Integer val) {55 if (val == null || val < 0 || val > 255)56 return null;57 return ((float) val) / 255f;58 }59 52 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3860 r3865 52 52 } 53 53 Pair<StyleList, Range> p = getImpl(osm, scale, nc); 54 if (osm instanceof Node && p.a.isEmpty()) { 55 p.a = StyleList.SIMPLE_NODE; 56 } else if (osm instanceof Way && !Utils.exists(p.a, LineElemStyle.class)) { 57 AreaElemStyle area = Utils.find(p.a, AreaElemStyle.class); 58 LineElemStyle line = (area == null ? LineElemStyle.UNTAGGED_WAY : LineElemStyle.createSimpleLineStyle(area.color)); 59 p.a = new StyleList(p.a, line); 54 if (osm instanceof Node) { 55 boolean hasNonModifier = false; 56 for (ElemStyle s : p.a) { 57 if (!s.isModifier) { 58 hasNonModifier = true; 59 break; 60 } 61 } 62 if (!hasNonModifier) { 63 p.a = new StyleList(p.a, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE); 64 } 65 } else if (osm instanceof Way) { 66 boolean hasNonModifierLine = false; 67 for (ElemStyle s : p.a) { 68 if (s instanceof LineElemStyle && !s.isModifier) { 69 hasNonModifierLine = true; 70 break; 71 } 72 } 73 if (!hasNonModifierLine) { 74 AreaElemStyle area = Utils.find(p.a, AreaElemStyle.class); 75 LineElemStyle line = (area == null ? LineElemStyle.UNTAGGED_WAY : LineElemStyle.createSimpleLineStyle(area.color)); 76 p.a = new StyleList(p.a, line); 77 } 60 78 } 61 79 osm.mappaintStyle = osm.mappaintStyle.put(p.a, p.b); -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3860 r3865 20 20 21 21 public static LineElemStyle createSimpleLineStyle(Color color) { 22 Cascade c = new Cascade( );22 Cascade c = new Cascade(false); 23 23 c.put("width", -1f); 24 24 c.put("color", color != null ? color : PaintColors.UNTAGGED.get()); … … 29 29 public static final LineElemStyle UNTAGGED_WAY = createSimpleLineStyle(null); 30 30 31 p ublic float realWidth; // the real width of this line in meter31 private BasicStroke line; 32 32 public Color color; 33 33 public Color dashesBackground; 34 35 private BasicStroke line; 34 public float realWidth; // the real width of this line in meter 35 36 36 private BasicStroke dashesLine; 37 37 … … 106 106 107 107 int alpha = 255; 108 Integer pAlpha = color_float2int(c.get("opacity", null, float.class));108 Integer pAlpha = Utils.color_float2int(c.get("opacity", null, float.class)); 109 109 if (pAlpha != null) { 110 110 alpha = pAlpha; … … 131 131 Color dashesBackground = c.get(prefix + "dashes-background-color", null, Color.class); 132 132 if (dashesBackground != null) { 133 pAlpha = color_float2int(c.get(prefix + "dashes-background-opacity", null, Float.class));133 pAlpha = Utils.color_float2int(c.get(prefix + "dashes-background-opacity", null, Float.class)); 134 134 if (pAlpha != null) { 135 135 alpha = pAlpha; -
trunk/src/org/openstreetmap/josm/gui/mappaint/MultiCascade.java
r3836 r3865 18 18 19 19 public Cascade getCascade(String key) { 20 Cascade ret = get(key); 21 if (ret == null) { 22 ret = new Cascade(); 23 put(key, ret); 20 if (key == null) 21 throw new IllegalArgumentException(); 22 Cascade c = get(key); 23 if (c == null) { 24 c = new Cascade(!key.equals("default")); 25 put(key, c); 24 26 } 25 return ret;27 return c; 26 28 } 27 29 -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3862 r3865 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import static org.openstreetmap.josm.tools.Utils.equal; 5 6 import java.awt.BasicStroke; 4 7 import java.awt.Color; 8 import java.awt.Stroke; 5 9 6 10 import javax.swing.GrayFilter; 7 11 import javax.swing.ImageIcon; 8 12 13 import org.openstreetmap.josm.Main; 9 14 import org.openstreetmap.josm.data.osm.Node; 10 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 22 27 public String annotation_key; 23 28 public ImageIcon icon; 29 public int iconAlpha; 30 public Symbol symbol; 31 24 32 private ImageIcon disabledIcon; 25 33 26 public static final NodeElemStyle SIMPLE_NODE_ELEMSTYLE = new NodeElemStyle(Cascade.EMPTY_CASCADE, true, null, null); 27 28 protected NodeElemStyle(Cascade c, boolean annotate, String annotation_key, ImageIcon icon) { 34 public static class Symbol { 35 public SymbolShape symbol; 36 public float size; 37 public Stroke stroke; 38 public Color strokeColor; 39 public Color fillColor; 40 41 public Symbol(SymbolShape symbol, float size, Stroke stroke, Color strokeColor, Color fillColor) { 42 if (stroke != null && strokeColor == null) 43 throw new IllegalArgumentException(); 44 if (stroke == null && fillColor == null) 45 throw new IllegalArgumentException(); 46 this.symbol = symbol; 47 this.size = size; 48 this.stroke = stroke; 49 this.strokeColor = strokeColor; 50 this.fillColor = fillColor; 51 } 52 53 @Override 54 public boolean equals(Object obj) { 55 if (obj == null || getClass() != obj.getClass()) 56 return false; 57 final Symbol other = (Symbol) obj; 58 return symbol == other.symbol && 59 size == other.size && 60 equal(stroke, other.stroke) && 61 equal(strokeColor, other.strokeColor) && 62 equal(fillColor, other.fillColor); 63 } 64 65 @Override 66 public int hashCode() { 67 int hash = 7; 68 hash = 67 * hash + symbol.hashCode(); 69 hash = 67 * hash + Float.floatToIntBits(size); 70 hash = 67 * hash + (stroke != null ? stroke.hashCode() : 0); 71 hash = 67 * hash + (strokeColor != null ? strokeColor.hashCode() : 0); 72 hash = 67 * hash + (fillColor != null ? fillColor.hashCode() : 0); 73 return hash; 74 } 75 76 @Override 77 public String toString() { 78 return "symbol=" + symbol + " size=" + size + 79 (stroke != null ? (" stroke=" + stroke + " strokeColor=" + strokeColor) : "") + 80 (fillColor != null ? (" fillColor=" + fillColor) : ""); 81 } 82 } 83 84 public enum SymbolShape { SQUARE, CIRCLE } 85 86 public static final NodeElemStyle SIMPLE_NODE_ELEMSTYLE = new NodeElemStyle(Cascade.EMPTY_CASCADE, true, null, null, 0, null); 87 88 protected NodeElemStyle(Cascade c, boolean annotate, String annotation_key, ImageIcon icon, int iconAlpha, Symbol symbol) { 29 89 super(c); 30 90 this.annotate = annotate; 31 91 this.annotation_key = annotation_key; 32 92 this.icon = icon; 93 this.iconAlpha = iconAlpha; 94 this.symbol = symbol; 33 95 } 34 96 35 97 public static NodeElemStyle create(Cascade c) { 36 98 IconReference iconRef = c.get("icon-image", null, IconReference.class); 37 if (iconRef == null) 38 return null; 39 ImageIcon icon = MapPaintStyles.getIcon(iconRef, false); 40 99 ImageIcon icon = null; 100 int iconAlpha = 0; 101 Symbol symbol = null; 102 103 if (iconRef != null) { 104 icon = MapPaintStyles.getIcon(iconRef, false); 105 iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255)))); 106 Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class)); 107 if (pAlpha != null) { 108 iconAlpha = pAlpha; 109 } 110 } else { 111 SymbolShape shape; 112 String shapeStr = c.get("symbol-shape", null, String.class); 113 if (equal(shapeStr, "square")) { 114 shape = SymbolShape.SQUARE; 115 } else if (equal(shapeStr, "circle")) { 116 shape = SymbolShape.CIRCLE; 117 } else 118 return null; 119 120 Float size = c.get("symbol-size", null, Float.class); 121 if (size == null || size <= 0) 122 return null; 123 124 Float strokeWidth = c.get("symbol-stroke-width", null, Float.class); 125 Color strokeColor = c.get("symbol-stroke-color", null, Color.class); 126 if (strokeColor != null) { 127 float strokeAlpha = c.get("symbol-stroke-opacity", 1f, Float.class); 128 strokeColor = new Color(strokeColor.getRed(), strokeColor.getGreen(), 129 strokeColor.getBlue(), Utils.color_float2int(strokeAlpha)); 130 } 131 Stroke stroke = null; 132 if (strokeWidth != null && strokeWidth > 0 && strokeColor != null) { 133 stroke = new BasicStroke(strokeWidth); 134 } 135 136 Color fillColor = c.get("symbol-fill-color", null, Color.class); 137 if (fillColor != null) { 138 float fillAlpha = c.get("symbol-fill-opacity", 1f, Float.class); 139 fillColor = new Color(fillColor.getRed(), fillColor.getGreen(), 140 fillColor.getBlue(), Utils.color_float2int(fillAlpha)); 141 } 142 143 if ((stroke == null || strokeColor == null) && fillColor == null) 144 return null; 145 146 symbol = new Symbol(shape, size, stroke, strokeColor, fillColor); 147 } 148 41 149 String text = c.get("text", null, String.class); 42 150 … … 44 152 String annotation_key = null; 45 153 46 if (annotate && !" yes".equalsIgnoreCase(text)) {154 if (annotate && !"auto".equalsIgnoreCase(text)) { 47 155 annotation_key = text; 48 156 } 49 return new NodeElemStyle(c, annotate, annotation_key, icon );157 return new NodeElemStyle(c, annotate, annotation_key, icon, iconAlpha, symbol); 50 158 } 51 159 … … 56 164 if (icon != null && painter.isShowIcons()) { 57 165 painter.drawNodeIcon(n, (painter.isInactive() || n.isDisabled()) ? getDisabledIcon() : icon, 58 selected, member, getName(n, painter)); 166 Utils.color_int2float(iconAlpha), selected, member, getName(n, painter)); 167 } else if (symbol != null) { 168 painter.drawNodeSymbol(n, symbol, selected, member, getName(n, painter)); 59 169 } else { 60 170 if (n.isHighlighted()) { … … 127 237 hash = 17 * hash + (annotation_key != null ? annotation_key.hashCode() : 0); 128 238 hash = 17 * hash + (icon != null ? icon.getImage().hashCode() : 0); 239 hash = 17 * hash + this.iconAlpha; 240 hash = 17 * hash + (this.symbol != null ? this.symbol.hashCode() : 0); 129 241 return hash; 130 242 } … … 143 255 if (annotate != other.annotate) 144 256 return false; 145 if (!Utils.equal(annotation_key, annotation_key)) 257 if (!equal(annotation_key, annotation_key)) 258 return false; 259 if (this.iconAlpha != other.iconAlpha) 260 return false; 261 if (!equal(symbol, other.symbol)) 146 262 return false; 147 263 return true; 148 264 } 149 265 266 150 267 @Override 151 268 public String toString() { 152 return "NodeElemStyle{" + super.toString() + "annotate=" + annotate + " annotation_key=" + annotation_key + " icon=" + icon + '}'; 269 return "NodeElemStyle{" + super.toString() + "annotate=" + annotate + " annotation_key=" + annotation_key + 270 (icon != null ? (" icon=" + icon + " iconAlpha=" + iconAlpha) : "") + 271 (symbol != null ? (" symbol=[" + symbol + "]") : "") + '}'; 153 272 } 154 273 -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleCache.java
r3836 r3865 48 48 { 49 49 private List<ElemStyle> lst; 50 51 public static final StyleList SIMPLE_NODE = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE);52 50 53 51 public StyleList() { -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r3863 r3865 129 129 c = mc.get("*").clone(); 130 130 } else { 131 c = new Cascade( );131 c = new Cascade(!sub.equals("default")); 132 132 } 133 133 mc.put(sub, c); -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r3863 r3865 20 20 import org.openstreetmap.josm.data.osm.Way; 21 21 import org.openstreetmap.josm.gui.mappaint.Cascade; 22 import org.openstreetmap.josm.gui.mappaint.ElemStyle;23 22 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 24 23 import org.openstreetmap.josm.gui.mappaint.Range; … … 289 288 if (icon.annotate != null) { 290 289 if (icon.annotate) { 291 def.put("text", " yes");290 def.put("text", "auto"); 292 291 } else { 293 292 def.remove("text"); … … 306 305 int alpha = p.line.color.getAlpha(); 307 306 if (alpha != 255) { 308 def.put("opacity", ElemStyle.color_int2float(alpha));307 def.put("opacity", Utils.color_int2float(alpha)); 309 308 } 310 309 } … … 335 334 int alpha = mod.color.getAlpha(); 336 335 if (alpha != 255) { 337 c.put("opacity", ElemStyle.color_int2float(alpha));336 c.put("opacity", Utils.color_int2float(alpha)); 338 337 } 339 338 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r3859 r3865 124 124 return String.format("#%06x(alpha=%d)", c.getRGB() & 0x00ffffff, c.getAlpha()); 125 125 } 126 127 /** 128 * convert float range 0 <= x <= 1 to integer range 0..255 129 * when dealing with colors and color alpha value 130 */ 131 public static Integer color_float2int(Float val) { 132 if (val == null) 133 return null; 134 if (val < 0 || val > 1) 135 return 255; 136 return (int) (255f * val + 0.5f); 137 } 138 139 /** 140 * convert back 141 */ 142 public static Float color_int2float(Integer val) { 143 if (val == null) 144 return null; 145 if (val < 0 || val > 255) 146 return 1f; 147 return ((float) val) / 255f; 148 } 149 126 150 }
Note:
See TracChangeset
for help on using the changeset viewer.