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);
108 deg.setMinimumSize(deg.getPreferredSize());
109 min.setMinimumSize(min.getPreferredSize());
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)));
119 add(Box.createRigidArea(new Dimension(5, 0)));
124 public class AltosSiteMapPreload extends JDialog implements ActionListener {
133 final static int radius = 4;
134 final static int width = (radius * 2 + 1);
135 final static int height = (radius * 2 + 1);
137 JToggleButton load_button;
139 JButton close_button;
141 static final String[] lat_hemi_names = { "N", "S" };
142 static final String[] lon_hemi_names = { "E", "W" };
144 class updatePbar implements Runnable {
148 public updatePbar(int x, int y, String in_s) {
149 n = (x + radius) + (y + radius) * width + 1;
156 if (n < width * height) {
162 load_button.setSelected(false);
168 class bgLoad extends Thread {
172 public bgLoad(AltosSiteMap in_map) {
177 for (int y = -map.radius; y <= map.radius; y++) {
178 for (int x = -map.radius; x <= map.radius; x++) {
180 pngfile = map.initMap(new Point(x,y));
181 SwingUtilities.invokeLater(new updatePbar(x, y, pngfile));
187 public void actionPerformed(ActionEvent e) {
188 String cmd = e.getActionCommand();
190 if (cmd.equals("close"))
193 if (cmd.equals("load")) {
196 final double latitude = lat.get_value();
197 final double longitude = lon.get_value();
198 map.setBaseLocation(latitude,longitude);
200 bgLoad thread = new bgLoad(map);
202 } catch (NumberFormatException ne) {
203 load_button.setSelected(false);
209 public AltosSiteMapPreload(AltosUI in_owner) {
212 Container pane = getContentPane();
213 GridBagConstraints c = new GridBagConstraints();
214 Insets i = new Insets(4,4,4,4);
216 pane.setLayout(new GridBagLayout());
218 map = new AltosSiteMap(4);
220 c.fill = GridBagConstraints.BOTH;
221 c.anchor = GridBagConstraints.CENTER;
229 c.anchor = GridBagConstraints.CENTER;
233 pbar = new JProgressBar();
235 pbar.setMaximum(width * height);
238 pbar.setStringPainted(true);
240 c.fill = GridBagConstraints.HORIZONTAL;
241 c.anchor = GridBagConstraints.CENTER;
252 lat = new AltosMapPos(owner,
256 c.fill = GridBagConstraints.NONE;
257 c.anchor = GridBagConstraints.CENTER;
265 c.anchor = GridBagConstraints.CENTER;
269 lon = new AltosMapPos(owner,
274 c.fill = GridBagConstraints.NONE;
275 c.anchor = GridBagConstraints.CENTER;
283 c.anchor = GridBagConstraints.CENTER;
287 load_button = new JToggleButton("Load Map");
288 load_button.addActionListener(this);
289 load_button.setActionCommand("load");
291 c.fill = GridBagConstraints.NONE;
292 c.anchor = GridBagConstraints.CENTER;
300 c.anchor = GridBagConstraints.CENTER;
302 pane.add(load_button, c);
304 close_button = new JButton("Close");
305 close_button.addActionListener(this);
306 close_button.setActionCommand("close");
308 c.fill = GridBagConstraints.NONE;
309 c.anchor = GridBagConstraints.CENTER;
317 c.anchor = GridBagConstraints.CENTER;
319 pane.add(close_button, c);
322 setLocationRelativeTo(owner);