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_3;
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_5.*;
30 public class AltosUIMapLine {
31 AltosUILatLon start, end;
33 private Font font = null;
34 static public int stroke_width = 6;
36 public void set_font(Font font) {
40 private AltosUILatLon lat_lon(MouseEvent e, AltosUIMapTransform t) {
41 return t.screen_lat_lon(e.getPoint());
44 public void dragged(MouseEvent e, AltosUIMapTransform t) {
48 public void pressed(MouseEvent e, AltosUIMapTransform t) {
49 start = lat_lon(e, t);
53 private String line_dist() {
55 AltosGreatCircle g = new AltosGreatCircle(start.lat, start.lon,
57 double distance = g.distance;
59 if (AltosConvert.imperial_units) {
60 distance = AltosConvert.meters_to_feet(distance);
61 if (distance < 10000) {
67 else if (distance < 100)
69 else if (distance < 1000)
75 if (distance < 10000) {
81 else if (distance < 1000)
87 return String.format(format, distance);
90 public void paint(Graphics2D g, AltosUIMapTransform t) {
92 if (start == null || end == null)
95 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
97 Line2D.Double line = new Line2D.Double(t.screen(start),
100 g.setColor(Color.WHITE);
101 g.setStroke(new BasicStroke(stroke_width+4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
104 g.setColor(Color.BLUE);
105 g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
108 String message = line_dist();
110 bounds = font.getStringBounds(message, g.getFontRenderContext());
112 float x = (float) line.x1;
113 float y = (float) line.y1 + (float) bounds.getHeight() / 2.0f;
115 if (line.x1 < line.x2) {
116 x -= (float) bounds.getWidth() + 2.0f;
122 g.setColor(Color.WHITE);
123 for (int dy = -2; dy <= 2; dy += 2)
124 for (int dx = -2; dx <= 2; dx += 2)
125 g.drawString(message, x + dx, y + dy);
126 g.setColor(Color.BLUE);
127 g.drawString(message, x, y);