From 501fa41111b93cc213a1114a33612858e1e93ab5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 26 May 2015 00:29:53 -0700 Subject: altoslib/altosuilib: Get new Map display code running in altosui and telegps Looks like the display is all hooked up. Still need to replace the preload UIs. Signed-off-by: Keith Packard --- altosuilib/AltosUIMapNew.java | 539 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 539 insertions(+) create mode 100644 altosuilib/AltosUIMapNew.java (limited to 'altosuilib/AltosUIMapNew.java') diff --git a/altosuilib/AltosUIMapNew.java b/altosuilib/AltosUIMapNew.java new file mode 100644 index 00000000..4191a562 --- /dev/null +++ b/altosuilib/AltosUIMapNew.java @@ -0,0 +1,539 @@ +/* + * Copyright © 2010 Anthony Towns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.altosuilib_7; + +import java.awt.*; +import java.awt.event.*; +import java.awt.image.*; +import javax.swing.*; +import java.io.*; +import java.lang.Math; +import java.awt.geom.*; +import java.util.*; +import java.util.concurrent.*; +import javax.imageio.*; +import org.altusmetrum.altoslib_7.*; + +public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, AltosMapInterface { + + AltosMap map; + Graphics2D g; + Font tile_font; + Font line_font; + + static Point2D.Double point2d(AltosPointDouble pt) { + return new Point2D.Double(pt.x, pt.y); + } + + static final AltosPointDouble point_double(Point pt) { + return new AltosPointDouble(pt.x, pt.y); + } + + class MapMark extends AltosMapMark { + public void paint(AltosMapTransform t) { + AltosPointDouble pt = t.screen(lat_lon); + + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); + + if (0 <= state && state < AltosUIMapNew.stateColors.length) + g.setColor(AltosUIMapNew.stateColors[state]); + else + g.setColor(AltosUIMapNew.stateColors[AltosLib.ao_flight_invalid]); + + g.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); + g.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); + g.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); + } + + MapMark(double lat, double lon, int state) { + super(lat, lon, state); + } + } + + class MapView extends JComponent implements MouseMotionListener, MouseListener, ComponentListener, MouseWheelListener { + + private VolatileImage create_back_buffer() { + return getGraphicsConfiguration().createCompatibleVolatileImage(getWidth(), getHeight()); + } + + private void do_paint(Graphics my_g) { + g = (Graphics2D) my_g; + + map.paint(); + } + + public void paint(Graphics my_g) { + VolatileImage back_buffer = create_back_buffer(); + + Graphics2D top_g = (Graphics2D) my_g; + + do { + GraphicsConfiguration gc = getGraphicsConfiguration(); + int code = back_buffer.validate(gc); + if (code == VolatileImage.IMAGE_INCOMPATIBLE) + back_buffer = create_back_buffer(); + + Graphics g_back = back_buffer.getGraphics(); + g_back.setClip(top_g.getClip()); + do_paint(g_back); + g_back.dispose(); + + top_g.drawImage(back_buffer, 0, 0, this); + } while (back_buffer.contentsLost()); + back_buffer.flush(); + } + + public void repaint(AltosRectangle damage) { + repaint(damage.x, damage.y, damage.width, damage.height); + } + + private boolean is_drag_event(MouseEvent e) { + return e.getModifiers() == InputEvent.BUTTON1_MASK; + } + + /* MouseMotionListener methods */ + + public void mouseDragged(MouseEvent e) { + map.touch_continue(e.getPoint().x, e.getPoint().y, is_drag_event(e)); + } + + public void mouseMoved(MouseEvent e) { + } + + /* MouseListener methods */ + public void mouseClicked(MouseEvent e) { + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } + + public void mousePressed(MouseEvent e) { + map.touch_start(e.getPoint().x, e.getPoint().y, is_drag_event(e)); + } + + public void mouseReleased(MouseEvent e) { + } + + /* MouseWheelListener methods */ + + public void mouseWheelMoved(MouseWheelEvent e) { + int zoom_change = e.getWheelRotation(); + + map.notice_user_input(); + AltosLatLon mouse_lat_lon = map.transform.screen_lat_lon(new AltosPointInt(e.getPoint().x, e.getPoint().y)); + map.set_zoom(map.get_zoom() - zoom_change); + + AltosPointDouble new_mouse = map.transform.screen(mouse_lat_lon); + + int dx = getWidth()/2 - e.getPoint().x; + int dy = getHeight()/2 - e.getPoint().y; + + AltosLatLon new_centre = map.transform.screen_lat_lon(new AltosPointInt((int) new_mouse.x + dx, (int) new_mouse.y + dy)); + + map.centre(new_centre); + } + + /* ComponentListener methods */ + + public void componentHidden(ComponentEvent e) { + } + + public void componentMoved(ComponentEvent e) { + } + + public void componentResized(ComponentEvent e) { + map.set_transform(); + } + + public void componentShown(ComponentEvent e) { + map.set_transform(); + } + + MapView() { + addComponentListener(this); + addMouseMotionListener(this); + addMouseListener(this); + addMouseWheelListener(this); + } + } + + class MapLine extends AltosMapLine { + + public void paint(AltosMapTransform t) { + + if (start == null || end == null) + return; + + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + Line2D.Double line = new Line2D.Double(point2d(t.screen(start)), + point2d(t.screen(end))); + + g.setColor(Color.WHITE); + g.setStroke(new BasicStroke(stroke_width+4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); + g.draw(line); + + g.setColor(Color.BLUE); + g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); + g.draw(line); + + String message = line_dist(); + Rectangle2D bounds; + bounds = line_font.getStringBounds(message, g.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; + } + + g.setFont(line_font); + g.setColor(Color.WHITE); + for (int dy = -2; dy <= 2; dy += 2) + for (int dx = -2; dx <= 2; dx += 2) + g.drawString(message, x + dx, y + dy); + g.setColor(Color.BLUE); + g.drawString(message, x, y); + } + + public MapLine() { + } + } + + class MapPath extends AltosMapPath { + public void paint(AltosMapTransform t) { + Point2D.Double prev = null; + + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); + + for (AltosMapPathPoint point : points) { + Point2D.Double cur = point2d(t.screen(point.lat_lon)); + if (prev != null) { + Line2D.Double line = new Line2D.Double (prev, cur); + Rectangle bounds = line.getBounds(); + + if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) { + if (0 <= point.state && point.state < AltosUIMapNew.stateColors.length) + g.setColor(AltosUIMapNew.stateColors[point.state]); + else + g.setColor(AltosUIMapNew.stateColors[AltosLib.ao_flight_invalid]); + + g.draw(line); + } + } + prev = cur; + } + } + } + + class MapTile extends AltosMapTile { + public MapTile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { + super(listener, upper_left, center, zoom, maptype, px_size); + } + + public void paint(AltosMapTransform t) { + + AltosPointDouble point_double = t.screen(upper_left); + Point point = new Point((int) (point_double.x + 0.5), + (int) (point_double.y + 0.5)); + + if (!g.hitClip(point.x, point.y, px_size, px_size)) + return; + + AltosImage altos_image = cache.get(this, store, px_size, px_size); + + AltosUIImage ui_image = (AltosUIImage) altos_image; + + Image image = null; + + if (ui_image != null) + image = ui_image.image; + + if (image != null) { + g.drawImage(image, point.x, point.y, null); + } else { + g.setColor(Color.GRAY); + g.fillRect(point.x, point.y, px_size, px_size); + + if (t.has_location()) { + String message = null; + switch (status) { + case AltosUIMapCache.loading: + message = "Loading..."; + break; + case AltosUIMapCache.bad_request: + message = "Internal error"; + break; + case AltosUIMapCache.failed: + message = "Network error, check connection"; + break; + case AltosUIMapCache.forbidden: + message = "Too many requests, try later"; + break; + } + if (message != null && tile_font != null) { + g.setFont(tile_font); + g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + Rectangle2D bounds = tile_font.getStringBounds(message, g.getFontRenderContext()); + + float x = px_size / 2.0f; + float y = px_size / 2.0f; + x = x - (float) bounds.getWidth() / 2.0f; + y = y + (float) bounds.getHeight() / 2.0f; + g.setColor(Color.BLACK); + g.drawString(message, (float) point_double.x + x, (float) point_double.y + y); + } + } + } + } + } + + public static final Color stateColors[] = { + Color.WHITE, // startup + Color.WHITE, // idle + Color.WHITE, // pad + Color.RED, // boost + Color.PINK, // fast + Color.YELLOW, // coast + Color.CYAN, // drogue + Color.BLUE, // main + Color.BLACK, // landed + Color.BLACK, // invalid + Color.CYAN, // stateless + }; + + /* AltosMapInterface functions */ + + public AltosMapPath new_path() { + return new MapPath(); + } + + public AltosMapLine new_line() { + return new MapLine(); + } + + public AltosImage load_image(File file) throws Exception { + return new AltosUIImage(ImageIO.read(file)); + } + + public AltosMapMark new_mark(double lat, double lon, int state) { + return new MapMark(lat, lon, state); + } + + public AltosMapTile new_tile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { + return new MapTile(listener, upper_left, center, zoom, maptype, px_size); + } + + public int width() { + return view.getWidth(); + } + + public int height() { + return view.getHeight(); + } + + public void repaint() { + view.repaint(); + } + + public void repaint(AltosRectangle damage) { + view.repaint(damage); + } + + public void set_zoom_label(String label) { + zoom_label.setText(label); + } + + /* AltosFlightDisplay interface */ + + public void set_font() { + tile_font = AltosUILib.value_font; + line_font = AltosUILib.status_font; + } + + public void font_size_changed(int font_size) { + set_font(); + repaint(); + } + + public void units_changed(boolean imperial_units) { + repaint(); + } + + JLabel zoom_label; + + public void set_maptype(int type) { + map.set_maptype(type); + maptype_combo.setSelectedIndex(type); + } + + /* AltosUIMapPreload functions */ + + public void set_zoom(int zoom) { + map.set_zoom(zoom); + } + + public void add_mark(double lat, double lon, int status) { + map.add_mark(lat, lon, status); + } + + public void clear_marks() { + map.clear_marks(); + } + + /* AltosFlightDisplay interface */ + public void reset() { + // nothing + } + + public void show(AltosState state, AltosListenerState listener_state) { + map.show(state, listener_state); + } + + public String getName() { + return "Map"; + } + + /* internal layout bits */ + private GridBagLayout layout = new GridBagLayout(); + + JComboBox maptype_combo; + + public void set_load_params(double lat, double lon, int radius, AltosMapTileListener listener) { + map.set_load_params(lat, lon, radius, listener); + } + + MapView view; + + public AltosUIMapNew() { + + set_font(); + + view = new MapView(); + + view.setPreferredSize(new Dimension(500,500)); + view.setVisible(true); + view.setEnabled(true); + + GridBagLayout my_layout = new GridBagLayout(); + + setLayout(my_layout); + + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.BOTH; + c.gridx = 0; + c.gridy = 0; + c.gridwidth = 1; + c.gridheight = 10; + c.weightx = 1; + c.weighty = 1; + add(view, c); + + int y = 0; + + zoom_label = new JLabel("", JLabel.CENTER); + + c = new GridBagConstraints(); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + c.gridy = y++; + c.weightx = 0; + c.weighty = 0; + add(zoom_label, c); + + JButton zoom_reset = new JButton("0"); + zoom_reset.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + map.set_zoom(map.default_zoom); + } + }); + + c = new GridBagConstraints(); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + c.gridy = y++; + c.weightx = 0; + c.weighty = 0; + add(zoom_reset, c); + + JButton zoom_in = new JButton("+"); + zoom_in.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + map.set_zoom(map.get_zoom() + 1); + } + }); + + c = new GridBagConstraints(); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + c.gridy = y++; + c.weightx = 0; + c.weighty = 0; + add(zoom_in, c); + + JButton zoom_out = new JButton("-"); + zoom_out.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + map.set_zoom(map.get_zoom() - 1); + } + }); + c = new GridBagConstraints(); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + c.gridy = y++; + c.weightx = 0; + c.weighty = 0; + add(zoom_out, c); + + maptype_combo = new JComboBox(map.maptype_labels); + + maptype_combo.setEditable(false); + maptype_combo.setMaximumRowCount(maptype_combo.getItemCount()); + maptype_combo.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + map.set_maptype(maptype_combo.getSelectedIndex()); + } + }); + + c = new GridBagConstraints(); + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + c.gridy = y++; + c.weightx = 0; + c.weighty = 0; + add(maptype_combo, c); + + map = new AltosMap(this); + } +} -- cgit v1.2.3 From 4895f443e4a748de2677e51869f20c05d265c944 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 26 May 2015 00:56:17 -0700 Subject: altosuilib: Remove old map bits Signed-off-by: Keith Packard --- altosui/AltosGraphUI.java | 4 +- altosui/AltosIdleMonitorUI.java | 4 +- altosuilib/AltosUILatLon.java | 44 --- altosuilib/AltosUIMap.java | 250 ------------- altosuilib/AltosUIMapCache.java | 137 ------- altosuilib/AltosUIMapCacheListener.java | 22 -- altosuilib/AltosUIMapImage.java | 113 ------ altosuilib/AltosUIMapLine.java | 129 ------- altosuilib/AltosUIMapMark.java | 59 ---- altosuilib/AltosUIMapNew.java | 13 +- altosuilib/AltosUIMapPath.java | 96 ----- altosuilib/AltosUIMapPreload.java | 608 -------------------------------- altosuilib/AltosUIMapPreloadNew.java | 18 +- altosuilib/AltosUIMapRectangle.java | 45 --- altosuilib/AltosUIMapStore.java | 203 ----------- altosuilib/AltosUIMapStoreListener.java | 22 -- altosuilib/AltosUIMapTile.java | 192 ---------- altosuilib/AltosUIMapTileListener.java | 24 -- altosuilib/AltosUIMapTransform.java | 106 ------ altosuilib/AltosUIMapView.java | 457 ------------------------ altosuilib/AltosUIMapZoomListener.java | 22 -- altosuilib/AltosUIPreferences.java | 35 -- altosuilib/Makefile.am | 17 - telegps/TeleGPS.java | 16 +- telegps/TeleGPSGraphUI.java | 4 +- 25 files changed, 25 insertions(+), 2615 deletions(-) delete mode 100644 altosuilib/AltosUILatLon.java delete mode 100644 altosuilib/AltosUIMap.java delete mode 100644 altosuilib/AltosUIMapCache.java delete mode 100644 altosuilib/AltosUIMapCacheListener.java delete mode 100644 altosuilib/AltosUIMapImage.java delete mode 100644 altosuilib/AltosUIMapLine.java delete mode 100644 altosuilib/AltosUIMapMark.java delete mode 100644 altosuilib/AltosUIMapPath.java delete mode 100644 altosuilib/AltosUIMapPreload.java delete mode 100644 altosuilib/AltosUIMapRectangle.java delete mode 100644 altosuilib/AltosUIMapStore.java delete mode 100644 altosuilib/AltosUIMapStoreListener.java delete mode 100644 altosuilib/AltosUIMapTile.java delete mode 100644 altosuilib/AltosUIMapTileListener.java delete mode 100644 altosuilib/AltosUIMapTransform.java delete mode 100644 altosuilib/AltosUIMapView.java delete mode 100644 altosuilib/AltosUIMapZoomListener.java (limited to 'altosuilib/AltosUIMapNew.java') diff --git a/altosui/AltosGraphUI.java b/altosui/AltosGraphUI.java index 42a17658..70543610 100644 --- a/altosui/AltosGraphUI.java +++ b/altosui/AltosGraphUI.java @@ -35,7 +35,7 @@ public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, Alt JTabbedPane pane; AltosGraph graph; AltosUIEnable enable; - AltosUIMap map; + AltosUIMapNew map; AltosState state; AltosGraphDataSet graphDataSet; AltosFlightStats stats; @@ -47,7 +47,7 @@ public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, Alt for (AltosState state : states) { if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) { if (map == null) - map = new AltosUIMap(); + map = new AltosUIMapNew(); map.show(state, null); has_gps = true; } diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index 2c7ff5fc..4f6fdd48 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -35,7 +35,7 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl AltosFlightStatus flightStatus; AltosIgnitor ignitor; AltosIdleMonitor thread; - AltosUIMap sitemap; + AltosUIMapNew sitemap; int serial; boolean remote; boolean has_ignitor; @@ -278,7 +278,7 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl ignitor = new AltosIgnitor(); - sitemap = new AltosUIMap(); + sitemap = new AltosUIMapNew(); /* Make the tabbed pane use the rest of the window space */ bag.add(pane, constraints(0, 3, GridBagConstraints.BOTH)); diff --git a/altosuilib/AltosUILatLon.java b/altosuilib/AltosUILatLon.java deleted file mode 100644 index c9fb8e92..00000000 --- a/altosuilib/AltosUILatLon.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_7.*; - -public class AltosUILatLon { - public double lat; - public double lon; - - public boolean equals(AltosUILatLon other) { - if (other == null) - return false; - return lat == other.lat && lon == other.lon; - } - - public AltosUILatLon(double lat, double lon) { - this.lat = lat; - this.lon = lon; - } -} diff --git a/altosuilib/AltosUIMap.java b/altosuilib/AltosUIMap.java deleted file mode 100644 index 5d6fae40..00000000 --- a/altosuilib/AltosUIMap.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_7.*; - -public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosUIMapZoomListener { - - static final int px_size = 512; - - static final int maptype_hybrid = 0; - static final int maptype_roadmap = 1; - static final int maptype_satellite = 2; - static final int maptype_terrain = 3; - static final int maptype_default = maptype_hybrid; - - static final String[] maptype_names = { - "hybrid", - "roadmap", - "satellite", - "terrain" - }; - - public static final String[] maptype_labels = { - "Hybrid", - "Roadmap", - "Satellite", - "Terrain" - }; - - public static final Color stateColors[] = { - Color.WHITE, // startup - Color.WHITE, // idle - Color.WHITE, // pad - Color.RED, // boost - Color.PINK, // fast - Color.YELLOW, // coast - Color.CYAN, // drogue - Color.BLUE, // main - Color.BLACK, // landed - Color.BLACK, // invalid - Color.CYAN, // stateless - }; - - public void reset() { - // nothing - } - - public void font_size_changed(int font_size) { - view.set_font(); - } - - public void units_changed(boolean imperial_units) { - view.set_units(); - } - - JLabel zoom_label; - - private void set_zoom_label() { - zoom_label.setText(String.format("Zoom %d", view.zoom() - view.default_zoom)); - } - - public void zoom_changed(int zoom) { - set_zoom_label(); - } - - public void set_zoom(int zoom) { - view.set_zoom(zoom); - } - - public int get_zoom() { - return view.zoom(); - } - - public void set_maptype(int type) { - view.set_maptype(type); - maptype_combo.setSelectedIndex(type); - } - - public void show(AltosState state, AltosListenerState listener_state) { - view.show(state, listener_state); - } - - public void centre(double lat, double lon) { - view.centre(lat, lon); - } - - public void centre(AltosState state) { - if (!state.gps.locked && state.gps.nsat < 4) - return; - centre(state.gps.lat, state.gps.lon); - } - - public void add_mark(double lat, double lon, int state) { - view.add_mark(lat, lon, state); - } - - public void clear_marks() { - view.clear_marks(); - } - - AltosUIMapView view; - - private GridBagLayout layout = new GridBagLayout(); - - JComboBox maptype_combo; - - public void set_load_params(double lat, double lon, int radius, AltosUIMapTileListener listener) { - view.set_load_params(lat, lon, radius, listener); - } - - public boolean all_fetched() { - return view.all_fetched(); - } - - public static void prefetch_maps(double lat, double lon) { - } - - public String getName() { - return "Map"; - } - - public AltosUIMap() { - - view = new AltosUIMapView(); - - view.setPreferredSize(new Dimension(500,500)); - view.setVisible(true); - view.setEnabled(true); - view.add_zoom_listener(this); - - GridBagLayout my_layout = new GridBagLayout(); - - setLayout(my_layout); - - GridBagConstraints c = new GridBagConstraints(); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.BOTH; - c.gridx = 0; - c.gridy = 0; - c.gridwidth = 1; - c.gridheight = 10; - c.weightx = 1; - c.weighty = 1; - add(view, c); - - int y = 0; - - zoom_label = new JLabel("", JLabel.CENTER); - set_zoom_label(); - - c = new GridBagConstraints(); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - c.gridy = y++; - c.weightx = 0; - c.weighty = 0; - add(zoom_label, c); - - JButton zoom_reset = new JButton("0"); - zoom_reset.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - set_zoom(view.default_zoom); - } - }); - - c = new GridBagConstraints(); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - c.gridy = y++; - c.weightx = 0; - c.weighty = 0; - add(zoom_reset, c); - - JButton zoom_in = new JButton("+"); - zoom_in.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - set_zoom(get_zoom() + 1); - } - }); - - c = new GridBagConstraints(); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - c.gridy = y++; - c.weightx = 0; - c.weighty = 0; - add(zoom_in, c); - - JButton zoom_out = new JButton("-"); - zoom_out.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - set_zoom(get_zoom() - 1); - } - }); - c = new GridBagConstraints(); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - c.gridy = y++; - c.weightx = 0; - c.weighty = 0; - add(zoom_out, c); - - maptype_combo = new JComboBox(maptype_labels); - - maptype_combo.setEditable(false); - maptype_combo.setMaximumRowCount(maptype_combo.getItemCount()); - maptype_combo.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - view.set_maptype(maptype_combo.getSelectedIndex()); - } - }); - - c = new GridBagConstraints(); - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 1; - c.gridy = y++; - c.weightx = 0; - c.weighty = 0; - add(maptype_combo, c); - } -} diff --git a/altosuilib/AltosUIMapCache.java b/altosuilib/AltosUIMapCache.java deleted file mode 100644 index d08b634d..00000000 --- a/altosuilib/AltosUIMapCache.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import javax.swing.*; -import javax.imageio.ImageIO; -import java.awt.image.*; -import java.awt.*; -import java.io.*; -import java.net.*; - -public class AltosUIMapCache implements AltosUIMapCacheListener { - static final int success = 0; - static final int loading = 1; - static final int failed = 2; - static final int bad_request = 3; - static final int forbidden = 4; - - int min_cache_size; /* configured minimum cache size */ - int cache_size; /* current cache size */ - int requested_cache_size; /* cache size computed by application */ - - private Object fetch_lock = new Object(); - private Object cache_lock = new Object(); - - AltosUIMapImage[] images = new AltosUIMapImage[cache_size]; - - long used; - - public void set_cache_size(int new_size) { - - requested_cache_size = new_size; - - if (new_size < min_cache_size) - new_size = min_cache_size; - - if (new_size == cache_size) - return; - - synchronized(cache_lock) { - AltosUIMapImage[] new_images = new AltosUIMapImage[new_size]; - - for (int i = 0; i < cache_size; i++) { - if (i < new_size) - new_images[i] = images[i]; - else if (images[i] != null) - images[i].flush(); - } - images = new_images; - cache_size = new_size; - } - } - - public Image get(AltosUIMapTile tile, AltosUIMapStore store, int width, int height) { - int oldest = -1; - long age = used; - - synchronized(cache_lock) { - AltosUIMapImage image = null; - for (int i = 0; i < cache_size; i++) { - image = images[i]; - - if (image == null) { - oldest = i; - break; - } - if (store.equals(image.store)) { - image.used = used++; - return image.image; - } - if (image.used < age) { - oldest = i; - age = image.used; - } - } - - try { - image = new AltosUIMapImage(tile, store); - image.used = used++; - if (images[oldest] != null) - images[oldest].flush(); - - images[oldest] = image; - - if (image.image == null) - tile.set_status(loading); - else - tile.set_status(success); - - return image.image; - } catch (IOException e) { - tile.set_status(failed); - return null; - } - } - } - - public void map_cache_changed(int map_cache) { - min_cache_size = map_cache; - - set_cache_size(requested_cache_size); - } - - public void dispose() { - AltosUIPreferences.unregister_map_cache_listener(this); - - for (int i = 0; i < cache_size; i++) { - AltosUIMapImage image = images[i]; - - if (image != null) - image.flush(); - } - } - - public AltosUIMapCache() { - min_cache_size = AltosUIPreferences.map_cache(); - - set_cache_size(0); - - AltosUIPreferences.register_map_cache_listener(this); - } -} diff --git a/altosuilib/AltosUIMapCacheListener.java b/altosuilib/AltosUIMapCacheListener.java deleted file mode 100644 index 9ae66f66..00000000 --- a/altosuilib/AltosUIMapCacheListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -public interface AltosUIMapCacheListener { - public void map_cache_changed(int map_cache); -} diff --git a/altosuilib/AltosUIMapImage.java b/altosuilib/AltosUIMapImage.java deleted file mode 100644 index e0ac7b5a..00000000 --- a/altosuilib/AltosUIMapImage.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import javax.swing.*; -import javax.imageio.ImageIO; -import java.awt.image.*; -import java.awt.*; -import java.io.*; -import java.net.*; - -public class AltosUIMapImage implements AltosUIMapStoreListener { - static final long google_maps_ratelimit_ms = 1200; - // Google limits static map queries to 50 per minute per IP, so - // each query should take at least 1.2 seconds. - - static final int success = 0; - static final int loading = 1; - static final int failed = 2; - static final int bad_request = 3; - static final int forbidden = 4; - - static long forbidden_time; - static boolean forbidden_set = false; - static final long forbidden_interval = 60l * 1000l * 1000l * 1000l; - - AltosUIMapTile tile; /* Notify when image has been loaded */ - Image image; - AltosUIMapStore store; - long used; - - class loader implements Runnable { - public void run() { - if (image != null) - tile.notify_image(image); - try { - image = ImageIO.read(store.file); - } catch (Exception ex) { - } - if (image == null) - tile.set_status(failed); - else - tile.set_status(success); - tile.notify_image(image); - } - } - - private void load() { - loader l = new loader(); - Thread lt = new Thread(l); - lt.start(); - } - - public void flush() { - if (image != null) { - image.flush(); - image = null; - } - } - - public boolean has_map() { - return store.status() == AltosUIMapStore.success; - } - - public synchronized void notify_store(AltosUIMapStore store, int status) { - switch (status) { - case AltosUIMapStore.loading: - break; - case AltosUIMapStore.success: - load(); - break; - default: - tile.set_status(status); - tile.notify_image(null); - } - } - - public AltosUIMapImage(AltosUIMapTile tile, AltosUIMapStore store) throws IOException { - this.tile = tile; - this.image = null; - this.store = store; - this.used = 0; - - int status = store.status(); - switch (status) { - case AltosUIMapStore.loading: - store.add_listener(this); - break; - case AltosUIMapStore.success: - load(); - break; - default: - tile.set_status(status); - tile.notify_image(null); - break; - } - } -} diff --git a/altosuilib/AltosUIMapLine.java b/altosuilib/AltosUIMapLine.java deleted file mode 100644 index 62ed4360..00000000 --- a/altosuilib/AltosUIMapLine.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_7.*; - -public class AltosUIMapLine { - AltosUILatLon start, end; - - private Font font = null; - static public int stroke_width = 6; - - public void set_font(Font font) { - this.font = font; - } - - private AltosUILatLon lat_lon(MouseEvent e, AltosUIMapTransform t) { - return t.screen_lat_lon(e.getPoint()); - } - - public void dragged(MouseEvent e, AltosUIMapTransform t) { - end = lat_lon(e, t); - } - - public void pressed(MouseEvent e, AltosUIMapTransform t) { - start = lat_lon(e, t); - end = null; - } - - private String line_dist() { - String format; - AltosGreatCircle g = new AltosGreatCircle(start.lat, start.lon, - end.lat, end.lon); - double distance = g.distance; - - 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(Graphics2D g, AltosUIMapTransform t) { - - if (start == null || end == null) - return; - - g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - Line2D.Double line = new Line2D.Double(t.screen(start), - t.screen(end)); - - g.setColor(Color.WHITE); - g.setStroke(new BasicStroke(stroke_width+4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - g.draw(line); - - g.setColor(Color.BLUE); - g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - g.draw(line); - - String message = line_dist(); - Rectangle2D bounds; - bounds = font.getStringBounds(message, g.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; - } - - g.setFont(font); - g.setColor(Color.WHITE); - for (int dy = -2; dy <= 2; dy += 2) - for (int dx = -2; dx <= 2; dx += 2) - g.drawString(message, x + dx, y + dy); - g.setColor(Color.BLUE); - g.drawString(message, x, y); - } -} diff --git a/altosuilib/AltosUIMapMark.java b/altosuilib/AltosUIMapMark.java deleted file mode 100644 index 09990da8..00000000 --- a/altosuilib/AltosUIMapMark.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_7.*; - -public class AltosUIMapMark { - - AltosUILatLon lat_lon; - int state; - - static public int stroke_width = 6; - - public void paint(Graphics2D g, AltosUIMapTransform t) { - - Point2D.Double pt = t.screen(lat_lon); - - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - - if (0 <= state && state < AltosUIMap.stateColors.length) - g.setColor(AltosUIMap.stateColors[state]); - else - g.setColor(AltosUIMap.stateColors[AltosLib.ao_flight_invalid]); - - g.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); - g.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); - g.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); - } - - public AltosUIMapMark (double lat, double lon, int state) { - lat_lon = new AltosUILatLon(lat, lon); - this.state = state; - } -} diff --git a/altosuilib/AltosUIMapNew.java b/altosuilib/AltosUIMapNew.java index 4191a562..511d8fe6 100644 --- a/altosuilib/AltosUIMapNew.java +++ b/altosuilib/AltosUIMapNew.java @@ -283,16 +283,16 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt if (t.has_location()) { String message = null; switch (status) { - case AltosUIMapCache.loading: + case AltosMapTile.loading: message = "Loading..."; break; - case AltosUIMapCache.bad_request: + case AltosMapTile.bad_request: message = "Internal error"; break; - case AltosUIMapCache.failed: + case AltosMapTile.failed: message = "Network error, check connection"; break; - case AltosUIMapCache.forbidden: + case AltosMapTile.forbidden: message = "Too many requests, try later"; break; } @@ -419,6 +419,11 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt return "Map"; } + /* AltosGraphUI interface */ + public void centre(AltosState state) { + map.centre(state); + } + /* internal layout bits */ private GridBagLayout layout = new GridBagLayout(); diff --git a/altosuilib/AltosUIMapPath.java b/altosuilib/AltosUIMapPath.java deleted file mode 100644 index b75dccea..00000000 --- a/altosuilib/AltosUIMapPath.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_7.*; - -class PathPoint { - AltosUILatLon lat_lon; - int state; - - public PathPoint(AltosUILatLon lat_lon, int state) { - this.lat_lon = lat_lon; - this.state = state; - } - - public boolean equals(PathPoint other) { - if (other == null) - return false; - - return lat_lon.equals(other.lat_lon) && state == other.state; - } -} - -public class AltosUIMapPath { - - LinkedList points = new LinkedList(); - PathPoint last_point = null; - - static public int stroke_width = 6; - - public void paint(Graphics2D g, AltosUIMapTransform t) { - Point2D.Double prev = null; - - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - - for (PathPoint point : points) { - Point2D.Double cur = t.screen(point.lat_lon); - if (prev != null) { - Line2D.Double line = new Line2D.Double (prev, cur); - Rectangle bounds = line.getBounds(); - - if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) { - if (0 <= point.state && point.state < AltosUIMap.stateColors.length) - g.setColor(AltosUIMap.stateColors[point.state]); - else - g.setColor(AltosUIMap.stateColors[AltosLib.ao_flight_invalid]); - - g.draw(line); - } - } - prev = cur; - } - } - - public AltosUIMapRectangle add(double lat, double lon, int state) { - PathPoint point = new PathPoint(new AltosUILatLon (lat, lon), state); - AltosUIMapRectangle rect = null; - - if (!point.equals(last_point)) { - if (last_point != null) - rect = new AltosUIMapRectangle(last_point.lat_lon, point.lat_lon); - points.add (point); - last_point = point; - } - return rect; - } - - public void clear () { - points = new LinkedList(); - } -} diff --git a/altosuilib/AltosUIMapPreload.java b/altosuilib/AltosUIMapPreload.java deleted file mode 100644 index 5b99ec03..00000000 --- a/altosuilib/AltosUIMapPreload.java +++ /dev/null @@ -1,608 +0,0 @@ -/* - * Copyright © 2011 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.util.*; -import java.text.*; -import java.lang.Math; -import java.net.URL; -import java.net.URLConnection; -import org.altusmetrum.altoslib_7.*; - -class AltosUIMapPos extends Box { - AltosUIFrame owner; - JLabel label; - JComboBox hemi; - JTextField deg; - JLabel deg_label; - JTextField min; - JLabel min_label; - - public void set_value(double new_value) { - double d, m; - int h; - - h = 0; - if (new_value < 0) { - h = 1; - new_value = -new_value; - } - d = Math.floor(new_value); - deg.setText(String.format("%3.0f", d)); - m = (new_value - d) * 60.0; - min.setText(String.format("%7.4f", m)); - hemi.setSelectedIndex(h); - } - - public double get_value() throws ParseException { - int h = hemi.getSelectedIndex(); - String d_t = deg.getText(); - String m_t = min.getText(); - double d, m, v; - try { - d = AltosParse.parse_double_locale(d_t); - } catch (ParseException pe) { - JOptionPane.showMessageDialog(owner, - String.format("Invalid degrees \"%s\"", - d_t), - "Invalid number", - JOptionPane.ERROR_MESSAGE); - throw pe; - } - try { - if (m_t.equals("")) - m = 0; - else - m = AltosParse.parse_double_locale(m_t); - } catch (ParseException pe) { - JOptionPane.showMessageDialog(owner, - String.format("Invalid minutes \"%s\"", - m_t), - "Invalid number", - JOptionPane.ERROR_MESSAGE); - throw pe; - } - v = d + m/60.0; - if (h == 1) - v = -v; - return v; - } - - public AltosUIMapPos(AltosUIFrame in_owner, - String label_value, - String[] hemi_names, - double default_value) { - super(BoxLayout.X_AXIS); - owner = in_owner; - label = new JLabel(label_value); - hemi = new JComboBox(hemi_names); - hemi.setEditable(false); - deg = new JTextField(5); - deg.setMinimumSize(deg.getPreferredSize()); - deg.setHorizontalAlignment(JTextField.RIGHT); - deg_label = new JLabel("°"); - min = new JTextField(9); - min.setMinimumSize(min.getPreferredSize()); - min_label = new JLabel("'"); - set_value(default_value); - add(label); - add(Box.createRigidArea(new Dimension(5, 0))); - add(hemi); - add(Box.createRigidArea(new Dimension(5, 0))); - add(deg); - add(Box.createRigidArea(new Dimension(5, 0))); - add(deg_label); - add(Box.createRigidArea(new Dimension(5, 0))); - add(min); - add(Box.createRigidArea(new Dimension(5, 0))); - add(min_label); - } -} - -class AltosUISite { - String name; - double latitude; - double longitude; - - public String toString() { - return name; - } - - public AltosUISite(String in_name, double in_latitude, double in_longitude) { - name = in_name; - latitude = in_latitude; - longitude = in_longitude; - } - - public AltosUISite(String line) throws ParseException { - String[] elements = line.split(":"); - - if (elements.length < 3) - throw new ParseException(String.format("Invalid site line %s", line), 0); - - name = elements[0]; - - try { - latitude = AltosParse.parse_double_net(elements[1]); - longitude = AltosParse.parse_double_net(elements[2]); - } catch (ParseException pe) { - throw new ParseException(String.format("Invalid site line %s", line), 0); - } - } -} - -class AltosUISites extends Thread { - AltosUIMapPreload preload; - URL url; - LinkedList sites; - - void notify_complete() { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - preload.set_sites(); - } - }); - } - - void add(AltosUISite site) { - sites.add(site); - } - - void add(String line) { - try { - add(new AltosUISite(line)); - } catch (ParseException pe) { - System.out.printf("parse exception %s\n", pe.toString()); - } - } - - public void run() { - try { - URLConnection uc = url.openConnection(); - //int length = uc.getContentLength(); - - InputStreamReader in_stream = new InputStreamReader(uc.getInputStream(), AltosLib.unicode_set); - BufferedReader in = new BufferedReader(in_stream); - - for (;;) { - String line = in.readLine(); - if (line == null) - break; - add(line); - } - } catch (IOException e) { - } finally { - notify_complete(); - } - } - - public AltosUISites(AltosUIMapPreload in_preload) { - sites = new LinkedList(); - preload = in_preload; - try { - url = new URL(AltosLib.launch_sites_url); - } catch (java.net.MalformedURLException e) { - notify_complete(); - } - start(); - } -} - -public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, ItemListener, AltosUIMapTileListener { - AltosUIFrame owner; - AltosUIMap map; - AltosUIMapCache cache = new AltosUIMapCache(); - - AltosUIMapPos lat; - AltosUIMapPos lon; - - JProgressBar pbar; - int pbar_max; - int pbar_cur; - - AltosUISites sites; - JLabel site_list_label; - JComboBox site_list; - - JToggleButton load_button; - boolean loading; - JButton close_button; - - JCheckBox[] maptypes = new JCheckBox[AltosUIMap.maptype_terrain - AltosUIMap.maptype_hybrid + 1]; - - JComboBox min_zoom; - JComboBox max_zoom; - JComboBox radius; - - Integer[] zooms = { -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6 }; - Integer[] radii = { 1, 2, 3, 4, 5 }; - - static final String[] lat_hemi_names = { "N", "S" }; - static final String[] lon_hemi_names = { "E", "W" }; - - class updatePbar implements Runnable { - String s; - - public updatePbar(String in_s) { - s = in_s; - } - - public void run() { - int n = ++pbar_cur; - - pbar.setMaximum(pbar_max); - pbar.setValue(n); - pbar.setString(s); - } - } - - double latitude, longitude; - int min_z; - int max_z; - int cur_z; - int all_types; - int cur_type; - int r; - - int tiles_per_layer; - int tiles_loaded; - int layers_total; - int layers_loaded; - - - private void do_load() { - tiles_loaded = 0; - map.set_zoom(cur_z + AltosUIMapView.default_zoom); - map.set_maptype(cur_type); - map.set_load_params(latitude, longitude, r, this); - } - - private int next_type(int start) { - int next_type; - for (next_type = start; - next_type <= AltosUIMap.maptype_terrain && (all_types & (1 << next_type)) == 0; - next_type++) - ; - return next_type; - } - - private void next_load() { - int next_type = next_type(cur_type + 1); - - if (next_type > AltosUIMap.maptype_terrain) { - if (cur_z == max_z) { - return; - } else { - cur_z++; - } - next_type = next_type(0); - } - cur_type = next_type; - do_load(); - } - - private void start_load() { - cur_z = min_z; - int ntype = 0; - all_types = 0; - for (int t = AltosUIMap.maptype_hybrid; t <= AltosUIMap.maptype_terrain; t++) - if (maptypes[t].isSelected()) { - all_types |= (1 << t); - ntype++; - } - if (ntype == 0) { - all_types |= (1 << AltosUIMap.maptype_hybrid); - ntype = 1; - } - - cur_type = next_type(0); - tiles_per_layer = (r * 2 + 1) * (r * 2 + 1); - layers_total = (max_z - min_z + 1) * ntype; - layers_loaded = 0; - pbar_max = layers_total * tiles_per_layer; - pbar_cur = 0; - - map.clear_marks(); - map.add_mark(latitude,longitude, AltosLib.ao_flight_boost); - do_load(); - } - - /* AltosUIMapTileListener methods */ - - public synchronized void notify_tile(AltosUIMapTile tile, int status) { - if (status == AltosUIMapStore.loading) - return; - - SwingUtilities.invokeLater(new updatePbar(tile.store.file.toString())); - ++tiles_loaded; - if (tiles_loaded == tiles_per_layer) { - ++layers_loaded; - if (layers_loaded == layers_total) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - pbar.setValue(0); - pbar.setString(""); - load_button.setSelected(false); - loading = false; - } - }); - } else { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - next_load(); - } - }); - } - } - } - - public AltosUIMapCache cache() { return cache; } - - public void set_sites() { - int i = 1; - for (AltosUISite site : sites.sites) { - site_list.insertItemAt(site, i); - i++; - } - } - - public void itemStateChanged(ItemEvent e) { - int state = e.getStateChange(); - - if (state == ItemEvent.SELECTED) { - Object o = e.getItem(); - if (o instanceof AltosUISite) { - AltosUISite site = (AltosUISite) o; - lat.set_value(site.latitude); - lon.set_value(site.longitude); - } - } - } - - public void actionPerformed(ActionEvent e) { - String cmd = e.getActionCommand(); - - if (cmd.equals("close")) - setVisible(false); - - if (cmd.equals("load")) { - if (!loading) { - try { - latitude = lat.get_value(); - longitude = lon.get_value(); - min_z = (Integer) min_zoom.getSelectedItem(); - max_z = (Integer) max_zoom.getSelectedItem(); - if (max_z < min_z) - max_z = min_z; - r = (Integer) radius.getSelectedItem(); - loading = true; - } catch (ParseException pe) { - load_button.setSelected(false); - } - start_load(); - } - } - } - - public AltosUIMapPreload(AltosUIFrame in_owner) { - owner = in_owner; - - Container pane = getContentPane(); - GridBagConstraints c = new GridBagConstraints(); - Insets i = new Insets(4,4,4,4); - - setTitle("AltOS Load Maps"); - - pane.setLayout(new GridBagLayout()); - - map = new AltosUIMap(); - - c.fill = GridBagConstraints.BOTH; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - c.weightx = 1; - c.weighty = 1; - - c.gridx = 0; - c.gridy = 0; - c.gridwidth = 10; - c.anchor = GridBagConstraints.CENTER; - - pane.add(map, c); - - pbar = new JProgressBar(); - pbar.setMinimum(0); - pbar.setMaximum(1); - pbar.setValue(0); - pbar.setString(""); - pbar.setStringPainted(true); - - c.fill = GridBagConstraints.HORIZONTAL; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - c.weightx = 1; - c.weighty = 0; - - c.gridx = 0; - c.gridy = 1; - c.gridwidth = 10; - - pane.add(pbar, c); - - site_list_label = new JLabel ("Known Launch Sites:"); - - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - c.weightx = 1; - c.weighty = 0; - - c.gridx = 0; - c.gridy = 2; - c.gridwidth = 1; - - pane.add(site_list_label, c); - - site_list = new JComboBox(new AltosUISite[] { new AltosUISite("Site List", 0, 0) }); - site_list.addItemListener(this); - - sites = new AltosUISites(this); - - c.fill = GridBagConstraints.HORIZONTAL; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - c.weightx = 1; - c.weighty = 0; - - c.gridx = 1; - c.gridy = 2; - c.gridwidth = 1; - - pane.add(site_list, c); - - lat = new AltosUIMapPos(owner, - "Latitude:", - lat_hemi_names, - 37.167833333); - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - c.weightx = 0; - c.weighty = 0; - - c.gridx = 0; - c.gridy = 3; - c.gridwidth = 1; - c.anchor = GridBagConstraints.CENTER; - - pane.add(lat, c); - - lon = new AltosUIMapPos(owner, - "Longitude:", - lon_hemi_names, - -97.73975); - - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - c.weightx = 0; - c.weighty = 0; - - c.gridx = 1; - c.gridy = 3; - c.gridwidth = 1; - c.anchor = GridBagConstraints.CENTER; - - pane.add(lon, c); - - load_button = new JToggleButton("Load Map"); - load_button.addActionListener(this); - load_button.setActionCommand("load"); - - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - c.weightx = 1; - c.weighty = 0; - - c.gridx = 0; - c.gridy = 4; - c.gridwidth = 1; - c.anchor = GridBagConstraints.CENTER; - - pane.add(load_button, c); - - close_button = new JButton("Close"); - close_button.addActionListener(this); - close_button.setActionCommand("close"); - - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - c.insets = i; - c.weightx = 1; - c.weighty = 0; - - c.gridx = 1; - c.gridy = 4; - c.gridwidth = 1; - c.anchor = GridBagConstraints.CENTER; - - pane.add(close_button, c); - - JLabel types_label = new JLabel("Map Types"); - c.gridx = 2; - c.gridwidth = 2; - c.gridy = 2; - pane.add(types_label, c); - - c.gridwidth = 1; - - for (int type = AltosUIMap.maptype_hybrid; type <= AltosUIMap.maptype_terrain; type++) { - maptypes[type] = new JCheckBox(AltosUIMap.maptype_labels[type], - type == AltosUIMap.maptype_hybrid); - c.gridx = 2 + (type >> 1); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridy = (type & 1) + 3; - pane.add(maptypes[type], c); - } - - JLabel min_zoom_label = new JLabel("Minimum Zoom"); - c.gridx = 4; - c.gridy = 2; - pane.add(min_zoom_label, c); - - min_zoom = new JComboBox(zooms); - min_zoom.setSelectedItem(zooms[10]); - min_zoom.setEditable(false); - c.gridx = 5; - c.gridy = 2; - pane.add(min_zoom, c); - - JLabel max_zoom_label = new JLabel("Maximum Zoom"); - c.gridx = 4; - c.gridy = 3; - pane.add(max_zoom_label, c); - - max_zoom = new JComboBox(zooms); - max_zoom.setSelectedItem(zooms[14]); - max_zoom.setEditable(false); - c.gridx = 5; - c.gridy = 3; - pane.add(max_zoom, c); - - JLabel radius_label = new JLabel("Tile Radius"); - c.gridx = 4; - c.gridy = 4; - pane.add(radius_label, c); - - radius = new JComboBox(radii); - radius.setSelectedItem(radii[4]); - radius.setEditable(true); - c.gridx = 5; - c.gridy = 4; - pane.add(radius, c); - - pack(); - setLocationRelativeTo(owner); - setVisible(true); - } -} diff --git a/altosuilib/AltosUIMapPreloadNew.java b/altosuilib/AltosUIMapPreloadNew.java index 7d3c2a0b..af196105 100644 --- a/altosuilib/AltosUIMapPreloadNew.java +++ b/altosuilib/AltosUIMapPreloadNew.java @@ -227,7 +227,7 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener boolean loading; JButton close_button; - JCheckBox[] maptypes = new JCheckBox[AltosUIMap.maptype_terrain - AltosUIMap.maptype_hybrid + 1]; + JCheckBox[] maptypes = new JCheckBox[AltosMap.maptype_terrain - AltosMap.maptype_hybrid + 1]; JComboBox min_zoom; JComboBox max_zoom; @@ -271,7 +271,7 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener private void do_load() { tiles_loaded = 0; - map.set_zoom(cur_z + AltosUIMapView.default_zoom); + map.set_zoom(cur_z + AltosMap.default_zoom); map.set_maptype(cur_type); map.set_load_params(latitude, longitude, r, this); } @@ -279,7 +279,7 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener private int next_type(int start) { int next_type; for (next_type = start; - next_type <= AltosUIMap.maptype_terrain && (all_types & (1 << next_type)) == 0; + next_type <= AltosMap.maptype_terrain && (all_types & (1 << next_type)) == 0; next_type++) ; return next_type; @@ -288,7 +288,7 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener private void next_load() { int next_type = next_type(cur_type + 1); - if (next_type > AltosUIMap.maptype_terrain) { + if (next_type > AltosMap.maptype_terrain) { if (cur_z == max_z) { return; } else { @@ -304,13 +304,13 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener cur_z = min_z; int ntype = 0; all_types = 0; - for (int t = AltosUIMap.maptype_hybrid; t <= AltosUIMap.maptype_terrain; t++) + for (int t = AltosMap.maptype_hybrid; t <= AltosMap.maptype_terrain; t++) if (maptypes[t].isSelected()) { all_types |= (1 << t); ntype++; } if (ntype == 0) { - all_types |= (1 << AltosUIMap.maptype_hybrid); + all_types |= (1 << AltosMap.maptype_hybrid); ntype = 1; } @@ -557,9 +557,9 @@ public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener c.gridwidth = 1; - for (int type = AltosUIMap.maptype_hybrid; type <= AltosUIMap.maptype_terrain; type++) { - maptypes[type] = new JCheckBox(AltosUIMap.maptype_labels[type], - type == AltosUIMap.maptype_hybrid); + for (int type = AltosMap.maptype_hybrid; type <= AltosMap.maptype_terrain; type++) { + maptypes[type] = new JCheckBox(AltosMap.maptype_labels[type], + type == AltosMap.maptype_hybrid); c.gridx = 2 + (type >> 1); c.fill = GridBagConstraints.HORIZONTAL; c.gridy = (type & 1) + 3; diff --git a/altosuilib/AltosUIMapRectangle.java b/altosuilib/AltosUIMapRectangle.java deleted file mode 100644 index 008623cb..00000000 --- a/altosuilib/AltosUIMapRectangle.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -public class AltosUIMapRectangle { - AltosUILatLon ul, lr; - - public AltosUIMapRectangle(AltosUILatLon a, AltosUILatLon b) { - double ul_lat, ul_lon; - double lr_lat, lr_lon; - - if (a.lat > b.lat) { - ul_lat = a.lat; - lr_lat = b.lat; - } else { - ul_lat = b.lat; - lr_lat = a.lat; - } - if (a.lon < b.lon) { - ul_lon = a.lon; - lr_lon = b.lon; - } else { - ul_lon = b.lon; - lr_lon = a.lon; - } - - ul = new AltosUILatLon(ul_lat, ul_lon); - lr = new AltosUILatLon(lr_lat, lr_lon); - } -} diff --git a/altosuilib/AltosUIMapStore.java b/altosuilib/AltosUIMapStore.java deleted file mode 100644 index ba505a7c..00000000 --- a/altosuilib/AltosUIMapStore.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.io.*; -import java.net.*; -import java.util.*; - -public class AltosUIMapStore { - String url; - File file; - LinkedList listeners = new LinkedList(); - - static final int success = 0; - static final int loading = 1; - static final int failed = 2; - static final int bad_request = 3; - static final int forbidden = 4; - - int status; - - public int status() { - return status; - } - - public synchronized void add_listener(AltosUIMapStoreListener listener) { - if (!listeners.contains(listener)) - listeners.add(listener); - } - - public synchronized void remove_listener(AltosUIMapStoreListener listener) { - listeners.remove(listener); - } - - private synchronized void notify_listeners(int status) { - this.status = status; - for (AltosUIMapStoreListener listener : listeners) - listener.notify_store(this, status); - } - - static Object forbidden_lock = new Object(); - static long forbidden_time; - static boolean forbidden_set; - - private int fetch_url() { - URL u; - - try { - u = new URL(url); - } catch (java.net.MalformedURLException e) { - return bad_request; - } - - byte[] data; - URLConnection uc = null; - try { - uc = u.openConnection(); - String type = uc.getContentType(); - int contentLength = uc.getContentLength(); - if (uc instanceof HttpURLConnection) { - int response = ((HttpURLConnection) uc).getResponseCode(); - switch (response) { - case HttpURLConnection.HTTP_FORBIDDEN: - case HttpURLConnection.HTTP_PAYMENT_REQUIRED: - case HttpURLConnection.HTTP_UNAUTHORIZED: - synchronized (forbidden_lock) { - forbidden_time = System.nanoTime(); - forbidden_set = true; - return forbidden; - } - } - } - InputStream in = new BufferedInputStream(uc.getInputStream()); - int bytesRead = 0; - int offset = 0; - data = new byte[contentLength]; - while (offset < contentLength) { - bytesRead = in.read(data, offset, data.length - offset); - if (bytesRead == -1) - break; - offset += bytesRead; - } - in.close(); - - if (offset != contentLength) - return failed; - - } catch (IOException e) { - return failed; - } - - try { - FileOutputStream out = new FileOutputStream(file); - out.write(data); - out.flush(); - out.close(); - } catch (FileNotFoundException e) { - return bad_request; - } catch (IOException e) { - if (file.exists()) - file.delete(); - return bad_request; - } - return success; - } - - static Object fetch_lock = new Object(); - - static final long forbidden_interval = 60l * 1000l * 1000l * 1000l; - static final long google_maps_ratelimit_ms = 1200; - - class loader implements Runnable { - - public void run() { - if (file.exists()) { - notify_listeners(success); - return; - } - - synchronized(forbidden_lock) { - if (forbidden_set && (System.nanoTime() - forbidden_time) < forbidden_interval) { - notify_listeners(forbidden); - return; - } - } - - int new_status; - - if (!AltosUIVersion.has_google_maps_api_key()) { - synchronized (fetch_lock) { - long startTime = System.nanoTime(); - new_status = fetch_url(); - if (new_status == success) { - long duration_ms = (System.nanoTime() - startTime) / 1000000; - if (duration_ms < google_maps_ratelimit_ms) { - try { - Thread.sleep(google_maps_ratelimit_ms - duration_ms); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - } - } else { - new_status = fetch_url(); - } - notify_listeners(new_status); - } - } - - private void load() { - loader l = new loader(); - Thread lt = new Thread(l); - lt.start(); - } - - private AltosUIMapStore (String url, File file) { - this.url = url; - this.file = file; - - if (file.exists()) - status = success; - else { - status = loading; - load(); - } - } - - public boolean equals(AltosUIMapStore other) { - return url.equals(other.url); - } - - static HashMap stores = new HashMap(); - - public static AltosUIMapStore get(String url, File file) { - AltosUIMapStore store; - synchronized(stores) { - if (stores.containsKey(url)) { - store = stores.get(url); - } else { - store = new AltosUIMapStore(url, file); - stores.put(url, store); - } - } - return store; - } - -} diff --git a/altosuilib/AltosUIMapStoreListener.java b/altosuilib/AltosUIMapStoreListener.java deleted file mode 100644 index 5a522387..00000000 --- a/altosuilib/AltosUIMapStoreListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -public interface AltosUIMapStoreListener { - abstract void notify_store(AltosUIMapStore store, int status); -} diff --git a/altosuilib/AltosUIMapTile.java b/altosuilib/AltosUIMapTile.java deleted file mode 100644 index 755dbde2..00000000 --- a/altosuilib/AltosUIMapTile.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.awt.*; -import java.awt.image.*; -import javax.swing.*; -import javax.imageio.*; -import java.awt.geom.*; -import java.io.*; -import java.util.*; -import java.awt.RenderingHints.*; -import org.altusmetrum.altoslib_7.*; - -public class AltosUIMapTile { - AltosUIMapTileListener listener; - AltosUILatLon upper_left, center; - int px_size; - int zoom; - int maptype; - AltosUIMapStore store; - AltosUIMapCache cache; - int status; - - private File map_file() { - double lat = center.lat; - double lon = center.lon; - char chlat = lat < 0 ? 'S' : 'N'; - char chlon = lon < 0 ? 'W' : 'E'; - - if (lat < 0) lat = -lat; - if (lon < 0) lon = -lon; - String maptype_string = String.format("%s-", AltosUIMap.maptype_names[maptype]); - String format_string; - if (maptype == AltosUIMap.maptype_hybrid || maptype == AltosUIMap.maptype_satellite || maptype == AltosUIMap.maptype_terrain) - format_string = "jpg"; - else - format_string = "png"; - return new File(AltosUIPreferences.mapdir(), - String.format("map-%c%.6f,%c%.6f-%s%d.%s", - chlat, lat, chlon, lon, maptype_string, zoom, format_string)); - } - - private String map_url() { - String format_string; - if (maptype == AltosUIMap.maptype_hybrid || maptype == AltosUIMap.maptype_satellite || maptype == AltosUIMap.maptype_terrain) - format_string = "jpg"; - else - format_string = "png32"; - - if (AltosUIVersion.has_google_maps_api_key()) - return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=%s&format=%s&key=%s", - center.lat, center.lon, zoom, px_size, px_size, AltosUIMap.maptype_names[maptype], format_string, AltosUIVersion.google_maps_api_key); - else - return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=%s&format=%s", - center.lat, center.lon, zoom, px_size, px_size, AltosUIMap.maptype_names[maptype], format_string); - } - private Font font = null; - - public void set_font(Font font) { - this.font = font; - } - - int painting_serial; - int painted_serial; - - Image image; - - public void paint_graphics(Graphics2D g2d, AltosUIMapTransform t, int serial) { - if (serial < painted_serial) - return; - - Point2D.Double point_double = t.screen(upper_left); - Point point = new Point((int) (point_double.x + 0.5), - (int) (point_double.y + 0.5)); - - painted_serial = serial; - - if (!g2d.hitClip(point.x, point.y, px_size, px_size)) - return; - - if (image != null) { - g2d.drawImage(image, point.x, point.y, null); - image = null; - } else { - g2d.setColor(Color.GRAY); - g2d.fillRect(point.x, point.y, px_size, px_size); - - if (t.has_location()) { - String message = null; - switch (status) { - case AltosUIMapCache.loading: - message = "Loading..."; - break; - case AltosUIMapCache.bad_request: - message = "Internal error"; - break; - case AltosUIMapCache.failed: - message = "Network error, check connection"; - break; - case AltosUIMapCache.forbidden: - message = "Too many requests, try later"; - break; - } - if (message != null && font != null) { - g2d.setFont(font); - g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - Rectangle2D bounds = font.getStringBounds(message, g2d.getFontRenderContext()); - - float x = px_size / 2.0f; - float y = px_size / 2.0f; - x = x - (float) bounds.getWidth() / 2.0f; - y = y + (float) bounds.getHeight() / 2.0f; - g2d.setColor(Color.BLACK); - g2d.drawString(message, (float) point_double.x + x, (float) point_double.y + y); - } - } - } - } - - public void set_status(int status) { - this.status = status; - listener.notify_tile(this, status); - } - - public void notify_image(Image image) { - listener.notify_tile(this, status); - } - - public void paint(Graphics g, AltosUIMapTransform t) { - Graphics2D g2d = (Graphics2D) g; - boolean queued = false; - - Point2D.Double point = t.screen(upper_left); - - if (!g.hitClip((int) (point.x + 0.5), (int) (point.y + 0.5), px_size, px_size)) - return; - - ++painting_serial; - - if (image == null && t.has_location()) - image = cache.get(this, store, px_size, px_size); - - paint_graphics(g2d, t, painting_serial); - } - - public int store_status() { - return store.status(); - } - - public void add_store_listener(AltosUIMapStoreListener listener) { - store.add_listener(listener); - } - - public void remove_store_listener(AltosUIMapStoreListener listener) { - store.remove_listener(listener); - } - - public AltosUIMapTile(AltosUIMapTileListener listener, AltosUILatLon upper_left, AltosUILatLon center, int zoom, int maptype, int px_size, Font font) { - this.listener = listener; - this.upper_left = upper_left; - cache = listener.cache(); - - while (center.lon < -180.0) - center.lon += 360.0; - while (center.lon > 180.0) - center.lon -= 360.0; - - this.center = center; - this.zoom = zoom; - this.maptype = maptype; - this.px_size = px_size; - this.font = font; - status = AltosUIMapCache.loading; - store = AltosUIMapStore.get(map_url(), map_file()); - } -} diff --git a/altosuilib/AltosUIMapTileListener.java b/altosuilib/AltosUIMapTileListener.java deleted file mode 100644 index 01e5146b..00000000 --- a/altosuilib/AltosUIMapTileListener.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -public interface AltosUIMapTileListener { - abstract public void notify_tile(AltosUIMapTile tile, int status); - - abstract public AltosUIMapCache cache(); -} diff --git a/altosuilib/AltosUIMapTransform.java b/altosuilib/AltosUIMapTransform.java deleted file mode 100644 index 3b85ca6a..00000000 --- a/altosuilib/AltosUIMapTransform.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_7.*; - -public class AltosUIMapTransform { - - double scale_x, scale_y; - - double offset_x, offset_y; - - public AltosUILatLon lat_lon (Point2D.Double point) { - double lat, lon; - double rads; - - lon = point.x/scale_x; - rads = 2 * Math.atan(Math.exp(-point.y/scale_y)); - lat = Math.toDegrees(rads - Math.PI/2); - - return new AltosUILatLon(lat,lon); - } - - public Point2D.Double screen_point(Point screen) { - return new Point2D.Double(screen.x + offset_x, screen.y + offset_y); - } - - public AltosUILatLon screen_lat_lon(Point screen) { - return lat_lon(screen_point(screen)); - } - - public Point2D.Double point(AltosUILatLon lat_lon) { - double x, y; - double e; - - x = lat_lon.lon * scale_x; - - e = Math.sin(Math.toRadians(lat_lon.lat)); - e = Math.max(e,-(1-1.0E-15)); - e = Math.min(e, 1-1.0E-15 ); - - y = 0.5*Math.log((1+e)/(1-e))*-scale_y; - - return new Point2D.Double(x, y); - } - - public Point2D.Double screen(Point2D.Double point) { - return new Point2D.Double(point.x - offset_x, point.y - offset_y); - } - - public Point screen(Point point) { - return new Point((int) (point.x - offset_x + 0.5), - (int) (point.y - offset_y + 0.5)); - } - - public Rectangle screen(AltosUIMapRectangle map_rect) { - Point2D.Double ul = screen(map_rect.ul); - Point2D.Double lr = screen(map_rect.lr); - - return new Rectangle((int) ul.x, (int) ul.y, (int) (lr.x - ul.x), (int) (lr.y - ul.y)); - } - - public Point2D.Double screen(AltosUILatLon lat_lon) { - return screen(point(lat_lon)); - } - - private boolean has_location; - - public boolean has_location() { - return has_location; - } - - public AltosUIMapTransform(int width, int height, int zoom, AltosUILatLon centre_lat_lon) { - scale_x = 256/360.0 * Math.pow(2, zoom); - scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - - Point2D.Double centre_pt = point(centre_lat_lon); - - has_location = (centre_lat_lon.lat != 0 || centre_lat_lon.lon != 0); - offset_x = centre_pt.x - width / 2.0; - offset_y = centre_pt.y - height / 2.0; - } -} diff --git a/altosuilib/AltosUIMapView.java b/altosuilib/AltosUIMapView.java deleted file mode 100644 index 331b0aea..00000000 --- a/altosuilib/AltosUIMapView.java +++ /dev/null @@ -1,457 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -import java.awt.*; -import java.awt.event.*; -import java.awt.image.*; -import javax.swing.*; -import java.io.*; -import java.lang.*; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_7.*; - -public class AltosUIMapView extends Component implements MouseMotionListener, MouseListener, MouseWheelListener, ComponentListener, AltosUIMapTileListener, AltosUIMapStoreListener { - - AltosUIMapPath path = new AltosUIMapPath(); - - AltosUIMapLine line = new AltosUIMapLine(); - - AltosUIMapCache cache = new AltosUIMapCache(); - - LinkedList marks = new LinkedList(); - - LinkedList zoom_listeners = new LinkedList(); - - boolean have_boost = false; - boolean have_landed = false; - - ConcurrentHashMap tiles = new ConcurrentHashMap(); - - static final int default_zoom = 15; - static final int min_zoom = 3; - static final int max_zoom = 21; - static final int px_size = 512; - - int load_radius; - AltosUILatLon load_centre = null; - AltosUIMapTileListener load_listener; - - int zoom = default_zoom; - int maptype = AltosUIMap.maptype_default; - - long user_input_time; - - /* Milliseconds to wait after user action before auto-scrolling - */ - static final long auto_scroll_delay = 20 * 1000; - - AltosUIMapTransform transform; - AltosUILatLon centre; - - public void set_font() { - line.set_font(AltosUILib.status_font); - for (AltosUIMapTile tile : tiles.values()) - tile.set_font(AltosUILib.value_font); - repaint(); - } - - public void set_units() { - repaint(); - } - - private boolean is_drag_event(MouseEvent e) { - return e.getModifiers() == InputEvent.BUTTON1_MASK; - } - - Point drag_start; - - private void drag(MouseEvent e) { - if (drag_start == null) - return; - - int dx = e.getPoint().x - drag_start.x; - int dy = e.getPoint().y - drag_start.y; - - AltosUILatLon new_centre = transform.screen_lat_lon(new Point(getWidth() / 2 - dx, getHeight() / 2 - dy)); - centre (new_centre.lat, new_centre.lon); - drag_start = e.getPoint(); - } - - private void drag_start(MouseEvent e) { - drag_start = e.getPoint(); - } - - private void notice_user_input() { - user_input_time = System.currentTimeMillis(); - } - - private boolean recent_user_input() { - return (System.currentTimeMillis() - user_input_time) < auto_scroll_delay; - } - - /* MouseMotionListener methods */ - - public void mouseDragged(MouseEvent e) { - notice_user_input(); - if (is_drag_event(e)) - drag(e); - else { - line.dragged(e, transform); - repaint(); - } - } - - public void mouseMoved(MouseEvent e) { - } - - /* MouseListener methods */ - public void mouseClicked(MouseEvent e) { - } - - public void mouseEntered(MouseEvent e) { - } - - public void mouseExited(MouseEvent e) { - } - - public void mousePressed(MouseEvent e) { - notice_user_input(); - if (is_drag_event(e)) - drag_start(e); - else { - line.pressed(e, transform); - repaint(); - } - } - - public void mouseReleased(MouseEvent e) { - } - - /* MouseWheelListener methods */ - - public void mouseWheelMoved(MouseWheelEvent e) { - int zoom_change = e.getWheelRotation(); - - notice_user_input(); - AltosUILatLon mouse_lat_lon = transform.screen_lat_lon(e.getPoint()); - set_zoom(zoom() - zoom_change); - - Point2D.Double new_mouse = transform.screen(mouse_lat_lon); - - int dx = getWidth()/2 - e.getPoint().x; - int dy = getHeight()/2 - e.getPoint().y; - - AltosUILatLon new_centre = transform.screen_lat_lon(new Point((int) new_mouse.x + dx, (int) new_mouse.y + dy)); - - centre(new_centre.lat, new_centre.lon); - } - - /* ComponentListener methods */ - - public void componentHidden(ComponentEvent e) { - } - - public void componentMoved(ComponentEvent e) { - } - - public void componentResized(ComponentEvent e) { - set_transform(); - } - - public void componentShown(ComponentEvent e) { - set_transform(); - } - - public void repaint(Rectangle r, int pad) { - repaint(r.x - pad, r.y - pad, r.width + pad*2, r.height + pad*2); - } - - public void repaint(AltosUIMapRectangle rect, int pad) { - repaint (transform.screen(rect), pad); - } - - private boolean far_from_centre(AltosUILatLon lat_lon) { - - if (centre == null || transform == null) - return true; - - Point2D.Double screen = transform.screen(lat_lon); - - int width = getWidth(); - int dx = Math.abs ((int) screen.x - width/2); - - if (dx > width / 4) - return true; - - int height = getHeight(); - int dy = Math.abs ((int) screen.y - height/2); - - if (dy > height / 4) - return true; - - return false; - } - - public void show(AltosState state, AltosListenerState listener_state) { - - /* If insufficient gps data, nothing to update - */ - AltosGPS gps = state.gps; - - if (gps == null) - return; - - if (!gps.locked && gps.nsat < 4) - return; - - AltosUIMapRectangle damage = path.add(gps.lat, gps.lon, state.state); - - switch (state.state) { - case AltosLib.ao_flight_boost: - if (!have_boost) { - add_mark(gps.lat, gps.lon, state.state); - have_boost = true; - } - break; - case AltosLib.ao_flight_landed: - if (!have_landed) { - add_mark(gps.lat, gps.lon, state.state); - have_landed = true; - } - break; - } - - if (damage != null) - repaint(damage, AltosUIMapPath.stroke_width); - maybe_centre(gps.lat, gps.lon); - } - - private void set_transform() { - Rectangle bounds = getBounds(); - - transform = new AltosUIMapTransform(bounds.width, bounds.height, zoom, centre); - repaint(); - } - - public boolean set_zoom(int zoom) { - if (min_zoom <= zoom && zoom <= max_zoom && zoom != this.zoom) { - this.zoom = zoom; - tiles.clear(); - set_transform(); - - for (AltosUIMapZoomListener listener : zoom_listeners) - listener.zoom_changed(this.zoom); - - return true; - } - return false; - } - - public void add_zoom_listener(AltosUIMapZoomListener listener) { - if (!zoom_listeners.contains(listener)) - zoom_listeners.add(listener); - } - - public void remove_zoom_listener(AltosUIMapZoomListener listener) { - zoom_listeners.remove(listener); - } - - public void set_load_params(double lat, double lon, int radius, AltosUIMapTileListener listener) { - load_centre = new AltosUILatLon(lat, lon); - load_radius = radius; - load_listener = listener; - centre(lat, lon); - make_tiles(); - for (AltosUIMapTile tile : tiles.values()) { - tile.add_store_listener(this); - if (tile.store_status() != AltosUIMapStore.loading) - listener.notify_tile(tile, tile.store_status()); - } - repaint(); - } - - public boolean all_fetched() { - for (AltosUIMapTile tile : tiles.values()) { - if (tile.store_status() == AltosUIMapStore.loading) - return false; - } - return true; - } - - public boolean set_maptype(int maptype) { - if (maptype != this.maptype) { - this.maptype = maptype; - tiles.clear(); - repaint(); - return true; - } - return false; - } - - public int get_maptype() { - return maptype; - } - - public int zoom() { - return zoom; - } - - public void centre(AltosUILatLon lat_lon) { - centre = lat_lon; - set_transform(); - } - - public void centre(double lat, double lon) { - centre(new AltosUILatLon(lat, lon)); - } - - public void maybe_centre(double lat, double lon) { - AltosUILatLon lat_lon = new AltosUILatLon(lat, lon); - if (centre == null || (!recent_user_input() && far_from_centre(lat_lon))) - centre(lat_lon); - } - - private VolatileImage create_back_buffer() { - return getGraphicsConfiguration().createCompatibleVolatileImage(getWidth(), getHeight()); - } - - private Point floor(Point2D.Double point) { - return new Point ((int) Math.floor(point.x / px_size) * px_size, - (int) Math.floor(point.y / px_size) * px_size); - } - - private Point ceil(Point2D.Double point) { - return new Point ((int) Math.ceil(point.x / px_size) * px_size, - (int) Math.ceil(point.y / px_size) * px_size); - } - - private void make_tiles() { - Point upper_left; - Point lower_right; - - if (load_centre != null) { - Point centre = floor(transform.point(load_centre)); - - upper_left = new Point(centre.x - load_radius * px_size, - centre.y - load_radius * px_size); - lower_right = new Point(centre.x + load_radius * px_size, - centre.y + load_radius * px_size); - } else { - upper_left = floor(transform.screen_point(new Point(0, 0))); - lower_right = floor(transform.screen_point(new Point(getWidth(), getHeight()))); - } - LinkedList to_remove = new LinkedList(); - - for (Point point : tiles.keySet()) { - if (point.x < upper_left.x || lower_right.x < point.x || - point.y < upper_left.y || lower_right.y < point.y) { - to_remove.add(point); - } - } - - for (Point point : to_remove) - tiles.remove(point); - - cache.set_cache_size((getWidth() / px_size + 2) * (getHeight() / px_size + 2)); - for (int y = upper_left.y; y <= lower_right.y; y += px_size) { - for (int x = upper_left.x; x <= lower_right.x; x += px_size) { - Point point = new Point(x, y); - - if (!tiles.containsKey(point)) { - AltosUILatLon ul = transform.lat_lon(new Point2D.Double(x, y)); - AltosUILatLon center = transform.lat_lon(new Point2D.Double(x + px_size/2, y + px_size/2)); - AltosUIMapTile tile = new AltosUIMapTile(this, ul, center, zoom, maptype, - px_size, AltosUILib.value_font); - tiles.put(point, tile); - } - } - } - } - - /* AltosUIMapTileListener methods */ - public synchronized void notify_tile(AltosUIMapTile tile, int status) { - for (Point point : tiles.keySet()) { - if (tile == tiles.get(point)) { - Point screen = transform.screen(point); - repaint(screen.x, screen.y, px_size, px_size); - } - } - } - - public AltosUIMapCache cache() { return cache; } - - /* AltosUIMapStoreListener methods */ - public synchronized void notify_store(AltosUIMapStore store, int status) { - if (load_listener != null) { - for (AltosUIMapTile tile : tiles.values()) - if (store.equals(tile.store)) - load_listener.notify_tile(tile, status); - } - } - - private void do_paint(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - - make_tiles(); - - for (AltosUIMapTile tile : tiles.values()) - tile.paint(g2d, transform); - - synchronized(marks) { - for (AltosUIMapMark mark : marks) - mark.paint(g2d, transform); - } - - path.paint(g2d, transform); - - line.paint(g2d, transform); - } - - public void paint(Graphics g) { - } - - public void update(Graphics g) { - paint(g); - } - - public void add_mark(double lat, double lon, int state) { - synchronized(marks) { - marks.add(new AltosUIMapMark(lat, lon, state)); - } - repaint(); - } - - public void clear_marks() { - synchronized(marks) { - marks.clear(); - } - } - - public AltosUIMapView() { - centre(0, 0); - - addComponentListener(this); - addMouseMotionListener(this); - addMouseListener(this); - addMouseWheelListener(this); - set_font(); - } -} diff --git a/altosuilib/AltosUIMapZoomListener.java b/altosuilib/AltosUIMapZoomListener.java deleted file mode 100644 index 6d7f5fa7..00000000 --- a/altosuilib/AltosUIMapZoomListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.altosuilib_7; - -public interface AltosUIMapZoomListener { - abstract public void zoom_changed(int zoom); -} diff --git a/altosuilib/AltosUIPreferences.java b/altosuilib/AltosUIPreferences.java index 6394f537..e9378442 100644 --- a/altosuilib/AltosUIPreferences.java +++ b/altosuilib/AltosUIPreferences.java @@ -55,10 +55,6 @@ public class AltosUIPreferences extends AltosPreferences { public static int position = AltosUILib.position_top_left; - static LinkedList map_cache_listeners; - - public static int map_cache = 9; - public static void init() { AltosPreferences.init(new AltosUIPreferencesBackend()); @@ -75,9 +71,6 @@ public class AltosUIPreferences extends AltosPreferences { position = backend.getInt(positionPreference, AltosUILib.position_top_left); position_listeners = new LinkedList(); - - map_cache = backend.getInt(mapCachePreference, 9); - map_cache_listeners = new LinkedList(); } static { init(); } @@ -225,32 +218,4 @@ public class AltosUIPreferences extends AltosPreferences { return position; } } - - public static void register_map_cache_listener(AltosUIMapCacheListener l) { - synchronized(backend) { - map_cache_listeners.add(l); - } - } - - public static void unregister_map_cache_listener(AltosUIMapCacheListener l) { - synchronized (backend) { - map_cache_listeners.remove(l); - } - } - - public static void set_map_cache(int new_map_cache) { - synchronized(backend) { - map_cache = new_map_cache; - backend.putInt(mapCachePreference, map_cache); - flush_preferences(); - for (AltosUIMapCacheListener l: map_cache_listeners) - l.map_cache_changed(map_cache); - } - } - - public static int map_cache() { - synchronized(backend) { - return map_cache; - } - } } diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am index 7ec94ba0..71f1c2de 100644 --- a/altosuilib/Makefile.am +++ b/altosuilib/Makefile.am @@ -58,25 +58,8 @@ altosuilib_JAVA = \ AltosBTDeviceIterator.java \ AltosBTManage.java \ AltosBTKnown.java \ - AltosUIMap.java \ AltosUIMapNew.java \ AltosUIMapPreloadNew.java \ - AltosUIMapView.java \ - AltosUIMapLine.java \ - AltosUIMapMark.java \ - AltosUIMapPath.java \ - AltosUIMapTile.java \ - AltosUIMapCache.java \ - AltosUIMapCacheListener.java \ - AltosUIMapImage.java \ - AltosUIMapTransform.java \ - AltosUIMapRectangle.java \ - AltosUIMapZoomListener.java \ - AltosUIMapTileListener.java \ - AltosUIMapPreload.java \ - AltosUIMapStore.java \ - AltosUIMapStoreListener.java \ - AltosUILatLon.java \ AltosUIFlightTab.java \ AltosUIIndicator.java \ AltosUIUnitsIndicator.java \ diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 0e46a780..3b880b96 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -651,7 +651,6 @@ public class TeleGPS public static void help(int code) { System.out.printf("Usage: altosui [OPTION]... [FILE]...\n"); System.out.printf(" Options:\n"); - System.out.printf(" --fetchmaps \tpre-fetch maps for site map view\n"); System.out.printf(" --replay \t\trelive the glory of past flights \n"); System.out.printf(" --graph \t\tgraph a flight\n"); System.out.printf(" --csv\tgenerate comma separated output for spreadsheets, etc\n"); @@ -676,20 +675,7 @@ public class TeleGPS for (int i = 0; i < args.length; i++) { if (args[i].equals("--help")) help(0); - else if (args[i].equals("--fetchmaps")) { - if (args.length < i + 3) { - help(1); - } else { - try { - double lat = AltosParse.parse_double_locale(args[i+1]); - double lon = AltosParse.parse_double_locale(args[i+2]); - AltosUIMap.prefetch_maps(lat, lon); - } catch (ParseException e) { - System.out.printf("Can't parse number %s\n", e.toString()); - } - i += 2; - } - } else if (args[i].equals("--replay")) + else if (args[i].equals("--replay")) process = process_replay; else if (args[i].equals("--kml")) process = process_kml; diff --git a/telegps/TeleGPSGraphUI.java b/telegps/TeleGPSGraphUI.java index ab094ac9..f9ca9408 100644 --- a/telegps/TeleGPSGraphUI.java +++ b/telegps/TeleGPSGraphUI.java @@ -38,7 +38,7 @@ public class TeleGPSGraphUI extends AltosUIFrame JTabbedPane pane; AltosGraph graph; AltosUIEnable enable; - AltosUIMap map; + AltosUIMapNew map; AltosState state; AltosFlightStats stats; AltosGraphDataSet graphDataSet; @@ -69,7 +69,7 @@ public class TeleGPSGraphUI extends AltosUIFrame graph = new AltosGraph(enable, stats, graphDataSet); statsTable = new AltosFlightStatsTable(stats); - map = new AltosUIMap(); + map = new AltosUIMapNew(); pane.add("Graph", graph.panel); pane.add("Configure Graph", enable); -- cgit v1.2.3 From ff01fb7275973cdbfd976d3b4e638c6235108121 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 28 May 2015 01:00:22 -0700 Subject: altosuilib: Get rid of AltosUIMapNew.set_load_params This isn't needed anywhere. Signed-off-by: Keith Packard --- altosuilib/AltosUIMapNew.java | 4 ---- 1 file changed, 4 deletions(-) (limited to 'altosuilib/AltosUIMapNew.java') diff --git a/altosuilib/AltosUIMapNew.java b/altosuilib/AltosUIMapNew.java index 511d8fe6..05f47b53 100644 --- a/altosuilib/AltosUIMapNew.java +++ b/altosuilib/AltosUIMapNew.java @@ -429,10 +429,6 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt JComboBox maptype_combo; - public void set_load_params(double lat, double lon, int radius, AltosMapTileListener listener) { - map.set_load_params(lat, lon, radius, listener); - } - MapView view; public AltosUIMapNew() { -- cgit v1.2.3 From 0beb02f1848e34892cca6e34ba83d6ca836d6df2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 29 May 2015 09:49:30 -0700 Subject: altoslib: Require 'debug' hook in AltosMapInterface This lets the map users redirect debug messages as appropriate Signed-off-by: Keith Packard --- altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java | 1 + altoslib/AltosMap.java | 10 ++++++++++ altoslib/AltosMapInterface.java | 2 ++ altosuilib/AltosUIMapNew.java | 4 ++++ 4 files changed, 17 insertions(+) (limited to 'altosuilib/AltosUIMapNew.java') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java index cc1acd67..f1f1b6de 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java @@ -57,6 +57,7 @@ public abstract class AltosDroidTab extends Fragment implements AltosUnitsListen public void set_visible(boolean visible) { FragmentTransaction ft = AltosDroid.fm.beginTransaction(); + AltosDebug.debug("set visible %b %s\n", visible, tab_name()); if (visible) { AltosState state = last_state; AltosGreatCircle from_receiver = last_from_receiver; diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java index 85f95eef..d99730b4 100644 --- a/altoslib/AltosMap.java +++ b/altoslib/AltosMap.java @@ -109,6 +109,10 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { return map_interface.height(); } + public void debug(String format, Object ... arguments) { + map_interface.debug(format, arguments); + } + public AltosPointInt floor(AltosPointDouble point) { return new AltosPointInt ((int) Math.floor(point.x / AltosMap.px_size) * AltosMap.px_size, (int) Math.floor(point.y / AltosMap.px_size) * AltosMap.px_size); @@ -150,6 +154,7 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { } public void set_transform() { + debug("set_transform, centre is %s\n", centre); if (centre != null) { transform = new AltosMapTransform(width(), height(), zoom, centre); repaint(); @@ -376,6 +381,11 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { int dx = x - drag_start.x; int dy = y - drag_start.y; + if (transform == null) { + debug("Transform not set in drag\n"); + return; + } + AltosLatLon new_centre = transform.screen_lat_lon(new AltosPointInt(width() / 2 - dx, height() / 2 - dy)); centre(new_centre); drag_start = new AltosPointInt(x, y); diff --git a/altoslib/AltosMapInterface.java b/altoslib/AltosMapInterface.java index 195574e9..e6cb5971 100644 --- a/altoslib/AltosMapInterface.java +++ b/altoslib/AltosMapInterface.java @@ -40,4 +40,6 @@ public interface AltosMapInterface { public abstract void repaint(AltosRectangle damage); public abstract void set_zoom_label(String label); + + public abstract void debug(String format, Object ... arguments); } diff --git a/altosuilib/AltosUIMapNew.java b/altosuilib/AltosUIMapNew.java index 05f47b53..3efffb00 100644 --- a/altosuilib/AltosUIMapNew.java +++ b/altosuilib/AltosUIMapNew.java @@ -369,6 +369,10 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt zoom_label.setText(label); } + public void debug(String format, Object ... arguments) { + System.out.printf(format, arguments); + } + /* AltosFlightDisplay interface */ public void set_font() { -- cgit v1.2.3 From 4a33336b8f468c5b0f2e14c0ee0242c9a24a8b90 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Jun 2015 11:54:20 -0700 Subject: altosuilib: Allow for no transform in map mouse wheel function Signed-off-by: Keith Packard --- altosuilib/AltosUIMapNew.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'altosuilib/AltosUIMapNew.java') diff --git a/altosuilib/AltosUIMapNew.java b/altosuilib/AltosUIMapNew.java index 3efffb00..5f63a3c2 100644 --- a/altosuilib/AltosUIMapNew.java +++ b/altosuilib/AltosUIMapNew.java @@ -140,17 +140,23 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt int zoom_change = e.getWheelRotation(); map.notice_user_input(); - AltosLatLon mouse_lat_lon = map.transform.screen_lat_lon(new AltosPointInt(e.getPoint().x, e.getPoint().y)); + AltosLatLon mouse_lat_lon = null; + + if (map.transform != null) + mouse_lat_lon = map.transform.screen_lat_lon(new AltosPointInt(e.getPoint().x, e.getPoint().y)); + map.set_zoom(map.get_zoom() - zoom_change); - AltosPointDouble new_mouse = map.transform.screen(mouse_lat_lon); + if (mouse_lat_lon != null) { + AltosPointDouble new_mouse = map.transform.screen(mouse_lat_lon); - int dx = getWidth()/2 - e.getPoint().x; - int dy = getHeight()/2 - e.getPoint().y; + int dx = getWidth()/2 - e.getPoint().x; + int dy = getHeight()/2 - e.getPoint().y; - AltosLatLon new_centre = map.transform.screen_lat_lon(new AltosPointInt((int) new_mouse.x + dx, (int) new_mouse.y + dy)); + AltosLatLon new_centre = map.transform.screen_lat_lon(new AltosPointInt((int) new_mouse.x + dx, (int) new_mouse.y + dy)); - map.centre(new_centre); + map.centre(new_centre); + } } /* ComponentListener methods */ -- cgit v1.2.3 From 08e4e291d32bdb3ac3271a85190d277b1874d277 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 21 Jun 2015 09:35:28 -0700 Subject: altosuilib: Use AltosMap set_zoom_centre instead of in-line version Shares the same function with altosdroid this way. Signed-off-by: Keith Packard --- altosuilib/AltosUIMapNew.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'altosuilib/AltosUIMapNew.java') diff --git a/altosuilib/AltosUIMapNew.java b/altosuilib/AltosUIMapNew.java index 5f63a3c2..246222bc 100644 --- a/altosuilib/AltosUIMapNew.java +++ b/altosuilib/AltosUIMapNew.java @@ -139,24 +139,7 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt public void mouseWheelMoved(MouseWheelEvent e) { int zoom_change = e.getWheelRotation(); - map.notice_user_input(); - AltosLatLon mouse_lat_lon = null; - - if (map.transform != null) - mouse_lat_lon = map.transform.screen_lat_lon(new AltosPointInt(e.getPoint().x, e.getPoint().y)); - - map.set_zoom(map.get_zoom() - zoom_change); - - if (mouse_lat_lon != null) { - AltosPointDouble new_mouse = map.transform.screen(mouse_lat_lon); - - int dx = getWidth()/2 - e.getPoint().x; - int dy = getHeight()/2 - e.getPoint().y; - - AltosLatLon new_centre = map.transform.screen_lat_lon(new AltosPointInt((int) new_mouse.x + dx, (int) new_mouse.y + dy)); - - map.centre(new_centre); - } + map.set_zoom_centre(map.get_zoom() - zoom_change, new AltosPointInt(e.getPoint().x, e.getPoint().y)); } /* ComponentListener methods */ -- cgit v1.2.3 From 0f56903774d9e8bb033dfc0af6945e8ddc1d3065 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 22 Jun 2015 20:08:05 -0700 Subject: altosdroid: Select tracker by clicking on map This lets you pick a tracker from the map, rather than having to use the menu. Signed-off-by: Keith Packard --- altosdroid/Notebook | 24 ++++++--- .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 48 ++++++++++++----- .../AltosDroid/AltosDroidMapInterface.java | 2 +- .../altusmetrum/AltosDroid/AltosMapOffline.java | 61 ++++++++++++++++++---- .../org/altusmetrum/AltosDroid/AltosMapOnline.java | 6 ++- .../src/org/altusmetrum/AltosDroid/TabMap.java | 12 +---- altoslib/AltosMap.java | 21 ++++++++ altoslib/AltosMapInterface.java | 2 + altoslib/AltosMapTransform.java | 7 +++ altosuilib/AltosUIMapNew.java | 5 ++ 10 files changed, 146 insertions(+), 42 deletions(-) (limited to 'altosuilib/AltosUIMapNew.java') diff --git a/altosdroid/Notebook b/altosdroid/Notebook index c0ba2098..6804aa5d 100644 --- a/altosdroid/Notebook +++ b/altosdroid/Notebook @@ -15,14 +15,6 @@ Desired AltosDroid feature list *) Monitor-idle mode - *) Select tracker by clicking map - - *) Auto select tracker after long delay - - *) Evaluate performance issues - - *) Merge offline/online maps into single tab with mode - *) Make voice responses depend on selected tab *) Monitor TeleMega igniters @@ -96,3 +88,19 @@ Completed features *) TeleBT battery voltage Done + + *) Evaluate performance issues + + Done. Offline maps were duplicating tabs at every redisplay. + + *) Merge offline/online maps into single tab with mode + + Done. + + *) Auto select tracker after long delay + + Done. + + *) Select tracker by clicking map + + Done. diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index f6645105..c5da6d0e 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -18,10 +18,9 @@ package org.altusmetrum.AltosDroid; import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Timer; -import java.util.TimerTask; import java.text.*; +import java.util.*; +import java.io.*; import android.app.Activity; import android.app.PendingIntent; @@ -248,11 +247,13 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { } } + int selected_serial = 0; int current_serial; long switch_time; void set_switch_time() { switch_time = System.currentTimeMillis(); + selected_serial = 0; } boolean registered_units_listener; @@ -262,6 +263,9 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { if (new_telemetry_state != null) telemetry_state = new_telemetry_state; + if (selected_serial != 0) + current_serial = selected_serial; + if (current_serial == 0) current_serial = telemetry_state.latest_serial; @@ -271,6 +275,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { } serials = telemetry_state.states.keySet().toArray(new Integer[0]); + Arrays.sort(serials); update_title(telemetry_state); @@ -282,7 +287,9 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { int age = state_age(state); if (age < 20) aged = false; - if (switch_time != 0 && (switch_time - state.received_time) > 0) + if (current_serial == selected_serial) + aged = false; + else if (switch_time != 0 && (switch_time - state.received_time) > 0) aged = true; } @@ -828,13 +835,26 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { void select_tracker(int serial) { int i; - for (i = 0; i < serials.length; i++) - if (serials[i] == serial) - break; - if (i == serials.length) + + AltosDebug.debug("select tracker %d\n", serial); + + if (serial == selected_serial) { + AltosDebug.debug("%d already selected\n", serial); return; + } + + if (serial != 0) { + for (i = 0; i < serials.length; i++) + if (serials[i] == serial) + break; - current_serial = serial; + if (i == serials.length) { + AltosDebug.debug("attempt to select unknown tracker %d\n", serial); + return; + } + } + + current_serial = selected_serial = serial; update_state(null); } @@ -933,15 +953,19 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener { return true; case R.id.select_tracker: if (serials != null) { - String[] trackers = new String[serials.length]; + String[] trackers = new String[serials.length+1]; + trackers[0] = "Auto"; for (int i = 0; i < serials.length; i++) - trackers[i] = String.format("%d", serials[i]); + trackers[i+1] = String.format("%d", serials[i]); AlertDialog.Builder builder_serial = new AlertDialog.Builder(this); builder_serial.setTitle("Select a tracker"); builder_serial.setItems(trackers, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { - select_tracker(serials[item]); + if (item == 0) + select_tracker(0); + else + select_tracker(serials[item-1]); } }); AlertDialog alert_serial = builder_serial.create(); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidMapInterface.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidMapInterface.java index 681cd311..7aff1341 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidMapInterface.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidMapInterface.java @@ -23,7 +23,7 @@ import android.location.Location; import org.altusmetrum.altoslib_7.*; public interface AltosDroidMapInterface { - public void onCreateView(int map_type); + public void onCreateView(AltosDroid altos_droid); public void set_visible(boolean visible); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java index 3ff6ff25..12dd2f25 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java @@ -36,7 +36,9 @@ import android.util.*; class Rocket implements Comparable { AltosLatLon position; String name; + int serial; long last_packet; + boolean active; AltosMapOffline map_offline; void paint() { @@ -49,14 +51,18 @@ class Rocket implements Comparable { this.last_packet = last_packet; } - Rocket(String name, AltosMapOffline map_offline) { - this.name = name; - this.map_offline = map_offline; + void set_active(boolean active) { + this.active = active; } public int compareTo(Object o) { Rocket other = (Rocket) o; + if (active && !other.active) + return 1; + if (other.active && !active) + return -1; + long diff = last_packet - other.last_packet; if (diff > 0) @@ -65,12 +71,19 @@ class Rocket implements Comparable { return -1; return 0; } + + Rocket(int serial, AltosMapOffline map_offline) { + this.serial = serial; + this.name = String.format("%d", serial); + this.map_offline = map_offline; + } } public class AltosMapOffline extends View implements ScaleGestureDetector.OnScaleGestureListener, AltosMapInterface, AltosDroidMapInterface { ScaleGestureDetector scale_detector; boolean scaling; AltosMap map; + AltosDroid altos_droid; AltosLatLon here; AltosLatLon pad; @@ -236,6 +249,24 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal public void set_zoom_label(String label) { } + public void select_object(AltosLatLon latlon) { + if (map.transform == null) + return; + for (Rocket rocket : sorted_rockets()) { + if (rocket.position == null) { + debug("rocket %d has no position\n", rocket.serial); + continue; + } + double distance = map.transform.hypot(latlon, rocket.position); + debug("check select %d distance %g width %d\n", rocket.serial, distance, rocket_bitmap.getWidth()); + if (distance < rocket_bitmap.getWidth() * 2.0) { + debug("selecting %d\n", rocket.serial); + altos_droid.select_tracker(rocket.serial); + break; + } + } + } + class Line { AltosLatLon a, b; @@ -295,16 +326,20 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal } } + private Rocket[] sorted_rockets() { + Rocket[] rocket_array = rockets.values().toArray(new Rocket[0]); + + Arrays.sort(rocket_array); + return rocket_array; + } + private void draw_positions() { line.set_a(map.last_position); line.set_b(here); line.paint(); draw_bitmap(pad, pad_bitmap, pad_off_x, pad_off_y); - Rocket[] rocket_array = rockets.values().toArray(new Rocket[0]); - - Arrays.sort(rocket_array); - for (Rocket rocket : rocket_array) + for (Rocket rocket : sorted_rockets()) rocket.paint(); draw_bitmap(here, here_bitmap, here_off_x, here_off_y); } @@ -379,6 +414,8 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal map.touch_start((int) event.getX(), (int) event.getY(), true); } else if (event.getAction() == MotionEvent.ACTION_MOVE) { map.touch_continue((int) event.getX(), (int) event.getY(), true); + } else if (event.getAction() == MotionEvent.ACTION_UP) { + map.touch_stop((int) event.getX(), (int) event.getY(), true); } return true; } @@ -425,11 +462,13 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal if (rockets.containsKey(serial)) rocket = rockets.get(serial); else { - rocket = new Rocket(String.format("%d", serial), this); + rocket = new Rocket(serial, this); rockets.put(serial, rocket); } if (t_state.gps != null) rocket.set_position(new AltosLatLon(t_state.gps.lat, t_state.gps.lon), t_state.received_time); + if (state != null) + rocket.set_active(state.serial == serial); } } if (receiver != null) { @@ -437,9 +476,10 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal } } - public void onCreateView(int map_type) { + public void onCreateView(AltosDroid altos_droid) { + this.altos_droid = altos_droid; map = new AltosMap(this); - map.set_maptype(map_type); + map.set_maptype(altos_droid.map_type); pad_bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pad); /* arrow at the bottom of the launchpad image */ @@ -464,6 +504,7 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal public AltosMapOffline(Context context, AttributeSet attrs) { super(context, attrs); + this.altos_droid = altos_droid; scale_detector = new ScaleGestureDetector(context, this); } } diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOnline.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOnline.java index 9503a0bd..3f5f32be 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOnline.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOnline.java @@ -121,7 +121,11 @@ public class AltosMapOnline implements AltosDroidMapInterface { private AltosLatLon my_position = null; private AltosLatLon target_position = null; - public void onCreateView(final int map_type) { + private AltosDroid altos_droid; + + public void onCreateView(AltosDroid altos_droid) { + this.altos_droid = altos_droid; + final int map_type = altos_droid.map_type; mMapFragment = new SupportMapFragment() { @Override public void onActivityCreated(Bundle savedInstanceState) { diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java index 9c39e105..cd59dfe7 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java @@ -57,14 +57,6 @@ public class TabMap extends AltosDroidTab { super.onCreate(savedInstanceState); } - private void make_offline_map() { - } - - private void make_online_map() { - map_online = new AltosMapOnline(view.getContext()); - map_online.onCreateView(altos_droid.map_type); - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.tab_map, container, false); @@ -77,9 +69,9 @@ public class TabMap extends AltosDroidTab { mReceiverLatitudeView = (TextView)view.findViewById(R.id.receiver_lat_value); mReceiverLongitudeView = (TextView)view.findViewById(R.id.receiver_lon_value); map_offline = (AltosMapOffline)view.findViewById(R.id.map_offline); - map_offline.onCreateView(altos_droid.map_type); + map_offline.onCreateView(altos_droid); map_online = new AltosMapOnline(view.getContext()); - map_online.onCreateView(altos_droid.map_type); + map_online.onCreateView(altos_droid); set_map_source(AltosDroidPreferences.map_source()); return view; } diff --git a/altoslib/AltosMap.java b/altoslib/AltosMap.java index adf52ab9..8d12a180 100644 --- a/altoslib/AltosMap.java +++ b/altoslib/AltosMap.java @@ -391,6 +391,10 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { AltosPointInt drag_start; + boolean dragged; + + static final double drag_far = 20; + private void drag(int x, int y) { if (drag_start == null) return; @@ -398,6 +402,11 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { int dx = x - drag_start.x; int dy = y - drag_start.y; + double distance = Math.hypot(dx, dy); + + if (distance > drag_far) + dragged = true; + if (transform == null) { debug("Transform not set in drag\n"); return; @@ -410,6 +419,12 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { private void drag_start(int x, int y) { drag_start = new AltosPointInt(x, y); + dragged = false; + } + + private void drag_stop(int x, int y) { + if (!dragged) + map_interface.select_object (transform.screen_lat_lon(new AltosPointInt(x,y))); } private void line_start(int x, int y) { @@ -442,6 +457,12 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener { line(x, y); } + public void touch_stop(int x, int y, boolean is_drag) { + notice_user_input(); + if (is_drag) + drag_stop(x, y); + } + public AltosMap(AltosMapInterface map_interface) { this.map_interface = map_interface; cache = new AltosMapCache(map_interface); diff --git a/altoslib/AltosMapInterface.java b/altoslib/AltosMapInterface.java index e6cb5971..7e8dd236 100644 --- a/altoslib/AltosMapInterface.java +++ b/altoslib/AltosMapInterface.java @@ -42,4 +42,6 @@ public interface AltosMapInterface { public abstract void set_zoom_label(String label); public abstract void debug(String format, Object ... arguments); + + public abstract void select_object(AltosLatLon latlon); } diff --git a/altoslib/AltosMapTransform.java b/altoslib/AltosMapTransform.java index 30994ecb..11ed4eb9 100644 --- a/altoslib/AltosMapTransform.java +++ b/altoslib/AltosMapTransform.java @@ -51,6 +51,13 @@ public class AltosMapTransform { return new AltosPointDouble(screen.x + offset_x, screen.y + offset_y); } + public double hypot(AltosLatLon a, AltosLatLon b) { + AltosPointDouble a_pt = point(a); + AltosPointDouble b_pt = point(b); + + return Math.hypot(a_pt.x - b_pt.x, a_pt.y - b_pt.y); + } + public AltosLatLon screen_lat_lon(AltosPointInt screen) { return lat_lon(screen_point(screen)); } diff --git a/altosuilib/AltosUIMapNew.java b/altosuilib/AltosUIMapNew.java index 246222bc..8ac18296 100644 --- a/altosuilib/AltosUIMapNew.java +++ b/altosuilib/AltosUIMapNew.java @@ -358,10 +358,15 @@ public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, Alt zoom_label.setText(label); } + public void select_object(AltosLatLon latlon) { + debug("select at %f,%f\n", latlon.lat, latlon.lon); + } + public void debug(String format, Object ... arguments) { System.out.printf(format, arguments); } + /* AltosFlightDisplay interface */ public void set_font() { -- cgit v1.2.3