Changeset 3880 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint
- Timestamp:
- 2011-02-10T00:05:18+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r3879 r3880 26 26 public BufferedImage fillImage; 27 27 public float fillImageAlpha; 28 public TextElement text; 28 29 29 protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage, float fillImageAlpha ) {30 protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) { 30 31 super(c); 31 32 CheckParameterUtil.ensureParameterNotNull(color); … … 33 34 this.fillImage = fillImage; 34 35 this.fillImageAlpha = fillImageAlpha; 36 this.text = text; 35 37 } 36 38 … … 73 75 } 74 76 } 77 78 TextElement text = null; 79 String textPos = c.get("text-position", null, String.class); 80 if (textPos == null || Utils.equal(textPos, "center")) { 81 text = TextElement.create(c); 82 } 75 83 76 84 if (color != null) 77 return new AreaElemStyle(c, color, fillImage, fillImageAlpha );85 return new AreaElemStyle(c, color, fillImage, fillImageAlpha, text); 78 86 else 79 87 return null; … … 90 98 } 91 99 } 92 painter.drawArea((Way) osm, myColor, fillImage, fillImageAlpha, 93 painter.isShowNames() ? painter.getAreaName(osm) : null); 100 painter.drawArea((Way) osm, myColor, fillImage, fillImageAlpha, text); 94 101 } else if (osm instanceof Relation) 95 102 { … … 100 107 } 101 108 } 102 painter.drawArea((Relation) osm, myColor, fillImage, fillImageAlpha, 103 painter.getAreaName(osm)); 109 painter.drawArea((Relation) osm, myColor, fillImage, fillImageAlpha, text); 104 110 } 105 111 } … … 119 125 if (fillImageAlpha != other.fillImageAlpha) 120 126 return false; 127 if (!Utils.equal(text, other.text)) 128 return false; 121 129 return true; 122 130 } … … 128 136 hash = 61 * hash + (fillImage != null ? fillImage.hashCode() : 0); 129 137 hash = 61 * hash + Float.floatToIntBits(fillImageAlpha); 138 hash = 61 * hash + (text != null ? text.hashCode() : 0); 130 139 return hash; 131 140 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r3865 r3880 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import static org.openstreetmap.josm.tools.Utils.equal; 5 6 import java.awt.Font; 7 8 import org.openstreetmap.josm.Main; 4 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 10 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 6 11 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 12 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.RelativeFloat; 7 13 8 14 abstract public class ElemStyle { … … 26 32 27 33 public abstract void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member); 34 35 protected static Float getWidth(Cascade c, String key, Float relativeTo) { 36 Float width = c.get(key, null, Float.class, true); 37 if (width != null) { 38 if (width == -1f) 39 return (float) MapPaintSettings.INSTANCE.getDefaultSegmentWidth(); 40 if (width > 0) 41 return width; 42 } else { 43 String width_key = c.get(key, null, String.class, true); 44 if (equal(width_key, "thinnest")) 45 return 0f; 46 else if (relativeTo != null) { 47 RelativeFloat width_rel = c.get(key, null, RelativeFloat.class, true); 48 if (width_rel != null) 49 return relativeTo + width_rel.val; 50 } 51 } 52 return null; 53 } 54 55 protected static Font getFont(Cascade c) { 56 String name = c.get("font-family", Main.pref.get("mappaint.font", "Helvetica"), String.class); 57 float size = c.get("font-size", (float) Main.pref.getInteger("mappaint.fontsize", 8), Float.class); 58 int weight = Font.PLAIN; 59 String weightStr = c.get("font-wheight", null, String.class); 60 if (equal(weightStr, "bold")) { 61 weight = Font.BOLD; 62 } 63 int style = Font.PLAIN; 64 String styleStr = c.get("font-style", null, String.class); 65 if (equal(styleStr, "italic")) { 66 style = Font.ITALIC; 67 } 68 return new Font(name, weight | style, Math.round(size)); 69 } 28 70 29 71 @Override -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3871 r3880 14 14 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 15 15 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 16 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.RelativeFloat;17 16 import org.openstreetmap.josm.tools.Utils; 18 17 … … 32 31 public Color color; 33 32 public Color dashesBackground; 33 public TextElement text; 34 34 public float realWidth; // the real width of this line in meter 35 35 36 36 private BasicStroke dashesLine; 37 37 38 protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float realWidth) {38 protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, TextElement text, float realWidth) { 39 39 super(c); 40 40 this.line = line; … … 42 42 this.dashesLine = dashesLine; 43 43 this.dashesBackground = dashesBackground; 44 this.text = text; 44 45 this.realWidth = realWidth; 45 46 } 46 47 47 48 public static LineElemStyle createLine(Environment env) { 48 return createImpl(env, "");49 return createImpl(env, false); 49 50 } 50 51 51 52 public static LineElemStyle createCasing(Environment env) { 52 LineElemStyle casing = createImpl(env, "casing-");53 LineElemStyle casing = createImpl(env, true); 53 54 if (casing != null) { 54 55 casing.object_z_index = -1; … … 57 58 } 58 59 59 private static LineElemStyle createImpl(Environment env, String prefix) {60 private static LineElemStyle createImpl(Environment env, boolean casing) { 60 61 Cascade c = env.getCascade(); 61 Float width = c.get(prefix + "width", null, Float.class, true); 62 if (width != null) { 63 if (width == -1f) { 64 width = (float) MapPaintSettings.INSTANCE.getDefaultSegmentWidth(); 65 } 66 if (width <= 0) 67 return null; 62 Cascade c_def = env.mc.getCascade("default"); 63 64 String prefix = casing ? "casing-" : ""; 65 66 Float width; 67 if (casing) { 68 Float widthOnDefault = getWidth(c_def, "width", null); 69 Float widthLine = getWidth(c, "width", widthOnDefault); 70 width = getWidth(c, "casing-width", widthLine); 68 71 } else { 69 String width_key = c.get(prefix + "width", null, String.class, true); 70 if (equal(width_key, "thinnest")) { 71 width = 0f; 72 } else if (! equal(env.layer, "default")) { 73 RelativeFloat width_rel = c.get(prefix + "width", null, RelativeFloat.class, true); 74 if (width_rel != null) { 75 width = env.mc.getCascade("default").get("width", 0f, Float.class) + width_rel.val; 76 } else 77 return null; 78 } else 79 return null; 80 } 72 Float widthOnDefault = getWidth(c_def, "width", null); 73 width = getWidth(c, "width", widthOnDefault); 74 } 75 76 if (width == null) 77 return null; 81 78 82 79 float realWidth = c.get(prefix + "real-width", 0f, Float.class); … … 178 175 } 179 176 180 return new LineElemStyle(c, line, color, dashesLine, dashesBackground, realWidth); 177 TextElement text = null; 178 if (!casing) { 179 String textPos = c.get("text-position", null, String.class); 180 if (textPos == null || equal(textPos, "line")) { 181 text = TextElement.create(c); 182 } 183 } 184 185 return new LineElemStyle(c, line, color, dashesLine, dashesBackground, text, realWidth); 181 186 } 182 187 … … 222 227 } 223 228 224 painter.drawWay(w, markColor != null ? markColor : color, myLine, myDashLine, myDashedColor, showDirection,229 painter.drawWay(w, markColor != null ? markColor : color, myLine, myDashLine, myDashedColor, text, showDirection, 225 230 selected ? false : reversedDirection, showOnlyHeadArrowOnly); 226 231 … … 249 254 equal(dashesLine, other.dashesLine) && 250 255 equal(dashesBackground, other.dashesBackground) && 256 equal(text, other.text) && 251 257 realWidth == other.realWidth; 252 258 } … … 259 265 hash = 29 * hash + (dashesLine != null ? dashesLine.hashCode() : 0); 260 266 hash = 29 * hash + (dashesBackground != null ? dashesBackground.hashCode() : 0); 267 hash = 29 * hash + (text != null ? text.hashCode() : 0); 261 268 hash = 29 * hash + Float.floatToIntBits(realWidth); 262 269 return hash; -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3879 r3880 18 18 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 19 19 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 20 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;21 20 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 22 21 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 31 30 public int iconAlpha; 32 31 public Symbol symbol; 33 public TextElement text;32 public NodeTextElement text; 34 33 35 34 private ImageIcon disabledIcon; … … 89 88 } 90 89 91 public static class TextElement { 92 public String textKey; 90 public static class NodeTextElement extends TextElement { 93 91 public HorizontalTextAlignment hAlign; 94 92 public VerticalTextAlignment vAlign; 95 public Font font; 96 public int xOffset; 97 public int yOffset; 98 public Color color; 99 100 public TextElement(String textKey, HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign, Font font, int xOffset, int yOffset, Color color) { 93 94 public NodeTextElement(String textKey, HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign, Font font, int xOffset, int yOffset, Color color) { 95 super(textKey, font, xOffset, yOffset, color); 101 96 CheckParameterUtil.ensureParameterNotNull(hAlign); 102 97 CheckParameterUtil.ensureParameterNotNull(vAlign); 103 CheckParameterUtil.ensureParameterNotNull(font);104 CheckParameterUtil.ensureParameterNotNull(color);105 this.textKey = textKey;106 98 this.hAlign = hAlign; 107 99 this.vAlign = vAlign; 108 this.font = font;109 this.xOffset = xOffset;110 this.yOffset = yOffset;111 this.color = color;112 100 } 113 101 114 102 @Override 115 103 public boolean equals(Object obj) { 104 if (!super.equals(obj)) 105 return false; 116 106 if (obj == null || getClass() != obj.getClass()) 117 107 return false; 118 final TextElement other = (TextElement) obj; 119 return equal(textKey, other.textKey) && 120 hAlign == other.hAlign && 121 vAlign == other.vAlign && 122 equal(font, other.font) && 123 xOffset == other.xOffset && 124 yOffset == other.yOffset && 125 equal(color, other.color); 108 final NodeTextElement other = (NodeTextElement) obj; 109 return hAlign == other.hAlign && 110 vAlign == other.vAlign; 126 111 } 127 112 128 113 @Override 129 114 public int hashCode() { 130 int hash = 3; 131 hash = 79 * hash + (textKey != null ? textKey.hashCode() : 0); 132 hash = 79 * hash + hAlign.hashCode(); 133 hash = 79 * hash + vAlign.hashCode(); 134 hash = 79 * hash + font.hashCode(); 135 hash = 79 * hash + xOffset; 136 hash = 79 * hash + yOffset; 137 hash = 79 * hash + color.hashCode(); 115 int hash = super.hashCode(); 116 hash = 97 * hash + hAlign.hashCode(); 117 hash = 97 * hash + vAlign.hashCode(); 138 118 return hash; 139 119 } 120 140 121 } 141 122 … … 147 128 } 148 129 149 protected NodeElemStyle(Cascade c, ImageIcon icon, int iconAlpha, Symbol symbol, TextElement text) {130 protected NodeElemStyle(Cascade c, ImageIcon icon, int iconAlpha, Symbol symbol, NodeTextElement text) { 150 131 super(c); 151 132 this.icon = icon; … … 179 160 return null; 180 161 181 TextElement text = null; 182 String textStr = c.get("text", null, String.class); 183 if (textStr != null) { 184 String textKey = null; 185 if (!"auto".equalsIgnoreCase(textStr)) { 186 textKey = textStr; 187 } 162 NodeTextElement text = null; 163 TextElement te = TextElement.create(c); 164 if (te != null) { 188 165 HorizontalTextAlignment hAlign = HorizontalTextAlignment.RIGHT; 189 166 String hAlignStr = c.get("text-anchor-horizontal", null, String.class); … … 208 185 vAlign = VerticalTextAlignment.BELOW; 209 186 } 210 String name = c.get("font-family", Main.pref.get("mappaint.font", "Helvetica"), String.class); 211 float size = c.get("font-size", (float) Main.pref.getInteger("mappaint.fontsize", 8), Float.class); 212 int weight = Font.PLAIN; 213 String weightStr = c.get("font-wheight", null, String.class); 214 if (equal(weightStr, "bold")) { 215 weight = Font.BOLD; 216 } 217 int style = Font.PLAIN; 218 String styleStr = c.get("font-style", null, String.class); 219 if (equal(styleStr, "italic")) { 220 style = Font.ITALIC; 221 } 222 Font font = new Font(name, weight | style, Math.round(size)); 223 int xOffset = c.get("text-offset-x", 0f, Float.class).intValue(); 224 int yOffset = c.get("text-offset-y", 0f, Float.class).intValue(); 225 Color color = c.get("text-color", PaintColors.TEXT.get(), Color.class); 226 text = new TextElement(textKey, hAlign, vAlign, font, xOffset, yOffset, color); 187 text = new NodeTextElement(te.textKey, hAlign, vAlign, te.font, te.xOffset, te.yOffset, te.color); 227 188 } 228 189 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java
r3867 r3880 191 191 } 192 192 193 @SuppressWarnings("unchecked") 193 194 public boolean equal(Object a, Object b) { 194 195 // make sure the casts are done in a meaningful way, so -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r3860 r3880 49 49 return true; 50 50 if (base.equals("area")) { 51 if (osm instanceof Way && ((Way)osm).isClosed())51 if (osm instanceof Way) 52 52 return true; 53 53 if (osm instanceof Relation && ((Relation) osm).isMultipolygon()) -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r3865 r3880 350 350 if (p.area != null) { 351 351 def.putOrClear("fill-color", p.area.color); 352 def.putOrClear("text-position", "center"); 353 def.putOrClear("text", "auto"); 352 354 def.remove("fill-image"); 353 355 }
Note:
See TracChangeset
for help on using the changeset viewer.