2 * Copyright © 2014 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altosuilib_2;
21 import java.awt.event.*;
24 import java.lang.Math;
25 import java.awt.geom.*;
27 import java.util.concurrent.*;
28 import org.altusmetrum.altoslib_4.*;
30 public class AltosUIMapLine {
31 AltosUILatLon start, end;
33 private Font font = null;
35 public void set_font(Font font) {
39 private AltosUILatLon lat_lon(MouseEvent e, AltosUIMapTransform t) {
40 return t.screen_lat_lon(e.getPoint());
43 public void dragged(MouseEvent e, AltosUIMapTransform t) {
47 public void pressed(MouseEvent e, AltosUIMapTransform t) {
48 start = lat_lon(e, t);
52 private String line_dist() {
54 AltosGreatCircle g = new AltosGreatCircle(start.lat, start.lon,
56 double distance = g.distance;
58 if (AltosConvert.imperial_units) {
59 distance = AltosConvert.meters_to_feet(distance);
60 if (distance < 10000) {
66 else if (distance < 100)
68 else if (distance < 1000)
74 if (distance < 10000) {
80 else if (distance < 1000)
86 return String.format(format, distance);
89 public void paint(Graphics2D g, AltosUIMapTransform t) {
90 g.setColor(Color.BLUE);
92 if (start == null || end == null)
95 Line2D.Double line = new Line2D.Double(t.screen(start),
100 String message = line_dist();
102 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
104 bounds = font.getStringBounds(message, g.getFontRenderContext());
106 float x = (float) line.x1;
107 float y = (float) line.y1 + (float) bounds.getHeight() / 2.0f;
109 if (line.x1 < line.x2) {
110 x -= (float) bounds.getWidth() + 2.0f;
114 g.drawString(message, x, y);