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;
148 System.out.printf("update pbar %d\n", n);
155 if (n < width * height) {
161 load_button.setSelected(false);
167 class bgLoad extends Thread {
171 public bgLoad(AltosSiteMap in_map) {
176 for (int y = -map.radius; y <= map.radius; y++) {
177 for (int x = -map.radius; x <= map.radius; x++) {
179 pngfile = map.initMap(new Point(x,y));
180 SwingUtilities.invokeLater(new updatePbar(x, y, pngfile));
186 public void actionPerformed(ActionEvent e) {
187 String cmd = e.getActionCommand();
189 if (cmd.equals("close"))
192 if (cmd.equals("load")) {
195 final double latitude = lat.get_value();
196 final double longitude = lon.get_value();
197 map.setBaseLocation(latitude,longitude);
199 bgLoad thread = new bgLoad(map);
201 } catch (NumberFormatException ne) {
202 load_button.setSelected(false);
208 public AltosSiteMapPreload(AltosUI in_owner) {
211 Container pane = getContentPane();
212 GridBagConstraints c = new GridBagConstraints();
213 Insets i = new Insets(4,4,4,4);
215 pane.setLayout(new GridBagLayout());
217 map = new AltosSiteMap(4);
219 c.fill = GridBagConstraints.BOTH;
220 c.anchor = GridBagConstraints.CENTER;
228 c.anchor = GridBagConstraints.CENTER;
232 pbar = new JProgressBar();
234 pbar.setMaximum(width * height);
237 pbar.setStringPainted(true);
239 c.fill = GridBagConstraints.HORIZONTAL;
240 c.anchor = GridBagConstraints.CENTER;
251 lat = new AltosMapPos(owner,
255 c.fill = GridBagConstraints.NONE;
256 c.anchor = GridBagConstraints.CENTER;
264 c.anchor = GridBagConstraints.CENTER;
268 lon = new AltosMapPos(owner,
273 c.fill = GridBagConstraints.NONE;
274 c.anchor = GridBagConstraints.CENTER;
282 c.anchor = GridBagConstraints.CENTER;
286 load_button = new JToggleButton("Load Map");
287 load_button.addActionListener(this);
288 load_button.setActionCommand("load");
290 c.fill = GridBagConstraints.NONE;
291 c.anchor = GridBagConstraints.CENTER;
299 c.anchor = GridBagConstraints.CENTER;
301 pane.add(load_button, c);
303 close_button = new JButton("Close");
304 close_button.addActionListener(this);
305 close_button.setActionCommand("close");
307 c.fill = GridBagConstraints.NONE;
308 c.anchor = GridBagConstraints.CENTER;
316 c.anchor = GridBagConstraints.CENTER;
318 pane.add(close_button, c);
321 setLocationRelativeTo(owner);