- Timestamp:
- 2005-10-09T04:14:40+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 10 added
- 1 deleted
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/ExitAction.java
r11 r17 5 5 6 6 import javax.swing.AbstractAction; 7 import javax.swing.ImageIcon;8 7 9 import org.openstreetmap.josm.gui. Main;8 import org.openstreetmap.josm.gui.ImageProvider; 10 9 11 10 /** … … 20 19 */ 21 20 public ExitAction() { 22 super("Exit", new ImageIcon(Main.class.getResource("/images/exit.png")));21 super("Exit", ImageProvider.get("exit")); 23 22 putValue(MNEMONIC_KEY, KeyEvent.VK_X); 23 putValue(SHORT_DESCRIPTION, "Exit the application."); 24 24 } 25 25 -
src/org/openstreetmap/josm/actions/OpenGpxAction.java
r16 r17 1 1 package org.openstreetmap.josm.actions; 2 2 3 import java.awt.GridBagLayout; 3 4 import java.awt.event.ActionEvent; 4 5 import java.awt.event.KeyEvent; … … 8 9 9 10 import javax.swing.AbstractAction; 10 import javax.swing.ImageIcon; 11 import javax.swing.Box; 12 import javax.swing.JCheckBox; 11 13 import javax.swing.JFileChooser; 14 import javax.swing.JLabel; 12 15 import javax.swing.JOptionPane; 16 import javax.swing.JPanel; 13 17 import javax.swing.filechooser.FileFilter; 14 18 15 19 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.gui.GBC; 21 import org.openstreetmap.josm.gui.ImageProvider; 16 22 import org.openstreetmap.josm.gui.Main; 17 23 import org.openstreetmap.josm.gui.MapFrame; 24 import org.openstreetmap.josm.gui.layer.Layer; 25 import org.openstreetmap.josm.gui.layer.LayerFactory; 18 26 import org.openstreetmap.josm.io.GpxReader; 19 27 import org.openstreetmap.josm.io.DataReader.ConnectionException; … … 32 40 */ 33 41 public OpenGpxAction() { 34 super("Open GPX", new ImageIcon(Main.class.getResource("/images/opengpx.png")));42 super("Open GPX", ImageProvider.get("opengpx")); 35 43 putValue(MNEMONIC_KEY, KeyEvent.VK_O); 44 putValue(SHORT_DESCRIPTION, "Open a file in GPX format."); 36 45 } 37 46 … … 48 57 return "GPX or XML Files"; 49 58 }}); 50 fc.showOpenDialog(Main.main); 59 60 // additional options 61 JCheckBox rawGps = new JCheckBox("Raw GPS data", true); 62 rawGps.setToolTipText("Check this, if the data are obtained from a gps device."); 63 JCheckBox newLayer = new JCheckBox("As Layer", true); 64 newLayer.setToolTipText("Open as a new layer or replace all current layers."); 65 if (Main.main.getMapFrame() == null) { 66 newLayer.setEnabled(false); 67 newLayer.setSelected(false); 68 } 69 70 JPanel p = new JPanel(new GridBagLayout()); 71 p.add(new JLabel("Options"), GBC.eop()); 72 p.add(rawGps, GBC.eol()); 73 p.add(newLayer, GBC.eol()); 74 p.add(Box.createVerticalGlue(), GBC.eol().fill()); 75 fc.setAccessory(p); 76 77 if (fc.showOpenDialog(Main.main) != JFileChooser.APPROVE_OPTION) 78 return; 79 51 80 File gpxFile = fc.getSelectedFile(); 52 81 if (gpxFile == null) … … 54 83 55 84 try { 56 DataSet dataSet = new GpxReader(new FileReader(gpxFile)).parse(); 57 MapFrame map = new MapFrame(dataSet); 58 Main.main.setMapFrame(gpxFile.getName(), map); 85 DataSet dataSet = new GpxReader(new FileReader(gpxFile), rawGps.isSelected()).parse(); 86 87 Layer layer = LayerFactory.create(dataSet, gpxFile.getName(), rawGps.isSelected()); 88 89 if (Main.main.getMapFrame() == null || !newLayer.isSelected()) 90 Main.main.setMapFrame(gpxFile.getName(), new MapFrame(layer)); 91 else 92 Main.main.getMapFrame().mapView.addLayer(layer); 93 59 94 } catch (ParseException x) { 60 95 x.printStackTrace(); -
src/org/openstreetmap/josm/actions/PreferencesAction.java
r11 r17 5 5 6 6 import javax.swing.AbstractAction; 7 import javax.swing.ImageIcon;8 7 9 import org.openstreetmap.josm.gui. Main;8 import org.openstreetmap.josm.gui.ImageProvider; 10 9 import org.openstreetmap.josm.gui.PreferenceDialog; 11 10 … … 21 20 */ 22 21 public PreferencesAction() { 23 super("Preferences", new ImageIcon(Main.class.getResource("/images/preference.png")));22 super("Preferences", ImageProvider.get("preference")); 24 23 putValue(MNEMONIC_KEY, KeyEvent.VK_P); 24 putValue(SHORT_DESCRIPTION, "Open a preferences page for global settings."); 25 25 } 26 26 -
src/org/openstreetmap/josm/actions/SaveGpxAction.java
r16 r17 8 8 9 9 import javax.swing.AbstractAction; 10 import javax.swing.ImageIcon;11 10 import javax.swing.JFileChooser; 12 11 import javax.swing.JOptionPane; 13 12 13 import org.openstreetmap.josm.gui.ImageProvider; 14 14 import org.openstreetmap.josm.gui.Main; 15 15 import org.openstreetmap.josm.io.GpxWriter; … … 28 28 */ 29 29 public SaveGpxAction() { 30 super("Save GPX", new ImageIcon(Main.class.getResource("/images/savegpx.png")));30 super("Save GPX", ImageProvider.get("savegpx")); 31 31 putValue(MNEMONIC_KEY, KeyEvent.VK_S); 32 putValue(SHORT_DESCRIPTION, "Save the current active layer as GPX file."); 32 33 } 33 34 … … 46 47 try { 47 48 FileWriter fileWriter = new FileWriter(gpxFile); 48 GpxWriter out = new GpxWriter(fileWriter, Main.main.getMapFrame().mapView. dataSet);49 GpxWriter out = new GpxWriter(fileWriter, Main.main.getMapFrame().mapView.getActiveDataSet()); 49 50 out.output(); 50 51 fileWriter.close(); -
src/org/openstreetmap/josm/actions/mapmode/AddLineSegmentAction.java
r16 r17 10 10 import javax.swing.JOptionPane; 11 11 12 import org.openstreetmap.josm.data.osm.DataSet; 12 13 import org.openstreetmap.josm.data.osm.LineSegment; 13 14 import org.openstreetmap.josm.data.osm.Node; … … 129 130 130 131 if (start != end) { 132 DataSet ds = mv.getActiveDataSet(); 133 131 134 // try to find a line segment 132 135 for (Track t : ds.tracks()) … … 183 186 hintDrawn = !hintDrawn; 184 187 } 188 189 @Override 190 protected boolean isEditMode() { 191 return true; 192 } 185 193 } -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r16 r17 24 24 */ 25 25 public AddNodeAction(MapFrame mapFrame) { 26 super("Add nodes", "addnode", "Add n ew nodes to the map.", KeyEvent.VK_A, mapFrame);26 super("Add nodes", "addnode", "Add nodes to the map.", KeyEvent.VK_N, mapFrame); 27 27 } 28 28 … … 48 48 Node node = new Node(); 49 49 node.coor = mv.getPoint(e.getX(), e.getY(), true); 50 ds.nodes.add(node);50 mv.getActiveDataSet().nodes.add(node); 51 51 mv.repaint(); 52 52 } 53 53 } 54 55 @Override 56 protected boolean isEditMode() { 57 return true; 58 } 54 59 } -
src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java
r16 r17 6 6 import java.util.LinkedList; 7 7 8 import org.openstreetmap.josm.data.osm.DataSet; 8 9 import org.openstreetmap.josm.data.osm.LineSegment; 9 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 75 76 return; // not allowed together 76 77 78 DataSet ds = mv.getActiveDataSet(); 79 77 80 if (!ctrl && !shift) 78 81 ds.clearSelection(); // new selection will replace the old. … … 105 108 ds.clearSelection(); 106 109 } 110 111 @Override 112 protected boolean isEditMode() { 113 return true; 114 } 107 115 } -
src/org/openstreetmap/josm/actions/mapmode/CombineAction.java
r16 r17 9 9 import javax.swing.JOptionPane; 10 10 11 import org.openstreetmap.josm.data.osm.DataSet; 11 12 import org.openstreetmap.josm.data.osm.LineSegment; 12 13 import org.openstreetmap.josm.data.osm.Node; … … 82 83 mv.addMouseListener(this); 83 84 mv.addMouseMotionListener(this); 84 ds.clearSelection();85 mv.getActiveDataSet().clearSelection(); 85 86 } 86 87 … … 165 166 else 166 167 t1.keys.putAll(t2.keys); 167 ds.removeTrack(t2);168 mv.getActiveDataSet().removeTrack(t2); 168 169 } 169 170 } … … 178 179 */ 179 180 private void combine(LineSegment ls, Track t) { 181 DataSet ds = mv.getActiveDataSet(); 180 182 if (!ds.pendingLineSegments().contains(ls)) 181 183 throw new IllegalStateException("Should not be able to select non-pending line segments."); … … 216 218 Point start = mv.getScreenPoint(ls.getStart().coor); 217 219 Point end = mv.getScreenPoint(ls.getEnd().coor); 218 if (mv. dataSet.pendingLineSegments().contains(osm) && g.getColor() == Color.GRAY)220 if (mv.getActiveDataSet().pendingLineSegments().contains(osm) && g.getColor() == Color.GRAY) 219 221 g.drawLine(start.x, start.y, end.x, end.y); 220 222 else … … 225 227 } 226 228 } 229 230 @Override 231 protected boolean isEditMode() { 232 return true; 233 } 227 234 } -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r16 r17 10 10 import javax.swing.JOptionPane; 11 11 12 import org.openstreetmap.josm.data.osm.DataSet; 12 13 import org.openstreetmap.josm.data.osm.Key; 13 14 import org.openstreetmap.josm.data.osm.LineSegment; … … 93 94 return; 94 95 96 DataSet ds = mv.getActiveDataSet(); 97 95 98 if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0) 96 deleteWithReferences(sel );99 deleteWithReferences(sel, ds); 97 100 else 98 delete(sel );101 delete(sel, ds); 99 102 100 103 mv.repaint(); … … 126 129 * @param osm The object to delete. 127 130 */ 128 private void deleteWithReferences(OsmPrimitive osm ) {131 private void deleteWithReferences(OsmPrimitive osm, DataSet ds) { 129 132 // collect all tracks, areas and pending line segments that should be deleted 130 133 ArrayList<Track> tracksToDelete = new ArrayList<Track>(); … … 172 175 // removing all unreferenced nodes 173 176 for (Node n : checkUnreferencing) { 174 if (!isReferenced(n ))177 if (!isReferenced(n, ds)) 175 178 ds.nodes.remove(n); 176 179 } … … 187 190 * @param osm The object to delete. 188 191 */ 189 private void delete(OsmPrimitive osm ) {192 private void delete(OsmPrimitive osm, DataSet ds) { 190 193 if (osm instanceof Node) { 191 194 Node n = (Node)osm; 192 if (isReferenced(n )) {193 String combined = combine(n );195 if (isReferenced(n, ds)) { 196 String combined = combine(n, ds); 194 197 if (combined != null) { 195 198 JOptionPane.showMessageDialog(Main.main, combined); … … 222 225 * @return Whether the node is used by a track or area. 223 226 */ 224 private boolean isReferenced(Node n ) {227 private boolean isReferenced(Node n, DataSet ds) { 225 228 for (Track t : ds.tracks()) 226 229 for (LineSegment ls : t.segments()) … … 243 246 * are problems combining the node. 244 247 */ 245 private String combine(Node n ) {248 private String combine(Node n, DataSet ds) { 246 249 // first, check for pending line segments 247 250 for (LineSegment ls : ds.pendingLineSegments()) … … 365 368 return first; 366 369 } 370 371 @Override 372 protected boolean isEditMode() { 373 return true; 374 } 367 375 } -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r16 r17 7 7 8 8 import javax.swing.AbstractAction; 9 import javax.swing.ImageIcon;10 9 import javax.swing.JComponent; 11 10 import javax.swing.KeyStroke; 12 11 13 import org.openstreetmap.josm.data.osm.DataSet; 14 import org.openstreetmap.josm.gui.Main; 12 import org.openstreetmap.josm.gui.ImageProvider; 15 13 import org.openstreetmap.josm.gui.MapFrame; 16 14 import org.openstreetmap.josm.gui.MapView; 15 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 16 import org.openstreetmap.josm.gui.layer.Layer; 17 17 18 18 /** … … 34 34 */ 35 35 protected final MapView mv; 36 /**37 * Shortcut to the DataSet.38 */39 protected final DataSet ds;40 36 41 37 /** … … 46 42 */ 47 43 public MapMode(String name, String iconName, String tooltip, int mnemonic, MapFrame mapFrame) { 48 super(name, new ImageIcon(Main.class.getResource("/images/mapmode/"+iconName+".png")));44 super(name, ImageProvider.get("mapmode", iconName)); 49 45 putValue(MNEMONIC_KEY, mnemonic); 50 46 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(mnemonic,0)); … … 54 50 this.mapFrame = mapFrame; 55 51 mv = mapFrame.mapView; 56 ds = mv.dataSet; 52 mv.addLayerChangeListener(new LayerChangeListener(){ 53 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 54 setEnabled(!isEditMode() || newLayer.isEditable()); 55 } 56 public void layerAdded(Layer newLayer) {} 57 public void layerRemoved(Layer oldLayer) {} 58 }); 57 59 } 58 60 61 /** 62 * Subclasses should return whether they want to edit the map data or 63 * whether they are read-only. 64 */ 65 abstract protected boolean isEditMode(); 66 59 67 /** 60 68 * Register all listener to the mapView -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r16 r17 8 8 import java.util.HashSet; 9 9 10 import org.openstreetmap.josm.data.osm.DataSet; 10 11 import org.openstreetmap.josm.data.osm.Node; 11 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 79 80 return; 80 81 81 Collection<OsmPrimitive> selection = ds.getSelected();82 Collection<OsmPrimitive> selection = mv.getActiveDataSet().getSelected(); 82 83 // creating a list of all nodes that should be moved. 83 84 Collection<Node> movingNodes = new HashSet<Node>(); … … 110 111 return; 111 112 113 DataSet ds = mv.getActiveDataSet(); 114 112 115 if (ds.getSelected().size() == 0) { 113 116 OsmPrimitive osm = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); … … 131 134 mv.setCursor(oldCursor); 132 135 if (singleOsmPrimitive != null) { 133 singleOsmPrimitive.setSelected(false, ds);136 singleOsmPrimitive.setSelected(false, mv.getActiveDataSet()); 134 137 mv.repaint(); 135 138 } 136 139 } 140 141 @Override 142 protected boolean isEditMode() { 143 return true; 144 } 137 145 } -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r16 r17 5 5 import java.util.Collection; 6 6 7 import org.openstreetmap.josm.data.osm.DataSet; 7 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 9 import org.openstreetmap.josm.gui.MapFrame; … … 86 87 return; // not allowed together 87 88 89 DataSet ds = mv.getActiveDataSet(); 90 88 91 if (!ctrl && !shift) 89 92 ds.clearSelection(); // new selection will replace the old. … … 94 97 mv.repaint(); 95 98 } 99 100 @Override 101 protected boolean isEditMode() { 102 return false; 103 } 96 104 } -
src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r16 r17 68 68 selectionManager.unregister(mv); 69 69 } 70 71 @Override 72 protected boolean isEditMode() { 73 return false; 74 } 70 75 } -
src/org/openstreetmap/josm/data/GeoPoint.java
r9 r17 59 59 } 60 60 61 61 /** 62 * @return <code>true</code>, if the other GeoPoint has the same lat/lon values. 63 */ 64 public boolean equalsLatLon(GeoPoint other) { 65 return lat == other.lat && lon == other.lon; 66 } 62 67 } -
src/org/openstreetmap/josm/data/Preferences.java
r16 r17 1 1 package org.openstreetmap.josm.data; 2 2 3 import java.beans.PropertyChangeEvent; 4 import java.beans.PropertyChangeListener; 3 5 import java.io.File; 4 6 import java.io.FileReader; … … 38 40 39 41 42 /** 43 * Whether lines should be drawn between track points of raw gps data. 44 */ 45 private boolean drawRawGpsLines = false; 40 46 /** 41 47 * Whether nodes on the same place should be considered identical. … … 100 106 101 107 mergeNodes = root.getChild("mergeNodes") != null; 108 drawRawGpsLines = root.getChild("drawRawGpsLines") != null; 102 109 } catch (Exception e) { 103 110 if (e instanceof PreferencesException) … … 120 127 if (mergeNodes) 121 128 children.add(new Element("mergeNodes")); 129 if (drawRawGpsLines) 130 children.add(new Element("drawRawGpsLines")); 122 131 123 132 try { … … 134 143 135 144 /** 136 * This interface notifies any interested about changes in the projection137 * @author imi138 */139 public interface ProjectionChangeListener {140 void projectionChanged(Projection oldProjection, Projection newProjection);141 }142 /**143 145 * The list of all listeners to projection changes. 144 146 */ 145 private Collection<Pro jectionChangeListener> listener = new LinkedList<ProjectionChangeListener>();147 private Collection<PropertyChangeListener> listener = new LinkedList<PropertyChangeListener>(); 146 148 /** 147 149 * Add a listener of projection changes to the list of listeners. 148 150 * @param listener The listerner to add. 149 151 */ 150 public void addPro jectionChangeListener(ProjectionChangeListener listener) {152 public void addPropertyChangeListener(PropertyChangeListener listener) { 151 153 if (listener != null) 152 154 this.listener.add(listener); … … 155 157 * Remove the listener from the list. 156 158 */ 157 public void removePro jectionChangeListener(ProjectionChangeListener listener) {159 public void removePropertyChangeListener(PropertyChangeListener listener) { 158 160 this.listener.remove(listener); 159 161 } 162 /** 163 * Fires a PropertyChangeEvent if the old value differs from the new value. 164 */ 165 private <T> void firePropertyChanged(String name, T oldValue, T newValue) { 166 if (oldValue == newValue) 167 return; 168 PropertyChangeEvent evt = null; 169 for (PropertyChangeListener l : listener) { 170 if (evt == null) 171 evt = new PropertyChangeEvent(this, name, oldValue, newValue); 172 l.propertyChange(evt); 173 } 174 } 175 176 // getter / setter 177 160 178 /** 161 179 * Set the projection and fire an event to all ProjectionChangeListener … … 165 183 Projection old = this.projection; 166 184 this.projection = projection; 167 if (old != projection) 168 for (ProjectionChangeListener l : listener) 169 l.projectionChanged(old, projection); 185 firePropertyChanged("projection", old, projection); 170 186 } 171 187 /** … … 176 192 return projection; 177 193 } 194 public void setDrawRawGpsLines(boolean drawRawGpsLines) { 195 boolean old = this.drawRawGpsLines; 196 this.drawRawGpsLines = drawRawGpsLines; 197 firePropertyChanged("drawRawGpsLines", old, drawRawGpsLines); 198 } 199 public boolean isDrawRawGpsLines() { 200 return drawRawGpsLines; 201 } 178 202 } -
src/org/openstreetmap/josm/data/osm/DataSet.java
r16 r17 186 186 187 187 /** 188 * Import the given dataset by merging all data with this dataset. 189 * The objects imported are not cloned, so from now on, these data belong 190 * to both datasets. So use mergeFrom only if you are about to abandon the 191 * other dataset or this dataset. 192 * 193 * @param ds The DataSet to merge into this one. 194 * @param mergeEqualNodes If <code>true</code>, nodes with the same lat/lon 195 * are merged together. 196 */ 197 public void mergeFrom(DataSet ds, boolean mergeEqualNodes) { 198 if (mergeEqualNodes) { 199 LinkedList<Node> nodesToAdd = new LinkedList<Node>(); 200 for (Node n : ds.nodes) 201 for (Node mynode : nodes) { 202 if (mynode.coor.equalsLatLon(n.coor)) 203 mynode.mergeFrom(n); 204 else 205 nodesToAdd.add(n); 206 } 207 } else 208 nodes.addAll(ds.nodes); 209 tracks.addAll(ds.tracks); 210 pendingLineSegments.addAll(ds.pendingLineSegments); 211 } 212 213 /** 188 214 * Remove the selection from every value in the collection. 189 215 * @param list The collection to remove the selection from. -
src/org/openstreetmap/josm/data/osm/Node.java
r9 r17 33 33 return Collections.unmodifiableCollection(parentSegment); 34 34 } 35 36 /** 37 * Merge the node given at parameter with this node. 38 * All parents of the parameter-node become parents of this node. 39 * 40 * The argument node is not changed. 41 * 42 * @param node Merge the node to this. 43 */ 44 public void mergeFrom(Node node) { 45 parentSegment.addAll(node.parentSegment); 46 if (keys == null) 47 keys = node.keys; 48 else if (node.keys != null) 49 keys.putAll(node.keys); 50 } 35 51 36 52 /** -
src/org/openstreetmap/josm/data/osm/visitor/SelectionComponentVisitor.java
r11 r17 7 7 8 8 import javax.swing.Icon; 9 import javax.swing.ImageIcon;10 9 11 10 import org.openstreetmap.josm.data.osm.Key; … … 13 12 import org.openstreetmap.josm.data.osm.Node; 14 13 import org.openstreetmap.josm.data.osm.Track; 15 import org.openstreetmap.josm.gui. Main;14 import org.openstreetmap.josm.gui.ImageProvider; 16 15 17 16 /** … … 38 37 public void visit(Key k) { 39 38 name = k.name; 40 icon = new ImageIcon(Main.class.getResource("/images/data/key.png"));39 icon = ImageProvider.get("data", "key"); 41 40 } 42 41 … … 53 52 54 53 this.name = name; 55 icon = new ImageIcon("images/data/linesegment.png");54 icon = ImageProvider.get("data", "linesegment"); 56 55 } 57 56 … … 67 66 68 67 this.name = name; 69 icon = new ImageIcon("images/data/node.png");68 icon = ImageProvider.get("data", "node"); 70 69 } 71 70 … … 87 86 88 87 this.name = name; 89 icon = new ImageIcon("images/data/track.png");88 icon = ImageProvider.get("data", "track"); 90 89 } 91 90 -
src/org/openstreetmap/josm/data/projection/UTM.java
r16 r17 98 98 * Combobox with all ellipsoids for the configuration panel 99 99 */ 100 private JComboBox ellipsoidCombo = new JComboBox(allEllipsoids);100 private JComboBox ellipsoidCombo; 101 101 /** 102 102 * Spinner with all possible zones for the configuration panel 103 103 */ 104 private JSpinner zoneSpinner = new JSpinner(new SpinnerNumberModel(1,1,60,1));104 private JSpinner zoneSpinner; 105 105 /** 106 106 * Hemisphere combo for the configuration panel 107 107 */ 108 private JComboBox hemisphereCombo = new JComboBox(Hemisphere.values());108 private JComboBox hemisphereCombo; 109 109 110 110 … … 248 248 249 249 // ellipsoid 250 if (ellipsoidCombo == null) 251 ellipsoidCombo = new JComboBox(allEllipsoids); 250 252 panel.add(new JLabel("Ellipsoid"), gbc); 251 253 panel.add(ellipsoidCombo, GBC.eol()); … … 253 255 254 256 // zone 257 if (zoneSpinner == null) 258 zoneSpinner = new JSpinner(new SpinnerNumberModel(1,1,60,1)); 255 259 panel.add(new JLabel("Zone"), gbc); 256 260 panel.add(zoneSpinner, GBC.eol().insets(0,5,0,5)); … … 259 263 260 264 // hemisphere 265 if (hemisphereCombo == null) 266 hemisphereCombo = new JComboBox(Hemisphere.values()); 261 267 panel.add(new JLabel("Hemisphere"), gbc); 262 268 panel.add(hemisphereCombo, GBC.eop()); … … 268 274 public void actionPerformed(ActionEvent e) { 269 275 if (Main.main.getMapFrame() != null) { 270 DataSet ds = Main.main.getMapFrame().mapView. dataSet;276 DataSet ds = Main.main.getMapFrame().mapView.getActiveDataSet(); 271 277 ZoneData zd = autoDetect(ds); 272 278 if (zd.zone == 0) … … 291 297 @Override 292 298 public void commitConfigurationPanel() { 293 ellipsoid = (Ellipsoid)ellipsoidCombo.getSelectedItem(); 294 zone = (Integer)zoneSpinner.getValue(); 295 hemisphere = (Hemisphere)hemisphereCombo.getSelectedItem(); 296 fireStateChanged(); 299 if (ellipsoidCombo != null && zoneSpinner != null && hemisphereCombo != null) { 300 ellipsoid = (Ellipsoid)ellipsoidCombo.getSelectedItem(); 301 zone = (Integer)zoneSpinner.getValue(); 302 hemisphere = (Hemisphere)hemisphereCombo.getSelectedItem(); 303 fireStateChanged(); 304 } 297 305 } 298 306 } -
src/org/openstreetmap/josm/gui/Main.java
r16 r17 5 5 import java.awt.Container; 6 6 7 import javax.swing.ImageIcon;8 7 import javax.swing.JFrame; 9 8 import javax.swing.JMenu; … … 36 35 * Global application preferences 37 36 */ 38 public static Preferences pref = new Preferences();37 public final static Preferences pref = new Preferences(); 39 38 40 39 /** … … 141 140 //TODO: Check for changes and ask user 142 141 this.name = name; 142 if (this.mapFrame != null) 143 this.mapFrame.setVisible(false); 143 144 this.mapFrame = mapFrame; 144 145 panel.setVisible(false); 145 146 panel.removeAll(); 146 panel.add(mapFrame, BorderLayout.CENTER); 147 panel.add(mapFrame.toolBarActions, BorderLayout.WEST); 148 panel.add(mapFrame.statusLine, BorderLayout.SOUTH); 149 panel.setVisible(true); 147 if (mapFrame != null) { 148 mapFrame.fillPanel(panel); 149 panel.setVisible(true); 150 mapFrame.setVisible(true); 151 } 150 152 } 151 153 /** … … 167 169 */ 168 170 private static void setupUiDefaults() { 169 UIManager.put("OptionPane.okIcon", new ImageIcon(Main.class.getResource("/images/ok.png")));171 UIManager.put("OptionPane.okIcon", ImageProvider.get("ok")); 170 172 UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon")); 171 UIManager.put("OptionPane.cancelIcon", new ImageIcon(Main.class.getResource("/images/cancel.png")));173 UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel")); 172 174 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); 173 175 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r16 r17 3 3 import java.awt.BorderLayout; 4 4 import java.awt.Component; 5 import java.awt.Container; 5 6 import java.awt.event.WindowAdapter; 6 7 import java.awt.event.WindowEvent; … … 14 15 import javax.swing.JToolBar; 15 16 17 import org.openstreetmap.josm.actions.AutoScaleAction; 16 18 import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction; 17 19 import org.openstreetmap.josm.actions.mapmode.AddNodeAction; 18 20 import org.openstreetmap.josm.actions.mapmode.AddTrackAction; 19 21 import org.openstreetmap.josm.actions.mapmode.CombineAction; 20 import org.openstreetmap.josm.actions.mapmode.DebugAction;21 22 import org.openstreetmap.josm.actions.mapmode.DeleteAction; 22 23 import org.openstreetmap.josm.actions.mapmode.MapMode; … … 24 25 import org.openstreetmap.josm.actions.mapmode.SelectionAction; 25 26 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 26 import org.openstreetmap.josm. data.osm.DataSet;27 import org.openstreetmap.josm.gui.dialogs.LayerList; 27 28 import org.openstreetmap.josm.gui.dialogs.PropertiesDialog; 28 29 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; 30 import org.openstreetmap.josm.gui.layer.Layer; 29 31 30 32 /** … … 54 56 55 57 /** 56 * Construct a map with a given DataSet. The set cannot be replaced after construction 57 * (but of course, the data can be altered using the map's editing features). 58 * Construct a map with a given DataSet. The set cannot be replaced after 59 * construction (but of course, the data can be altered using the map's 60 * editing features). 61 * 62 * @param layer The first layer in the mapView. 58 63 */ 59 public MapFrame( DataSet dataSet) {64 public MapFrame(Layer layer) { 60 65 setSize(400,400); 61 66 setLayout(new BorderLayout()); 62 67 63 add(mapView = new MapView( dataSet), BorderLayout.CENTER);68 add(mapView = new MapView(layer), BorderLayout.CENTER); 64 69 65 70 // toolbar … … 73 78 toolBarActions.add(new IconToggleButton(this, new CombineAction(this))); 74 79 toolBarActions.add(new IconToggleButton(this, new DeleteAction(this))); 75 toolBarActions.add(new IconToggleButton(this, new DebugAction(this)));76 80 77 81 // all map modes in one button group … … 84 88 // autoScale 85 89 toolBarActions.addSeparator(); 86 final JToggleButton autoScaleButton = new IconToggleButton(this, mapView.new AutoScaleAction());90 final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(this)); 87 91 toolBarActions.add(autoScaleButton); 88 92 autoScaleButton.setText(null); … … 95 99 }); 96 100 101 // layer list 102 toolBarActions.add(new IconToggleButton(this, new LayerList(this))); 103 97 104 // properties 98 105 toolBarActions.add(new IconToggleButton(this, new PropertiesDialog(this))); 99 106 100 107 // selection dialog 101 SelectionListDialog selectionList = new SelectionListDialog( dataSet);108 SelectionListDialog selectionList = new SelectionListDialog(this); 102 109 final IconToggleButton buttonSelection = new IconToggleButton(this, selectionList); 103 110 selectionList.addWindowListener(new WindowAdapter(){ … … 110 117 111 118 // status line below the map 112 statusLine = new MapStatus( mapView);119 statusLine = new MapStatus(this); 113 120 } 121 122 123 /** 124 * Fires an property changed event "visible". 125 */ 126 @Override 127 public void setVisible(boolean aFlag) { 128 boolean old = isVisible(); 129 super.setVisible(aFlag); 130 if (old != aFlag) 131 firePropertyChange("visible", old, aFlag); 132 } 133 134 114 135 115 136 /** … … 124 145 mapMode.registerListener(); 125 146 } 147 148 /** 149 * Fill the given panel by adding all necessary components to the different 150 * locations. 151 * 152 * @param panel The container to fill. Must have an BorderLayout. 153 */ 154 public void fillPanel(Container panel) { 155 panel.add(this, BorderLayout.CENTER); 156 panel.add(toolBarActions, BorderLayout.WEST); 157 panel.add(statusLine, BorderLayout.SOUTH); 158 } 126 159 } -
src/org/openstreetmap/josm/gui/MapStatus.java
r16 r17 8 8 import java.awt.event.MouseEvent; 9 9 import java.awt.event.MouseMotionListener; 10 import java.beans.PropertyChangeEvent; 11 import java.beans.PropertyChangeListener; 10 12 import java.util.Map.Entry; 11 13 … … 50 52 */ 51 53 private JTextField nameText = new JTextField(30); 52 /**53 * The background thread thats collecting the data.54 */55 private Runnable collector;56 54 57 55 /** … … 78 76 */ 79 77 private Popup popup; 78 /** 79 * Signals the collector to shut down on next event. 80 */ 81 boolean exitCollector = false; 80 82 81 83 /** … … 90 92 ms.mousePos = mouseState.mousePos; 91 93 } 94 if (exitCollector) 95 return; 92 96 if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null) 93 97 continue; // freeze display when holding down ctrl … … 119 123 } 120 124 JLabel l = new JLabel(text.toString(), visitor.icon, JLabel.HORIZONTAL); 125 l.setVerticalTextPosition(JLabel.TOP); 121 126 122 127 Point p = mv.getLocationOnScreen(); … … 148 153 * @param mv The MapView the status line is part of. 149 154 */ 150 public MapStatus(final Map View mv) {151 this.mv = m v;155 public MapStatus(final MapFrame mapFrame) { 156 this.mv = mapFrame.mapView; 152 157 153 158 // Listen for mouse movements and set the position text field … … 165 170 }); 166 171 172 positionText.setEditable(false); 173 nameText.setEditable(false); 174 setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); 175 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 176 add(new JLabel("Lat/Lon ")); 177 add(positionText); 178 add(new JLabel(" Object ")); 179 add(nameText); 180 181 // The background thread 182 final Collector collector = new Collector(); 183 new Thread(collector).start(); 184 167 185 // Listen to keyboard/mouse events for pressing/releasing alt key and 168 186 // inform the collector. … … 177 195 } 178 196 }, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); 179 180 positionText.setEditable(false); 181 nameText.setEditable(false); 182 setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); 183 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 184 add(new JLabel("Lat/Lon ")); 185 add(positionText); 186 add(new JLabel(" Object ")); 187 add(nameText); 188 189 // The background thread 190 collector = new Collector(); 191 new Thread(collector).start(); 197 198 // listen for shutdowns to cancel the background thread 199 mapFrame.addPropertyChangeListener("visible", new PropertyChangeListener(){ 200 public void propertyChange(PropertyChangeEvent evt) { 201 if (evt.getNewValue() == Boolean.FALSE) { 202 collector.exitCollector = true; 203 synchronized (collector) { 204 collector.notify(); 205 } 206 } 207 } 208 }); 192 209 } 193 210 } -
src/org/openstreetmap/josm/gui/MapView.java
r16 r17 1 1 package org.openstreetmap.josm.gui; 2 2 3 import java.awt.Color; 3 4 import java.awt.Graphics; 4 5 import java.awt.Point; 5 import java.awt.event. ActionEvent;6 import java.awt.event.ComponentAdapter; 6 7 import java.awt.event.ComponentEvent; 7 import java.awt.event.ComponentListener; 8 import java.awt.event.KeyEvent; 9 10 import javax.swing.AbstractAction; 11 import javax.swing.ImageIcon; 8 import java.beans.PropertyChangeEvent; 9 import java.beans.PropertyChangeListener; 10 import java.util.ArrayList; 11 import java.util.Collection; 12 import java.util.Collections; 13 import java.util.LinkedList; 14 12 15 import javax.swing.JComponent; 13 16 import javax.swing.event.ChangeEvent; … … 16 19 import org.openstreetmap.josm.data.Bounds; 17 20 import org.openstreetmap.josm.data.GeoPoint; 18 import org.openstreetmap.josm.data.Preferences.ProjectionChangeListener;19 21 import org.openstreetmap.josm.data.osm.DataSet; 20 22 import org.openstreetmap.josm.data.osm.LineSegment; … … 23 25 import org.openstreetmap.josm.data.osm.Track; 24 26 import org.openstreetmap.josm.data.projection.Projection; 25 import org.openstreetmap.josm.gui.engine.Engine; 26 import org.openstreetmap.josm.gui.engine.SimpleEngine; 27 import org.openstreetmap.josm.gui.layer.Layer; 27 28 28 29 /** … … 36 37 * what projection the map is viewed etc.. 37 38 * 39 * MapView is able to administrate several layers, but there must be always at 40 * least one layer with a dataset in it (Layer.getDataSet returning non-null). 41 * 38 42 * @author imi 39 43 */ 40 public class MapView extends JComponent implements C omponentListener, ChangeListener, ProjectionChangeListener {41 42 /** 43 * Toggles the autoScale feature of the mapView44 public class MapView extends JComponent implements ChangeListener, PropertyChangeListener { 45 46 /** 47 * Interface to notify listeners of the change of the active layer. 44 48 * @author imi 45 49 */ 46 public class AutoScaleAction extends AbstractAction { 47 public AutoScaleAction() { 48 super("Auto Scale", new ImageIcon(Main.class.getResource("/images/autoscale.png"))); 49 putValue(MNEMONIC_KEY, KeyEvent.VK_A); 50 } 51 public void actionPerformed(ActionEvent e) { 52 autoScale = !autoScale; 53 recalculateCenterScale(); 54 } 50 public interface LayerChangeListener { 51 void activeLayerChange(Layer oldLayer, Layer newLayer); 52 void layerAdded(Layer newLayer); 53 void layerRemoved(Layer oldLayer); 55 54 } 56 55 … … 58 57 * Whether to adjust the scale property on every resize. 59 58 */ 60 privateboolean autoScale = true;59 boolean autoScale = true; 61 60 62 61 /** … … 70 69 71 70 /** 72 * The underlying DataSet. 73 */ 74 public final DataSet dataSet; 75 76 /** 77 * The drawing engine. 78 */ 79 private Engine engine; 71 * A list of all layers currently loaded. 72 */ 73 private ArrayList<Layer> layers = new ArrayList<Layer>(); 74 /** 75 * The layer from the layers list that is currently active. 76 */ 77 private Layer activeLayer; 78 /** 79 * The listener of the active layer changes. 80 */ 81 private Collection<LayerChangeListener> listeners = new LinkedList<LayerChangeListener>(); 80 82 81 83 /** 82 84 * Construct a MapView. 83 */ 84 public MapView(DataSet dataSet) { 85 this.dataSet = dataSet; 86 addComponentListener(this); 85 * @param layer The first layer in the view. 86 */ 87 public MapView(Layer layer) { 88 if (layer.getDataSet() == null) 89 throw new IllegalArgumentException("Initial layer must have a dataset."); 90 91 addComponentListener(new ComponentAdapter(){ 92 @Override 93 public void componentResized(ComponentEvent e) { 94 recalculateCenterScale(); 95 } 96 }); 87 97 88 98 // initialize the movement listener … … 90 100 91 101 // initialize the projection 92 projectionChanged(null, Main.pref.getProjection()); 93 Main.pref.addProjectionChangeListener(this); 94 95 // initialize the drawing engine 96 engine = new SimpleEngine(this); 102 addLayer(layer); 103 Main.pref.addPropertyChangeListener(this); 104 105 // init screen 106 recalculateCenterScale(); 107 } 108 109 /** 110 * Add a layer to the current MapView. The layer will be added at topmost 111 * position. 112 */ 113 public void addLayer(Layer layer) { 114 layers.add(0,layer); 115 116 DataSet ds = layer.getDataSet(); 117 118 if (ds != null) { 119 // initialize the projection if it was the first layer 120 if (layers.size() == 1) 121 Main.pref.getProjection().init(ds); 122 123 // initialize the dataset in the new layer 124 for (Node n : ds.nodes) 125 Main.pref.getProjection().latlon2xy(n.coor); 126 } 127 128 for (LayerChangeListener l : listeners) 129 l.layerAdded(layer); 130 131 setActiveLayer(layer); 132 } 133 134 /** 135 * Remove the layer from the mapview. If the layer was in the list before, 136 * an LayerChange event is fired. 137 */ 138 public void removeLayer(Layer layer) { 139 if (layers.remove(layer)) 140 for (LayerChangeListener l : listeners) 141 l.layerRemoved(layer); 142 } 143 144 /** 145 * Moves the layer to the given new position. No event is fired. 146 * @param layer The layer to move 147 * @param pos The new position of the layer 148 */ 149 public void moveLayer(Layer layer, int pos) { 150 int curLayerPos = layers.indexOf(layer); 151 if (curLayerPos == -1) 152 throw new IllegalArgumentException("layer not in list."); 153 if (pos == curLayerPos) 154 return; // already in place. 155 layers.remove(curLayerPos); 156 if (pos >= layers.size()) 157 layers.add(layer); 158 else 159 layers.add(pos, layer); 97 160 } 98 161 … … 168 231 double minDistanceSq = Double.MAX_VALUE; 169 232 OsmPrimitive minPrimitive = null; 233 234 // calculate the object based on the current active dataset. 235 DataSet ds = getActiveDataSet(); 170 236 171 237 // nodes 172 for (Node n : d ataSet.nodes) {238 for (Node n : ds.nodes) { 173 239 Point sp = getScreenPoint(n.coor); 174 240 double dist = p.distanceSq(sp); … … 182 248 183 249 // pending line segments 184 for (LineSegment ls : d ataSet.pendingLineSegments()) {250 for (LineSegment ls : ds.pendingLineSegments()) { 185 251 Point A = getScreenPoint(ls.getStart().coor); 186 252 Point B = getScreenPoint(ls.getEnd().coor); … … 197 263 // tracks & line segments 198 264 minDistanceSq = Double.MAX_VALUE; 199 for (Track t : d ataSet.tracks()) {265 for (Track t : ds.tracks()) { 200 266 for (LineSegment ls : t.segments()) { 201 267 Point A = getScreenPoint(ls.getStart().coor); … … 243 309 firePropertyChange("scale", oldScale, scale); 244 310 } 245 311 246 312 /** 247 313 * Draw the component. … … 249 315 @Override 250 316 public void paint(Graphics g) { 251 engine.init(g); 252 engine.drawBackground(getPoint(0,0,true), getPoint(getWidth(), getHeight(), true)); 253 254 for (Track t : dataSet.tracks()) 255 engine.drawTrack(t); 256 for (LineSegment ls : dataSet.pendingLineSegments()) 257 engine.drawPendingLineSegment(ls); 258 for (Node n : dataSet.nodes) 259 engine.drawNode(n); 317 g.setColor(Color.BLACK); 318 g.fillRect(0, 0, getWidth(), getHeight()); 319 320 for (int i = layers.size()-1; i >= 0; --i) { 321 Layer l = layers.get(i); 322 if (l.isVisible()) 323 l.paint(g, this); 324 } 260 325 } 261 326 … … 265 330 */ 266 331 public void stateChanged(ChangeEvent e) { 267 for (Node n : dataSet.nodes) 268 Main.pref.getProjection().latlon2xy(n.coor); 332 // reset all datasets. 333 Projection p = Main.pref.getProjection(); 334 for (Layer l : layers) { 335 DataSet ds = l.getDataSet(); 336 if (ds != null) 337 for (Node n : ds.nodes) 338 p.latlon2xy(n.coor); 339 } 269 340 recalculateCenterScale(); 270 341 } … … 292 363 this.autoScale = autoScale; 293 364 firePropertyChange("autoScale", !autoScale, autoScale); 365 recalculateCenterScale(); 294 366 } 295 367 } … … 303 375 304 376 377 /** 378 * Return the dataSet for the current selected layer. If the active layer 379 * does not have a dataset, return the DataSet from the next layer a.s.o. 380 * 381 * @return The DataSet of the current active layer. 382 */ 383 public DataSet getActiveDataSet() { 384 if (activeLayer.getDataSet() != null) 385 return activeLayer.getDataSet(); 386 for (Layer l : layers) { 387 DataSet ds = l.getDataSet(); 388 if (ds != null) 389 return ds; 390 } 391 throw new IllegalStateException("No dataset found."); 392 } 305 393 306 394 /** … … 310 398 * @param newProjection The new projection. Register as state change listener. 311 399 */ 312 public void projectionChanged(Projection oldProjection, Projection newProjection) { 313 if (oldProjection != null) 314 oldProjection.removeChangeListener(this); 315 if (newProjection != null) { 316 newProjection.addChangeListener(this); 317 newProjection.init(dataSet); 318 for (Node n : dataSet.nodes) 319 newProjection.latlon2xy(n.coor); 320 } 321 recalculateCenterScale(); 400 public void propertyChange(PropertyChangeEvent evt) { 401 if (!evt.getPropertyName().equals("projection")) 402 return; 403 if (evt.getOldValue() != null) 404 ((Projection)evt.getOldValue()).removeChangeListener(this); 405 if (evt.getNewValue() != null) { 406 Projection p = (Projection)evt.getNewValue(); 407 p.addChangeListener(this); 408 409 stateChanged(new ChangeEvent(this)); 410 } 322 411 } 323 412 … … 326 415 * scale, if in autoScale mode. 327 416 */ 328 privatevoid recalculateCenterScale() {417 void recalculateCenterScale() { 329 418 if (autoScale) { 330 419 // -20 to leave some border … … 335 424 if (h < 20) 336 425 h = 20; 337 Bounds bounds = dataSet.getBoundsXY(); 426 427 Bounds bounds = getActiveDataSet().getBoundsXY(); 338 428 339 429 boolean oldAutoScale = autoScale; … … 364 454 365 455 /** 366 * Call to recalculateCenterScale. 367 */ 368 public void componentResized(ComponentEvent e) { 369 recalculateCenterScale(); 370 } 371 372 /** 373 * Does nothing. Just to satisfy ComponentListener. 374 */ 375 public void componentMoved(ComponentEvent e) {} 376 /** 377 * Does nothing. Just to satisfy ComponentListener. 378 */ 379 public void componentShown(ComponentEvent e) {} 380 /** 381 * Does nothing. Just to satisfy ComponentListener. 382 */ 383 public void componentHidden(ComponentEvent e) {} 456 * Add a listener for changes of active layer. 457 * @param listener The listener that get added. 458 */ 459 public void addLayerChangeListener(LayerChangeListener listener) { 460 if (listener != null) 461 listeners.add(listener); 462 } 463 464 /** 465 * Remove the listener. 466 * @param listener The listener that get removed from the list. 467 */ 468 public void removeLayerChangeListener(LayerChangeListener listener) { 469 listeners.remove(listener); 470 } 471 472 /** 473 * @return An unmodificable list of all layers 474 */ 475 public Collection<Layer> getAllLayers() { 476 return Collections.unmodifiableCollection(layers); 477 } 478 479 /** 480 * Set the active selection to the given value and raise an layerchange event. 481 */ 482 public void setActiveLayer(Layer layer) { 483 if (!layers.contains(layer)) 484 throw new IllegalArgumentException("layer must be in layerlist"); 485 Layer old = activeLayer; 486 activeLayer = layer; 487 if (old != layer) { 488 if (old != null && old.getDataSet() != null) 489 old.getDataSet().clearSelection(); 490 for (LayerChangeListener l : listeners) 491 l.activeLayerChange(old, layer); 492 recalculateCenterScale(); 493 } 494 } 495 496 /** 497 * @return The current active layer 498 */ 499 public Layer getActiveLayer() { 500 return activeLayer; 501 } 384 502 } -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r16 r17 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.ActionListener; 9 import java.io.File;10 9 11 10 import javax.swing.AbstractAction; … … 13 12 import javax.swing.Box; 14 13 import javax.swing.DefaultListCellRenderer; 15 import javax.swing.ImageIcon;16 14 import javax.swing.JButton; 17 15 import javax.swing.JCheckBox; … … 54 52 Main.pref.setProjection(projection); 55 53 Main.pref.mergeNodes = mergeNodes.isSelected(); 54 Main.pref.setDrawRawGpsLines(drawRawGpsLines.isSelected()); 56 55 try { 57 56 Main.pref.save(); … … 96 95 */ 97 96 private JTabbedPane tabPane = new JTabbedPane(JTabbedPane.LEFT); 97 98 98 /** 99 99 * The checkbox stating whether nodes should be merged together. 100 100 */ 101 private JCheckBox drawRawGpsLines = new JCheckBox("Draw lines between raw gps points."); 102 /** 103 * The checkbox stating whether nodes should be merged together. 104 */ 101 105 private JCheckBox mergeNodes = new JCheckBox("Merge nodes with equal latitude/longitude."); 102 106 103 104 107 /** 105 108 * Create a preference setting dialog from an preferences-file. If the file does not … … 110 113 public PreferenceDialog() { 111 114 super(Main.main, "Preferences"); 112 113 Preferences pref = new Preferences();114 try {115 if (new File(Preferences.getPreferencesFile()).exists())116 pref.load();117 } catch (PreferencesException e) {118 JOptionPane.showMessageDialog(Main.main, "Preferences settings could not be parsed:\n"+e.getMessage());119 e.printStackTrace();120 return;121 }122 115 123 116 // look and feel combo box … … 128 121 return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus); 129 122 }}); 130 lafCombo.setSelectedItem( pref.laf);123 lafCombo.setSelectedItem(Main.pref.laf); 131 124 lafCombo.addActionListener(new ActionListener(){ 132 125 public void actionPerformed(ActionEvent e) { … … 136 129 // projection combo box 137 130 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 138 if (projectionCombo.getItemAt(i).getClass().equals( pref.getProjection().getClass())) {131 if (projectionCombo.getItemAt(i).getClass().equals(Main.pref.getProjection().getClass())) { 139 132 projectionCombo.setSelectedIndex(i); 140 133 break; … … 162 155 }); 163 156 157 // tooltips 158 drawRawGpsLines.setToolTipText("If your gps device draw to few lines, select this to draw lines along your track."); 159 drawRawGpsLines.setSelected(Main.pref.isDrawRawGpsLines()); 160 mergeNodes.setToolTipText("When importing GPX data, all nodes with exact the same lat/lon are merged."); 161 mergeNodes.setSelected(Main.pref.mergeNodes); 164 162 165 163 // Display tab … … 168 166 display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 169 167 display.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL)); 168 display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0)); 170 169 display.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 171 170 … … 180 179 181 180 map.add(new JLabel("GPX import / export"), GBC.eol()); 182 mergeNodes.setSelected(pref.mergeNodes); 183 map.add(mergeNodes, GBC.eol()); 181 map.add(mergeNodes, GBC.eol().insets(20,0,0,0)); 184 182 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 185 183 … … 222 220 p.add(descLabel, GBC.eol().insets(5,0,5,20).fill(GBC.HORIZONTAL)); 223 221 224 tabPane.addTab(null, new ImageIcon("images/preferences/"+icon+".png"), p);222 tabPane.addTab(null, ImageProvider.get("preferences", icon), p); 225 223 return p; 226 224 } -
src/org/openstreetmap/josm/gui/SelectionManager.java
r16 r17 15 15 import java.util.LinkedList; 16 16 17 import org.openstreetmap.josm.data.osm.DataSet; 17 18 import org.openstreetmap.josm.data.osm.LineSegment; 18 19 import org.openstreetmap.josm.data.osm.Node; … … 271 272 } else { 272 273 // nodes 273 for (Node n : mv.dataSet.nodes) { 274 DataSet ds = mv.getActiveDataSet(); 275 for (Node n : ds.nodes) { 274 276 if (r.contains(mv.getScreenPoint(n.coor))) 275 277 selection.add(n); … … 277 279 278 280 // pending line segments 279 for (LineSegment ls : mv.dataSet.pendingLineSegments())281 for (LineSegment ls : ds.pendingLineSegments()) 280 282 if (rectangleContainLineSegment(r, alt, ls)) 281 283 selection.add(ls); 282 284 283 285 // tracks 284 for (Track t : mv.dataSet.tracks()) {286 for (Track t : ds.tracks()) { 285 287 boolean wholeTrackSelected = !t.segments().isEmpty(); 286 288 for (LineSegment ls : t.segments()) -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r16 r17 21 21 /** 22 22 * Create a new PropertiesDialog 23 * @param frame The mapFrame, this dialog is attached to.24 23 */ 25 public PropertiesDialog( final MapFrame frame) {26 super( "Properties of "+Main.main.getNameOfLoadedMapFrame(), "Properties Dialog", "properties", KeyEvent.VK_P, "Property page for this map.");24 public PropertiesDialog(MapFrame mapFrame) { 25 super(mapFrame, "Properties of "+Main.main.getNameOfLoadedMapFrame(), "Properties Dialog", "properties", KeyEvent.VK_P, "Property page for this map."); 27 26 putValue(MNEMONIC_KEY, KeyEvent.VK_P); 28 27 -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r11 r17 10 10 import javax.swing.DefaultListCellRenderer; 11 11 import javax.swing.DefaultListModel; 12 import javax.swing.ImageIcon;13 12 import javax.swing.JButton; 14 13 import javax.swing.JLabel; … … 21 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 21 import org.openstreetmap.josm.data.osm.visitor.SelectionComponentVisitor; 22 import org.openstreetmap.josm.gui.ImageProvider; 23 23 import org.openstreetmap.josm.gui.Main; 24 import org.openstreetmap.josm.gui.MapFrame; 25 import org.openstreetmap.josm.gui.MapView; 26 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 27 import org.openstreetmap.josm.gui.layer.Layer; 24 28 25 29 /** … … 30 34 * @author imi 31 35 */ 32 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener {36 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener { 33 37 34 38 /** … … 43 47 * The dataset, all selections are part of. 44 48 */ 45 private final DataSet dataSet;49 private final MapView mapView; 46 50 47 51 /** 48 52 * Create a SelectionList dialog. 49 * @param dataSet The dataset this dialog operates on.53 * @param mapView The mapView to get the dataset from. 50 54 */ 51 public SelectionListDialog( DataSet dataSet) {52 super( "Current Selection", "Selection List", "selectionlist", KeyEvent.VK_E, "Open a selection list window.");53 this. dataSet = dataSet;55 public SelectionListDialog(MapFrame mapFrame) { 56 super(mapFrame, "Current Selection", "Selection List", "selectionlist", KeyEvent.VK_E, "Open a selection list window."); 57 this.mapView = mapFrame.mapView; 54 58 setLayout(new BorderLayout()); 55 59 setSize(300,400); … … 71 75 getContentPane().add(new JScrollPane(displaylist), BorderLayout.CENTER); 72 76 73 JButton button = new JButton("Select", new ImageIcon(Main.class.getResource("/images/mapmode/selection.png"))); 77 JButton button = new JButton("Select", ImageProvider.get("mapmode", "selection")); 78 button.setToolTipText("Set the selected elements on the map to the selected items in the list above."); 74 79 button.addActionListener(new ActionListener(){ 75 80 public void actionPerformed(ActionEvent e) { … … 79 84 getContentPane().add(button, BorderLayout.SOUTH); 80 85 81 selectionChanged( dataSet.getSelected());86 selectionChanged(mapView.getActiveDataSet().getSelected()); 82 87 } 83 88 … … 85 90 public void setVisible(boolean b) { 86 91 if (b) { 87 dataSet.addSelectionChangedListener(this); 88 selectionChanged(dataSet.getSelected()); 89 } else 90 dataSet.removeSelectionChangedListener(this); 92 mapView.addLayerChangeListener(this); 93 mapView.getActiveDataSet().addSelectionChangedListener(this); 94 selectionChanged(mapView.getActiveDataSet().getSelected()); 95 } else { 96 mapView.removeLayerChangeListener(this); 97 mapView.getActiveDataSet().removeSelectionChangedListener(this); 98 } 91 99 super.setVisible(b); 92 100 } … … 110 118 */ 111 119 public void updateMap() { 112 dataSet.clearSelection(); 120 DataSet ds = mapView.getActiveDataSet(); 121 ds.clearSelection(); 113 122 for (int i = 0; i < list.getSize(); ++i) 114 123 if (displaylist.isSelectedIndex(i)) 115 ((OsmPrimitive)list.get(i)).setSelected(true, d ataSet);124 ((OsmPrimitive)list.get(i)).setSelected(true, ds); 116 125 Main.main.getMapFrame().repaint(); 117 126 } 127 128 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 129 DataSet ds = oldLayer.getDataSet(); 130 if (ds != null) 131 ds.removeSelectionChangedListener(this); 132 ds = newLayer.getDataSet(); 133 if (ds != null) 134 ds.addSelectionChangedListener(this); 135 } 136 137 /** 138 * Does nothing. Only to satisfy LayerChangeListener 139 */ 140 public void layerAdded(Layer newLayer) {} 141 /** 142 * Does nothing. Only to satisfy LayerChangeListener 143 */ 144 public void layerRemoved(Layer oldLayer) {} 118 145 } -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r16 r17 2 2 3 3 import java.awt.event.ActionEvent; 4 import java.awt.event.KeyEvent; 4 import java.beans.PropertyChangeEvent; 5 import java.beans.PropertyChangeListener; 5 6 import java.util.HashMap; 6 7 import java.util.Map; … … 8 9 import javax.swing.AbstractButton; 9 10 import javax.swing.Action; 10 import javax.swing. ImageIcon;11 import javax.swing.JComponent; 11 12 import javax.swing.JDialog; 12 13 import javax.swing.KeyStroke; 13 14 15 import org.openstreetmap.josm.gui.ImageProvider; 14 16 import org.openstreetmap.josm.gui.Main; 17 import org.openstreetmap.josm.gui.MapFrame; 15 18 16 19 /** … … 26 29 * @param title The title of the dialog. 27 30 */ 28 public ToggleDialog( String title, String name, String iconName, int mnemonic, String tooltip) {31 public ToggleDialog(MapFrame mapFrame, String title, String name, String iconName, int mnemonic, String tooltip) { 29 32 super(Main.main, title, false); 30 putValue(SMALL_ICON, new ImageIcon(Main.class.getResource("/images/dialogs/"+iconName+".png")));33 putValue(SMALL_ICON, ImageProvider.get("dialogs", iconName)); 31 34 putValue(NAME, name); 32 35 putValue(MNEMONIC_KEY, mnemonic); 33 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E,0)); 34 putValue(LONG_DESCRIPTION, "Open a selection list window."); 36 KeyStroke ks = KeyStroke.getKeyStroke(mnemonic,0); 37 putValue(ACCELERATOR_KEY, ks); 38 mapFrame.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks, this); 39 mapFrame.getActionMap().put(this, this); 40 putValue(LONG_DESCRIPTION, tooltip); 41 mapFrame.addPropertyChangeListener("visible", new PropertyChangeListener(){ 42 public void propertyChange(PropertyChangeEvent evt) { 43 if (evt.getNewValue() == Boolean.FALSE) 44 setVisible(false); 45 } 46 }); 35 47 } 36 48 -
src/org/openstreetmap/josm/gui/engine/Engine.java
r16 r17 2 2 3 3 import java.awt.Graphics; 4 import java.beans.PropertyChangeEvent;5 import java.beans.PropertyChangeListener;6 4 7 import org.openstreetmap.josm.data.GeoPoint;8 5 import org.openstreetmap.josm.data.osm.LineSegment; 9 6 import org.openstreetmap.josm.data.osm.Node; 10 7 import org.openstreetmap.josm.data.osm.Track; 11 import org.openstreetmap.josm.data.projection.Projection;12 8 import org.openstreetmap.josm.gui.MapView; 13 9 … … 18 14 * @author imi 19 15 */ 20 abstract public class Engine implements PropertyChangeListener{16 abstract public class Engine { 21 17 22 /**23 * The projection method, this engine uses to render the graphics.24 */25 protected Projection projection;26 18 /** 27 19 * The Graphics surface to draw on. This should be set before each painting … … 32 24 * The mapView, this engine was created for. 33 25 */ 34 protected finalMapView mv;26 protected MapView mv; 35 27 36 37 /**38 * Creates an Engine from an MapView it belongs to.39 * @param mapView The mapview this engine belongs to.40 */41 public Engine(MapView mapView) {42 mv = mapView;43 mv.addPropertyChangeListener(this);44 }45 28 46 29 /** … … 48 31 * @param g 49 32 */ 50 public void init(Graphics g ) {33 public void init(Graphics g, MapView mv) { 51 34 this.g = g; 35 this.mv = mv; 52 36 } 53 54 /**55 * Draw the background. The coordinates are given as hint (e.g. to draw56 * an background image).57 */58 abstract public void drawBackground(GeoPoint ul, GeoPoint lr);59 37 60 38 /** … … 73 51 */ 74 52 abstract public void drawPendingLineSegment(LineSegment ls); 75 76 /**77 * Called when the projection method for the map changed. Subclasses with78 * caches depending on the projection should empty the cache now.79 */80 public void propertyChange(PropertyChangeEvent e) {81 if (e.getPropertyName().equals("projection"))82 projection = (Projection)e.getNewValue();83 }84 53 } -
src/org/openstreetmap/josm/gui/engine/SimpleEngine.java
r16 r17 6 6 import java.util.HashSet; 7 7 8 import org.openstreetmap.josm.data.GeoPoint;9 8 import org.openstreetmap.josm.data.osm.LineSegment; 10 9 import org.openstreetmap.josm.data.osm.Node; 11 10 import org.openstreetmap.josm.data.osm.Track; 12 import org.openstreetmap.josm.gui.MapView;13 11 14 12 /** … … 22 20 private final static Color darkblue = new Color(0,0,128); 23 21 private final static Color darkgreen = new Color(0,128,0); 24 25 public SimpleEngine(MapView mapView) {26 super(mapView);27 }28 29 /**30 * Draws black background.31 */32 @Override33 public void drawBackground(GeoPoint ulGeo, GeoPoint lrGeo) {34 g.setColor(Color.BLACK);35 g.fillRect(0,0,mv.getWidth(),mv.getHeight());36 }37 22 38 23 /** -
src/org/openstreetmap/josm/io/GpxReader.java
r16 r17 40 40 */ 41 41 public Reader source; 42 /** 43 * If <code>true</code>, only nodes and tracks are imported (but no key/value 44 * pairs). That is to support background gps information as an hint for 45 * real OSM data. 46 */ 47 private final boolean rawGps; 42 48 43 49 /** 44 50 * Construct a parser from a specific data source. 45 51 * @param source The data source, as example a FileReader to read from a file. 46 */ 47 public GpxReader(Reader source) { 52 * @param rawGps Whether the gpx file describes raw gps data. Only very few 53 * information (only nodes and line segments) imported for raw gps to 54 * save memory. 55 */ 56 public GpxReader(Reader source, boolean rawGps) { 48 57 this.source = source; 58 this.rawGps = rawGps; 49 59 } 50 60 … … 56 66 final SAXBuilder builder = new SAXBuilder(); 57 67 Element root = builder.build(source).getRootElement(); 58 System.out.println(root.getNamespacePrefix());59 68 60 69 // HACK, since the osm server seem to not provide a namespace. … … 85 94 Float.parseFloat(e.getAttributeValue("lat")), 86 95 Float.parseFloat(e.getAttributeValue("lon"))); 96 97 if (rawGps) 98 return data; 99 87 100 for (Object o : e.getChildren()) { 88 101 Element child = (Element)o; … … 126 139 for (Object o : e.getChildren()) { 127 140 Element child = (Element)o; 128 if (child.getName().equals("extensions")) 129 parseKeyValueExtensions(track, child); 130 else if (child.getName().equals("link")) 131 parseKeyValueLink(track, child); 132 else if (child.getName().equals("trkseg")) { 141 142 if (child.getName().equals("trkseg")) { 133 143 Node start = null; 134 144 for (Object w : child.getChildren("trkpt", GPX)) { … … 139 149 else { 140 150 LineSegment lineSegment = new LineSegment(start, node); 141 parseKeyValueExtensions(lineSegment, ((Element)w).getChild("extensions", GPX)); 151 if (!rawGps) 152 parseKeyValueExtensions(lineSegment, ((Element)w).getChild("extensions", GPX)); 142 153 track.add(lineSegment); 143 154 start = null; 144 155 } 145 156 } 146 } else 157 } 158 159 if (rawGps) 160 continue; 161 162 if (child.getName().equals("extensions")) 163 parseKeyValueExtensions(track, child); 164 else if (child.getName().equals("link")) 165 parseKeyValueLink(track, child); 166 else 147 167 parseKeyValueTag(track, child); 148 168 } … … 156 176 * to the node in the list (either the new added or the old found). 157 177 * 178 * If reading raw gps data, mergeNodes are always on (To save memory. You 179 * can't edit raw gps nodes anyway.) 180 * 158 181 * @param data The DataSet to add the node to. 159 182 * @param node The node that should be added. … … 161 184 */ 162 185 private Node addNode (DataSet data, Node node) { 163 if (Main.pref.mergeNodes )186 if (Main.pref.mergeNodes || rawGps) 164 187 for (Node n : data.nodes) 165 if (node.coor. lat == n.coor.lat && node.coor.lon == n.coor.lon)188 if (node.coor.equalsLatLon(n.coor)) 166 189 return n; 167 190 data.nodes.add(node);
Note:
See TracChangeset
for help on using the changeset viewer.