Changeset 3871 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2011-02-08T14:29:23+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r3867 r3871 13 13 import java.awt.Rectangle; 14 14 import java.awt.TexturePaint; 15 import java.awt.font.FontRenderContext; 16 import java.awt.font.LineMetrics; 15 17 import java.awt.geom.GeneralPath; 16 18 import java.awt.geom.Rectangle2D; … … 33 35 import org.openstreetmap.josm.gui.NavigatableComponent; 34 36 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle; 37 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.HorizontalTextAlignment; 35 38 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.Symbol; 39 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.TextElement; 40 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.VerticalTextAlignment; 36 41 import org.openstreetmap.josm.tools.ImageProvider; 37 42 import org.openstreetmap.josm.tools.LanguageInfo; … … 188 193 } 189 194 190 public void drawNodeIcon(Node n, ImageIcon icon, float iconAlpha, boolean selected, boolean member, String name) {195 public void drawNodeIcon(Node n, ImageIcon icon, float iconAlpha, boolean selected, boolean member, TextElement text) { 191 196 Point p = nc.getPoint(n); 192 197 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; … … 198 203 icon.paintIcon ( nc, g, p.x-w/2, p.y-h/2 ); 199 204 g.setPaintMode(); 200 if(name != null) { 201 if (inactive || n.isDisabled()) { 202 g.setColor(inactiveColor); 203 } else { 204 g.setColor(textColor); 205 } 206 Font defaultFont = g.getFont(); 207 g.setFont (orderFont); 208 g.drawString (name, p.x+w/2+2, p.y+h/2+2); 209 g.setFont(defaultFont); 210 } 205 drawNodeText(n, text, p, w/2, h/2); 211 206 if (selected || member) 212 207 { … … 216 211 } 217 212 218 public void drawNodeSymbol(Node n, Symbol s, boolean selected, boolean member, String name) {213 public void drawNodeSymbol(Node n, Symbol s, boolean selected, boolean member, TextElement text) { 219 214 Point p = nc.getPoint(n); 220 215 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 221 int radius = (int) (s.size / 2);216 int radius = s.size / 2; 222 217 223 218 if (s.fillColor != null) { 224 g.setColor(s.fillColor); 219 if (inactive || n.isDisabled()) { 220 g.setColor(inactiveColor); 221 } else { 222 g.setColor(s.fillColor); 223 } 225 224 switch (s.symbol) { 225 case SQUARE: 226 g.fillRect(p.x - radius, p.y - radius, s.size, s.size); 227 break; 226 228 case CIRCLE: 227 g.fillOval(p.x - radius, p.y - radius, (int) s.size, (int)s.size);229 g.fillOval(p.x - radius, p.y - radius, s.size, s.size); 228 230 break; 229 case SQUARE: 230 g.fillRect(p.x - radius, p.y - radius, (int) s.size, (int) s.size); 231 break; 231 default: 232 throw new AssertionError(); 232 233 } 233 234 } 234 235 if (s.stroke != null) { 235 236 g.setStroke(s.stroke); 236 g.setColor(s.strokeColor); 237 if (inactive || n.isDisabled()) { 238 g.setColor(inactiveColor); 239 } else { 240 g.setColor(s.strokeColor); 241 } 237 242 switch (s.symbol) { 243 case SQUARE: 244 g.drawRect(p.x - radius, p.y - radius, s.size - 1, s.size - 1); 245 break; 238 246 case CIRCLE: 239 g.drawOval(p.x - radius, p.y - radius, (int) s.size - 1, (int)s.size - 1);247 g.drawOval(p.x - radius, p.y - radius, s.size - 1, s.size - 1); 240 248 break; 241 case SQUARE: 242 g.drawRect(p.x - radius, p.y - radius, (int) s.size - 1, (int) s.size - 1); 243 break; 249 default: 250 throw new AssertionError(); 244 251 } 245 252 g.setStroke(new BasicStroke()); 246 253 } 254 drawNodeText(n, text, p, radius, radius); 247 255 } 248 256 … … 253 261 * @param color The color of the node. 254 262 */ 255 public void drawNode(Node n, Color color, int size, boolean fill, String name) {263 public void drawNode(Node n, Color color, int size, boolean fill, TextElement text) { 256 264 if (size > 1) { 257 265 Point p = nc.getPoint(n); … … 270 278 } 271 279 272 if(name != null) { 273 if (inactive || n.isDisabled()) { 274 g.setColor(inactiveColor); 275 } else { 276 g.setColor(textColor); 277 } 278 Font defaultFont = g.getFont(); 279 g.setFont (orderFont); 280 g.drawString (name, p.x+radius+2, p.y+radius+2); 281 g.setFont(defaultFont); 282 } 283 } 280 drawNodeText(n, text, p, radius, radius + 4); 281 } 282 } 283 284 private void drawNodeText(Node n, TextElement text, Point p, int w_half, int h_half) { 285 if (!isShowNames() || text == null) 286 return; 287 288 String s = text.textKey == null ? getNodeName(n) : n.get(text.textKey); 289 if (s == null) 290 return; 291 292 if (inactive || n.isDisabled()) { 293 g.setColor(inactiveColor); 294 } else { 295 g.setColor(text.color); 296 } 297 Font defaultFont = g.getFont(); 298 g.setFont(text.font); 299 300 int x = p.x + text.xOffset; 301 int y = p.y + text.yOffset; 302 /** 303 * 304 * left-above __center-above___ right-above 305 * left-top| |right-top 306 * | | 307 * left-center| center-center |right-center 308 * | | 309 * left-bottom|_________________|right-bottom 310 * left-below center-below right-below 311 * 312 */ 313 if (text.hAlign == HorizontalTextAlignment.RIGHT) { 314 x += w_half + 2; 315 } else { 316 FontRenderContext frc = g.getFontRenderContext(); 317 Rectangle2D bounds = text.font.getStringBounds(s, frc); 318 int textWidth = (int) bounds.getWidth(); 319 if (text.hAlign == HorizontalTextAlignment.CENTER) { 320 x -= textWidth / 2; 321 } else if (text.hAlign == HorizontalTextAlignment.LEFT) { 322 x -= w_half + 4 + textWidth; 323 } else throw new AssertionError(); 324 } 325 326 if (text.vAlign == VerticalTextAlignment.BOTTOM) { 327 y += h_half - 2; 328 } else { 329 FontRenderContext frc = g.getFontRenderContext(); 330 LineMetrics metrics = text.font.getLineMetrics(s, frc); 331 if (text.vAlign == VerticalTextAlignment.ABOVE) { 332 y -= h_half + metrics.getDescent(); 333 } else if (text.vAlign == VerticalTextAlignment.TOP) { 334 y -= h_half - metrics.getAscent(); 335 } else if (text.vAlign == VerticalTextAlignment.CENTER) { 336 y += (metrics.getAscent() - metrics.getDescent()) / 2; 337 } else if (text.vAlign == VerticalTextAlignment.BELOW) { 338 y += h_half + metrics.getAscent(); 339 } else throw new AssertionError(); 340 } 341 g.drawString(s, x, y); 342 g.setFont(defaultFont); 284 343 } 285 344
Note:
See TracChangeset
for help on using the changeset viewer.