Changeset 32088 in osm for applications/editors/josm/plugins/seachart/src/render/Renderer.java
- Timestamp:
- 2016-02-29T11:29:17+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/src/render/Renderer.java
r32084 r32088 548 548 } 549 549 550 public static void lightSector(Feature feature, Color col1, Color col2, double radius, double s1, double s2, booleandir, String str) {550 public static void lightSector(Feature feature, Color col1, Color col2, double radius, double s1, double s2, Double dir, String str) { 551 551 if ((zoom >= 16) && (radius > 0.2)) { 552 radius = 0.2 /(Math.pow(2, zoom-16));552 radius /= (Math.pow(2, zoom-15)); 553 553 } 554 554 double mid = (((s1 + s2) / 2) + (s1 > s2 ? 180 : 0)) % 360; … … 557 557 Point2D.Double centre = (Point2D.Double) context.getPoint(feature.geom.centre); 558 558 double radial = radius * context.mile(feature); 559 if (dir) { 560 g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians( mid)), centre.y + radial * Math.cos(Math.toRadians(mid))));559 if (dir != null) { 560 g2.draw(new Line2D.Double(centre.x, centre.y, centre.x - radial * Math.sin(Math.toRadians(dir)), centre.y + radial * Math.cos(Math.toRadians(dir)))); 561 561 } else { 562 562 if ((s1 != 0.0) || (s2 != 360.0)) { … … 574 574 } 575 575 if ((str != null) && (!str.isEmpty())) { 576 g2.setPaint(Color.black); 577 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 578 FontRenderContext frc = g2.getFontRenderContext(); 579 Font font = new Font("Arial", Font.PLAIN, 40); 580 GeneralPath path = new GeneralPath(); 581 GlyphVector gv = font.deriveFont(font.getSize2D() * (float)sScale).createGlyphVector(frc, (" " + str)); 582 double gwidth = gv.getLogicalBounds().getWidth(); 583 boolean hand = false; 584 double offset = 0; 585 Point2D origin; 586 if (dir) { 587 radial += 10 * sScale; 588 if (mid < 180) { 589 radial += gwidth; 590 hand = true; 591 } 592 origin = new Point2D.Double(centre.x - radial * Math.sin(Math.toRadians(mid)), centre.y + radial * Math.cos(Math.toRadians(mid))); 593 int length = gv.getNumGlyphs(); 594 for (int i = 0; i < length; i++) { 595 Shape shape = gv.getGlyphOutline(i); 596 Point2D point = gv.getGlyphPosition(i); 597 AffineTransform at = AffineTransform.getTranslateInstance(origin.getX(), origin.getY()); 598 at.rotate(Math.toRadians(mid + (hand ? -90 : 90))); 599 at.translate(-point.getX() + offset, -point.getY() + (15 * sScale)); 600 path.append(at.createTransformedShape(shape), false); 601 offset += gv.getGlyphMetrics(i).getAdvance(); 602 g2.fill(path); 603 } 604 } else { 605 double arc = (s2 > s1) ? (s2 - s1) : (s2 - s1 + 360); 606 double awidth = (Math.toRadians(arc) * radial); 607 if (gwidth < awidth) { 608 offset = 0; 609 double phi = 0; 610 if ((mid > 270) || (mid < 90)) { 611 hand = true; 612 phi = Math.toRadians(s2) - ((awidth - gwidth) / 2) /radial; 613 radial -= 20 * sScale; 614 } else { 615 phi = Math.toRadians(s1) + (((awidth - gwidth) / 2)) /radial; 616 radial += 20 * sScale; 617 } 618 origin = new Point2D.Double(centre.x - radial * Math.sin(phi), centre.y + radial * Math.cos(phi)); 619 int length = gv.getNumGlyphs(); 620 for (int i = 0; i < length; i++) { 621 Shape shape = gv.getGlyphOutline(i); 622 Point2D point = gv.getGlyphPosition(i); 623 AffineTransform at = AffineTransform.getTranslateInstance(origin.getX(), origin.getY()); 624 at.rotate(phi + (hand ? 0 : Math.toRadians(180))); 625 at.translate(-point.getX() + offset, -point.getY()); 626 path.append(at.createTransformedShape(shape), false); 627 double advance = gv.getGlyphMetrics(i).getAdvance(); 628 offset += advance; 629 phi += (hand ? -0.5 : +0.5) * advance / radial; 630 g2.fill(path); 631 } 632 } 576 FontRenderContext frc = g2.getFontRenderContext(); 577 Font font = new Font("Arial", Font.PLAIN, 40); 578 GlyphVector gv = font.deriveFont(font.getSize2D() * (float)sScale).createGlyphVector(frc, str); 579 double arc = (s2 > s1) ? (s2 - s1) : (s2 - s1 + 360); 580 double awidth = (Math.toRadians(arc) * radial); 581 boolean hand = ((mid > 270) || (mid < 90)); 582 double phi = Math.toRadians(mid); 583 radial += 30 * sScale; 584 AffineTransform at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale); 585 if (gv.getLogicalBounds().getWidth() < awidth) { 586 at.rotate(Math.toRadians(mid + (hand ? 0 : 180))); 587 Renderer.labelText(feature, str, font, Color.black, new Delta(Handle.CC, at)); 588 } else if (gv.getLogicalBounds().getHeight() < awidth) { 589 hand = (mid < 180); 590 at.rotate(Math.toRadians(mid + (hand ? -90 : 90))); 591 Renderer.labelText(feature, str, font, Color.black, hand ? new Delta(Handle.RC, at) : new Delta(Handle.LC, at)); 592 } 593 if (dir != null) { 594 font = new Font("Arial", Font.PLAIN, 30); 595 str = dir + "°"; 596 hand = (dir > 180); 597 phi = Math.toRadians(dir + (hand ? -0.5 : 0.5)); 598 radial -= 70 * sScale; 599 at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale); 600 at.rotate(Math.toRadians(dir + (hand ? 90 : -90))); 601 Renderer.labelText(feature, str, font, Color.black, hand ? new Delta(Handle.BR, at) : new Delta(Handle.BL, at)); 633 602 } 634 603 }
Note:
See TracChangeset
for help on using the changeset viewer.