Changeset 61 in josm for src/org/openstreetmap
- Timestamp:
- 2006-03-15T23:16:04+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/DownloadAction.java
r58 r61 32 32 import org.openstreetmap.josm.data.Bounds; 33 33 import org.openstreetmap.josm.data.GeoPoint; 34 import org.openstreetmap.josm.data.Preferences.PreferencesException; 34 35 import org.openstreetmap.josm.data.osm.DataSet; 35 36 import org.openstreetmap.josm.gui.BookmarkList; … … 55 56 public class DownloadAction extends JosmAction { 56 57 58 private enum DownloadStatus {FINISHED, REDISPLAY} 59 57 60 JTextField[] latlon = new JTextField[]{ 58 61 new JTextField(9), … … 68 71 69 72 public void actionPerformed(ActionEvent e) { 73 74 //TODO: Remove this in later versions (temporary only) 75 if (Main.pref.osmDataServer.endsWith("/0.2") || Main.pref.osmDataServer.endsWith("/0.2/")) { 76 int answer = JOptionPane.showConfirmDialog(Main.main, 77 "You seem to have an outdated server entry in your preferences.\n" + 78 "\n" + 79 "As of JOSM Release 1.2, you must no longer specify the API version in\n" + 80 "the osm url. For the OSM standard server, use http://www.openstreetmap.org/api" + 81 "\n" + 82 "Fix settings and continue?", "Outdated server url detected.", JOptionPane.YES_NO_OPTION); 83 if (answer != JOptionPane.YES_OPTION) 84 return; 85 int cutPos = Main.pref.osmDataServer.endsWith("/0.2") ? 4 : 5; 86 Main.pref.osmDataServer = Main.pref.osmDataServer.substring(0, Main.pref.osmDataServer.length()-cutPos); 87 try { 88 Main.pref.save(); 89 } catch (PreferencesException x) { 90 x.printStackTrace(); 91 JOptionPane.showMessageDialog(Main.main, "Could not save the preferences chane:\n" + 92 x.getMessage()); 93 } 94 } 95 70 96 JPanel dlg = new JPanel(new GridBagLayout()); 71 97 … … 208 234 209 235 // Finally: the dialog 210 int r = JOptionPane.showConfirmDialog(Main.main, dlg, "Choose an area", 211 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 212 if (r != JOptionPane.OK_OPTION) 213 return; 214 215 startDownload(); 236 while(true) { 237 int r = JOptionPane.showConfirmDialog(Main.main, dlg, "Choose an area", 238 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 239 if (r != JOptionPane.OK_OPTION) 240 return; 241 if (startDownload() == DownloadStatus.FINISHED) 242 break; 243 } 216 244 } 217 245 … … 219 247 * Read the values from the edit fields and start the download. 220 248 */ 221 private voidstartDownload() {249 private DownloadStatus startDownload() { 222 250 Bookmark b = readBookmark(); 223 251 if (b == null) { 224 252 JOptionPane.showMessageDialog(Main.main, "Please enter the desired coordinates or click on a bookmark."); 225 return ;226 } 227 253 return DownloadStatus.REDISPLAY; 254 } 255 228 256 final OsmServerReader osmReader = new OsmServerReader(b.latlon[0], b.latlon[1], b.latlon[2], b.latlon[3]); 229 257 new Thread(new PleaseWaitRunnable("Downloading data"){ … … 275 303 } 276 304 }).start(); 305 return DownloadStatus.FINISHED; 277 306 } 278 307 -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r58 r61 1 1 package org.openstreetmap.josm.actions.mapmode; 2 2 3 import java.awt.Rectangle;4 3 import java.awt.event.ActionEvent; 5 4 import java.awt.event.KeyEvent; … … 7 6 import java.util.Iterator; 8 7 import java.util.LinkedList; 8 9 import javax.swing.JOptionPane; 9 10 10 11 import org.openstreetmap.josm.Main; … … 14 15 import org.openstreetmap.josm.data.osm.Track; 15 16 import org.openstreetmap.josm.gui.MapFrame; 16 import org.openstreetmap.josm.gui.SelectionManager;17 import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;18 17 19 18 /** … … 34 33 * 35 34 */ 36 public class Add TrackAction extends MapMode implements SelectionEnded{35 public class AddWayAction extends MapMode { 37 36 38 /** 39 * The selection manager for this action, keeping track of all selections. 40 */ 41 SelectionManager selectionManager; 37 private MapMode followMode; 42 38 43 39 /** 44 * Create a new Add TrackAction.40 * Create a new AddWayAction. 45 41 * @param mapFrame The MapFrame this action belongs to. 42 * @param followMode The mode to go into when finished creating a way. 46 43 */ 47 public Add TrackAction(MapFrame mapFrame) {48 super("Add Way", "add track", "Combine line segments to a new way.", KeyEvent.VK_W, mapFrame);49 this. selectionManager = new SelectionManager(this, false, mv);44 public AddWayAction(MapFrame mapFrame, MapMode followMode) { 45 super("Add Way", "addway", "Combine line segments to a new way.", KeyEvent.VK_W, mapFrame); 46 this.followMode = followMode; 50 47 } 51 48 52 @Override53 public void registerListener() {54 super.registerListener();55 selectionManager.register(mv);56 }57 58 @Override59 public void unregisterListener() {60 super.unregisterListener();61 selectionManager.unregister(mv);62 }63 64 65 49 @Override 66 50 public void actionPerformed(ActionEvent e) { 67 51 makeTrack(); 68 52 super.actionPerformed(e); 69 } 70 71 /** 72 * If Shift is pressed, only add the selected line segments to the selection. 73 * If Ctrl is pressed, only remove the selected line segments from the selection. 74 * If both, Shift and Ctrl is pressed, do nothing. 75 * 76 * Else, form a new track out of all line segments in the selection and 77 * clear the selection afterwards. 78 * 79 * If Alt is pressed, consider all linesegments of all tracks a selected 80 * line segment is part of. Also consider all line segments that cross the 81 * selecting rectangle, instead only those that are fully within. 82 * 83 */ 84 public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) { 85 if (shift && ctrl) 86 return; // not allowed together 87 88 if (!ctrl && !shift) 89 Main.main.ds.clearSelection(); // new selection will replace the old. 90 91 Collection<OsmPrimitive> selectionList = selectionManager.getObjectsInRectangle(r,alt); 92 for (OsmPrimitive osm : selectionList) 93 osm.setSelected(!ctrl); 94 95 mv.repaint(); // from now on, the map has to be repainted. 96 97 if (ctrl || shift) 98 return; // no new track yet. 99 100 makeTrack(); 53 mapFrame.selectMapMode(followMode); 101 54 } 102 55 … … 111 64 // form a new track 112 65 LinkedList<LineSegment> lineSegments = new LinkedList<LineSegment>(); 66 int numberOfSelectedWays = 0; 113 67 for (OsmPrimitive osm : selection) { 114 68 if (osm instanceof Track) 115 lineSegments.addAll(((Track)osm).segments);69 numberOfSelectedWays++; 116 70 else if (osm instanceof LineSegment) 117 71 lineSegments.add((LineSegment)osm); 72 } 73 74 if (numberOfSelectedWays > 0) { 75 String ways = "way" + (numberOfSelectedWays==1?"":"s"); 76 int answer = JOptionPane.showConfirmDialog(Main.main, numberOfSelectedWays+" "+ways+" have been selected.\n" + 77 "Do you wish to select all segments belonging to the "+ways+" instead?"); 78 if (answer == JOptionPane.CANCEL_OPTION) 79 return; 80 if (answer == JOptionPane.YES_OPTION) { 81 for (OsmPrimitive osm : selection) 82 if (osm instanceof Track) 83 lineSegments.addAll(((Track)osm).segments); 84 } 118 85 } 119 86 -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r58 r61 145 145 keys.put(key, value); 146 146 } 147 148 public String get(Key key) { 149 return (keys == null) ? null : keys.get(key); 150 } 147 151 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r30 r61 17 17 import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction; 18 18 import org.openstreetmap.josm.actions.mapmode.AddNodeAction; 19 import org.openstreetmap.josm.actions.mapmode.Add TrackAction;19 import org.openstreetmap.josm.actions.mapmode.AddWayAction; 20 20 import org.openstreetmap.josm.actions.mapmode.DeleteAction; 21 21 import org.openstreetmap.josm.actions.mapmode.MapMode; … … 81 81 toolBarActions.setFloatable(false); 82 82 toolBarActions.add(new IconToggleButton(this, new ZoomAction(this))); 83 toolBarActions.add(new IconToggleButton(this, new SelectionAction(this))); 83 final SelectionAction selectionAction = new SelectionAction(this); 84 toolBarActions.add(new IconToggleButton(this, selectionAction)); 84 85 toolBarActions.add(new IconToggleButton(this, new MoveAction(this))); 85 86 toolBarActions.add(new IconToggleButton(this, new AddNodeAction(this))); 86 87 toolBarActions.add(new IconToggleButton(this, new AddLineSegmentAction(this))); 87 toolBarActions.add(new IconToggleButton(this, new Add TrackAction(this)));88 toolBarActions.add(new IconToggleButton(this, new AddWayAction(this, selectionAction))); 88 89 toolBarActions.add(new IconToggleButton(this, new DeleteAction(this))); 89 90 -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r39 r61 3 3 import java.awt.BorderLayout; 4 4 import java.awt.Dimension; 5 import java.awt.GridLayout; 5 6 import java.awt.event.ActionEvent; 6 7 import java.awt.event.ActionListener; … … 9 10 import java.awt.event.MouseEvent; 10 11 import java.util.Collection; 12 import java.util.Map.Entry; 11 13 12 14 import javax.swing.DefaultListModel; 13 15 import javax.swing.JButton; 14 16 import javax.swing.JList; 17 import javax.swing.JOptionPane; 18 import javax.swing.JPanel; 15 19 import javax.swing.JScrollPane; 16 20 import javax.swing.ListSelectionModel; … … 18 22 import org.openstreetmap.josm.Main; 19 23 import org.openstreetmap.josm.data.SelectionChangedListener; 24 import org.openstreetmap.josm.data.osm.Key; 20 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 26 import org.openstreetmap.josm.gui.ImageProvider; … … 61 66 add(new JScrollPane(displaylist), BorderLayout.CENTER); 62 67 68 JPanel buttonPanel = new JPanel(new GridLayout(1,2)); 69 63 70 JButton button = new JButton("Select", ImageProvider.get("mapmode", "selection")); 64 71 button.setToolTipText("Set the selected elements on the map to the selected items in the list above."); … … 68 75 } 69 76 }); 70 add(button, BorderLayout.SOUTH);77 buttonPanel.add(button); 71 78 79 button = new JButton("Search", ImageProvider.get("dialogs", "search")); 80 button.setToolTipText("Search for objects."); 81 button.addActionListener(new ActionListener(){ 82 public void actionPerformed(ActionEvent e) { 83 String search = JOptionPane.showInputDialog(Main.main, "Please enter a search string", "Search", JOptionPane.INFORMATION_MESSAGE); 84 if (search == null) 85 return; 86 Main.main.ds.clearSelection(); 87 for (OsmPrimitive osm : Main.main.ds.allNonDeletedPrimitives()) { 88 if (osm.keys != null) { 89 for (Entry<Key, String> ent : osm.keys.entrySet()) { 90 if (search.indexOf(ent.getKey().name) != -1 || search.indexOf(ent.getValue()) != -1) { 91 osm.setSelected(true); 92 break; 93 } 94 } 95 } 96 } 97 selectionChanged(Main.main.ds.getSelected()); 98 Main.main.getMapFrame().repaint(); 99 } 100 }); 101 buttonPanel.add(button); 102 103 add(buttonPanel, BorderLayout.SOUTH); 72 104 selectionChanged(Main.main.ds.getSelected()); 73 105 } -
src/org/openstreetmap/josm/io/OsmReader.java
r60 r61 16 16 import org.xml.sax.Attributes; 17 17 import org.xml.sax.SAXException; 18 import org.xml.sax.SAXParseException; 18 19 19 20 import uk.co.wilson.xml.MinML2; … … 93 94 readCommon(atts); 94 95 } else if (qName.equals("seg")) { 95 if (current instanceof Track) 96 ((Track)current).segments.add(lineSegments.get(getLong(atts, "id"))); 96 if (current instanceof Track) { 97 LineSegment ls = lineSegments.get(getLong(atts, "id")); 98 if (ls == null) 99 fatalError(new SAXParseException("Line segment "+getLong(atts, "id")+"has not been transfered before.", null)); 100 ((Track)current).segments.add(ls); 101 } 97 102 } else if (qName.equals("tag")) { 98 103 current.put(Key.get(atts.getValue("k")), atts.getValue("v")); … … 102 107 } catch (NullPointerException x) { 103 108 throw new SAXException("NullPointerException. Possible some missing tags.", x); 109 } 110 } 111 112 113 @Override 114 public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 115 if (qName.equals("node") || qName.equals("segment") || qName.equals("way") || qName.equals("area")) { 116 current.visit(adder); 104 117 } 105 118 } … … 122 135 } 123 136 124 @Override125 public void endElement(String namespaceURI, String localName, String qName) throws SAXException {126 if (qName.equals("node") || qName.equals("segment") || qName.equals("way") || qName.equals("area")) {127 current.visit(adder);128 }129 }130 131 137 private double getDouble(Attributes atts, String value) { 132 138 return Double.parseDouble(atts.getValue(value)); -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r58 r61 6 6 import java.io.InputStreamReader; 7 7 import java.io.OutputStreamWriter; 8 import java.io.StringWriter; 8 9 import java.io.Writer; 9 10 import java.net.HttpURLConnection; … … 166 167 OsmWriter.outputSingle(out, osm, true); 167 168 out.close(); 169 170 StringWriter o = new StringWriter(); 171 OsmWriter.outputSingle(o, osm, true); 172 System.out.println(o.getBuffer().toString()); 168 173 } 169 174 … … 172 177 osm.id = readId(con.getInputStream()); 173 178 System.out.println("got return: "+retCode+" with id "+osm.id); 179 String retMsg = con.getResponseMessage(); 174 180 con.disconnect(); 181 if (retCode != 200) 182 throw new RuntimeException(retCode+" "+retMsg); 175 183 } catch (UnknownHostException e) { 176 184 throw new RuntimeException("Unknown host: "+e.getMessage(), e); -
src/org/openstreetmap/josm/io/OsmWriter.java
r59 r61 13 13 import org.openstreetmap.josm.data.osm.Track; 14 14 import org.openstreetmap.josm.data.osm.visitor.Visitor; 15 import org.xml.sax.SAXException; 15 16 16 17 /** … … 20 21 */ 21 22 public class OsmWriter implements Visitor { 23 24 private class RuntimeEncodingException extends RuntimeException { 25 public RuntimeEncodingException(Throwable t) { 26 super(t); 27 } 28 public RuntimeEncodingException() { 29 } 30 } 22 31 23 32 /** … … 38 47 private final boolean osmConform; 39 48 49 private final static HashMap<Character, String> encoding = new HashMap<Character, String>(); 50 static { 51 encoding.put('<', "<"); 52 encoding.put('>', ">"); 53 encoding.put('"', """); 54 encoding.put('\'', "'"); 55 encoding.put('&', "&"); 56 encoding.put('\n', "
"); 57 encoding.put('\r', "
"); 58 encoding.put('\t', "	"); 59 } 60 40 61 /** 41 62 * Output the data to the stream … … 46 67 public static void output(Writer out, DataSet ds, boolean osmConform) { 47 68 OsmWriter writer = new OsmWriter(out, osmConform); 69 writer.out.println("<?xml version='1.0' encoding='UTF-8'?>"); 48 70 writer.out.println("<osm version='0.3' generator='JOSM'>"); 49 71 for (Node n : ds.nodes) … … 56 78 } 57 79 58 public static void outputSingle(Writer out, OsmPrimitive osm, boolean osmConform) { 59 OsmWriter writer = new OsmWriter(out, osmConform); 60 writer.out.println("<osm version='0.3' generator='JOSM'>"); 61 osm.visit(writer); 62 writer.out.println("</osm>"); 80 public static void outputSingle(Writer out, OsmPrimitive osm, boolean osmConform) throws SAXException { 81 try { 82 OsmWriter writer = new OsmWriter(out, osmConform); 83 writer.out.println("<?xml version='1.0' encoding='UTF-8'?>"); 84 writer.out.println("<osm version='0.3' generator='JOSM'>"); 85 osm.visit(writer); 86 writer.out.println("</osm>"); 87 } catch (RuntimeEncodingException e) { 88 throw new SAXException("Your Java installation does not support the required UTF-8 encoding", (Exception)e.getCause()); 89 } 63 90 } 64 91 65 92 private OsmWriter(Writer out, boolean osmConform) { 66 93 if (out instanceof PrintWriter) … … 70 97 this.osmConform = osmConform; 71 98 } 72 99 73 100 public void visit(Node n) { 74 101 addCommon(n, "node"); … … 112 139 out.println(">"); 113 140 for (Entry<Key, String> e : osm.keys.entrySet()) 114 out.println(" <tag k='"+e.getKey().name+"' v='"+e.getValue()+"' />"); 115 out.println(" </"+tagname+">"); 141 out.println(" <tag k='"+ encode(e.getKey().name) + 142 "' v='"+encode(e.getValue())+ "' />"); 143 out.println(" </" + tagname + ">"); 116 144 } else if (tagOpen) 117 145 out.println(" />"); 118 146 else 119 out.println(" </" +tagname+">");147 out.println(" </" + tagname + ">"); 120 148 } 149 150 /** 151 * Encode the given string in XML1.0 format. 152 * Optimized to fast pass strings that don't need encoding (normal case). 153 */ 154 public String encode(String unencoded) { 155 StringBuilder buffer = null; 156 for (int i = 0; i < unencoded.length(); ++i) { 157 String encS = encoding.get(unencoded.charAt(i)); 158 if (encS != null) { 159 if (buffer == null) 160 buffer = new StringBuilder(unencoded.substring(0,i)); 161 buffer.append(encS); 162 } else if (buffer != null) 163 buffer.append(unencoded.charAt(i)); 164 } 165 return (buffer == null) ? unencoded : buffer.toString(); 166 } 167 121 168 122 169 /** … … 140 187 } 141 188 } 142
Note:
See TracChangeset
for help on using the changeset viewer.