- Timestamp:
- 2011-08-18T13:01:55+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/QuadTiling.java
r4191 r4319 4 4 public class QuadTiling 5 5 { 6 public static int NR_LEVELS = 24;7 public static double WORLD_PARTS = (1 << NR_LEVELS);6 public static final int NR_LEVELS = 24; 7 public static final double WORLD_PARTS = (1 << NR_LEVELS); 8 8 9 public static int TILES_PER_LEVEL_SHIFT = 2; // Has to be 2. Other parts of QuadBuckets code rely on it10 public static int TILES_PER_LEVEL = 1<<TILES_PER_LEVEL_SHIFT;11 static public int X_PARTS = 360;12 static public int X_BIAS = -180;9 public static final int TILES_PER_LEVEL_SHIFT = 2; // Has to be 2. Other parts of QuadBuckets code rely on it 10 public static final int TILES_PER_LEVEL = 1<<TILES_PER_LEVEL_SHIFT; 11 static public final int X_PARTS = 360; 12 static public final int X_BIAS = -180; 13 13 14 static public int Y_PARTS = 180;15 static public int Y_BIAS = -90;14 static public final int Y_PARTS = 180; 15 static public final int Y_BIAS = -90; 16 16 17 17 public static LatLon tile2LatLon(long quad) -
trunk/src/org/openstreetmap/josm/data/osm/BBox.java
r3719 r4319 136 136 /** 137 137 * Tests, weather two BBoxes intersect as an area. 138 * I.e. w eather there exists a point that lies in both of them.138 * I.e. whether there exists a point that lies in both of them. 139 139 */ 140 140 public boolean intersects(BBox b) { -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r4317 r4319 38 38 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData; 39 39 import org.openstreetmap.josm.gui.NavigatableComponent; 40 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle; 41 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.HorizontalTextAlignment; 42 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.VerticalTextAlignment; 40 43 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle; 41 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.HorizontalTextAlignment;42 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.NodeTextElement;43 44 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.Symbol; 44 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.VerticalTextAlignment;45 45 import org.openstreetmap.josm.gui.mappaint.TextElement; 46 46 import org.openstreetmap.josm.tools.ImageProvider; … … 496 496 } 497 497 498 public void drawNodeIcon(Node n, ImageIcon icon, float iconAlpha, boolean selected, boolean member , NodeTextElement text) {498 public void drawNodeIcon(Node n, ImageIcon icon, float iconAlpha, boolean selected, boolean member) { 499 499 Point p = nc.getPoint(n); 500 500 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; … … 506 506 icon.paintIcon ( nc, g, p.x-w/2, p.y-h/2 ); 507 507 g.setPaintMode(); 508 drawNodeText(n, text, p, w/2, h/2);509 508 if (selected || member) 510 509 { … … 529 528 } 530 529 531 public void drawNodeSymbol(Node n, Symbol s, Color fillColor, Color strokeColor , NodeTextElement text) {530 public void drawNodeSymbol(Node n, Symbol s, Color fillColor, Color strokeColor) { 532 531 Point p = nc.getPoint(n); 533 532 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; … … 604 603 g.setStroke(new BasicStroke()); 605 604 } 606 drawNodeText(n, text, p, radius, radius);607 605 } 608 606 … … 613 611 * @param color The color of the node. 614 612 */ 615 public void drawNode(Node n, Color color, int size, boolean fill , NodeTextElement text) {613 public void drawNode(Node n, Color color, int size, boolean fill) { 616 614 if (size > 1) { 617 615 Point p = nc.getPoint(n); … … 629 627 g.drawRect(p.x - radius, p.y - radius, size, size); 630 628 } 631 632 drawNodeText(n, text, p, radius, radius + 4); 633 } 634 } 635 636 private void drawNodeText(Node n, NodeTextElement text, Point p, int w_half, int h_half) { 637 if (!isShowNames() || text == null) 629 } 630 } 631 632 public void drawBoxText(Node n, BoxTextElemStyle bs) { 633 if (!isShowNames() || bs == null) 638 634 return; 639 640 /* 641 * abort if we can't compose the label to be rendered 642 */ 643 if (text.labelCompositionStrategy == null) return; 635 636 Point p = nc.getPoint((Node) n); 637 TextElement text = bs.text; 644 638 String s = text.labelCompositionStrategy.compose(n); 645 639 if (s == null) return; … … 661 655 * 662 656 */ 663 if ( text.hAlign == HorizontalTextAlignment.RIGHT) {664 x += w_half+ 2;657 if (bs.hAlign == HorizontalTextAlignment.RIGHT) { 658 x += bs.box.x + bs.box.width + 2; 665 659 } else { 666 660 FontRenderContext frc = g.getFontRenderContext(); 667 661 Rectangle2D bounds = text.font.getStringBounds(s, frc); 668 662 int textWidth = (int) bounds.getWidth(); 669 if ( text.hAlign == HorizontalTextAlignment.CENTER) {663 if (bs.hAlign == HorizontalTextAlignment.CENTER) { 670 664 x -= textWidth / 2; 671 } else if ( text.hAlign == HorizontalTextAlignment.LEFT) {672 x -= w_half+ 4 + textWidth;665 } else if (bs.hAlign == HorizontalTextAlignment.LEFT) { 666 x -= - bs.box.x + 4 + textWidth; 673 667 } else throw new AssertionError(); 674 668 } 675 669 676 if ( text.vAlign == VerticalTextAlignment.BOTTOM) {677 y += h_half - 2;670 if (bs.vAlign == VerticalTextAlignment.BOTTOM) { 671 y += bs.box.y + bs.box.height; 678 672 } else { 679 673 FontRenderContext frc = g.getFontRenderContext(); 680 674 LineMetrics metrics = text.font.getLineMetrics(s, frc); 681 if ( text.vAlign == VerticalTextAlignment.ABOVE) {682 y -= h_half+ metrics.getDescent();683 } else if ( text.vAlign == VerticalTextAlignment.TOP) {684 y -= h_half- metrics.getAscent();685 } else if ( text.vAlign == VerticalTextAlignment.CENTER) {675 if (bs.vAlign == VerticalTextAlignment.ABOVE) { 676 y -= - bs.box.y + metrics.getDescent(); 677 } else if (bs.vAlign == VerticalTextAlignment.TOP) { 678 y -= - bs.box.y - metrics.getAscent(); 679 } else if (bs.vAlign == VerticalTextAlignment.CENTER) { 686 680 y += (metrics.getAscent() - metrics.getDescent()) / 2; 687 } else if ( text.vAlign == VerticalTextAlignment.BELOW) {688 y += h_half+ metrics.getAscent() + 2;681 } else if (bs.vAlign == VerticalTextAlignment.BELOW) { 682 y += bs.box.y + bs.box.height + metrics.getAscent() + 2; 689 683 } else throw new AssertionError(); 690 684 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r4318 r4319 79 79 if (!hasNonModifier) { 80 80 p.a = new StyleList(p.a, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE); 81 if (BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE.text.labelCompositionStrategy.compose(osm) != null) { 82 p.a = new StyleList(p.a, BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE); 83 } 81 84 } 82 85 } else if (osm instanceof Way && isDefaultLines()) { … … 301 304 addIfNotNull(sl, LineTextElemStyle.create(env)); 302 305 } else if (osm instanceof Node) { 303 addIfNotNull(sl, NodeElemStyle.create(env)); 306 NodeElemStyle nodeStyle = NodeElemStyle.create(env); 307 if (nodeStyle != null) { 308 sl.add(nodeStyle); 309 addIfNotNull(sl, BoxTextElemStyle.create(env, nodeStyle.getBox())); 310 } 304 311 } else if (osm instanceof Relation) { 305 312 if (((Relation)osm).isMultipolygon()) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r4318 r4319 6 6 import java.awt.BasicStroke; 7 7 import java.awt.Color; 8 import java.awt.Dimension; 9 import java.awt.Image; 8 import java.awt.Rectangle; 10 9 import java.awt.Stroke; 11 10 … … 19 18 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 20 19 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 21 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;22 20 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 23 import org.openstreetmap.josm.tools.CheckParameterUtil;24 21 import org.openstreetmap.josm.tools.Pair; 25 22 import org.openstreetmap.josm.tools.Utils; … … 32 29 public int iconAlpha; 33 30 public Symbol symbol; 34 public NodeTextElement text;35 31 36 32 private ImageIcon disabledIcon; 37 33 38 34 public enum SymbolShape { SQUARE, CIRCLE, TRIANGLE, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, NONAGON, DECAGON } 39 public enum HorizontalTextAlignment { LEFT, CENTER, RIGHT }40 public enum VerticalTextAlignment { ABOVE, TOP, CENTER, BOTTOM, BELOW }41 35 42 36 public static class Symbol { … … 90 84 } 91 85 92 public static class NodeTextElement extends TextElement {93 public HorizontalTextAlignment hAlign;94 public VerticalTextAlignment vAlign;95 96 public NodeTextElement(TextElement text, HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign) {97 super(text);98 CheckParameterUtil.ensureParameterNotNull(hAlign);99 CheckParameterUtil.ensureParameterNotNull(vAlign);100 this.hAlign = hAlign;101 this.vAlign = vAlign;102 }103 104 @Override105 public boolean equals(Object obj) {106 if (!super.equals(obj))107 return false;108 if (obj == null || getClass() != obj.getClass())109 return false;110 final NodeTextElement other = (NodeTextElement) obj;111 return hAlign == other.hAlign &&112 vAlign == other.vAlign;113 }114 115 @Override116 public int hashCode() {117 int hash = super.hashCode();118 hash = 97 * hash + hAlign.hashCode();119 hash = 97 * hash + vAlign.hashCode();120 return hash;121 }122 123 @Override124 public String toString() {125 return "NodeTextElement{" + toStringImpl() + '}';126 }127 128 @Override129 protected String toStringImpl() {130 return super.toStringImpl() + " hAlign=" + hAlign + " vAlign=" + vAlign;131 }132 }133 134 86 public static final NodeElemStyle SIMPLE_NODE_ELEMSTYLE; 135 87 static { 136 88 MultiCascade mc = new MultiCascade(); 137 89 Cascade c = mc.getOrCreateCascade("default"); 138 c.put("text", Keyword.AUTO);139 90 SIMPLE_NODE_ELEMSTYLE = create(new Environment(null, mc, "default", null), true); 140 } 141 142 protected NodeElemStyle(Cascade c, ImageIcon icon, Integer iconAlpha, Symbol symbol, NodeTextElement text) { 91 if (SIMPLE_NODE_ELEMSTYLE == null) throw new AssertionError(); 92 } 93 94 protected NodeElemStyle(Cascade c, ImageIcon icon, Integer iconAlpha, Symbol symbol) { 143 95 super(c, 1000f); 144 96 this.icon = icon; 145 97 this.iconAlpha = iconAlpha == null ? 0 : iconAlpha; 146 98 this.symbol = symbol; 147 this.text = text;148 99 } 149 100 … … 152 103 } 153 104 154 /*155 * Caches the default text color from the preferences.156 *157 * FIXME: the cache isn't updated if the user changes the preference during a JOSM158 * session. There should be preference listener updating this cache.159 */160 static private Color DEFAULT_TEXT_COLOR = null;161 static private void initDefaultParameters() {162 if (DEFAULT_TEXT_COLOR != null) return;163 DEFAULT_TEXT_COLOR = PaintColors.TEXT.get();164 }165 166 105 private static NodeElemStyle create(Environment env, boolean allowDefault) { 167 initDefaultParameters();168 106 Cascade c = env.mc.getCascade(env.layer); 169 107 … … 173 111 symbol = createSymbol(env); 174 112 } 175 176 NodeTextElement text = null; 177 TextElement te = TextElement.create(c, DEFAULT_TEXT_COLOR, symbol == null && icon == null && allowDefault); 178 // optimization: if we neither have a symbol, nor an icon, nor a text element 113 114 // optimization: if we neither have a symbol, nor an icon 179 115 // we don't have to check for the remaining style properties and we don't 180 116 // have to allocate a node element style. 181 if (symbol == null && icon == null && te == null) return null; 182 183 if (te != null) { 184 HorizontalTextAlignment hAlign = HorizontalTextAlignment.RIGHT; 185 Keyword hAlignKW = c.get("text-anchor-horizontal", Keyword.RIGHT, Keyword.class); 186 if (equal(hAlignKW.val, "left")) { 187 hAlign = HorizontalTextAlignment.LEFT; 188 } else if (equal(hAlignKW.val, "center")) { 189 hAlign = HorizontalTextAlignment.CENTER; 190 } else if (equal(hAlignKW.val, "right")) { 191 hAlign = HorizontalTextAlignment.RIGHT; 192 } 193 VerticalTextAlignment vAlign = VerticalTextAlignment.BOTTOM; 194 String vAlignStr = c.get("text-anchor-vertical", Keyword.BOTTOM, Keyword.class).val; 195 if (equal(vAlignStr, "above")) { 196 vAlign = VerticalTextAlignment.ABOVE; 197 } else if (equal(vAlignStr, "top")) { 198 vAlign = VerticalTextAlignment.TOP; 199 } else if (equal(vAlignStr, "center")) { 200 vAlign = VerticalTextAlignment.CENTER; 201 } else if (equal(vAlignStr, "bottom")) { 202 vAlign = VerticalTextAlignment.BOTTOM; 203 } else if (equal(vAlignStr, "below")) { 204 vAlign = VerticalTextAlignment.BELOW; 205 } 206 text = new NodeTextElement(te, hAlign, vAlign); 207 } 117 if (!allowDefault && symbol == null && icon == null) return null; 208 118 209 119 return new NodeElemStyle(c, 210 120 icon == null ? null : icon.a, 211 121 icon == null ? null : icon.b, 212 symbol, 213 text); 122 symbol); 214 123 } 215 124 … … 330 239 if (icon != null && painter.isShowIcons()) { 331 240 painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? getDisabledIcon() : icon, 332 Utils.color_int2float(iconAlpha), selected, member , text);241 Utils.color_int2float(iconAlpha), selected, member); 333 242 } else if (symbol != null) { 334 243 Color fillColor = symbol.fillColor; … … 360 269 } 361 270 } 362 painter.drawNodeSymbol(n, symbol, fillColor, strokeColor , text);271 painter.drawNodeSymbol(n, symbol, fillColor, strokeColor); 363 272 } else { 364 273 if (n.isHighlighted()) { 365 painter.drawNode(n, settings.getHighlightColor(), settings.getSelectedNodeSize(), settings.isFillSelectedNode() , text);274 painter.drawNode(n, settings.getHighlightColor(), settings.getSelectedNodeSize(), settings.isFillSelectedNode()); 366 275 } else { 367 276 Color color; … … 398 307 settings.isFillUnselectedNode(); 399 308 400 painter.drawNode(n, color, size, fill , text);309 painter.drawNode(n, color, size, fill); 401 310 } 402 311 } … … 412 321 return null; 413 322 return disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(icon.getImage())); 323 } 324 325 public Rectangle getBox() { 326 if (icon != null) { 327 int w = icon.getIconWidth(), h=icon.getIconHeight(); 328 return new Rectangle(-w/2, -h/2, w, h); 329 } else if (symbol != null) { 330 return new Rectangle(-symbol.size/2, -symbol.size/2, symbol.size, symbol.size); 331 } else { 332 // This is only executed once, so no performance concerns. 333 // However, it would be better, if the settings could be changed at runtime. 334 int size = Utils.max( 335 Main.pref.getInteger("mappaint.node.selected-size", 5), 336 Main.pref.getInteger("mappaint.node.unselected-size", 3), 337 Main.pref.getInteger("mappaint.node.connection-size", 5), 338 Main.pref.getInteger("mappaint.node.tagged-size", 3) 339 ); 340 return new Rectangle(-size/2, -size/2, size, size); 341 } 414 342 } 415 343 … … 420 348 hash = 17 * hash + iconAlpha; 421 349 hash = 17 * hash + (symbol != null ? symbol.hashCode() : 0); 422 hash = 17 * hash + (text != null ? text.hashCode() : 0);423 350 return hash; 424 351 } … … 438 365 return false; 439 366 if (!equal(symbol, other.symbol)) 440 return false;441 if (!equal(text, other.text))442 367 return false; 443 368 return true; … … 455 380 s.append(" symbol=[" + symbol + "]"); 456 381 } 457 if (text != null) {458 s.append(" text=[" + text.toStringImpl() + "]");459 }460 382 s.append('}'); 461 383 return s.toString();
Note:
See TracChangeset
for help on using the changeset viewer.