X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosuilib%2FAltosSiteMapTile.java;h=09f184a37869cf121f19e3f556b535f10ca7e4ea;hp=9610b248c994e5856dc5cb446e8fb41b6913e49a;hb=8e44580cbe978f1570d4d2ac13d3dd7cd470ecf7;hpb=c674a20432c2cb97e5bc2a3de891f78b9e172fe9 diff --git a/altosuilib/AltosSiteMapTile.java b/altosuilib/AltosSiteMapTile.java index 9610b248..09f184a3 100644 --- a/altosuilib/AltosSiteMapTile.java +++ b/altosuilib/AltosSiteMapTile.java @@ -44,6 +44,9 @@ public class AltosSiteMapTile extends JComponent { Point2D.Double boost; Point2D.Double landed; + Line2D.Double line; + double line_course; + double line_dist; LinkedList points; @@ -81,6 +84,7 @@ public class AltosSiteMapTile extends JComponent { file = null; status = AltosSiteMapCache.success; queue_repaint(); + line = null; } static Color stateColors[] = { @@ -106,6 +110,47 @@ public class AltosSiteMapTile extends JComponent { queue_repaint(); } + public void set_line(Line2D.Double line, double distance) { + this.line = line; + line_dist = distance; + queue_repaint(); + } + + private String line_dist() { + String format; + double distance = line_dist; + + if (AltosConvert.imperial_units) { + distance = AltosConvert.meters_to_feet(distance); + if (distance < 10000) { + format = "%4.0fft"; + } else { + distance /= 5280; + if (distance < 10) + format = "%5.3fmi"; + else if (distance < 100) + format = "%5.2fmi"; + else if (distance < 1000) + format = "%5.1fmi"; + else + format = "%5.0fmi"; + } + } else { + if (distance < 10000) { + format = "%4.0fm"; + } else { + distance /= 1000; + if (distance < 100) + format = "%5.2fkm"; + else if (distance < 1000) + format = "%5.1fkm"; + else + format = "%5.0fkm"; + } + } + return String.format(format, distance); + } + public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AltosPoint prev = null; @@ -143,7 +188,7 @@ public class AltosSiteMapTile extends JComponent { float x = getWidth() / 2.0f; float y = getHeight() / 2.0f; x = x - (float) bounds.getWidth() / 2.0f; - y = y - (float) bounds.getHeight() / 2.0f; + y = y + (float) bounds.getHeight() / 2.0f; g2d.setColor(Color.BLACK); g2d.drawString(message, x, y); } @@ -171,6 +216,27 @@ public class AltosSiteMapTile extends JComponent { g2d.setColor(Color.BLACK); draw_circle(g2d, landed); } + + if (line != null) { + g2d.setColor(Color.BLUE); + g2d.draw(line); + + String message = line_dist(); + g2d.setFont(font); + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + Rectangle2D bounds; + bounds = font.getStringBounds(message, g2d.getFontRenderContext()); + + float x = (float) line.x1; + float y = (float) line.y1 + (float) bounds.getHeight() / 2.0f; + + if (line.x1 < line.x2) { + x -= (float) bounds.getWidth() + 2.0f; + } else { + x += 2.0f; + } + g2d.drawString(message, x, y); + } } public synchronized void show(int state, Point2D.Double last_pt, Point2D.Double pt)