- Timestamp:
- 2006-01-22T16:10:57+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/DownloadAction.java
r42 r43 14 14 import javax.swing.JButton; 15 15 import javax.swing.JCheckBox; 16 import javax.swing.JDialog; 16 17 import javax.swing.JLabel; 17 18 import javax.swing.JOptionPane; … … 74 75 dlg.add(latlon[2], GBC.std()); 75 76 dlg.add(new JLabel("max lon"), GBC.std().insets(10,0,5,0)); 76 dlg.add(latlon[3], GBC.eo p());77 dlg.add(latlon[3], GBC.eol()); 77 78 78 79 if (Main.main.getMapFrame() != null) { … … 159 160 return; 160 161 } 161 OsmServerReader osmReader = new OsmServerReader(b.latlon[0], b.latlon[1], b.latlon[2], b.latlon[3]); 162 try { 163 String name = latlon[0].getText()+" "+latlon[1].getText()+" x "+ 164 latlon[2].getText()+" "+latlon[3].getText(); 165 166 Layer layer; 167 if (rawGps.isSelected()) { 168 layer = new RawGpsDataLayer(osmReader.parseRawGps(), name); 169 } else { 170 DataSet dataSet = osmReader.parseOsm(); 171 if (dataSet == null) 172 return; // user cancelled download 173 if (dataSet.nodes.isEmpty()) 174 JOptionPane.showMessageDialog(Main.main, "No data imported."); 175 176 layer = new OsmDataLayer(dataSet, name); 177 } 178 179 if (Main.main.getMapFrame() == null) 180 Main.main.setMapFrame(name, new MapFrame(layer)); 181 else 182 Main.main.getMapFrame().mapView.addLayer(layer); 183 } catch (JDOMException x) { 184 x.printStackTrace(); 185 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 186 } catch (FileNotFoundException x) { 187 x.printStackTrace(); 188 JOptionPane.showMessageDialog(Main.main, "URL nicht gefunden: "+x.getMessage()); 189 } catch (IOException x) { 190 x.printStackTrace(); 191 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 192 } 162 163 final OsmServerReader osmReader = new OsmServerReader(b.latlon[0], b.latlon[1], b.latlon[2], b.latlon[3]); 164 165 final JDialog pleaseWaitDlg = createPleaseWaitDialog("Downloading data"); 166 167 new Thread(){ 168 @Override 169 public void run() { 170 try { 171 String name = latlon[0].getText() + " " 172 + latlon[1].getText() + " x " + latlon[2].getText() 173 + " " + latlon[3].getText(); 174 175 Layer layer = null; 176 if (rawGps.isSelected()) { 177 layer = new RawGpsDataLayer(osmReader.parseRawGps(), 178 name); 179 } else { 180 DataSet dataSet = osmReader.parseOsm(); 181 if (dataSet == null) 182 return; // user cancelled download 183 if (dataSet.nodes.isEmpty()) 184 JOptionPane.showMessageDialog(Main.main, 185 "No data imported."); 186 187 layer = new OsmDataLayer(dataSet, name); 188 } 189 190 if (Main.main.getMapFrame() == null) 191 Main.main.setMapFrame(name, new MapFrame(layer)); 192 else 193 Main.main.getMapFrame().mapView.addLayer(layer); 194 pleaseWaitDlg.setVisible(false); 195 } catch (JDOMException x) { 196 pleaseWaitDlg.setVisible(false); 197 x.printStackTrace(); 198 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 199 } catch (FileNotFoundException x) { 200 pleaseWaitDlg.setVisible(false); 201 x.printStackTrace(); 202 JOptionPane.showMessageDialog(Main.main, 203 "URL nicht gefunden: " + x.getMessage()); 204 } catch (IOException x) { 205 pleaseWaitDlg.setVisible(false); 206 x.printStackTrace(); 207 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 208 } finally { 209 pleaseWaitDlg.setVisible(false); 210 } 211 } 212 }.start(); 213 214 pleaseWaitDlg.setVisible(true); 193 215 } 194 216 -
src/org/openstreetmap/josm/actions/JosmAction.java
r30 r43 4 4 5 5 import javax.swing.AbstractAction; 6 import javax.swing.BorderFactory; 7 import javax.swing.JDialog; 8 import javax.swing.JLabel; 6 9 10 import org.openstreetmap.josm.Main; 7 11 import org.openstreetmap.josm.gui.ImageProvider; 8 12 … … 30 34 putValue(ACCELERATOR_KEY, shortCut); 31 35 } 36 37 /** 38 * @return A dialog labeled "... Please Wait." where ... is the message parameter. 39 */ 40 protected JDialog createPleaseWaitDialog(String msg) { 41 final JDialog pleaseWaitDlg = new JDialog(Main.main, true); 42 pleaseWaitDlg.setUndecorated(true); 43 JLabel l = new JLabel(msg+". Please Wait."); 44 l.setBorder(BorderFactory.createCompoundBorder( 45 BorderFactory.createEtchedBorder(), 46 BorderFactory.createEmptyBorder(20,20,20,20))); 47 pleaseWaitDlg.getContentPane().add(l); 48 pleaseWaitDlg.pack(); 49 pleaseWaitDlg.setLocation(Main.main.getWidth()/2-pleaseWaitDlg.getWidth()/2, 50 Main.main.getHeight()/2-pleaseWaitDlg.getHeight()/2); 51 pleaseWaitDlg.setResizable(false); 52 pleaseWaitDlg.setAlwaysOnTop(true); 53 return pleaseWaitDlg; 54 } 32 55 } -
src/org/openstreetmap/josm/actions/UploadAction.java
r35 r43 8 8 import java.util.LinkedList; 9 9 10 import javax.swing.JDialog; 10 11 import javax.swing.JLabel; 11 12 import javax.swing.JList; … … 42 43 Collection<OsmPrimitive> update = new LinkedList<OsmPrimitive>(); 43 44 Collection<OsmPrimitive> delete = new LinkedList<OsmPrimitive>(); 45 boolean acceptedTracks = false; 44 46 for (OsmPrimitive osm : Main.main.ds.allPrimitives()) { 45 if (osm instanceof Track) { 47 boolean doSomething = true; 48 if (osm.id == 0 && !osm.isDeleted()) 49 add.add(osm); 50 else if ((osm.modified || osm.modifiedProperties) && !osm.isDeleted()) 51 update.add(osm); 52 else if (osm.isDeleted() && osm.id != 0) 53 delete.add(osm); 54 else 55 doSomething = false; 56 57 if (osm instanceof Track && doSomething && !acceptedTracks) { 46 58 int answer = JOptionPane.showConfirmDialog(Main.main, 47 59 "The server currently does not understand the concept of Tracks.\n" + … … 50 62 if (answer != JOptionPane.YES_OPTION) 51 63 return; 64 acceptedTracks = true; 52 65 } 53 if (osm.id == 0 && !osm.isDeleted())54 add.add(osm);55 else if ((osm.modified || osm.modifiedProperties) && !osm.isDeleted())56 update.add(osm);57 else if (osm.isDeleted() && osm.id != 0)58 delete.add(osm);59 66 } 60 67 … … 62 69 return; 63 70 64 OsmServerWriter server = new OsmServerWriter(); 65 try { 66 Collection<OsmPrimitive> all = new LinkedList<OsmPrimitive>(); 67 all.addAll(add); 68 all.addAll(update); 69 all.addAll(delete); 70 server.uploadOsm(all); 71 // finished without errors -> clean dataset 72 Main.main.getMapFrame().mapView.editLayer().cleanData(); 73 } catch (JDOMException x) { 74 x.printStackTrace(); 75 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 76 } 71 final OsmServerWriter server = new OsmServerWriter(); 72 final Collection<OsmPrimitive> all = new LinkedList<OsmPrimitive>(); 73 all.addAll(add); 74 all.addAll(update); 75 all.addAll(delete); 76 77 final JDialog dlg = createPleaseWaitDialog("Uploading data"); 78 new Thread(){ 79 @Override 80 public void run() { 81 try { 82 server.uploadOsm(all); 83 } catch (JDOMException x) { 84 dlg.setVisible(false); 85 x.printStackTrace(); 86 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 87 } finally { 88 dlg.setVisible(false); 89 } 90 } 91 }.start(); 92 93 dlg.setVisible(true); 94 95 // finished without errors -> clean dataset 96 Main.main.getMapFrame().mapView.editLayer().cleanData(); 77 97 } 78 98 -
src/org/openstreetmap/josm/data/Preferences.java
r42 r43 21 21 import org.openstreetmap.josm.data.projection.Mercator; 22 22 import org.openstreetmap.josm.data.projection.Projection; 23 import org.openstreetmap.josm.data.projection.UTM;24 23 25 24 … … 39 38 * The convertor used to translate lat/lon points to screen points. 40 39 */ 41 private Projection projection = new UTM();40 private Projection projection = new Epsg4263(); 42 41 43 42 … … 78 77 */ 79 78 public static final Projection[] allProjections = new Projection[]{ 80 new Mercator(), 81 new UTM(), 82 new Epsg4263() 79 new Epsg4263(), 80 new Mercator() 83 81 }; 84 82 … … 124 122 // projection 125 123 Class<?> projectionClass = Class.forName(root.getChildText("projection")); 126 projection = allProjections[0]; // defaults to UTM124 projection = allProjections[0]; 127 125 for (Projection p : allProjections) { 128 126 if (p.getClass() == projectionClass) { -
src/org/openstreetmap/josm/data/projection/Epsg4263.java
r42 r43 1 1 package org.openstreetmap.josm.data.projection; 2 3 import javax.swing.JComponent;4 2 5 3 import org.openstreetmap.josm.data.GeoPoint; … … 10 8 * @author imi 11 9 */ 12 public class Epsg4263 extends Projection {10 public class Epsg4263 implements Projection { 13 11 14 @Override15 12 public void latlon2xy(GeoPoint p) { 16 13 p.x = p.lon; … … 18 15 } 19 16 20 @Override21 17 public void xy2latlon(GeoPoint p) { 22 18 p.lat = p.y; … … 28 24 return "EPSG:4263"; 29 25 } 30 31 @Override32 public JComponent getConfigurationPanel() {33 return null;34 }35 36 @Override37 public void commitConfigurationPanel() {38 }39 26 } -
src/org/openstreetmap/josm/data/projection/Mercator.java
r39 r43 1 1 package org.openstreetmap.josm.data.projection; 2 3 import javax.swing.JComponent;4 2 5 3 import org.openstreetmap.josm.data.GeoPoint; … … 14 12 * @author imi 15 13 */ 16 public class Mercator extends Projection {14 public class Mercator implements Projection { 17 15 18 @Override19 16 public void latlon2xy(GeoPoint p) { 20 17 p.x = p.lon*Math.PI/180; … … 22 19 } 23 20 24 @Override25 21 public void xy2latlon(GeoPoint p) { 26 22 p.lon = p.x*180/Math.PI; … … 32 28 return "Mercator"; 33 29 } 34 35 @Override36 public JComponent getConfigurationPanel() {37 return null;38 }39 40 @Override41 public void commitConfigurationPanel() {42 }43 30 } -
src/org/openstreetmap/josm/data/projection/Projection.java
r41 r43 1 1 package org.openstreetmap.josm.data.projection; 2 2 3 import java.util.LinkedList;4 import java.util.List;5 6 import javax.swing.JComponent;7 import javax.swing.event.ChangeEvent;8 import javax.swing.event.ChangeListener;9 10 import org.openstreetmap.josm.data.Bounds;11 3 import org.openstreetmap.josm.data.GeoPoint; 12 4 … … 17 9 * @author imi 18 10 */ 19 abstract public class Projection implements Cloneable{11 public interface Projection { 20 12 21 13 public static double MAX_LAT = 85; 22 14 public static double MAX_LON = 180; 23 24 /**25 * The event list with all state chaned listener26 */27 List<ChangeListener> listener = new LinkedList<ChangeListener>();28 15 29 16 /** … … 32 19 * @param p The geo point to convert. x/y members of the point are filled. 33 20 */ 34 abstract publicvoid latlon2xy(GeoPoint p);21 void latlon2xy(GeoPoint p); 35 22 36 23 /** … … 39 26 * @param p The geo point to convert. lat/lon members of the point are filled. 40 27 */ 41 abstract publicvoid xy2latlon(GeoPoint p);28 void xy2latlon(GeoPoint p); 42 29 43 30 … … 47 34 * Describe the projection converter in one or two words. 48 35 */ 49 @Override 50 abstract public String toString(); 51 52 // miscellous functions 53 54 /** 55 * If the projection supports any configuration, this function return 56 * the configuration panel. If no configuration needed, 57 * return <code>null</code>. 58 * 59 * The items on the configuration panel should not update the configuration 60 * directly, but remember changed settings so a call to commitConfigurationPanel 61 * can set them. 62 * 63 * This function also rolls back all changes to the configuration panel interna 64 * components. 65 */ 66 abstract public JComponent getConfigurationPanel(); 67 /** 68 * Commits any changes from components created by addToConfigurationPanel. 69 * The projection should now obtain the new settings. If any setting has 70 * changed, the implementation have to call to fireStateChanged to inform 71 * the listeners. 72 */ 73 abstract public void commitConfigurationPanel(); 74 75 /** 76 * Initialize itself with the given bounding rectangle (regarding lat/lon). 77 * 78 * This function should initialize own parameters needed to do the 79 * projection at best effort. 80 * 81 * Init must not fire an state changed event, since it is usually called 82 * during the initialization of the mapFrame. 83 * 84 * This implementation does nothing. It is provided only for subclasses 85 * to initialize their data members. 86 */ 87 public void init(Bounds b) {} 88 89 /** 90 * Add an event listener to the state changed event queue. If passed 91 * <code>null</code>, nothing happens. 92 */ 93 public final void addChangeListener(ChangeListener l) { 94 if (l != null) 95 listener.add(l); 96 } 97 /** 98 * Remove an event listener from the event queue. If passed 99 * <code>null</code>, nothing happens. 100 */ 101 public final void removeChangeListener(ChangeListener l) { 102 listener.remove(l); 103 } 104 /** 105 * Fire an ChangeEvent to every listener on the queue. 106 */ 107 public final void fireStateChanged() { 108 ChangeEvent e = null; 109 for(ChangeListener l : listener) { 110 if (e == null) 111 e = new ChangeEvent(this); 112 l.stateChanged(e); 113 } 114 } 36 String toString(); 115 37 } -
src/org/openstreetmap/josm/gui/MapView.java
r42 r43 20 20 import org.openstreetmap.josm.data.GeoPoint; 21 21 import org.openstreetmap.josm.data.osm.DataSet; 22 import org.openstreetmap.josm.data.osm.Node;23 22 import org.openstreetmap.josm.data.projection.Projection; 24 23 import org.openstreetmap.josm.gui.layer.Layer; … … 97 96 */ 98 97 public void addLayer(Layer layer) { 99 // initialize the projection if it is the first layer100 if (layers.isEmpty())101 getProjection().init(layer.getBoundsLatLon());102 103 98 // reinitialize layer's data 104 99 layer.init(getProjection()); … … 339 334 // reset all datasets. 340 335 Projection p = getProjection(); 341 for ( Node n : Main.main.ds.nodes)342 p.latlon2xy(n.coor);336 for (Layer l : layers) 337 l.init(p); 343 338 recalculateCenterScale(); 344 339 } … … 351 346 */ 352 347 public void propertyChange(PropertyChangeEvent evt) { 353 if (!evt.getPropertyName().equals("projection")) 354 return; 355 if (evt.getOldValue() != null) 356 ((Projection)evt.getOldValue()).removeChangeListener(this); 357 if (evt.getNewValue() != null) { 358 Projection p = (Projection)evt.getNewValue(); 359 p.addChangeListener(this); 360 348 if (evt.getPropertyName().equals("projection")) 361 349 stateChanged(new ChangeEvent(this)); 362 }363 350 } 364 351 } -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r38 r43 15 15 import javax.swing.JCheckBox; 16 16 import javax.swing.JComboBox; 17 import javax.swing.JComponent;18 17 import javax.swing.JDialog; 19 18 import javax.swing.JLabel; … … 51 50 public void actionPerformed(ActionEvent e) { 52 51 Main.pref.laf = (LookAndFeelInfo)lafCombo.getSelectedItem(); 53 Projection projection = (Projection)projectionCombo.getSelectedItem(); 54 projection.commitConfigurationPanel(); 55 Main.pref.setProjection(projection); 52 Main.pref.setProjection((Projection)projectionCombo.getSelectedItem()); 56 53 Main.pref.osmDataServer = osmDataServer.getText(); 57 54 Main.pref.osmDataUsername = osmDataUsername.getText(); … … 99 96 * Combobox with all projections available 100 97 */ 101 JComboBox projectionCombo = new JComboBox(Preferences.allProjections .clone());98 JComboBox projectionCombo = new JComboBox(Preferences.allProjections); 102 99 /** 103 100 * The main tab panel. … … 160 157 } 161 158 } 162 JButton projectionDetail = new JButton("Configure");163 projectionDetail.addActionListener(new ActionListener(){164 public void actionPerformed(ActionEvent e) {165 Projection p = (Projection)projectionCombo.getSelectedItem();166 JComponent configurationPanel = p.getConfigurationPanel();167 if (configurationPanel == null) {168 JOptionPane.showMessageDialog(PreferenceDialog.this,169 "This projection does not need any configuration.");170 return;171 }172 JPanel detail = new JPanel(new GridBagLayout());173 detail.setLayout(new GridBagLayout());174 detail.add(configurationPanel, GBC.eop().fill());175 int result = JOptionPane.showConfirmDialog(176 PreferenceDialog.this, detail, "Configuration of "+p,177 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);178 if (result != JOptionPane.OK_OPTION)179 p.getConfigurationPanel(); // rollback180 }181 });182 159 183 160 // drawRawGpsLines … … 242 219 map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 243 220 map.add(projectionCombo, GBC.eol().fill(GBC.HORIZONTAL).insets(0,0,0,5)); 244 map.add(new JLabel("Projection details:"), GBC.std());245 map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));246 map.add(projectionDetail, GBC.eop());247 221 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 248 222 -
src/org/openstreetmap/josm/gui/WorldChooser.java
r42 r43 13 13 14 14 import javax.swing.ImageIcon; 15 import javax.swing.JComponent;16 15 import javax.swing.JTextField; 17 16 import javax.swing.SwingUtilities; … … 63 62 new MapMover(this); 64 63 projection = new Projection(){ 65 @Override66 64 public void latlon2xy(GeoPoint p) { 67 65 p.x = (p.lon+180) / 360 * world.getIconWidth(); 68 66 p.y = (p.lat+90) / 180 * world.getIconHeight(); 69 67 } 70 @Override71 68 public void xy2latlon(GeoPoint p) { 72 69 p.lon = p.x*360/world.getIconWidth() - 180; … … 76 73 public String toString() { 77 74 return "WorldChooser"; 78 }79 @Override80 public JComponent getConfigurationPanel() {81 return null;82 }83 @Override84 public void commitConfigurationPanel() {85 75 } 86 76 }; -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r41 r43 8 8 import java.net.HttpURLConnection; 9 9 import java.net.URL; 10 import java.net.UnknownHostException; 10 11 import java.util.Collection; 12 import java.util.HashMap; 11 13 12 14 import org.jdom.Document; … … 56 58 * Upload a single node. 57 59 */ 58 @SuppressWarnings("unchecked")59 60 public void visit(Node n) { 60 61 if (n.id == 0 && !n.isDeleted()) { 62 setCredits(n); 61 63 sendRequest("PUT", "newnode", n, true); 62 64 } else if (n.isDeleted()) { … … 67 69 } 68 70 71 /** 72 * Upload a line segment (without the nodes). 73 */ 69 74 public void visit(LineSegment ls) { 70 75 if (ls.id == 0 && !ls.isDeleted()) { 76 setCredits(ls); 71 77 sendRequest("PUT", "newsegment", ls, true); 72 78 } else if (ls.isDeleted()) { … … 75 81 sendRequest("PUT", "segment/" + ls.id, ls, true); 76 82 } 83 } 84 85 /** 86 * Add the created_by - property to indicate that JOSM was the 87 * creating application. 88 * @param osm The primitive to add the credits to 89 */ 90 private void setCredits(OsmPrimitive osm) { 91 if (osm.keys == null) 92 osm.keys = new HashMap<Key, String>(); 93 osm.keys.put(Key.get("created_by"), "JOSM"); 77 94 } 78 95 … … 130 147 osm.id = readId(con.getInputStream()); 131 148 con.disconnect(); 149 } catch (UnknownHostException e) { 150 throw new RuntimeException("Unknown host: "+e.getMessage(), e); 132 151 } catch (Exception e) { 133 152 throw new RuntimeException(e.getMessage(), e);
Note:
See TracChangeset
for help on using the changeset viewer.