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 {
43 public void set_value(double new_value) {
50 new_value = -new_value;
52 d = Math.floor(new_value);
53 deg.setText(String.format("%3.0f", d));
54 m = (new_value - d) * 60.0;
55 min.setText(String.format("%7.4f", m));
56 hemi.setSelectedIndex(h);
59 public double get_value() throws NumberFormatException {
60 int h = hemi.getSelectedIndex();
61 double d = Double.parseDouble(deg.getText());
62 double m = Double.parseDouble(min.getText());
63 double v = d + m/60.0;
69 public AltosMapPos(String label_value,
71 double default_value) {
72 super(BoxLayout.X_AXIS);
73 label = new JLabel(label_value);
74 hemi = new JComboBox(hemi_names);
75 hemi.setEditable(false);
76 deg = new JTextField("000");
77 deg_label = new JLabel("degrees");
78 min = new JTextField("00.0000");
79 min_label = new JLabel("minutes");
80 set_value(default_value);
82 add(Box.createRigidArea(new Dimension(5, 0)));
84 add(Box.createRigidArea(new Dimension(5, 0)));
86 add(Box.createRigidArea(new Dimension(5, 0)));
88 add(Box.createRigidArea(new Dimension(5, 0)));
90 add(Box.createRigidArea(new Dimension(5, 0)));
95 public class AltosSiteMapPreload extends JDialog implements ActionListener {
104 final static int width = 9;
105 final static int height = 9;
106 final static int tiles = width * height;
108 JToggleButton load_button;
110 JButton close_button;
112 static final String[] lat_hemi_names = { "N", "S" };
113 static final String[] lon_hemi_names = { "E", "W" };
115 class updatePbar implements Runnable {
119 public updatePbar(int in_n, String in_s) {
127 if (n == width * height) {
128 load_button.setSelected(false);
134 class bgLoad extends Thread {
138 public bgLoad(AltosSiteMap in_map) {
143 for (int y = 0; y < height; y++) {
144 for (int x = 0; x < width; x++) {
145 map.prefetchMap(y - height/2, x - width/2);
146 SwingUtilities.invokeLater(new updatePbar(y * height + x + 1,
147 map.pngfile.toString()));
153 public void actionPerformed(ActionEvent e) {
154 String cmd = e.getActionCommand();
156 if (cmd.equals("close"))
159 if (cmd.equals("load")) {
162 final double latitude = lat.get_value();
163 final double longitude = lon.get_value();
164 map.show(latitude,longitude);
165 bgLoad thread = new bgLoad(map);
171 public AltosSiteMapPreload(AltosUI in_owner) {
174 Container pane = getContentPane();
175 GridBagConstraints c = new GridBagConstraints();
176 Insets i = new Insets(4,4,4,4);
178 pane.setLayout(new GridBagLayout());
180 map = new AltosSiteMap();
182 c.fill = GridBagConstraints.BOTH;
183 c.anchor = GridBagConstraints.CENTER;
191 c.anchor = GridBagConstraints.CENTER;
195 pbar = new JProgressBar();
197 pbar.setMaximum(width * height);
200 pbar.setStringPainted(true);
202 c.fill = GridBagConstraints.HORIZONTAL;
203 c.anchor = GridBagConstraints.CENTER;
214 lat = new AltosMapPos("Latitude:",
217 c.fill = GridBagConstraints.NONE;
218 c.anchor = GridBagConstraints.CENTER;
226 c.anchor = GridBagConstraints.CENTER;
230 lon = new AltosMapPos("Longitude:",
234 c.fill = GridBagConstraints.NONE;
235 c.anchor = GridBagConstraints.CENTER;
243 c.anchor = GridBagConstraints.CENTER;
247 load_button = new JToggleButton("Load Map");
248 load_button.addActionListener(this);
249 load_button.setActionCommand("load");
251 c.fill = GridBagConstraints.NONE;
252 c.anchor = GridBagConstraints.CENTER;
260 c.anchor = GridBagConstraints.CENTER;
262 pane.add(load_button, c);
264 close_button = new JButton("Close");
265 close_button.addActionListener(this);
266 close_button.setActionCommand("close");
268 c.fill = GridBagConstraints.NONE;
269 c.anchor = GridBagConstraints.CENTER;
277 c.anchor = GridBagConstraints.CENTER;
279 pane.add(close_button, c);
282 setLocationRelativeTo(owner);