Changeset 15 in josm for src/org/openstreetmap
- Timestamp:
- 2005-10-07T01:13:49+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 27 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/OpenGpxAction.java
r12 r15 15 15 import org.openstreetmap.josm.data.osm.DataSet; 16 16 import org.openstreetmap.josm.gui.Main; 17 import org.openstreetmap.josm.gui.MapFrame;18 17 import org.openstreetmap.josm.io.GpxReader; 19 18 import org.openstreetmap.josm.io.DataReader.ConnectionException; … … 55 54 try { 56 55 DataSet dataSet = new GpxReader(new FileReader(gpxFile)).parse(); 57 MapFrame map = new MapFrame(dataSet); 58 Main.main.setMapFrame(gpxFile.getName(), map); 56 Main.main.setMapFrame(gpxFile.getName(), dataSet); 59 57 } catch (ParseException x) { 60 58 x.printStackTrace(); -
src/org/openstreetmap/josm/actions/SaveGpxAction.java
r11 r15 46 46 try { 47 47 FileWriter fileWriter = new FileWriter(gpxFile); 48 GpxWriter out = new GpxWriter(fileWriter, Main.main.getMapFrame(). mapView.dataSet);48 GpxWriter out = new GpxWriter(fileWriter, Main.main.getMapFrame().layer.dataSet); 49 49 out.output(); 50 50 fileWriter.close(); -
src/org/openstreetmap/josm/actions/mapmode/AddLineSegmentAction.java
r8 r15 59 59 public void registerListener() { 60 60 super.registerListener(); 61 mv.addMouseListener(this);62 mv.addMouseMotionListener(this);61 layer.addMouseListener(this); 62 layer.addMouseMotionListener(this); 63 63 } 64 64 … … 66 66 public void unregisterListener() { 67 67 super.unregisterListener(); 68 mv.removeMouseListener(this);69 mv.removeMouseMotionListener(this);68 layer.removeMouseListener(this); 69 layer.removeMouseMotionListener(this); 70 70 drawHint(false); 71 71 } … … 79 79 return; 80 80 81 OsmPrimitive clicked = mv.getNearest(e.getPoint(), false);81 OsmPrimitive clicked = layer.getNearest(e.getPoint(), false); 82 82 if (clicked == null || !(clicked instanceof Node)) 83 83 return; … … 96 96 return; 97 97 98 OsmPrimitive clicked = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);98 OsmPrimitive clicked = layer.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 99 99 if (clicked == null || clicked == second || !(clicked instanceof Node)) 100 100 return; … … 161 161 } 162 162 163 mv.repaint();163 layer.repaint(); 164 164 } 165 165 … … 175 175 return; 176 176 177 Graphics g = mv.getGraphics();177 Graphics g = layer.getGraphics(); 178 178 g.setColor(Color.BLACK); 179 179 g.setXORMode(Color.WHITE); 180 Point firstDrawn = mv.getScreenPoint(first.coor);181 Point secondDrawn = mv.getScreenPoint(second.coor);180 Point firstDrawn = layer.getScreenPoint(first.coor); 181 Point secondDrawn = layer.getScreenPoint(second.coor); 182 182 g.drawLine(firstDrawn.x, firstDrawn.y, secondDrawn.x, secondDrawn.y); 183 183 hintDrawn = !hintDrawn; -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r7 r15 30 30 public void registerListener() { 31 31 super.registerListener(); 32 mv.addMouseListener(this);32 layer.addMouseListener(this); 33 33 } 34 34 … … 36 36 public void unregisterListener() { 37 37 super.unregisterListener(); 38 mv.removeMouseListener(this);38 layer.removeMouseListener(this); 39 39 } 40 40 … … 47 47 if (e.getButton() == MouseEvent.BUTTON1) { 48 48 Node node = new Node(); 49 node.coor = mv.getPoint(e.getX(), e.getY(), true);49 node.coor = layer.getPoint(e.getX(), e.getY(), true); 50 50 ds.nodes.add(node); 51 mv.repaint();51 layer.repaint(); 52 52 } 53 53 } -
src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java
r8 r15 43 43 public AddTrackAction(MapFrame mapFrame) { 44 44 super("Add Track", "addtrack", "Combine line segments to a new track.", KeyEvent.VK_T, mapFrame); 45 this.selectionManager = new SelectionManager(this, false, mv);45 this.selectionManager = new SelectionManager(this, false, layer); 46 46 } 47 47 … … 49 49 public void registerListener() { 50 50 super.registerListener(); 51 selectionManager.register( mv);51 selectionManager.register(layer); 52 52 } 53 53 … … 55 55 public void unregisterListener() { 56 56 super.unregisterListener(); 57 selectionManager.unregister( mv);57 selectionManager.unregister(layer); 58 58 } 59 59 … … 82 82 osm.setSelected(!ctrl, ds); 83 83 84 mv.repaint(); // from now on, the map has to be repainted.84 layer.repaint(); // from now on, the map has to be repainted. 85 85 86 86 if (ctrl || shift) -
src/org/openstreetmap/josm/actions/mapmode/CombineAction.java
r8 r15 80 80 public void registerListener() { 81 81 super.registerListener(); 82 mv.addMouseListener(this);83 mv.addMouseMotionListener(this);82 layer.addMouseListener(this); 83 layer.addMouseMotionListener(this); 84 84 ds.clearSelection(); 85 85 } … … 88 88 public void unregisterListener() { 89 89 super.unregisterListener(); 90 mv.removeMouseListener(this);91 mv.removeMouseMotionListener(this);90 layer.removeMouseListener(this); 91 layer.removeMouseMotionListener(this); 92 92 drawCombineHint(false); 93 93 } … … 103 103 return; 104 104 105 OsmPrimitive clicked = mv.getNearest(e.getPoint(), true);105 OsmPrimitive clicked = layer.getNearest(e.getPoint(), true); 106 106 if (clicked == null || clicked instanceof Node) 107 107 return; … … 119 119 return; 120 120 121 OsmPrimitive clicked = mv.getNearest(e.getPoint(), true);121 OsmPrimitive clicked = layer.getNearest(e.getPoint(), true); 122 122 if (clicked == null || clicked == second || clicked instanceof Node) 123 123 return; … … 168 168 } 169 169 } 170 mv.repaint();170 layer.repaint(); 171 171 } 172 172 … … 198 198 return; 199 199 200 Graphics g = mv.getGraphics();200 Graphics g = layer.getGraphics(); 201 201 g.setColor(Color.BLACK); 202 202 g.setXORMode(Color.WHITE); … … 214 214 if (osm instanceof LineSegment) { 215 215 LineSegment ls = (LineSegment)osm; 216 Point start = mv.getScreenPoint(ls.getStart().coor);217 Point end = mv.getScreenPoint(ls.getEnd().coor);218 if ( mv.dataSet.pendingLineSegments().contains(osm) && g.getColor() == Color.GRAY)216 Point start = layer.getScreenPoint(ls.getStart().coor); 217 Point end = layer.getScreenPoint(ls.getEnd().coor); 218 if (layer.dataSet.pendingLineSegments().contains(osm) && g.getColor() == Color.GRAY) 219 219 g.drawLine(start.x, start.y, end.x, end.y); 220 220 else -
src/org/openstreetmap/josm/actions/mapmode/DebugAction.java
r8 r15 31 31 public void registerListener() { 32 32 super.registerListener(); 33 mv.addMouseMotionListener(this);34 mv.addMouseListener(this);33 layer.addMouseMotionListener(this); 34 layer.addMouseListener(this); 35 35 mapFrame.add(label, BorderLayout.SOUTH); 36 36 } … … 39 39 public void unregisterListener() { 40 40 super.unregisterListener(); 41 mv.removeMouseMotionListener(this);42 mv.removeMouseListener(this);41 layer.removeMouseMotionListener(this); 42 layer.removeMouseListener(this); 43 43 mapFrame.remove(label); 44 44 } … … 46 46 @Override 47 47 public void mouseClicked(MouseEvent e) { 48 Graphics g = mapFrame. mapView.getGraphics();48 Graphics g = mapFrame.layer.getGraphics(); 49 49 g.setColor(Color.WHITE); 50 for (Track t :mapFrame. mapView.dataSet.tracks())50 for (Track t :mapFrame.layer.dataSet.tracks()) 51 51 for (LineSegment ls : t.segments()) { 52 Point A = mapFrame. mapView.getScreenPoint(ls.getStart().coor);53 Point B = mapFrame. mapView.getScreenPoint(ls.getEnd().coor);52 Point A = mapFrame.layer.getScreenPoint(ls.getStart().coor); 53 Point B = mapFrame.layer.getScreenPoint(ls.getEnd().coor); 54 54 Point C = e.getPoint(); 55 55 Rectangle r = new Rectangle(A.x, A.y, B.x-A.x, B.y-A.y); -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r8 r15 71 71 public void registerListener() { 72 72 super.registerListener(); 73 mv.addMouseListener(this);73 layer.addMouseListener(this); 74 74 } 75 75 … … 77 77 public void unregisterListener() { 78 78 super.unregisterListener(); 79 mv.removeMouseListener(this);79 layer.removeMouseListener(this); 80 80 } 81 81 … … 89 89 return; 90 90 91 OsmPrimitive sel = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);91 OsmPrimitive sel = layer.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 92 92 if (sel == null) 93 93 return; … … 98 98 delete(sel); 99 99 100 mv.repaint();100 layer.repaint(); 101 101 } 102 102 -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r11 r15 14 14 import org.openstreetmap.josm.gui.Main; 15 15 import org.openstreetmap.josm.gui.MapFrame; 16 import org.openstreetmap.josm.gui. MapView;16 import org.openstreetmap.josm.gui.Layer; 17 17 18 18 /** … … 31 31 protected final MapFrame mapFrame; 32 32 /** 33 * Shortcut to the MapView.33 * Shortcut to the Layer. 34 34 */ 35 protected final MapView mv;35 protected final Layer layer; 36 36 /** 37 37 * Shortcut to the DataSet. … … 53 53 mapFrame.getActionMap().put(this, this); 54 54 this.mapFrame = mapFrame; 55 mv= mapFrame.mapView;56 ds = mv.dataSet;55 layer = mapFrame.layer; 56 ds = layer.dataSet; 57 57 } 58 58 59 59 /** 60 * Register all listener to the mapView 61 * @param mapView The view, where the listener should be registered. 60 * Register all listener to the layer 62 61 */ 63 62 public void registerListener() { … … 67 66 /** 68 67 * Unregister all listener previously registered. 69 * @param mapView The view from which the listener should be deregistered.70 68 */ 71 69 public void unregisterListener() { -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r8 r15 48 48 public void registerListener() { 49 49 super.registerListener(); 50 mv.addMouseListener(this);51 mv.addMouseMotionListener(this);50 layer.addMouseListener(this); 51 layer.addMouseMotionListener(this); 52 52 } 53 53 … … 55 55 public void unregisterListener() { 56 56 super.unregisterListener(); 57 mv.removeMouseListener(this);58 mv.removeMouseMotionListener(this);57 layer.removeMouseListener(this); 58 layer.removeMouseMotionListener(this); 59 59 } 60 60 … … 86 86 87 87 for (Node n : movingNodes) { 88 Point pos = mv.getScreenPoint(n.coor);88 Point pos = layer.getScreenPoint(n.coor); 89 89 pos.x += dx; 90 90 pos.y += dy; 91 n.coor = mv.getPoint(pos.x, pos.y, true);91 n.coor = layer.getPoint(pos.x, pos.y, true); 92 92 } 93 mv.repaint();93 layer.repaint(); 94 94 95 95 mousePos = e.getPoint(); … … 111 111 112 112 if (ds.getSelected().size() == 0) { 113 OsmPrimitive osm = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);113 OsmPrimitive osm = layer.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 114 114 if (osm != null) 115 115 osm.setSelected(true, ds); 116 116 singleOsmPrimitive = osm; 117 mv.repaint();117 layer.repaint(); 118 118 } else 119 119 singleOsmPrimitive = null; 120 120 121 121 mousePos = e.getPoint(); 122 oldCursor = mv.getCursor();123 mv.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));122 oldCursor = layer.getCursor(); 123 layer.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 124 124 } 125 125 … … 129 129 @Override 130 130 public void mouseReleased(MouseEvent e) { 131 mv.setCursor(oldCursor);131 layer.setCursor(oldCursor); 132 132 if (singleOsmPrimitive != null) { 133 133 singleOsmPrimitive.setSelected(false, ds); 134 mv.repaint();134 layer.repaint(); 135 135 } 136 136 } -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r8 r15 46 46 * and the user clicked in or 10 pixel away from an area, this area is selected. 47 47 * If there is even no area, nothing is selected. Shift and Ctrl key applies to 48 * this as usual. For more, @see MapView#getNearest(Point, boolean)48 * this as usual. For more, @see Layer#getNearest(Point, boolean) 49 49 * 50 50 * @author imi … … 63 63 public SelectionAction(MapFrame mapFrame) { 64 64 super("Selection", "selection", "Select objects by dragging or clicking", KeyEvent.VK_S, mapFrame); 65 this.selectionManager = new SelectionManager(this, false, mv);65 this.selectionManager = new SelectionManager(this, false, layer); 66 66 } 67 67 … … 69 69 public void registerListener() { 70 70 super.registerListener(); 71 selectionManager.register( mv);71 selectionManager.register(layer); 72 72 } 73 73 … … 75 75 public void unregisterListener() { 76 76 super.unregisterListener(); 77 selectionManager.unregister( mv);77 selectionManager.unregister(layer); 78 78 } 79 79 … … 92 92 for (OsmPrimitive osm : selectionList) 93 93 osm.setSelected(!ctrl, ds); 94 mv.repaint();94 layer.repaint(); 95 95 } 96 96 } -
src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r7 r15 6 6 import org.openstreetmap.josm.data.GeoPoint; 7 7 import org.openstreetmap.josm.gui.MapFrame; 8 import org.openstreetmap.josm.gui. MapView;8 import org.openstreetmap.josm.gui.Layer; 9 9 import org.openstreetmap.josm.gui.SelectionManager; 10 10 import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; … … 14 14 * 15 15 * Holding down the left mouse button select a rectangle with the same aspect 16 * ratio than the current map view.16 * ratio than the current layer. 17 17 * Holding down left and right let the user move the former selected rectangle. 18 18 * Releasing the left button zoom to the selection. … … 28 28 * Shortcut to the mapview. 29 29 */ 30 private final MapViewmv;30 private final Layer mv; 31 31 /** 32 32 * Manager that manages the selection rectangle with the aspect ratio of the 33 * MapView.33 * Layer. 34 34 */ 35 35 private final SelectionManager selectionManager; … … 42 42 public ZoomAction(MapFrame mapFrame) { 43 43 super("Zoom", "zoom", "Zoom in by dragging", KeyEvent.VK_Z, mapFrame); 44 mv = mapFrame. mapView;44 mv = mapFrame.layer; 45 45 selectionManager = new SelectionManager(this, true, mv); 46 46 } -
src/org/openstreetmap/josm/data/Preferences.java
r6 r15 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; 5 7 import java.io.FileWriter; 8 import java.util.LinkedList; 6 9 import java.util.List; 7 10 … … 25 28 public class Preferences { 26 29 30 27 31 /** 28 32 * The look and feel. Classname of the look and feel class to use. 29 33 */ 30 public LookAndFeelInfo laf = UIManager.getInstalledLookAndFeels()[0]; 31 34 private LookAndFeelInfo laf = UIManager.getInstalledLookAndFeels()[0]; 32 35 /** 33 36 * The convertor used to translate lat/lon points to screen points. 34 37 */ 35 public Projection projection = new UTM(); 38 private Projection projection = new UTM(); 39 /** 40 * Whether nodes on the same place should be considered identical. 41 */ 42 private boolean mergeNodes = true; 43 36 44 37 45 38 46 /** 39 * Whether nodes on the same place should be considered identical. 47 * Exception thrown in case of any loading/saving error (including parse errors). 48 * @author imi 40 49 */ 41 public boolean mergeNodes = true; 42 43 50 public static class PreferencesException extends Exception { 51 public PreferencesException(String message, Throwable cause) { 52 super(message, cause); 53 } 54 } 44 55 45 56 /** … … 51 62 }; 52 63 64 65 66 67 // listener stuff 68 69 /** 70 * The event listener list 71 */ 72 private List<PropertyChangeListener> listener = new LinkedList<PropertyChangeListener>(); 73 /** 74 * If <code>listener != null</code>, add it to the listener list. 75 */ 76 public void addPropertyChangeListener(PropertyChangeListener listener) { 77 if (listener != null) 78 this.listener.add(listener); 79 } 80 /** 81 * If <code>listener != null</code>, remove it from the listener list. 82 */ 83 public void removePropertyChangeListener(PropertyChangeListener listener) { 84 if (listener != null) 85 this.listener.remove(listener); 86 } 87 /** 88 * Fires an event that the property has changed. 89 */ 90 private void firePropertyChanged(String propName, Object oldValue, Object newValue) { 91 PropertyChangeEvent event = null; 92 for (PropertyChangeListener l : listener) { 93 if (event == null) 94 event = new PropertyChangeEvent(this, propName, oldValue, newValue); 95 l.propertyChange(event); 96 } 97 } 98 99 100 53 101 /** 54 102 * Return the location of the preferences file … … 58 106 } 59 107 60 /**61 * Exception thrown in case of any loading/saving error (including parse errors).62 * @author imi63 */64 public static class PreferencesException extends Exception {65 public PreferencesException(String message, Throwable cause) {66 super(message, cause);67 }68 }69 108 /** 70 109 * Load from disk. … … 81 120 for (LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) 82 121 if (lafInfo.getClassName().equals(lafClassName)) { 83 laf =lafInfo;122 setLaf(lafInfo); 84 123 break; 85 124 } 86 if ( laf== null)125 if (getLaf() == null) 87 126 throw new PreferencesException("Look and Feel not found.", null); 88 89 projection = (Projection)Class.forName(root.getChildText("projection")).newInstance(); 90 mergeNodes = root.getChild("mergeNodes") != null; 127 128 // set projection 129 Class<?> projectionClass = Class.forName(root.getChildText("projection")); 130 projection = allProjections[0]; // defaults to UTM 131 for (Projection p : allProjections) { 132 if (p.getClass() == projectionClass) { 133 projection = p; 134 break; 135 } 136 } 137 138 setMergeNodes(root.getChild("mergeNodes") != null); 91 139 } catch (Exception e) { 92 140 if (e instanceof PreferencesException) … … 105 153 106 154 List children = root.getChildren(); 107 children.add(new Element("laf").setText( laf.getClassName()));108 children.add(new Element("projection").setText( projection.getClass().getName()));109 if ( mergeNodes)155 children.add(new Element("laf").setText(getLaf().getClassName())); 156 children.add(new Element("projection").setText(getProjection().getClass().getName())); 157 if (isMergeNodes()) 110 158 children.add(new Element("mergeNodes")); 111 159 … … 118 166 } 119 167 } 168 169 // getter / setter 170 171 public void setProjection(Projection projection) { 172 Projection old = this.projection; 173 this.projection = projection; 174 firePropertyChanged("projection", old, projection); 175 } 176 public Projection getProjection() { 177 return projection; 178 } 179 public void setMergeNodes(boolean mergeNodes) { 180 boolean old = this.mergeNodes; 181 this.mergeNodes = mergeNodes; 182 firePropertyChanged("mergeNodes", old, mergeNodes); 183 } 184 public boolean isMergeNodes() { 185 return mergeNodes; 186 } 187 public void setLaf(LookAndFeelInfo laf) { 188 LookAndFeelInfo old = this.laf; 189 this.laf = laf; 190 firePropertyChanged("laf", old, laf); 191 } 192 public LookAndFeelInfo getLaf() { 193 return laf; 194 } 120 195 } -
src/org/openstreetmap/josm/data/osm/DataSet.java
r8 r15 113 113 Node first = nodes.iterator().next(); 114 114 Bounds b = new Bounds(first.coor.clone(), first.coor.clone()); 115 for (Node w: nodes)115 for (Node n : nodes) 116 116 { 117 if (Double.isNaN( w.coor.x) || Double.isNaN(w.coor.y))117 if (Double.isNaN(n.coor.x) || Double.isNaN(n.coor.y)) 118 118 return null; 119 if ( w.coor.x < b.min.x)120 b.min.x = w.coor.x;121 if ( w.coor.y < b.min.y)122 b.min.y = w.coor.y;123 if ( w.coor.x > b.max.x)124 b.max.x = w.coor.x;125 if ( w.coor.y > b.max.y)126 b.max.y = w.coor.y;119 if (n.coor.x < b.min.x) 120 b.min.x = n.coor.x; 121 if (n.coor.y < b.min.y) 122 b.min.y = n.coor.y; 123 if (n.coor.x > b.max.x) 124 b.max.x = n.coor.x; 125 if (n.coor.y > b.max.y) 126 b.max.y = n.coor.y; 127 127 } 128 128 return b; -
src/org/openstreetmap/josm/data/projection/Projection.java
r7 r15 10 10 import org.openstreetmap.josm.data.GeoPoint; 11 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.data.osm.Node;13 12 14 13 /** … … 66 65 */ 67 66 abstract public JComponent getConfigurationPanel(); 68 67 69 68 /** 70 69 * Initialize itself with the given dataSet. 71 70 * 72 71 * This function should initialize own parameters needed to do the 73 * projection and then initialize every Node of the dataset with x/y 74 * projection values. 72 * projection at best effort. 75 73 * 76 * This implementation loops through the dataset's nodes and call latlon2xy77 * for each member. Subclasses can call this toinitialize the dataset.78 * 79 * init must not fire an state changed event, since it is usually called80 * from the event handler.74 * Init must not fire an state changed event, since it is usually called 75 * during the initialization of the mapFrame. 76 * 77 * This implementation does nothing. It is provided only for subclasses 78 * to initialize their data members. 81 79 * 82 80 * @param dataSet … … 88 86 * is far away from any coordinate in the dataset) 89 87 */ 90 public void init(DataSet dataSet) { 91 for (Node w : dataSet.nodes) 92 latlon2xy(w.coor); 93 } 94 95 /** 96 * All projections support cloning. 97 */ 98 @Override 99 public Projection clone() { 100 try {return (Projection)super.clone();} catch (CloneNotSupportedException e) {} 101 return null; 102 } 88 public void init(DataSet dataSet) {} 103 89 104 90 /** -
src/org/openstreetmap/josm/data/projection/UTM.java
r6 r15 210 210 hemisphere = lat > 0 ? Hemisphere.north : Hemisphere.south; 211 211 } 212 super.init(dataSet);213 212 } 214 213 -
src/org/openstreetmap/josm/gui/Layer.java
r14 r15 3 3 import java.awt.Graphics; 4 4 import java.awt.Point; 5 import java.awt.event.ActionEvent;6 5 import java.awt.event.ComponentEvent; 7 6 import java.awt.event.ComponentListener; 8 import java.awt.event.KeyEvent; 9 10 import javax.swing.AbstractAction; 11 import javax.swing.ImageIcon; 7 import java.beans.PropertyChangeEvent; 8 import java.beans.PropertyChangeListener; 9 12 10 import javax.swing.JComponent; 13 11 import javax.swing.event.ChangeEvent; … … 27 25 /** 28 26 * This is a component used in the MapFrame for browsing the map. It use is to 29 * provide the MapMode's enough capabilities to operate. 27 * provide the MapMode's enough capabilities to operate. 30 28 * 31 * MapViewholdsthe map data, organize it, convert it, provide access to it.29 * Layer holds one dataset. There can be more than one Layer active. 32 30 * 33 * MapView hold meta-data about the data set currently displayed, as scale level, 34 * center point viewed, what scrolling mode or editing mode is selected or with 35 * what projection the map is viewed etc.. 36 * 31 * Layer hold data of the current displayed graphics as scale level and 32 * center point view. 33 * 37 34 * @author imi 38 35 */ 39 public class MapView extends JComponent implements ComponentListener, ChangeListener { 40 41 /** 42 * Toggles the autoScale feature of the mapView 43 * @author imi 44 */ 45 public class AutoScaleAction extends AbstractAction { 46 public AutoScaleAction() { 47 super("Auto Scale", new ImageIcon(Main.class.getResource("/images/autoscale.png"))); 48 putValue(MNEMONIC_KEY, KeyEvent.VK_A); 49 } 50 public void actionPerformed(ActionEvent e) { 51 autoScale = !autoScale; 52 recalculateCenterScale(); 53 } 54 } 36 public class Layer extends JComponent implements ComponentListener, ChangeListener, PropertyChangeListener { 55 37 56 38 /** … … 69 51 70 52 /** 71 * Used projection method in this map72 */73 private Projection projection = Main.pref.projection.clone();74 75 /**76 53 * The underlying DataSet. 77 54 */ … … 84 61 85 62 /** 86 * Construct a MapView.87 */ 88 public MapView(DataSet dataSet) {63 * Construct a Layer. 64 */ 65 public Layer(DataSet dataSet) { 89 66 this.dataSet = dataSet; 90 67 addComponentListener(this); … … 93 70 new MapMover(this); 94 71 95 // initialize the projection96 setProjection(Main.pref.projection.clone());97 98 72 // initialize the drawing engine 99 73 engine = new SimpleEngine(this); 74 75 // initialize on the preferences for projection changes. 76 Main.pref.addPropertyChangeListener(this); 100 77 } 101 78 … … 120 97 p.y = (getHeight()/2.0 - y)*scale + center.y; 121 98 if (latlon) 122 getProjection().xy2latlon(p); 99 Main.pref.getProjection().xy2latlon(p); 123 100 return p; 124 101 } … … 138 115 throw new IllegalArgumentException("point: Either lat/lon or x/y must be set."); 139 116 p = point.clone(); 140 projection.latlon2xy(p);117 Main.pref.getProjection().latlon2xy(p); 141 118 } 142 119 int x = ((int)Math.round((p.x-center.x) / scale + getWidth()/2)); … … 236 213 autoScale = false; 237 214 center = newCenter.clone(); 238 projection.xy2latlon(center);215 Main.pref.getProjection().xy2latlon(center); 239 216 this.scale = scale; 240 217 recalculateCenterScale(); … … 268 245 */ 269 246 public void stateChanged(ChangeEvent e) { 270 projection.init(dataSet); 271 recalculateCenterScale(); 272 } 273 274 /** 275 * Set a new projection method. This call is not cheap, as it will 276 * transform the whole underlying dataSet and repaint itself. 277 * 278 * @param projection The new projection method to set. 279 */ 280 public void setProjection(Projection projection) { 281 if (projection == this.projection) 282 return; 283 284 Projection oldProjection = this.projection; 285 286 if (this.projection != null) 287 this.projection.removeChangeListener(this); 288 this.projection = projection; 289 projection.addChangeListener(this); 290 291 stateChanged(new ChangeEvent(this)); 292 firePropertyChange("projection", oldProjection, projection); 293 } 294 295 /** 296 * Return the projection method for this map view. 297 * @return The projection method. 298 */ 299 public Projection getProjection() { 300 return projection; 247 initDataSet(); 248 } 249 250 /** 251 * Called when a property, as example the projection of the Main preferences 252 * changes. 253 */ 254 public void propertyChange(PropertyChangeEvent evt) { 255 if (evt.getPropertyName().equals("projection")) { 256 Projection oldProjection = (Projection)evt.getOldValue(); 257 if (oldProjection != null) 258 oldProjection.removeChangeListener(this); 259 260 Projection newProjection = (Projection)evt.getNewValue(); 261 if (newProjection != null) 262 newProjection.addChangeListener(this); 263 264 initDataSet(); 265 } 301 266 } 302 267 … … 322 287 if (this.autoScale != autoScale) { 323 288 this.autoScale = autoScale; 289 if (autoScale) 290 recalculateCenterScale(); 324 291 firePropertyChange("autoScale", !autoScale, autoScale); 325 292 } … … 333 300 } 334 301 302 /** 303 * Initialize the DataSet with the projection taken from the preference 304 * settings. 305 */ 306 public void initDataSet() { 307 for (Node n : dataSet.nodes) 308 Main.pref.getProjection().latlon2xy(n.coor); 309 recalculateCenterScale(); 310 } 335 311 336 312 … … 357 333 // no bounds means standard scale and center 358 334 center = new GeoPoint(51.526447, -0.14746371); 359 getProjection().latlon2xy(center); 335 Main.pref.getProjection().latlon2xy(center); 360 336 scale = 10; 361 337 } else { 362 338 center = bounds.centerXY(); 363 getProjection().xy2latlon(center); 339 Main.pref.getProjection().xy2latlon(center); 364 340 double scaleX = (bounds.max.x-bounds.min.x)/w; 365 341 double scaleY = (bounds.max.y-bounds.min.y)/h; -
src/org/openstreetmap/josm/gui/Main.java
r9 r15 19 19 import org.openstreetmap.josm.data.Preferences; 20 20 import org.openstreetmap.josm.data.Preferences.PreferencesException; 21 import org.openstreetmap.josm.data.osm.DataSet; 22 import org.openstreetmap.josm.data.projection.Projection; 21 23 22 24 /** … … 119 121 120 122 try { 121 UIManager.setLookAndFeel(pref. laf.getClassName());123 UIManager.setLookAndFeel(pref.getLaf().getClassName()); 122 124 } catch (Exception e) { 123 125 e.printStackTrace(); … … 131 133 132 134 /** 133 * Set the main's mapframe. If a changed old mapFrame is alreadyset,134 * ask the user whether he want to save, discard or abort. If the user 135 * Create and set the main's mapframe. If a changed old mapFrame is already 136 * set, ask the user whether he want to save, discard or abort. If the user 135 137 * aborts, nothing happens. 136 138 */ 137 public void setMapFrame(String name, MapFrame mapFrame) {139 public void setMapFrame(String name, DataSet dataSet) { 138 140 //TODO: Check for changes and ask user 141 MapFrame mapFrame = new MapFrame(dataSet); 139 142 this.name = name; 140 143 this.mapFrame = mapFrame; … … 144 147 panel.add(mapFrame.toolBarActions, BorderLayout.WEST); 145 148 panel.add(mapFrame.statusLine, BorderLayout.SOUTH); 149 for (Projection p : Preferences.allProjections) 150 p.init(dataSet); 151 mapFrame.layer.initDataSet(); 146 152 panel.setVisible(true); 147 153 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r9 r15 14 14 import javax.swing.JToolBar; 15 15 16 import org.openstreetmap.josm.actions.AutoScaleAction; 16 17 import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction; 17 18 import org.openstreetmap.josm.actions.mapmode.AddNodeAction; … … 25 26 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 26 27 import org.openstreetmap.josm.data.osm.DataSet; 27 import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;28 28 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; 29 29 … … 43 43 * The view control displayed. 44 44 */ 45 public MapView mapView;45 public Layer layer; 46 46 /** 47 47 * The toolbar with the action icons … … 61 61 setLayout(new BorderLayout()); 62 62 63 add( mapView= newMapView(dataSet), BorderLayout.CENTER);63 add(layer = new Layer(dataSet), BorderLayout.CENTER); 64 64 65 65 // toolbar … … 84 84 // autoScale 85 85 toolBarActions.addSeparator(); 86 final JToggleButton autoScaleButton = new IconToggleButton(this, mapView.new AutoScaleAction());86 final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(layer)); 87 87 toolBarActions.add(autoScaleButton); 88 88 autoScaleButton.setText(null); 89 autoScaleButton.setSelected( mapView.isAutoScale());90 mapView.addPropertyChangeListener(new PropertyChangeListener(){89 autoScaleButton.setSelected(layer.isAutoScale()); 90 layer.addPropertyChangeListener(new PropertyChangeListener(){ 91 91 public void propertyChange(PropertyChangeEvent evt) { 92 92 if (evt.getPropertyName().equals("autoScale")) 93 autoScaleButton.setSelected( mapView.isAutoScale());93 autoScaleButton.setSelected(layer.isAutoScale()); 94 94 } 95 95 }); 96 97 // properties98 toolBarActions.add(new IconToggleButton(this, new PropertiesDialog(this)));99 96 100 97 // selection dialog … … 110 107 111 108 // status line below the map 112 statusLine = new MapStatus( mapView);109 statusLine = new MapStatus(layer); 113 110 } 114 111 -
src/org/openstreetmap/josm/gui/MapMover.java
r6 r15 26 26 * The map to move around. 27 27 */ 28 private final MapViewmv;28 private final Layer mv; 29 29 /** 30 30 * The old cursor when we changed it to movement cursor. … … 34 34 /** 35 35 * Create a new MapMover 36 * @param mapViewThe map that should be moved.36 * @param layer The map that should be moved. 37 37 */ 38 public MapMover( MapView mapView) {39 this.mv = mapView;38 public MapMover(Layer layer) { 39 this.mv = layer; 40 40 mv.addMouseListener(this); 41 41 mv.addMouseMotionListener(this); -
src/org/openstreetmap/josm/gui/MapStatus.java
r9 r15 39 39 40 40 /** 41 * The MapViewthis status belongs.41 * The Layer this status belongs. 42 42 */ 43 final MapViewmv;43 final Layer mv; 44 44 /** 45 45 * The position of the mouse cursor. … … 145 145 146 146 /** 147 * Construct a new MapStatus and attach it to the map view.148 * @param mv The MapViewthe status line is part of.147 * Construct a new MapStatus and attach it to the Layer. 148 * @param mv The Layer the status line is part of. 149 149 */ 150 public MapStatus(final MapViewmv) {150 public MapStatus(final Layer mv) { 151 151 this.mv = mv; 152 152 -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r11 r15 48 48 public void actionPerformed(ActionEvent e) { 49 49 Preferences pref = new Preferences(); 50 pref. laf =(LookAndFeelInfo)lafCombo.getSelectedItem();51 pref. projection=(Projection)projectionCombo.getSelectedItem();52 pref. mergeNodes=mergeNodes.isSelected();53 Main.pref. projection= pref.projection;50 pref.setLaf((LookAndFeelInfo)lafCombo.getSelectedItem()); 51 pref.setProjection((Projection)projectionCombo.getSelectedItem()); 52 pref.setMergeNodes(mergeNodes.isSelected()); 53 Main.pref.setProjection(pref.getProjection()); 54 54 try { 55 55 pref.save(); … … 125 125 return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus); 126 126 }}); 127 lafCombo.setSelectedItem(pref. laf);127 lafCombo.setSelectedItem(pref.getLaf()); 128 128 lafCombo.addActionListener(new ActionListener(){ 129 129 public void actionPerformed(ActionEvent e) { … … 133 133 // projection method combo box 134 134 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 135 if (projectionCombo.getItemAt(i).getClass().equals(pref. projection.getClass())) {135 if (projectionCombo.getItemAt(i).getClass().equals(pref.getProjection().getClass())) { 136 136 projectionCombo.setSelectedIndex(i); 137 137 break; … … 160 160 map.add(labelNoteProjection, GBC.eol().insets(0,5,0,20)); 161 161 map.add(new JLabel("GPX import / export"), GBC.eol()); 162 mergeNodes.setSelected(pref. mergeNodes);162 mergeNodes.setSelected(pref.isMergeNodes()); 163 163 map.add(mergeNodes, GBC.eol()); 164 164 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); -
src/org/openstreetmap/josm/gui/SelectionManager.java
r8 r15 88 88 private Point mousePos; 89 89 /** 90 * The MapView, the selection rectangle is drawn onto.91 */ 92 private final MapViewmv;90 * The Layer, the selection rectangle is drawn onto. 91 */ 92 private final Layer mv; 93 93 /** 94 94 * Whether the selection rectangle must obtain the aspect ratio of the … … 104 104 * @param aspectRatio If true, the selection window must obtain the aspect 105 105 * ratio of the drawComponent. 106 * @param mapViewThe view, the rectangle is drawn onto.107 */ 108 public SelectionManager(SelectionEnded selectionEndedListener, boolean aspectRatio, MapView mapView) {106 * @param layer The view, the rectangle is drawn onto. 107 */ 108 public SelectionManager(SelectionEnded selectionEndedListener, boolean aspectRatio, Layer layer) { 109 109 this.selectionEndedListener = selectionEndedListener; 110 110 this.aspectRatio = aspectRatio; 111 this.mv = mapView;111 this.mv = layer; 112 112 } 113 113 -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r8 r15 1 1 package org.openstreetmap.josm.gui.dialogs; 2 2 3 import java.awt.event.ActionEvent;4 import java.awt.event.ActionListener;5 3 import java.awt.event.KeyEvent; 6 4 7 5 import javax.swing.BorderFactory; 8 6 import javax.swing.Box; 9 import javax.swing.BoxLayout;10 import javax.swing.JComboBox;11 import javax.swing.JComponent;12 import javax.swing.JLabel;13 import javax.swing.JPanel;14 import javax.swing.border.Border;15 7 16 import org.openstreetmap.josm.data.Preferences;17 import org.openstreetmap.josm.data.projection.Projection;18 8 import org.openstreetmap.josm.gui.Main; 19 9 import org.openstreetmap.josm.gui.MapFrame; … … 35 25 putValue(MNEMONIC_KEY, KeyEvent.VK_P); 36 26 37 final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0); 27 // final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0); 38 28 Box panel = Box.createVerticalBox(); 39 29 40 30 // making an array of all projections and the current one within 41 Projection[] allProjections = Preferences.allProjections.clone(); 42 for (int i = 0; i < allProjections.length; ++i) 43 if (allProjections[i].getClass() == frame. mapView.getProjection().getClass())44 allProjections[i] = frame. mapView.getProjection();45 46 // projection 47 Box projectionPanel = Box.createHorizontalBox(); 48 projectionPanel.setBorder(panelBorder); 49 projectionPanel.add(new JLabel("Projection")); 50 final JComboBox projectionCombo = new JComboBox(allProjections); 51 projectionPanel.add(projectionCombo); 52 panel.add(projectionPanel); 53 final JPanel configurationPanel = new JPanel(); 54 configurationPanel.setLayout(new BoxLayout(configurationPanel, BoxLayout.X_AXIS)); 55 56 // projections details 57 projectionCombo.addActionListener(new ActionListener(){ 58 public void actionPerformed(ActionEvent e) { 59 configurationPanel.removeAll(); 60 frame. mapView.setProjection((Projection)projectionCombo.getSelectedItem());61 JComponent panel = frame. mapView.getProjection().getConfigurationPanel();62 if (panel != null) { 63 panel.setBorder(panelBorder); 64 configurationPanel.add(panel); 65 } 66 pack(); 67 } 68 }); 69 panel.add(configurationPanel); 70 projectionCombo.setSelectedItem(frame. mapView.getProjection());31 // Projection[] allProjections = Preferences.allProjections.clone(); 32 // for (int i = 0; i < allProjections.length; ++i) 33 // if (allProjections[i].getClass() == frame.layer.getProjection().getClass()) 34 // allProjections[i] = frame.layer.getProjection(); 35 // 36 // // projection 37 // Box projectionPanel = Box.createHorizontalBox(); 38 // projectionPanel.setBorder(panelBorder); 39 // projectionPanel.add(new JLabel("Projection")); 40 // final JComboBox projectionCombo = new JComboBox(allProjections); 41 // projectionPanel.add(projectionCombo); 42 // panel.add(projectionPanel); 43 // final JPanel configurationPanel = new JPanel(); 44 // configurationPanel.setLayout(new BoxLayout(configurationPanel, BoxLayout.X_AXIS)); 45 // 46 // // projections details 47 // projectionCombo.addActionListener(new ActionListener(){ 48 // public void actionPerformed(ActionEvent e) { 49 // configurationPanel.removeAll(); 50 // frame.layer.setProjection((Projection)projectionCombo.getSelectedItem()); 51 // JComponent panel = frame.layer.getProjection().getConfigurationPanel(); 52 // if (panel != null) { 53 // panel.setBorder(panelBorder); 54 // configurationPanel.add(panel); 55 // } 56 // pack(); 57 // } 58 // }); 59 // panel.add(configurationPanel); 60 // projectionCombo.setSelectedItem(frame.layer.getProjection()); 71 61 72 62 panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r11 r15 2 2 3 3 import java.awt.event.ActionEvent; 4 import java.awt.event.KeyEvent;5 4 import java.util.HashMap; 6 5 import java.util.Map; … … 31 30 putValue(NAME, name); 32 31 putValue(MNEMONIC_KEY, mnemonic); 33 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_E,0));34 putValue(LONG_DESCRIPTION, "Open a selection list window.");32 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(mnemonic,0)); 33 putValue(LONG_DESCRIPTION, tooltip); 35 34 } 36 35 -
src/org/openstreetmap/josm/gui/engine/Engine.java
r8 r15 2 2 3 3 import java.awt.Graphics; 4 import java.beans.PropertyChangeEvent;5 import java.beans.PropertyChangeListener;6 4 7 5 import org.openstreetmap.josm.data.GeoPoint; … … 9 7 import org.openstreetmap.josm.data.osm.Node; 10 8 import org.openstreetmap.josm.data.osm.Track; 11 import org.openstreetmap.josm.data.projection.Projection; 12 import org.openstreetmap.josm.gui.MapView; 9 import org.openstreetmap.josm.gui.Layer; 13 10 14 11 /** … … 18 15 * @author imi 19 16 */ 20 abstract public class Engine implements PropertyChangeListener{17 abstract public class Engine { 21 18 22 /**23 * The projection method, this engine uses to render the graphics.24 */25 protected Projection projection;26 19 /** 27 20 * The Graphics surface to draw on. This should be set before each painting … … 30 23 protected Graphics g; 31 24 /** 32 * The mapView, this engine was created for.25 * The layer, this engine was created for. 33 26 */ 34 protected final MapView mv;27 protected final Layer layer; 35 28 36 29 37 30 /** 38 * Creates an Engine from an MapViewit belongs to.39 * @param mapViewThe mapview this engine belongs to.31 * Creates an Engine from an Layer it belongs to. 32 * @param layer The mapview this engine belongs to. 40 33 */ 41 public Engine(MapView mapView) { 42 mv = mapView; 43 mv.addPropertyChangeListener(this); 34 public Engine(Layer layer) { 35 this.layer = layer; 44 36 } 45 37 … … 73 65 */ 74 66 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 67 } -
src/org/openstreetmap/josm/gui/engine/SimpleEngine.java
r8 r15 10 10 import org.openstreetmap.josm.data.osm.Node; 11 11 import org.openstreetmap.josm.data.osm.Track; 12 import org.openstreetmap.josm.gui. MapView;12 import org.openstreetmap.josm.gui.Layer; 13 13 14 14 /** … … 23 23 private final static Color darkgreen = new Color(0,128,0); 24 24 25 public SimpleEngine( MapView mapView) {26 super( mapView);25 public SimpleEngine(Layer layer) { 26 super(layer); 27 27 } 28 28 … … 33 33 public void drawBackground(GeoPoint ulGeo, GeoPoint lrGeo) { 34 34 g.setColor(Color.BLACK); 35 g.fillRect(0,0, mv.getWidth(),mv.getHeight());35 g.fillRect(0,0,layer.getWidth(),layer.getHeight()); 36 36 } 37 37 … … 109 109 private void drawLineSegment(LineSegment ls, Color color) { 110 110 g.setColor(ls.isSelected() ? Color.WHITE : color); 111 Point p1 = mv.getScreenPoint(ls.getStart().coor);112 Point p2 = mv.getScreenPoint(ls.getEnd().coor);111 Point p1 = layer.getScreenPoint(ls.getStart().coor); 112 Point p2 = layer.getScreenPoint(ls.getEnd().coor); 113 113 g.drawLine(p1.x, p1.y, p2.x, p2.y); 114 114 } … … 121 121 */ 122 122 private void drawNode(Node n, Color color) { 123 Point p = mv.getScreenPoint(n.coor);123 Point p = layer.getScreenPoint(n.coor); 124 124 g.setColor(color); 125 125 g.drawRect(p.x-1, p.y-1, 2, 2); -
src/org/openstreetmap/josm/io/GpxReader.java
r13 r15 161 161 */ 162 162 private Node addNode (DataSet data, Node node) { 163 if (Main.pref. mergeNodes)163 if (Main.pref.isMergeNodes()) 164 164 for (Node n : data.nodes) 165 165 if (node.coor.lat == n.coor.lat && node.coor.lon == n.coor.lon)
Note:
See TracChangeset
for help on using the changeset viewer.