Changeset 29202 in osm for applications/editors/josm/plugins/smed2/src/symbols
- Timestamp:
- 2013-01-17T12:08:28+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/smed2/src/symbols
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/symbols/Notices.java
r29198 r29202 51 51 private static final Symbol Sport = new Symbol(); 52 52 static { 53 Sport.add(new Instr(Prim.TEXT, new Caption("SPORT", new TextStyle(new Font("Arial", Font.BOLD, 15)), (float)-25.0, (float)5.0)));53 Sport.add(new Instr(Prim.TEXT, new Caption("SPORT", new Font("Arial", Font.BOLD, 15), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 0))))); 54 54 } 55 55 private static final Symbol Turn = new Symbol(); … … 65 65 private static final Symbol VHF = new Symbol(); 66 66 static { 67 VHF.add(new Instr(Prim.TEXT, new Caption("VHF", new TextStyle(new Font("Arial", Font.BOLD, 20)), (float)-20.0, (float)-5.0)));67 VHF.add(new Instr(Prim.TEXT, new Caption("VHF", new Font("Arial", Font.BOLD, 20), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 0))))); 68 68 } 69 69 private static final Symbol Waterbike = new Symbol(); -
applications/editors/josm/plugins/smed2/src/symbols/Symbols.java
r29199 r29202 15 15 import java.awt.Graphics2D; 16 16 import java.awt.Rectangle; 17 import java.awt.font.TextLayout; 17 18 import java.awt.geom.*; 18 19 import java.util.ArrayList; … … 59 60 Object params; 60 61 61 Instr(Prim itype, Object iparams) {62 public Instr(Prim itype, Object iparams) { 62 63 type = itype; 63 64 params = iparams; … … 85 86 } 86 87 87 public static class TextStyle {88 Font font;89 90 public TextStyle(Font ifont) {91 font = ifont;92 }93 }94 95 88 public static class Caption { 96 89 String str; 97 TextStyle style; 98 float x; 99 float y; 100 101 public Caption(String istr, TextStyle istyle, float ix, float iy) { 90 Font font; 91 Delta dd; 92 93 public Caption(String istr, Font ifont, Delta idd) { 102 94 str = istr; 103 style = istyle; 104 x = ix; 105 y = iy; 95 font = ifont; 96 dd = idd; 106 97 } 107 98 } … … 167 158 switch (dd.h) { 168 159 case CC: 169 dx = bbox.x + (bbox.width / 2.0);170 dy = bbox.y + (bbox.height / 2.0);160 dx -= bbox.x + (bbox.width / 2.0); 161 dy -= bbox.y + (bbox.height / 2.0); 171 162 break; 172 163 case TL: 173 dx = bbox.x;174 dy = bbox.y;164 dx -= bbox.x; 165 dy -= bbox.y; 175 166 break; 176 167 case TR: 177 dx = bbox.x + bbox.width;178 dy = bbox.y;168 dx -= bbox.x + bbox.width; 169 dy -= bbox.y; 179 170 break; 180 171 case TC: 181 dx = bbox.x + (bbox.width / 2.0);182 dy = bbox.y;172 dx -= bbox.x + (bbox.width / 2.0); 173 dy -= bbox.y; 183 174 break; 184 175 case LC: 185 dx = bbox.x;186 dy = bbox.y + (bbox.height / 2.0);176 dx -= bbox.x; 177 dy -= bbox.y + (bbox.height / 2.0); 187 178 break; 188 179 case RC: 189 dx = bbox.x + bbox.width;190 dy = bbox.y + (bbox.height / 2.0);180 dx -= bbox.x + bbox.width; 181 dy -= bbox.y + (bbox.height / 2.0); 191 182 break; 192 183 case BL: 193 dx = bbox.x;194 dy = bbox.y + bbox.height;184 dx -= bbox.x; 185 dy -= bbox.y + bbox.height; 195 186 break; 196 187 case BR: 197 dx = bbox.x + bbox.width;198 dy = bbox.y + bbox.height;188 dx -= bbox.x + bbox.width; 189 dy -= bbox.y + bbox.height; 199 190 break; 200 191 case BC: 201 dx = bbox.x + (bbox.width / 2.0);202 dy = bbox.y + bbox.height;192 dx -= bbox.x + (bbox.width / 2.0); 193 dy -= bbox.y + bbox.height; 203 194 break; 204 195 } 205 g2.translate( -dx, -dy);196 g2.translate(dx, dy); 206 197 } 207 198 break; … … 296 287 case TEXT: 297 288 Caption c = (Caption) item.params; 298 g2.setFont(c.style.font); 299 g2.drawString(c.str, c.x, c.y); 289 TextLayout layout = new TextLayout(c.str, c.font, g2.getFontRenderContext()); 290 Rectangle2D bb = layout.getBounds(); 291 dx = 0; 292 dy = 0; 293 if (c.dd != null) { 294 g2.transform(c.dd.t); 295 switch (c.dd.h) { 296 case CC: 297 dx -= bb.getX() + (bb.getWidth() / 2.0); 298 dy -= bb.getY() + (bb.getHeight() / 2.0); 299 break; 300 case TL: 301 dx -= bb.getX(); 302 dy -= bb.getY(); 303 break; 304 case TR: 305 dx -= bb.getX() + bb.getWidth(); 306 dy -= bb.getY(); 307 break; 308 case TC: 309 dx -= bb.getX() + (bb.getWidth() / 2.0); 310 dy -= bb.getY(); 311 break; 312 case LC: 313 dx -= bb.getX(); 314 dy -= bb.getY() + (bb.getHeight() / 2.0); 315 break; 316 case RC: 317 dx -= bb.getX() + bb.getWidth(); 318 dy -= bb.getY() + (bb.getHeight() / 2.0); 319 break; 320 case BL: 321 dx -= bb.getX(); 322 dy -= bb.getY() + bb.getHeight(); 323 break; 324 case BR: 325 dx -= bb.getX() + bb.getWidth(); 326 dy -= bb.getY() + bb.getHeight(); 327 break; 328 case BC: 329 dx -= bb.getX() + (bb.getWidth() / 2.0); 330 dy -= bb.getY() + bb.getHeight(); 331 break; 332 } 333 } 334 layout.draw(g2, (float)dx, (float)dy); 300 335 break; 301 336 }
Note:
See TracChangeset
for help on using the changeset viewer.