Changeset 24 in josm
- Timestamp:
- 2005-10-28T17:06:06+02:00 (19 years ago)
- Files:
-
- 4 added
- 12 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r23 r24 19 19 import org.openstreetmap.josm.actions.OpenOsmServerAction; 20 20 import org.openstreetmap.josm.actions.PreferencesAction; 21 import org.openstreetmap.josm.actions.SaveAction; 21 22 import org.openstreetmap.josm.actions.SaveGpxAction; 22 23 import org.openstreetmap.josm.data.Preferences; … … 76 77 OpenOsmServerAction openServerAction = new OpenOsmServerAction(); 77 78 OpenGpxAction openGpxAction = new OpenGpxAction(); 79 SaveAction saveAction = new SaveAction(); 78 80 SaveGpxAction saveGpxAction = new SaveGpxAction(); 79 81 ExitAction exitAction = new ExitAction(); … … 88 90 fileMenu.setMnemonic('F'); 89 91 fileMenu.add(openGpxAction); 92 fileMenu.add(saveAction); 90 93 fileMenu.add(saveGpxAction); 91 94 fileMenu.addSeparator(); … … 114 117 toolBar.add(openServerAction); 115 118 toolBar.add(openGpxAction); 119 toolBar.add(saveAction); 116 120 toolBar.add(saveGpxAction); 117 121 toolBar.addSeparator(); -
src/org/openstreetmap/josm/actions/AboutAction.java
r21 r24 5 5 import java.awt.GridBagLayout; 6 6 import java.awt.event.ActionEvent; 7 import java.awt.event.InputEvent; 7 8 import java.awt.event.KeyEvent; 8 9 import java.io.BufferedReader; … … 21 22 import javax.swing.JTabbedPane; 22 23 import javax.swing.JTextArea; 24 import javax.swing.KeyStroke; 23 25 import javax.swing.event.HyperlinkEvent; 24 26 import javax.swing.event.HyperlinkListener; -
src/org/openstreetmap/josm/actions/OpenGpxAction.java
r23 r24 3 3 import java.awt.GridBagLayout; 4 4 import java.awt.event.ActionEvent; 5 import java.awt.event.InputEvent; 5 6 import java.awt.event.KeyEvent; 6 7 import java.io.File; … … 16 17 import javax.swing.JOptionPane; 17 18 import javax.swing.JPanel; 19 import javax.swing.KeyStroke; 18 20 import javax.swing.filechooser.FileFilter; 19 21 … … 45 47 public OpenGpxAction() { 46 48 super("Open GPX", ImageProvider.get("opengpx")); 49 putValue(ACCELERATOR_KEY, KeyStroke.getAWTKeyStroke(KeyEvent.VK_O, 50 InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); 47 51 putValue(MNEMONIC_KEY, KeyEvent.VK_O); 48 52 putValue(SHORT_DESCRIPTION, "Open a file in GPX format."); -
src/org/openstreetmap/josm/actions/OpenOsmServerAction.java
r23 r24 35 35 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 36 36 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer; 37 import org.openstreetmap.josm.io.Osm Reader;37 import org.openstreetmap.josm.io.OsmServerReader; 38 38 39 39 /** … … 147 147 return; 148 148 } 149 Osm Reader osmReader = new OsmReader(Main.pref.osmDataServer,149 OsmServerReader osmReader = new OsmServerReader(Main.pref.osmDataServer, 150 150 b.latlon[0], b.latlon[1], b.latlon[2], b.latlon[3]); 151 151 try { -
src/org/openstreetmap/josm/actions/PreferencesAction.java
r17 r24 2 2 3 3 import java.awt.event.ActionEvent; 4 import java.awt.event.InputEvent; 4 5 import java.awt.event.KeyEvent; 5 6 6 7 import javax.swing.AbstractAction; 8 import javax.swing.KeyStroke; 7 9 8 10 import org.openstreetmap.josm.gui.ImageProvider; … … 21 23 public PreferencesAction() { 22 24 super("Preferences", ImageProvider.get("preference")); 25 putValue(ACCELERATOR_KEY, KeyStroke.getAWTKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK)); 23 26 putValue(MNEMONIC_KEY, KeyEvent.VK_P); 24 27 putValue(SHORT_DESCRIPTION, "Open a preferences page for global settings."); -
src/org/openstreetmap/josm/actions/SaveGpxAction.java
r22 r24 2 2 3 3 import java.awt.event.ActionEvent; 4 import java.awt.event.InputEvent; 4 5 import java.awt.event.KeyEvent; 5 6 import java.io.File; … … 10 11 import javax.swing.JFileChooser; 11 12 import javax.swing.JOptionPane; 13 import javax.swing.KeyStroke; 12 14 13 15 import org.openstreetmap.josm.Main; … … 29 31 public SaveGpxAction() { 30 32 super("Save GPX", ImageProvider.get("savegpx")); 33 putValue(ACCELERATOR_KEY, KeyStroke.getAWTKeyStroke(KeyEvent.VK_S, 34 InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)); 31 35 putValue(MNEMONIC_KEY, KeyEvent.VK_S); 32 putValue(SHORT_DESCRIPTION, " Save the current active layeras GPX file.");36 putValue(SHORT_DESCRIPTION, "Export the current data as GPX file."); 33 37 } 34 38 35 @SuppressWarnings("unchecked")36 39 public void actionPerformed(ActionEvent event) { 37 40 if (Main.main.getMapFrame() == null) { -
src/org/openstreetmap/josm/actions/mapmode/AddLineSegmentAction.java
r23 r24 54 54 */ 55 55 public AddLineSegmentAction(MapFrame mapFrame) { 56 super("Add Line Segment", "addlinesegment", "Add a line segment between two nodes.", KeyEvent.VK_ L, mapFrame);56 super("Add Line Segment", "addlinesegment", "Add a line segment between two nodes.", KeyEvent.VK_G, mapFrame); 57 57 } 58 58 -
src/org/openstreetmap/josm/data/osm/Key.java
r23 r24 22 22 * All keys are stored here. 23 23 */ 24 p rivate staticMap<String, Key> allKeys = new HashMap<String, Key>();24 public static final Map<String, Key> allKeys = new HashMap<String, Key>(); 25 25 26 26 /** … … 51 51 visitor.visit(this); 52 52 } 53 54 @Override 55 public String toString() { 56 return name; 57 } 53 58 } -
src/org/openstreetmap/josm/gui/MapView.java
r23 r24 406 406 if (bounds == null) 407 407 bounds = l.getBoundsXY(); 408 else 409 bounds = bounds.mergeXY(l.getBoundsXY()); 408 else { 409 Bounds lb = l.getBoundsXY(); 410 if (lb != null) 411 bounds = bounds.mergeXY(lb); 412 } 410 413 } 411 414 -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r21 r24 1 1 package org.openstreetmap.josm.gui.dialogs; 2 2 3 import java.awt.BorderLayout; 4 import java.awt.Component; 5 import java.awt.Font; 6 import java.awt.GridLayout; 7 import java.awt.event.ActionEvent; 8 import java.awt.event.ActionListener; 3 9 import java.awt.event.KeyEvent; 4 5 import javax.swing.BorderFactory; 6 import javax.swing.Box; 10 import java.awt.event.MouseAdapter; 11 import java.awt.event.MouseEvent; 12 import java.awt.event.WindowEvent; 13 import java.awt.event.WindowFocusListener; 14 import java.util.Collection; 15 import java.util.Iterator; 16 import java.util.TreeMap; 17 import java.util.TreeSet; 18 import java.util.Vector; 19 import java.util.Map.Entry; 20 21 import javax.swing.JButton; 22 import javax.swing.JComboBox; 23 import javax.swing.JDialog; 7 24 import javax.swing.JLabel; 8 import javax.swing.border.Border; 25 import javax.swing.JOptionPane; 26 import javax.swing.JPanel; 27 import javax.swing.JScrollPane; 28 import javax.swing.JTable; 29 import javax.swing.JTextField; 30 import javax.swing.ListSelectionModel; 31 import javax.swing.table.DefaultTableCellRenderer; 32 import javax.swing.table.DefaultTableModel; 9 33 10 34 import org.openstreetmap.josm.Main; 35 import org.openstreetmap.josm.command.ChangeKeyValueCommand; 36 import org.openstreetmap.josm.data.SelectionChangedListener; 37 import org.openstreetmap.josm.data.osm.Key; 38 import org.openstreetmap.josm.data.osm.OsmPrimitive; 39 import org.openstreetmap.josm.gui.ImageProvider; 11 40 import org.openstreetmap.josm.gui.MapFrame; 41 import org.openstreetmap.josm.gui.MapView; 12 42 13 43 /** 14 * Open a Property dialog for the current visible map. When saving to own josm- 15 * data format, the properties are saved along. 44 * This dialog displays the properties of the current selected primitives. 45 * 46 * If no object is selected, the dialog list is empty. 47 * If only one is selected, all properties of this object are selected. 48 * If more than one object are selected, the sum of all properties are displayed. If the 49 * different objects share the same property, the shared value is displayed. If they have 50 * different values, all of them are put in a combo box and the string "<different>" 51 * is displayed in italic. 52 * 53 * Below the list, the user can click on an add, modify and delete property button to 54 * edit the table selection value. 55 * 56 * The command is applied to all selected entries. 16 57 * 17 58 * @author imi 18 59 */ 19 public class PropertiesDialog extends ToggleDialog { 20 60 public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener { 61 62 /** 63 * Watches for double clicks and start editing or new property, depending on the 64 * location, the click was. 65 * @author imi 66 */ 67 public class DblClickWatch extends MouseAdapter { 68 @Override 69 public void mouseClicked(MouseEvent e) { 70 if (e.getClickCount() < 2) 71 return; 72 if (e.getSource() instanceof JScrollPane) 73 add(); 74 else { 75 int row = propertyTable.rowAtPoint(e.getPoint()); 76 edit(row); 77 } 78 } 79 } 80 81 /** 82 * Edit the value in the table row 83 * @param row The row of the table, from which the value is edited. 84 */ 85 void edit(int row) { 86 String key = data.getValueAt(row, 0).toString(); 87 Collection<OsmPrimitive> sel = Main.main.ds.getSelected(); 88 String msg = "<html>This will change "+sel.size()+" object"+(sel.size()==1?"":"s")+".<br><br>"+ 89 "Please select a new value for '"+key+"'.<br>(Empty string deletes the key.)"; 90 final JComboBox combo = (JComboBox)data.getValueAt(row, 1); 91 JPanel p = new JPanel(new BorderLayout()); 92 p.add(new JLabel(msg+"</html>"), BorderLayout.NORTH); 93 p.add(combo, BorderLayout.CENTER); 94 95 final JOptionPane optionPane = new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 96 final JDialog dlg = optionPane.createDialog(PropertiesDialog.this, "Change values?"); 97 dlg.addWindowFocusListener(new WindowFocusListener(){ 98 public void windowGainedFocus(WindowEvent e) { 99 combo.requestFocusInWindow(); 100 } 101 public void windowLostFocus(WindowEvent e) { 102 } 103 }); 104 combo.getEditor().addActionListener(new ActionListener(){ 105 public void actionPerformed(ActionEvent e) { 106 optionPane.setValue(JOptionPane.OK_OPTION); 107 dlg.setVisible(false); 108 } 109 }); 110 dlg.setVisible(true); 111 112 Object answer = optionPane.getValue(); 113 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE || 114 (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION)) 115 return; 116 117 String value = combo.getEditor().getItem().toString(); 118 if (value.equals("<different>")) 119 return; 120 if (value.equals("")) 121 value = null; // delete the key 122 mv.editLayer().add(new ChangeKeyValueCommand(sel, Key.get(key), value)); 123 124 if (value == null) 125 selectionChanged(sel); // update whole table 126 else 127 PropertiesDialog.this.repaint(); // repaint is enough 128 } 129 130 /** 131 * Open the add selection dialog and add a new key/value to the table (and to the 132 * dataset, of course). 133 */ 134 void add() { 135 Collection<OsmPrimitive> sel = Main.main.ds.getSelected(); 136 137 JPanel p = new JPanel(new BorderLayout()); 138 p.add(new JLabel("<html>This will change "+sel.size()+" object"+(sel.size()==1?"":"s")+".<br><br>"+ 139 "Please select a key"), BorderLayout.NORTH); 140 Vector<String> allKeys = new Vector<String>(Key.allKeys.keySet()); 141 for (Iterator<String> it = allKeys.iterator(); it.hasNext();) { 142 String s = it.next(); 143 for (int i = 0; i < data.getRowCount(); ++i) { 144 if (s.equals(data.getValueAt(i, 0))) { 145 it.remove(); 146 break; 147 } 148 } 149 } 150 JComboBox keys = new JComboBox(allKeys); 151 keys.setEditable(true); 152 p.add(keys, BorderLayout.CENTER); 153 154 JPanel p2 = new JPanel(new BorderLayout()); 155 p.add(p2, BorderLayout.SOUTH); 156 p2.add(new JLabel("Please select a value"), BorderLayout.NORTH); 157 JTextField values = new JTextField(); 158 p2.add(values, BorderLayout.CENTER); 159 int answer = JOptionPane.showConfirmDialog(PropertiesDialog.this, p, 160 "Change values?", JOptionPane.OK_CANCEL_OPTION); 161 if (answer != JOptionPane.OK_OPTION) 162 return; 163 String key = keys.getEditor().getItem().toString(); 164 String value = values.getText(); 165 if (value.equals("")) 166 return; 167 mv.editLayer().add(new ChangeKeyValueCommand(sel, Key.get(key), value)); 168 selectionChanged(sel); // update table 169 } 170 171 /** 172 * Delete the keys from the given row. 173 * @param row The row, which key gets deleted from the dataset. 174 */ 175 private void delete(int row) { 176 String key = data.getValueAt(row, 0).toString(); 177 Collection<OsmPrimitive> sel = Main.main.ds.getSelected(); 178 mv.editLayer().add(new ChangeKeyValueCommand(sel, Key.get(key), null)); 179 selectionChanged(sel); // update table 180 } 181 182 /** 183 * The property data. 184 */ 185 private final DefaultTableModel data = new DefaultTableModel(){ 186 @Override 187 public boolean isCellEditable(int row, int column) { 188 return false; 189 } 190 @Override 191 public Class<?> getColumnClass(int columnIndex) { 192 return columnIndex == 1 ? JComboBox.class : String.class; 193 } 194 }; 195 /** 196 * The properties list. 197 */ 198 private final JTable propertyTable = new JTable(data); 199 /** 200 * The map view this dialog operates on. 201 */ 202 private final MapView mv; 203 21 204 /** 22 205 * Create a new PropertiesDialog 23 206 */ 24 207 public PropertiesDialog(MapFrame mapFrame) { 25 super(mapFrame, "Properties of "+Main.main.getNameOfLoadedMapFrame(), "Properties Dialog", "properties", KeyEvent.VK_P, "Property page for this map.");26 putValue(MNEMONIC_KEY, KeyEvent.VK_P);27 28 final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0);29 Box panel = Box.createVerticalBox();208 super(mapFrame, "Properties", "Properties Dialog", "properties", KeyEvent.VK_P, "Property for selected objects."); 209 mv = mapFrame.mapView; 210 211 setLayout(new BorderLayout()); 212 setSize(350,450); 30 213 31 JLabel todo = new JLabel("Nothing implemented yet."); 32 todo.setBorder(panelBorder); 33 panel.add(todo); 214 data.setColumnIdentifiers(new String[]{"Key", "Value"}); 215 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 216 propertyTable.setDefaultRenderer(JComboBox.class, new DefaultTableCellRenderer(){ 217 @Override 218 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 219 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 220 if (c instanceof JLabel) { 221 String str = ((JComboBox)value).getEditor().getItem().toString(); 222 ((JLabel)c).setText(str); 223 if (str.equals("<different>")) 224 c.setFont(c.getFont().deriveFont(Font.ITALIC)); 225 } 226 return c; 227 } 228 }); 229 propertyTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer(){ 230 @Override 231 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 232 return super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 233 } 234 }); 235 propertyTable.addMouseListener(new DblClickWatch()); 236 237 JScrollPane scrollPane = new JScrollPane(propertyTable); 238 scrollPane.addMouseListener(new DblClickWatch()); 239 getContentPane().add(scrollPane, BorderLayout.CENTER); 34 240 35 panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 36 setContentPane(panel); 37 pack(); 38 setResizable(false); 241 JPanel buttonPanel = new JPanel(new GridLayout(1,3)); 242 ActionListener buttonAction = new ActionListener(){ 243 public void actionPerformed(ActionEvent e) { 244 int sel = propertyTable.getSelectedRow(); 245 if (e.getActionCommand().equals("Add")) 246 add(); 247 else if (e.getActionCommand().equals("Edit")) { 248 if (sel == -1) 249 JOptionPane.showMessageDialog(PropertiesDialog.this, "Please select the row to edit."); 250 else 251 edit(sel); 252 } else if (e.getActionCommand().equals("Delete")) { 253 if (sel == -1) 254 JOptionPane.showMessageDialog(PropertiesDialog.this, "Please select the row to delete."); 255 else 256 delete(sel); 257 } 258 } 259 }; 260 buttonPanel.add(createButton("Add", "Add a new key/value pair to all objects", KeyEvent.VK_A, buttonAction)); 261 buttonPanel.add(createButton("Edit", "Edit the value of the selected key for all objects", KeyEvent.VK_E, buttonAction)); 262 buttonPanel.add(createButton("Delete", "Delete the selected key in all objects", KeyEvent.VK_DELETE, buttonAction)); 263 getContentPane().add(buttonPanel, BorderLayout.SOUTH); 264 } 265 266 private JButton createButton(String name, String tooltip, int mnemonic, ActionListener actionListener) { 267 JButton b = new JButton(name, ImageProvider.get("dialogs", name.toLowerCase())); 268 b.setActionCommand(name); 269 b.addActionListener(actionListener); 270 b.setToolTipText(tooltip); 271 b.setMnemonic(mnemonic); 272 return b; 273 } 274 275 @Override 276 public void setVisible(boolean b) { 277 if (b) { 278 Main.main.ds.addSelectionChangedListener(this); 279 selectionChanged(Main.main.ds.getSelected()); 280 } else { 281 Main.main.ds.removeSelectionChangedListener(this); 282 } 283 super.setVisible(b); 284 } 285 286 public void selectionChanged(Collection<OsmPrimitive> newSelection) { 287 if (propertyTable.getCellEditor() != null) 288 propertyTable.getCellEditor().cancelCellEditing(); 289 data.setRowCount(0); 290 TreeMap<String, Collection<String>> props = new TreeMap<String, Collection<String>>(); 291 for (OsmPrimitive osm : newSelection) { 292 if (osm.keys != null) { 293 for (Entry<Key, String> e : osm.keys.entrySet()) { 294 Collection<String> value = props.get(e.getKey().name); 295 if (value == null) { 296 value = new TreeSet<String>(); 297 props.put(e.getKey().name, value); 298 } 299 value.add(e.getValue()); 300 } 301 } 302 } 303 for (Entry<String, Collection<String>> e : props.entrySet()) { 304 JComboBox value = new JComboBox(e.getValue().toArray()); 305 value.setEditable(true); 306 if (e.getValue().size() > 1) 307 value.getEditor().setItem("<different>"); 308 data.addRow(new Object[]{e.getKey(), value}); 309 } 39 310 } 40 311 } -
src/org/openstreetmap/josm/io/GpxReader.java
r23 r24 40 40 */ 41 41 public Reader source; 42 42 43 43 /** 44 44 * Construct a parser from a specific data source. … … 132 132 } 133 133 } 134 } 135 136 if (child.getName().equals("extensions")) 134 } else if (child.getName().equals("extensions")) 137 135 parseKeyValueExtensions(track, child); 138 136 else if (child.getName().equals("link")) … … 157 155 * @return Either the parameter node or the old node found in the dataset. 158 156 */ 159 private Node addNode 157 private Node addNode(DataSet data, Node node) { 160 158 if (Main.pref.mergeNodes) 161 159 for (Node n : data.nodes) -
src/org/openstreetmap/josm/io/OsmServerReader.java
r23 r24 18 18 * @author imi 19 19 */ 20 public class Osm Reader extends OsmConnection {20 public class OsmServerReader extends OsmConnection { 21 21 22 22 /** … … 32 32 * Construct the reader and store the information for attaching 33 33 */ 34 public Osm Reader(String server,34 public OsmServerReader(String server, 35 35 double lat1, double lon1, double lat2, double lon2) { 36 36 this.lon2 = lon2; -
src/org/openstreetmap/josm/io/OsmWriter.java
r22 r24 2 2 3 3 import java.io.IOException; 4 import java.io.Writer; 4 5 import java.util.Collection; 6 import java.util.HashSet; 5 7 import java.util.LinkedList; 8 import java.util.List; 9 import java.util.Set; 10 import java.util.Map.Entry; 6 11 7 import javax.swing.JOptionPane; 8 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.command.Command; 12 import org.jdom.Document; 13 import org.jdom.Element; 14 import org.jdom.output.Format; 15 import org.jdom.output.XMLOutputter; 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Key; 18 import org.openstreetmap.josm.data.osm.LineSegment; 19 import org.openstreetmap.josm.data.osm.Node; 11 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 import org.openstreetmap.josm.data.osm.Track; 12 22 13 23 14 24 /** 15 * S end back the modified data to the osm server.25 * Save the dataset into a stream as osm intern xml format. 16 26 * @author imi 17 27 */ … … 19 29 20 30 /** 21 * The server base url to handle the osm requests.31 * The output writer to write the xml stream to. 22 32 */ 23 private final String server;33 private final Writer out; 24 34 /** 25 35 * The commands that should be uploaded on the server. 26 36 */ 27 private final Collection<Command> commands; 37 private DataSet ds; 38 /** 39 * ID generator start for all nodes with id==0 40 */ 41 private long id = 0; 42 /** 43 * A collection of all ids used so far to look up and jump over used ids. 44 */ 45 private Set<Long> ids; 46 47 public OsmWriter(Writer out, DataSet dataSet) { 48 this.out = out; 49 ds = dataSet; 50 } 28 51 29 public OsmWriter(String server, Collection<Command> commands) { 30 this.server = server; 31 this.commands = commands; 52 /** 53 * Output the data to the stream 54 * @throws IOException In case of stream IO errors. 55 */ 56 @SuppressWarnings("unchecked") 57 public void output() throws IOException { 58 ids = allUsedIds(); 59 Element root = new Element("osm"); 60 List<Element> list = root.getChildren(); 61 Collection<Element> properties = new LinkedList<Element>(); 62 for (Node n : ds.nodes) 63 list.add(parseNode(n, properties)); 64 for (LineSegment ls : ds.pendingLineSegments) 65 list.add(parseLineSegment(ls, properties)); 66 // all other line segments 67 Collection<LineSegment> lineSegments = new HashSet<LineSegment>(); 68 for (Track t : ds.tracks) 69 lineSegments.addAll(t.segments); 70 for (LineSegment ls : lineSegments) 71 list.add(parseLineSegment(ls, properties)); 72 for (Track t : ds.tracks) 73 list.add(parseTrack(t, properties)); 74 list.addAll(properties); 75 76 Document d = new Document(root); 77 XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); 78 xmlOut.output(d, out); 79 } 80 81 /** 82 * Create an track element. Add all properties of the node to the properties-list. 83 */ 84 @SuppressWarnings("unchecked") 85 private Element parseTrack(Track t, Collection<Element> properties) { 86 Element e = new Element("track"); 87 addProperties(e, t, properties); 88 for (LineSegment ls : t.segments) 89 e.getChildren().add(new Element("segment").setAttribute("id", ""+ls.id)); 90 return e; 91 } 92 93 /** 94 * Create an node element. Add all properties of the node to the properties-list. 95 */ 96 private Element parseNode(Node n, Collection<Element> properties) { 97 Element e = new Element("node"); 98 addProperties(e, n, properties); 99 e.setAttribute("lat", ""+n.coor.lat); 100 e.setAttribute("lon", ""+n.coor.lon); 101 return e; 102 } 103 104 105 106 /** 107 * Create an line segment element. Add all properties of the node to the properties-list. 108 */ 109 private Element parseLineSegment(LineSegment ls, Collection<Element> properties) { 110 Element e = new Element("segment"); 111 addProperties(e, ls, properties); 112 e.setAttribute("start", ""+ls.start.id); 113 e.setAttribute("end", ""+ls.end.id); 114 return e; 32 115 } 33 116 34 117 /** 35 * Upload the commands to the server. 36 * @throws IOException 118 * Create a properties element. 37 119 */ 38 public void output() throws IOException { 39 Collection<OsmPrimitive> added = new LinkedList<OsmPrimitive>(); 40 Collection<OsmPrimitive> modified = new LinkedList<OsmPrimitive>(); 41 Collection<OsmPrimitive> deleted = new LinkedList<OsmPrimitive>(); 42 for (Command c : commands) 43 c.fillModifiedData(modified, deleted, added); 44 int answer = JOptionPane.showConfirmDialog(Main.main, "Send "+added.size()+" new, " 45 +modified.size()+" modified and "+deleted.size()+" deleted objects to server?"); 46 if (answer != JOptionPane.YES_OPTION) 47 return; 120 private Element parseProperty(OsmPrimitive osm, Entry<Key, String> entry) { 121 Element e = new Element("property"); 122 Key key = entry.getKey(); 123 if (key.id == 0) 124 key.id = generateId(); 125 e.setAttribute("id", ""+key.id); 126 e.setAttribute("object", ""+osm.id); 127 e.setAttribute("key", key.name); 128 e.setAttribute("value", entry.getValue()); 129 return e; 130 } 131 132 /** 133 * Add the id attribute to the element and the properties to the collection. 134 */ 135 private void addProperties(Element e, OsmPrimitive osm, Collection<Element> properties) { 136 if (osm.id == 0) 137 osm.id = generateId(); 138 e.setAttribute("id", ""+osm.id); 139 if (osm.keys != null) 140 for (Entry<Key, String> entry : osm.keys.entrySet()) 141 properties.add(parseProperty(osm, entry)); 142 } 143 144 /** 145 * Generate an new unused id. 146 */ 147 private long generateId() { 148 while (ids.contains(Long.valueOf(id))) 149 id++; 150 ids.add(id); 151 return id; 152 } 153 154 /** 155 * Return all used ids in a set. 156 */ 157 private Set<Long> allUsedIds() { 158 HashSet<Long> ids = new HashSet<Long>(); 159 for (OsmPrimitive osm : ds.nodes) 160 addIdAndKeyIds(osm, ids); 161 for (OsmPrimitive osm : ds.pendingLineSegments) 162 addIdAndKeyIds(osm, ids); 163 for (Track t : ds.tracks) { 164 addIdAndKeyIds(t, ids); 165 for (LineSegment ls : t.segments) { 166 addIdAndKeyIds(ls, ids); 167 addIdAndKeyIds(ls.start, ids); 168 addIdAndKeyIds(ls.end, ids); 169 } 170 } 171 return ids; 172 } 173 174 /** 175 * Return all used ids in the given osm primitive. 176 */ 177 private void addIdAndKeyIds(OsmPrimitive osm, Collection<Long> ids) { 178 ids.add(osm.id); 179 if (osm.keys != null) 180 for (Key key : osm.keys.keySet()) 181 ids.add(key.id); 48 182 } 49 183 } 184
Note:
See TracChangeset
for help on using the changeset viewer.