Changeset 3871 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2011-02-08T14:29:23+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
r3865 r3871 9 9 10 10 import org.openstreetmap.josm.gui.mappaint.mapcss.CSSColors; 11 import org.openstreetmap.josm.tools.Utils; 11 12 12 13 /** … … 183 184 res.append(Arrays.toString((float[]) val)); 184 185 } else if (val instanceof Color) { 185 res.append( String.format("#%x", ((Color) val).getRGB()));186 res.append(Utils.toString((Color)val)); 186 187 } else { 187 188 res.append(val+""); -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3865 r3871 164 164 165 165 float miterlimit = c.get(prefix + "miterlimit", 10f, Float.class); 166 if (miterlimit < 1f) { 167 miterlimit = 10f; 168 } 166 169 167 170 BasicStroke line = new BasicStroke(width, cap, join, miterlimit, dashes, dashesOffset); -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3865 r3871 6 6 import java.awt.BasicStroke; 7 7 import java.awt.Color; 8 import java.awt.Font; 8 9 import java.awt.Stroke; 9 10 … … 17 18 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 18 19 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 20 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 19 21 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 22 import org.openstreetmap.josm.tools.CheckParameterUtil; 20 23 import org.openstreetmap.josm.tools.Utils; 21 24 … … 24 27 */ 25 28 public class NodeElemStyle extends ElemStyle { 26 public boolean annotate; 27 public String annotation_key; 29 28 30 public ImageIcon icon; 29 31 public int iconAlpha; 30 32 public Symbol symbol; 33 public TextElement text; 31 34 32 35 private ImageIcon disabledIcon; 36 37 public enum SymbolShape { SQUARE, CIRCLE } 38 public enum HorizontalTextAlignment { LEFT, CENTER, RIGHT } 39 public enum VerticalTextAlignment { ABOVE, TOP, CENTER, BOTTOM, BELOW } 33 40 34 41 public static class Symbol { 35 42 public SymbolShape symbol; 36 public float size;43 public int size; 37 44 public Stroke stroke; 38 45 public Color strokeColor; 39 46 public Color fillColor; 40 47 41 public Symbol(SymbolShape symbol, float size, Stroke stroke, Color strokeColor, Color fillColor) {48 public Symbol(SymbolShape symbol, int size, Stroke stroke, Color strokeColor, Color fillColor) { 42 49 if (stroke != null && strokeColor == null) 43 50 throw new IllegalArgumentException(); … … 67 74 int hash = 7; 68 75 hash = 67 * hash + symbol.hashCode(); 69 hash = 67 * hash + Float.floatToIntBits(size);76 hash = 67 * hash + size; 70 77 hash = 67 * hash + (stroke != null ? stroke.hashCode() : 0); 71 78 hash = 67 * hash + (strokeColor != null ? strokeColor.hashCode() : 0); … … 81 88 } 82 89 } 90 91 public static class TextElement { 92 public String textKey; 93 public HorizontalTextAlignment hAlign; 94 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) { 101 CheckParameterUtil.ensureParameterNotNull(hAlign); 102 CheckParameterUtil.ensureParameterNotNull(vAlign); 103 CheckParameterUtil.ensureParameterNotNull(font); 104 CheckParameterUtil.ensureParameterNotNull(color); 105 this.textKey = textKey; 106 this.hAlign = hAlign; 107 this.vAlign = vAlign; 108 this.font = font; 109 this.xOffset = xOffset; 110 this.yOffset = yOffset; 111 this.color = color; 112 } 113 114 @Override 115 public boolean equals(Object obj) { 116 if (obj == null || getClass() != obj.getClass()) 117 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); 126 } 127 128 @Override 129 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(); 138 return hash; 139 } 140 } 83 141 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) { 142 public static final NodeElemStyle SIMPLE_NODE_ELEMSTYLE; 143 static { 144 Cascade c = new Cascade(false); 145 c.put("text", "auto"); 146 SIMPLE_NODE_ELEMSTYLE = create(c, true); 147 } 148 149 protected NodeElemStyle(Cascade c, ImageIcon icon, int iconAlpha, Symbol symbol, TextElement text) { 89 150 super(c); 90 this.annotate = annotate;91 this.annotation_key = annotation_key;92 151 this.icon = icon; 93 152 this.iconAlpha = iconAlpha; 94 153 this.symbol = symbol; 154 this.text = text; 95 155 } 96 156 97 157 public static NodeElemStyle create(Cascade c) { 158 return create(c, false); 159 } 160 161 private static NodeElemStyle create(Cascade c, boolean allowOnlyText) { 98 162 IconReference iconRef = c.get("icon-image", null, IconReference.class); 99 163 ImageIcon icon = null; … … 109 173 } 110 174 } 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 149 String text = c.get("text", null, String.class); 150 151 boolean annotate = text != null; 152 String annotation_key = null; 153 154 if (annotate && !"auto".equalsIgnoreCase(text)) { 155 annotation_key = text; 156 } 157 return new NodeElemStyle(c, annotate, annotation_key, icon, iconAlpha, symbol); 175 symbol = createSymbol(c); 176 } 177 178 if (icon == null && symbol == null && !allowOnlyText) 179 return null; 180 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 } 188 HorizontalTextAlignment hAlign = HorizontalTextAlignment.RIGHT; 189 String hAlignStr = c.get("text-anchor-horizontal", null, String.class); 190 if (equal(hAlignStr, "left")) { 191 hAlign = HorizontalTextAlignment.LEFT; 192 } else if (equal(hAlignStr, "center")) { 193 hAlign = HorizontalTextAlignment.CENTER; 194 } else if (equal(hAlignStr, "right")) { 195 hAlign = HorizontalTextAlignment.RIGHT; 196 } 197 VerticalTextAlignment vAlign = VerticalTextAlignment.BOTTOM; 198 String vAlignStr = c.get("text-anchor-vertical", null, String.class); 199 if (equal(vAlignStr, "above")) { 200 vAlign = VerticalTextAlignment.ABOVE; 201 } else if (equal(vAlignStr, "top")) { 202 vAlign = VerticalTextAlignment.TOP; 203 } else if (equal(vAlignStr, "center")) { 204 vAlign = VerticalTextAlignment.CENTER; 205 } else if (equal(vAlignStr, "bottom")) { 206 vAlign = VerticalTextAlignment.BOTTOM; 207 } else if (equal(vAlignStr, "below")) { 208 vAlign = VerticalTextAlignment.BELOW; 209 } 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); 227 } 228 229 return new NodeElemStyle(c, icon, iconAlpha, symbol, text); 230 } 231 232 private static Symbol createSymbol(Cascade c) { 233 SymbolShape shape; 234 String shapeStr = c.get("symbol-shape", null, String.class); 235 if (equal(shapeStr, "square")) { 236 shape = SymbolShape.SQUARE; 237 } else if (equal(shapeStr, "circle")) { 238 shape = SymbolShape.CIRCLE; 239 } else 240 return null; 241 242 Float size = c.get("symbol-size", null, Float.class); 243 if (size == null || size <= 0) 244 return null; 245 246 Float strokeWidth = c.get("symbol-stroke-width", null, Float.class); 247 Color strokeColor = c.get("symbol-stroke-color", null, Color.class); 248 if (strokeColor != null) { 249 float strokeAlpha = c.get("symbol-stroke-opacity", 1f, Float.class); 250 strokeColor = new Color(strokeColor.getRed(), strokeColor.getGreen(), 251 strokeColor.getBlue(), Utils.color_float2int(strokeAlpha)); 252 } 253 Stroke stroke = null; 254 if (strokeWidth != null && strokeWidth > 0 && strokeColor != null) { 255 stroke = new BasicStroke(strokeWidth); 256 } 257 258 Color fillColor = c.get("symbol-fill-color", null, Color.class); 259 if (fillColor != null) { 260 float fillAlpha = c.get("symbol-fill-opacity", 1f, Float.class); 261 fillColor = new Color(fillColor.getRed(), fillColor.getGreen(), 262 fillColor.getBlue(), Utils.color_float2int(fillAlpha)); 263 } 264 265 if ((stroke == null || strokeColor == null) && fillColor == null) 266 return null; 267 268 return new Symbol(shape, size.intValue(), stroke, strokeColor, fillColor); 158 269 } 159 270 … … 164 275 if (icon != null && painter.isShowIcons()) { 165 276 painter.drawNodeIcon(n, (painter.isInactive() || n.isDisabled()) ? getDisabledIcon() : icon, 166 Utils.color_int2float(iconAlpha), selected, member, getName(n, painter));277 Utils.color_int2float(iconAlpha), selected, member, text); 167 278 } else if (symbol != null) { 168 painter.drawNodeSymbol(n, symbol, selected, member, getName(n, painter));279 painter.drawNodeSymbol(n, symbol, selected, member, text); 169 280 } else { 170 281 if (n.isHighlighted()) { 171 painter.drawNode(n, settings.getHighlightColor(), settings.getSelectedNodeSize(), settings.isFillSelectedNode(), getName(n, painter));282 painter.drawNode(n, settings.getHighlightColor(), settings.getSelectedNodeSize(), settings.isFillSelectedNode(), text); 172 283 } else { 173 284 Color color; … … 204 315 settings.isFillUnselectedNode(); 205 316 206 painter.drawNode(n, color, size, fill, getName(n, painter));317 painter.drawNode(n, color, size, fill, text); 207 318 } 208 319 } … … 220 331 } 221 332 222 protected String getName(Node n, MapPainter painter) {223 if (painter.isShowNames() && annotate) {224 if (annotation_key != null) {225 return n.get(annotation_key);226 } else {227 return painter.getNodeName(n);228 }229 }230 return null;231 }232 233 333 @Override 234 334 public int hashCode() { 235 335 int hash = super.hashCode(); 236 hash = 17 * hash + (annotate ? 1 : 0);237 hash = 17 * hash + (annotation_key != null ? annotation_key.hashCode() : 0);238 336 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); 337 hash = 17 * hash + iconAlpha; 338 hash = 17 * hash + (symbol != null ? symbol.hashCode() : 0); 339 hash = 17 * hash + (text != null ? text.hashCode() : 0); 241 340 return hash; 242 341 } … … 253 352 if (icon != other.icon && (icon == null || other.icon == null || icon.getImage() != other.icon.getImage())) 254 353 return false; 255 if (annotate != other.annotate)256 return false;257 if (!equal(annotation_key, annotation_key))258 return false;259 354 if (this.iconAlpha != other.iconAlpha) 260 355 return false; 261 356 if (!equal(symbol, other.symbol)) 357 return false; 358 if (!equal(text, other.text)) 262 359 return false; 263 360 return true; … … 267 364 @Override 268 365 public String toString() { 269 return "NodeElemStyle{" + super.toString() + "annotate=" + annotate + " annotation_key=" + annotation_key +270 (icon != null ? (" 366 return "NodeElemStyle{" + super.toString() + 367 (icon != null ? ("icon=" + icon + " iconAlpha=" + iconAlpha) : "") + 271 368 (symbol != null ? (" symbol=[" + symbol + "]") : "") + '}'; 272 369 }
Note:
See TracChangeset
for help on using the changeset viewer.