2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 import java.awt.image.*;
22 import java.awt.event.*;
24 import javax.swing.event.MouseInputAdapter;
25 import javax.imageio.ImageIO;
26 import javax.swing.table.*;
30 import java.util.prefs.*;
31 import java.lang.Math;
32 import java.awt.geom.Point2D;
33 import java.awt.geom.Line2D;
35 class AltosMapPos extends Box {
44 public void set_value(double new_value) {
51 new_value = -new_value;
53 d = Math.floor(new_value);
54 deg.setText(String.format("%3.0f", d));
55 m = (new_value - d) * 60.0;
56 min.setText(String.format("%7.4f", m));
57 hemi.setSelectedIndex(h);
60 public double get_value() throws NumberFormatException {
61 int h = hemi.getSelectedIndex();
62 String d_t = deg.getText();
63 String m_t = min.getText();
66 d = Double.parseDouble(d_t);
67 } catch (NumberFormatException ne) {
68 JOptionPane.showMessageDialog(owner,
69 String.format("Invalid degrees \"%s\"",
72 JOptionPane.ERROR_MESSAGE);
79 m = Double.parseDouble(m_t);
80 } catch (NumberFormatException ne) {
81 JOptionPane.showMessageDialog(owner,
82 String.format("Invalid minutes \"%s\"",
85 JOptionPane.ERROR_MESSAGE);
94 public AltosMapPos(AltosUI in_owner,
97 double default_value) {
98 super(BoxLayout.X_AXIS);
100 label = new JLabel(label_value);
101 hemi = new JComboBox(hemi_names);
102 hemi.setEditable(false);
103 deg = new JTextField("000");
104 deg_label = new JLabel("°");
105 min = new JTextField("00.0000");
106 min_label = new JLabel("'");
107 set_value(default_value);
109 add(Box.createRigidArea(new Dimension(5, 0)));
111 add(Box.createRigidArea(new Dimension(5, 0)));
113 add(Box.createRigidArea(new Dimension(5, 0)));
115 add(Box.createRigidArea(new Dimension(5, 0)));
117 add(Box.createRigidArea(new Dimension(5, 0)));
122 public class AltosSiteMapPreload extends JDialog implements ActionListener {
131 final static int radius = 4;
132 final static int width = (radius * 2 + 1);
133 final static int height = (radius * 2 + 1);
135 JToggleButton load_button;
137 JButton close_button;
139 static final String[] lat_hemi_names = { "N", "S" };
140 static final String[] lon_hemi_names = { "E", "W" };
142 class updatePbar implements Runnable {
146 public updatePbar(int x, int y, String in_s) {
147 n = (x + radius) + (y + radius) * width + 1;
154 if (n < width * height) {
160 load_button.setSelected(false);
166 class bgLoad extends Thread {
170 public bgLoad(AltosSiteMap in_map) {
175 for (int y = -map.radius; y <= map.radius; y++) {
176 for (int x = -map.radius; x <= map.radius; x++) {
178 pngfile = map.initMap(new Point(x,y));
179 SwingUtilities.invokeLater(new updatePbar(x, y, pngfile));
185 public void actionPerformed(ActionEvent e) {
186 String cmd = e.getActionCommand();
188 if (cmd.equals("close"))
191 if (cmd.equals("load")) {
194 final double latitude = lat.get_value();
195 final double longitude = lon.get_value();
196 map.setBaseLocation(latitude,longitude);
198 bgLoad thread = new bgLoad(map);
200 } catch (NumberFormatException ne) {
201 load_button.setSelected(false);
207 public AltosSiteMapPreload(AltosUI in_owner) {
210 Container pane = getContentPane();
211 GridBagConstraints c = new GridBagConstraints();
212 Insets i = new Insets(4,4,4,4);
214 pane.setLayout(new GridBagLayout());
216 map = new AltosSiteMap(4);
218 c.fill = GridBagConstraints.BOTH;
219 c.anchor = GridBagConstraints.CENTER;
227 c.anchor = GridBagConstraints.CENTER;
231 pbar = new JProgressBar();
233 pbar.setMaximum(width * height);
236 pbar.setStringPainted(true);
238 c.fill = GridBagConstraints.HORIZONTAL;
239 c.anchor = GridBagConstraints.CENTER;
250 lat = new AltosMapPos(owner,
254 c.fill = GridBagConstraints.NONE;
255 c.anchor = GridBagConstraints.CENTER;
263 c.anchor = GridBagConstraints.CENTER;
267 lon = new AltosMapPos(owner,
272 c.fill = GridBagConstraints.NONE;
273 c.anchor = GridBagConstraints.CENTER;
281 c.anchor = GridBagConstraints.CENTER;
285 load_button = new JToggleButton("Load Map");
286 load_button.addActionListener(this);
287 load_button.setActionCommand("load");
289 c.fill = GridBagConstraints.NONE;
290 c.anchor = GridBagConstraints.CENTER;
298 c.anchor = GridBagConstraints.CENTER;
300 pane.add(load_button, c);
302 close_button = new JButton("Close");
303 close_button.addActionListener(this);
304 close_button.setActionCommand("close");
306 c.fill = GridBagConstraints.NONE;
307 c.anchor = GridBagConstraints.CENTER;
315 c.anchor = GridBagConstraints.CENTER;
317 pane.add(close_button, c);
320 setLocationRelativeTo(owner);