Changeset 237 in josm
- Timestamp:
- 2007-05-17T03:20:42+02:00 (18 years ago)
- Files:
-
- 8 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r211 r237 29 29 30 30 import org.openstreetmap.josm.actions.DownloadAction; 31 import org.openstreetmap.josm.actions.DownloadAction.DownloadTask; 31 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 32 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 32 33 import org.openstreetmap.josm.actions.mapmode.MapMode; 33 34 import org.openstreetmap.josm.actions.search.SearchAction; … … 41 42 import org.openstreetmap.josm.gui.PleaseWaitDialog; 42 43 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 44 import org.openstreetmap.josm.gui.download.BoundingBoxSelection; 45 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 43 46 import org.openstreetmap.josm.gui.layer.Layer; 44 47 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 372 375 private static void downloadFromParamString(final boolean rawGps, String s) { 373 376 if (s.startsWith("http:")) { 374 final Bounds b = DownloadAction.osmurl2bounds(s);377 final Bounds b = BoundingBoxSelection.osmurl2bounds(s); 375 378 if (b == null) 376 379 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed url: \"{0}\"", s)); 377 380 else { 378 DownloadTask osmTask = main.menu.download.downloadTasks.get(0); 381 //DownloadTask osmTask = main.menu.download.downloadTasks.get(0); 382 DownloadTask osmTask = new DownloadOsmTask(); 379 383 osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon()); 380 384 } … … 394 398 if (st.countTokens() == 4) { 395 399 try { 396 DownloadTask task = main.menu.download.downloadTasks.get(rawGps ? 1 : 0); 400 //DownloadTask task = main.menu.download.downloadTasks.get(rawGps ? 1 : 0); 401 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); 397 402 task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())); 398 403 return; -
src/org/openstreetmap/josm/actions/DownloadAction.java
r178 r237 39 39 import org.openstreetmap.josm.gui.BookmarkList; 40 40 import org.openstreetmap.josm.gui.MapView; 41 import org.openstreetmap.josm.gui.WorldChooser; 41 import org.openstreetmap.josm.gui.download.DownloadDialog; 42 import org.openstreetmap.josm.gui.download.WorldChooser; 43 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 44 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 42 45 import org.openstreetmap.josm.tools.GBC; 43 46 … … 51 54 */ 52 55 public class DownloadAction extends JosmAction { 53 54 public interface DownloadTask { 55 /** 56 * Execute the download. 57 */ 58 void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon); 59 /** 60 * @return The checkbox presented to the user 61 */ 62 JCheckBox getCheckBox(); 63 /** 64 * @return The name of the preferences suffix to use for storing the 65 * selection state. 66 */ 67 String getPreferencesSuffix(); 68 } 69 70 /** 71 * The list of download tasks. First entry should be the osm data entry 72 * and the second the gps entry. After that, plugins can register additional 73 * download possibilities. 74 */ 75 public final List<DownloadTask> downloadTasks = new ArrayList<DownloadTask>(5); 76 77 /** 78 * minlat, minlon, maxlat, maxlon 79 */ 80 public JTextField[] latlon = new JTextField[]{ 81 new JTextField(9), 82 new JTextField(9), 83 new JTextField(9), 84 new JTextField(9)}; 85 56 57 public DownloadDialog dialog; 58 86 59 public DownloadAction() { 87 60 super(tr("Download from OSM"), "download", tr("Download map data from the OSM server."), KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true); 88 // TODO remove when bug in Java6 is fixed89 for (JTextField f : latlon)90 f.setMinimumSize(new Dimension(100,new JTextField().getMinimumSize().height));91 92 downloadTasks.add(new DownloadOsmTask());93 downloadTasks.add(new DownloadGpsTask());94 61 } 95 62 96 63 public void actionPerformed(ActionEvent e) { 97 JPanel dlg = new JPanel(new GridBagLayout()); 64 dialog = new DownloadDialog(Integer.parseInt(Main.pref.get("download.tab", "0"))); 65 66 JPanel downPanel = new JPanel(new GridBagLayout()); 67 downPanel.add(dialog, GBC.eol().fill(GBC.BOTH)); 98 68 99 // World image 100 WorldChooser wc = new WorldChooser(); 101 dlg.add(wc, GBC.eop()); 102 wc.setToolTipText(tr("Move and zoom the image like the main map. Select an area to download by dragging.")); 69 JOptionPane pane = new JOptionPane(downPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 70 JDialog dlg = pane.createDialog(Main.parent, tr("Download")); 103 71 104 // Bounding box edits 105 dlg.add(new JLabel(tr("Bounding box")), GBC.eol()); 106 dlg.add(new JLabel(tr("min lat")), GBC.std().insets(10,0,5,0)); 107 dlg.add(latlon[0], GBC.std()); 108 dlg.add(new JLabel(tr("min lon")), GBC.std().insets(10,0,5,0)); 109 dlg.add(latlon[1], GBC.eol()); 110 dlg.add(new JLabel(tr("max lat")), GBC.std().insets(10,0,5,0)); 111 dlg.add(latlon[2], GBC.std()); 112 dlg.add(new JLabel(tr("max lon")), GBC.std().insets(10,0,5,0)); 113 dlg.add(latlon[3], GBC.eol()); 114 if (Main.map != null) { 115 MapView mv = Main.map.mapView; 116 setEditBounds(new Bounds( 117 mv.getLatLon(0, mv.getHeight()), 118 mv.getLatLon(mv.getWidth(), 0))); 119 } 72 if (dlg.getWidth() > 1000) 73 dlg.setSize(1000, dlg.getHeight()); 74 if (dlg.getHeight() > 600) 75 dlg.setSize(dlg.getWidth(),600); 120 76 121 // adding the download tasks 122 dlg.add(new JLabel(tr("Download the following data:")), GBC.eol().insets(0,5,0,0)); 123 for (DownloadTask task : downloadTasks) { 124 dlg.add(task.getCheckBox(), GBC.eol().insets(20,0,0,0)); 125 task.getCheckBox().setSelected(Main.pref.getBoolean("download."+task.getPreferencesSuffix())); 126 } 127 128 // OSM url edit 129 dlg.add(new JLabel(tr("URL from www.openstreetmap.org")), GBC.eol().insets(0,5,0,0)); 130 final JTextField osmUrl = new JTextField(); 131 dlg.add(osmUrl, GBC.eop().fill(GBC.HORIZONTAL)); 132 final KeyListener osmUrlRefresher = new KeyAdapter(){ 133 @Override public void keyTyped(KeyEvent e) { 134 SwingUtilities.invokeLater(new Runnable() { 135 public void run() { 136 try { 137 double latMin = Double.parseDouble(latlon[0].getText()); 138 double lonMin = Double.parseDouble(latlon[1].getText()); 139 double latMax = Double.parseDouble(latlon[2].getText()); 140 double lonMax = Double.parseDouble(latlon[3].getText()); 141 double lat = (latMax+latMin)/2; 142 double lon = (lonMax+lonMin)/2; 143 // convert to mercator (for calculation of zoom only) 144 latMin = Math.log(Math.tan(Math.PI/4.0+latMin/180.0*Math.PI/2.0))*180.0/Math.PI; 145 latMax = Math.log(Math.tan(Math.PI/4.0+latMax/180.0*Math.PI/2.0))*180.0/Math.PI; 146 double size = Math.max(Math.abs(latMax-latMin), Math.abs(lonMax-lonMin)); 147 int zoom = 0; 148 while (zoom <= 20) { 149 if (size >= 180) 150 break; 151 size *= 2; 152 zoom++; 153 } 154 osmUrl.setText("http://www.openstreetmap.org/index.html?lat="+lat+"&lon="+lon+"&zoom="+zoom); 155 } catch (NumberFormatException x) { 156 osmUrl.setText(""); 157 } 158 osmUrl.setCaretPosition(0); 159 } 160 }); 161 } 162 }; 163 for (JTextField f : latlon) 164 f.addKeyListener(osmUrlRefresher); 165 SwingUtilities.invokeLater(new Runnable() {public void run() {osmUrlRefresher.keyTyped(null);}}); 166 osmUrl.addKeyListener(new KeyAdapter(){ 167 @Override public void keyTyped(KeyEvent e) { 168 SwingUtilities.invokeLater(new Runnable() { 169 public void run() { 170 Bounds b = osmurl2bounds(osmUrl.getText()); 171 if (b != null) 172 setEditBounds(b); 173 else 174 for (JTextField f : latlon) 175 f.setText(""); 176 } 177 }); 178 } 179 }); 180 181 // Bookmarks 182 dlg.add(new JLabel(tr("Bookmarks")), GBC.eol()); 183 final BookmarkList bookmarks = new BookmarkList(); 184 bookmarks.getSelectionModel().addListSelectionListener(new ListSelectionListener(){ 185 public void valueChanged(ListSelectionEvent e) { 186 Preferences.Bookmark b = (Preferences.Bookmark)bookmarks.getSelectedValue(); 187 for (int i = 0; i < 4; ++i) { 188 latlon[i].setText(b == null ? "" : ""+b.latlon[i]); 189 latlon[i].setCaretPosition(0); 77 dlg.setVisible(true); 78 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) { 79 Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab())); 80 for (DownloadTask task : dialog.downloadTasks) { 81 Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected()); 82 if (task.getCheckBox().isSelected()) { 83 task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon); 190 84 } 191 osmUrlRefresher.keyTyped(null);192 }193 });194 wc.addListMarker(bookmarks);195 dlg.add(new JScrollPane(bookmarks), GBC.eol().fill());196 197 JPanel buttons = new JPanel(new GridLayout(1,2));198 JButton add = new JButton(tr("Add"));199 add.addActionListener(new ActionListener(){200 public void actionPerformed(ActionEvent e) {201 Preferences.Bookmark b = readBookmark();202 if (b == null) {203 JOptionPane.showMessageDialog(Main.parent, tr("Please enter the desired coordinates first."));204 return;205 }206 b.name = JOptionPane.showInputDialog(Main.parent,tr("Please enter a name for the location."));207 if (b.name != null && !b.name.equals("")) {208 ((DefaultListModel)bookmarks.getModel()).addElement(b);209 bookmarks.save();210 }211 }212 });213 buttons.add(add);214 JButton remove = new JButton(tr("Remove"));215 remove.addActionListener(new ActionListener(){216 public void actionPerformed(ActionEvent e) {217 Object sel = bookmarks.getSelectedValue();218 if (sel == null) {219 JOptionPane.showMessageDialog(Main.parent,tr("Select a bookmark first."));220 return;221 }222 ((DefaultListModel)bookmarks.getModel()).removeElement(sel);223 bookmarks.save();224 }225 });226 buttons.add(remove);227 dlg.add(buttons, GBC.eop().fill(GBC.HORIZONTAL));228 229 Dimension d = dlg.getPreferredSize();230 wc.setPreferredSize(new Dimension(d.width, d.width/2));231 wc.addInputFields(latlon, osmUrl, osmUrlRefresher);232 233 // Finally: the dialog234 Preferences.Bookmark b;235 boolean anySelected = false;236 do {237 final JOptionPane pane = new JOptionPane(dlg, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);238 final JDialog panedlg = pane.createDialog(Main.parent, tr("Choose an area"));239 bookmarks.addMouseListener(new MouseAdapter(){240 @Override public void mouseClicked(MouseEvent e) {241 if (e.getClickCount() >= 2) {242 pane.setValue(JOptionPane.OK_OPTION);243 panedlg.setVisible(false);244 }245 }246 });247 panedlg.setVisible(true);248 Object answer = pane.getValue();249 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION))250 return;251 b = readBookmark();252 253 for (DownloadTask task : downloadTasks) {254 if (task.getCheckBox().isSelected()) {255 anySelected = true;256 break;257 }258 }259 260 if (b == null)261 JOptionPane.showMessageDialog(Main.parent,tr("Please enter the desired coordinates or click on a bookmark."));262 else if (!anySelected)263 JOptionPane.showMessageDialog(Main.parent,tr("Please select at least one download data type."));264 } while (b == null || !anySelected);265 266 double minlon = b.latlon[0];267 double minlat = b.latlon[1];268 double maxlon = b.latlon[2];269 double maxlat = b.latlon[3];270 download(minlon, minlat, maxlon, maxlat);271 }272 273 /**274 * Read a bookmark from the current set edit fields. If one of the fields is275 * empty or contain illegal chars, <code>null</code> is returned.276 * The name of the bookmark is <code>null</code>.277 * @return A bookmark containing information from the edit fields and rawgps278 * checkbox.279 */280 Preferences.Bookmark readBookmark() {281 try {282 Preferences.Bookmark b = new Preferences.Bookmark();283 for (int i = 0; i < 4; ++i) {284 if (latlon[i].getText().equals(""))285 return null;286 b.latlon[i] = Double.parseDouble(latlon[i].getText());287 }288 return b;289 } catch (NumberFormatException x) {290 return null;291 }292 }293 294 public static Bounds osmurl2bounds(String url) {295 int i = url.indexOf('?');296 if (i == -1)297 return null;298 String[] args = url.substring(i+1).split("&");299 HashMap<String, Double> map = new HashMap<String, Double>();300 for (String arg : args) {301 int eq = arg.indexOf('=');302 if (eq != -1) {303 try {304 map.put(arg.substring(0, eq), Double.parseDouble(arg.substring(eq + 1)));305 } catch (NumberFormatException e) {306 }307 }308 }309 try {310 double size = 180.0 / Math.pow(2, map.get("zoom"));311 return new Bounds(312 new LatLon(map.get("lat") - size/2, map.get("lon") - size),313 new LatLon(map.get("lat") + size/2, map.get("lon") + size));314 } catch (Exception x) { // NPE or IAE315 return null;316 }317 }318 319 /**320 * Set the four edit fields to the given bounds coordinates.321 */322 private void setEditBounds(Bounds b) {323 LatLon bottomLeft = b.min;324 LatLon topRight = b.max;325 if (bottomLeft.isOutSideWorld())326 bottomLeft = new LatLon(-89.999, -179.999); // do not use the Projection constants, since this looks better.327 if (topRight.isOutSideWorld())328 topRight = new LatLon(89.999, 179.999);329 latlon[0].setText(""+bottomLeft.lat());330 latlon[1].setText(""+bottomLeft.lon());331 latlon[2].setText(""+topRight.lat());332 latlon[3].setText(""+topRight.lon());333 for (JTextField f : latlon)334 f.setCaretPosition(0);335 }336 337 /**338 * Do the download for the given area.339 */340 public void download(double minlat, double minlon, double maxlat, double maxlon) {341 for (DownloadTask task : downloadTasks) {342 Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected());343 if (task.getCheckBox().isSelected()) {344 task.download(this, minlat, minlon, maxlat, maxlon);345 85 } 346 86 } -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r175 r237 10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.actions.DownloadAction; 12 import org.openstreetmap.josm.actions.DownloadAction.DownloadTask;13 12 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 13 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 14 14 import org.openstreetmap.josm.gui.layer.RawGpsLayer; 15 15 import org.openstreetmap.josm.gui.layer.RawGpsLayer.GpsPoint; … … 37 37 if (rawData == null) 38 38 return; 39 String name = action. latlon[0].getText() + " " + action.latlon[1].getText() + " x " + this.action.latlon[2].getText() + " " + this.action.latlon[3].getText();39 String name = action.dialog.minlat + " " + action.dialog.minlon + " x " + action.dialog.maxlat + " " + action.dialog.maxlon; 40 40 Main.main.addLayer(new RawGpsLayer(rawData, name, null)); 41 41 } -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r175 r237 9 9 import org.openstreetmap.josm.Main; 10 10 import org.openstreetmap.josm.actions.DownloadAction; 11 import org.openstreetmap.josm.actions.DownloadAction.DownloadTask;12 11 import org.openstreetmap.josm.data.osm.DataSet; 13 12 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 13 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 14 14 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 15 15 import org.openstreetmap.josm.io.BoundingBoxDownloader; -
src/org/openstreetmap/josm/gui/MapFrame.java
r214 r237 28 28 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; 29 29 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 30 import org.openstreetmap.josm.gui.dialogs.UserListDialog; 30 31 import org.openstreetmap.josm.tools.Destroyable; 31 32 … … 105 106 addToggleDialog(new HistoryDialog()); 106 107 addToggleDialog(new SelectionListDialog()); 108 addToggleDialog(new UserListDialog()); 107 109 addToggleDialog(conflictDialog = new ConflictDialog()); 108 110 addToggleDialog(new CommandStackDialog(this)); -
src/org/openstreetmap/josm/gui/MapMover.java
r206 r237 13 13 import javax.swing.AbstractAction; 14 14 import javax.swing.JComponent; 15 import javax.swing.JPanel; 15 16 import javax.swing.KeyStroke; 16 17 … … 24 25 * @author imi 25 26 */ 26 class MapMover extends MouseAdapter implements MouseMotionListener, MouseWheelListener {27 public class MapMover extends MouseAdapter implements MouseMotionListener, MouseWheelListener { 27 28 28 29 private final class ZoomerAction extends AbstractAction { … … 72 73 * Create a new MapMover 73 74 */ 74 MapMover(NavigatableComponent navComp, boolean registerKeys) {75 public MapMover(NavigatableComponent navComp, JPanel contentPane) { 75 76 this.nc = navComp; 76 77 nc.addMouseListener(this); … … 81 82 int[] k = {KeyEvent.VK_COMMA, KeyEvent.VK_PERIOD, KeyEvent.VK_UP, KeyEvent.VK_RIGHT, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT}; 82 83 83 if ( registerKeys) {84 if (contentPane != null) { 84 85 for (int i = 0; i < n.length; ++i) { 85 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(k[i], KeyEvent.CTRL_DOWN_MASK), "MapMover.Zoomer."+n[i]);86 Main.contentPane.getActionMap().put("MapMover.Zoomer."+n[i], new ZoomerAction(n[i]));86 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(k[i], KeyEvent.CTRL_DOWN_MASK), "MapMover.Zoomer."+n[i]); 87 contentPane.getActionMap().put("MapMover.Zoomer."+n[i], new ZoomerAction(n[i])); 87 88 } 88 89 } -
src/org/openstreetmap/josm/gui/MapScaler.java
r155 r237 8 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.actions.HelpAction.Helpful; 10 import org.openstreetmap.josm.data.projection.Projection; 10 11 import org.openstreetmap.josm.tools.ColorHelper; 11 12 12 13 public class MapScaler extends JComponent implements Helpful { 13 14 14 private final MapView mv; 15 private final NavigatableComponent mv; 16 private final Projection proj; 15 17 16 public MapScaler( MapView mv) {18 public MapScaler(NavigatableComponent mv, Projection proj) { 17 19 this.mv = mv; 20 this.proj = proj; 18 21 setSize(100,30); 19 22 setOpaque(false); … … 21 24 22 25 @Override public void paint(Graphics g) { 23 double circum = mv.getScale()*100* Main.proj.scaleFactor()*40041455; // circumference of the earth in meter26 double circum = mv.getScale()*100*proj.scaleFactor()*40041455; // circumference of the earth in meter 24 27 String text = circum > 1000 ? (Math.round(circum/100)/10.0)+"km" : Math.round(circum)+"m"; 25 28 g.setColor(ColorHelper.html2color(Main.pref.get("color.scale", "#ffffff"))); -
src/org/openstreetmap/josm/gui/MapView.java
r215 r237 79 79 }); 80 80 81 new MapMover(this, true);81 new MapMover(this, Main.contentPane); 82 82 83 83 // listend to selection changes to redraw the map … … 92 92 zoomSlider.setBounds(3, 0, 114, 30); 93 93 94 MapScaler scaler = new MapScaler(this );94 MapScaler scaler = new MapScaler(this, Main.proj); 95 95 add(scaler); 96 96 scaler.setLocation(10,30); -
src/org/openstreetmap/josm/plugins/Plugin.java
r199 r237 8 8 import java.net.URL; 9 9 import java.net.URLClassLoader; 10 import java.util.List; 10 11 11 12 import org.openstreetmap.josm.Main; 12 13 import org.openstreetmap.josm.gui.MapFrame; 14 import org.openstreetmap.josm.gui.download.DownloadSelection; 13 15 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 14 16 … … 75 77 * if any available. 76 78 */ 77 public PreferenceSetting getPreferenceSetting() { return null;}79 public PreferenceSetting getPreferenceSetting() { return null; } 78 80 81 /** 82 * Called in the download dialog to give the plugin a chance to modify the list 83 * of bounding box selectors. 84 */ 85 public void addDownloadSelection(List<DownloadSelection> list) {} 79 86 80 87 /** -
src/org/openstreetmap/josm/plugins/PluginProxy.java
r168 r237 1 1 package org.openstreetmap.josm.plugins; 2 2 3 import java.util.List; 4 3 5 import org.openstreetmap.josm.gui.MapFrame; 6 import org.openstreetmap.josm.gui.download.DownloadSelection; 4 7 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 5 8 … … 41 44 } 42 45 } 46 47 @Override public void addDownloadSelection(List<DownloadSelection> list) { 48 try { 49 plugin.getClass().getMethod("getDownloadSelection", List.class).invoke(plugin); 50 } catch (NoSuchMethodException e) { 51 // ignore 52 } catch (Exception e) { 53 throw new PluginException(this, info.name, e); 54 } 55 } 43 56 }
Note:
See TracChangeset
for help on using the changeset viewer.