Changeset 16 in josm
- Timestamp:
- 2005-10-08T17:14:54+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 deleted
- 29 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/OpenGpxAction.java
r15 r16 15 15 import org.openstreetmap.josm.data.osm.DataSet; 16 16 import org.openstreetmap.josm.gui.Main; 17 import org.openstreetmap.josm.gui.MapFrame; 17 18 import org.openstreetmap.josm.io.GpxReader; 18 19 import org.openstreetmap.josm.io.DataReader.ConnectionException; … … 54 55 try { 55 56 DataSet dataSet = new GpxReader(new FileReader(gpxFile)).parse(); 56 Main.main.setMapFrame(gpxFile.getName(), dataSet); 57 MapFrame map = new MapFrame(dataSet); 58 Main.main.setMapFrame(gpxFile.getName(), map); 57 59 } catch (ParseException x) { 58 60 x.printStackTrace(); -
src/org/openstreetmap/josm/actions/SaveGpxAction.java
r15 r16 46 46 try { 47 47 FileWriter fileWriter = new FileWriter(gpxFile); 48 GpxWriter out = new GpxWriter(fileWriter, Main.main.getMapFrame(). layer.dataSet);48 GpxWriter out = new GpxWriter(fileWriter, Main.main.getMapFrame().mapView.dataSet); 49 49 out.output(); 50 50 fileWriter.close(); -
src/org/openstreetmap/josm/actions/mapmode/AddLineSegmentAction.java
r15 r16 59 59 public void registerListener() { 60 60 super.registerListener(); 61 layer.addMouseListener(this);62 layer.addMouseMotionListener(this);61 mv.addMouseListener(this); 62 mv.addMouseMotionListener(this); 63 63 } 64 64 … … 66 66 public void unregisterListener() { 67 67 super.unregisterListener(); 68 layer.removeMouseListener(this);69 layer.removeMouseMotionListener(this);68 mv.removeMouseListener(this); 69 mv.removeMouseMotionListener(this); 70 70 drawHint(false); 71 71 } … … 79 79 return; 80 80 81 OsmPrimitive clicked = layer.getNearest(e.getPoint(), false);81 OsmPrimitive clicked = mv.getNearest(e.getPoint(), false); 82 82 if (clicked == null || !(clicked instanceof Node)) 83 83 return; … … 96 96 return; 97 97 98 OsmPrimitive clicked = layer.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);98 OsmPrimitive clicked = mv.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 layer.repaint();163 mv.repaint(); 164 164 } 165 165 … … 175 175 return; 176 176 177 Graphics g = layer.getGraphics();177 Graphics g = mv.getGraphics(); 178 178 g.setColor(Color.BLACK); 179 179 g.setXORMode(Color.WHITE); 180 Point firstDrawn = layer.getScreenPoint(first.coor);181 Point secondDrawn = layer.getScreenPoint(second.coor);180 Point firstDrawn = mv.getScreenPoint(first.coor); 181 Point secondDrawn = mv.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
r15 r16 30 30 public void registerListener() { 31 31 super.registerListener(); 32 layer.addMouseListener(this);32 mv.addMouseListener(this); 33 33 } 34 34 … … 36 36 public void unregisterListener() { 37 37 super.unregisterListener(); 38 layer.removeMouseListener(this);38 mv.removeMouseListener(this); 39 39 } 40 40 … … 47 47 if (e.getButton() == MouseEvent.BUTTON1) { 48 48 Node node = new Node(); 49 node.coor = layer.getPoint(e.getX(), e.getY(), true);49 node.coor = mv.getPoint(e.getX(), e.getY(), true); 50 50 ds.nodes.add(node); 51 layer.repaint();51 mv.repaint(); 52 52 } 53 53 } -
src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java
r15 r16 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, layer);45 this.selectionManager = new SelectionManager(this, false, mv); 46 46 } 47 47 … … 49 49 public void registerListener() { 50 50 super.registerListener(); 51 selectionManager.register( layer);51 selectionManager.register(mv); 52 52 } 53 53 … … 55 55 public void unregisterListener() { 56 56 super.unregisterListener(); 57 selectionManager.unregister( layer);57 selectionManager.unregister(mv); 58 58 } 59 59 … … 82 82 osm.setSelected(!ctrl, ds); 83 83 84 layer.repaint(); // from now on, the map has to be repainted.84 mv.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
r15 r16 80 80 public void registerListener() { 81 81 super.registerListener(); 82 layer.addMouseListener(this);83 layer.addMouseMotionListener(this);82 mv.addMouseListener(this); 83 mv.addMouseMotionListener(this); 84 84 ds.clearSelection(); 85 85 } … … 88 88 public void unregisterListener() { 89 89 super.unregisterListener(); 90 layer.removeMouseListener(this);91 layer.removeMouseMotionListener(this);90 mv.removeMouseListener(this); 91 mv.removeMouseMotionListener(this); 92 92 drawCombineHint(false); 93 93 } … … 103 103 return; 104 104 105 OsmPrimitive clicked = layer.getNearest(e.getPoint(), true);105 OsmPrimitive clicked = mv.getNearest(e.getPoint(), true); 106 106 if (clicked == null || clicked instanceof Node) 107 107 return; … … 119 119 return; 120 120 121 OsmPrimitive clicked = layer.getNearest(e.getPoint(), true);121 OsmPrimitive clicked = mv.getNearest(e.getPoint(), true); 122 122 if (clicked == null || clicked == second || clicked instanceof Node) 123 123 return; … … 168 168 } 169 169 } 170 layer.repaint();170 mv.repaint(); 171 171 } 172 172 … … 198 198 return; 199 199 200 Graphics g = layer.getGraphics();200 Graphics g = mv.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 = layer.getScreenPoint(ls.getStart().coor);217 Point end = layer.getScreenPoint(ls.getEnd().coor);218 if ( layer.dataSet.pendingLineSegments().contains(osm) && g.getColor() == Color.GRAY)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) 219 219 g.drawLine(start.x, start.y, end.x, end.y); 220 220 else -
src/org/openstreetmap/josm/actions/mapmode/DebugAction.java
r15 r16 31 31 public void registerListener() { 32 32 super.registerListener(); 33 layer.addMouseMotionListener(this);34 layer.addMouseListener(this);33 mv.addMouseMotionListener(this); 34 mv.addMouseListener(this); 35 35 mapFrame.add(label, BorderLayout.SOUTH); 36 36 } … … 39 39 public void unregisterListener() { 40 40 super.unregisterListener(); 41 layer.removeMouseMotionListener(this);42 layer.removeMouseListener(this);41 mv.removeMouseMotionListener(this); 42 mv.removeMouseListener(this); 43 43 mapFrame.remove(label); 44 44 } … … 46 46 @Override 47 47 public void mouseClicked(MouseEvent e) { 48 Graphics g = mapFrame. layer.getGraphics();48 Graphics g = mapFrame.mapView.getGraphics(); 49 49 g.setColor(Color.WHITE); 50 for (Track t :mapFrame. layer.dataSet.tracks())50 for (Track t :mapFrame.mapView.dataSet.tracks()) 51 51 for (LineSegment ls : t.segments()) { 52 Point A = mapFrame. layer.getScreenPoint(ls.getStart().coor);53 Point B = mapFrame. layer.getScreenPoint(ls.getEnd().coor);52 Point A = mapFrame.mapView.getScreenPoint(ls.getStart().coor); 53 Point B = mapFrame.mapView.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
r15 r16 71 71 public void registerListener() { 72 72 super.registerListener(); 73 layer.addMouseListener(this);73 mv.addMouseListener(this); 74 74 } 75 75 … … 77 77 public void unregisterListener() { 78 78 super.unregisterListener(); 79 layer.removeMouseListener(this);79 mv.removeMouseListener(this); 80 80 } 81 81 … … 89 89 return; 90 90 91 OsmPrimitive sel = layer.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);91 OsmPrimitive sel = mv.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 layer.repaint();100 mv.repaint(); 101 101 } 102 102 -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r15 r16 14 14 import org.openstreetmap.josm.gui.Main; 15 15 import org.openstreetmap.josm.gui.MapFrame; 16 import org.openstreetmap.josm.gui. Layer;16 import org.openstreetmap.josm.gui.MapView; 17 17 18 18 /** … … 31 31 protected final MapFrame mapFrame; 32 32 /** 33 * Shortcut to the Layer.33 * Shortcut to the MapView. 34 34 */ 35 protected final Layer layer;35 protected final MapView mv; 36 36 /** 37 37 * Shortcut to the DataSet. … … 53 53 mapFrame.getActionMap().put(this, this); 54 54 this.mapFrame = mapFrame; 55 layer= mapFrame.layer;56 ds = layer.dataSet;55 mv = mapFrame.mapView; 56 ds = mv.dataSet; 57 57 } 58 58 59 59 /** 60 * Register all listener to the layer 60 * Register all listener to the mapView 61 * @param mapView The view, where the listener should be registered. 61 62 */ 62 63 public void registerListener() { … … 66 67 /** 67 68 * Unregister all listener previously registered. 69 * @param mapView The view from which the listener should be deregistered. 68 70 */ 69 71 public void unregisterListener() { -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r15 r16 48 48 public void registerListener() { 49 49 super.registerListener(); 50 layer.addMouseListener(this);51 layer.addMouseMotionListener(this);50 mv.addMouseListener(this); 51 mv.addMouseMotionListener(this); 52 52 } 53 53 … … 55 55 public void unregisterListener() { 56 56 super.unregisterListener(); 57 layer.removeMouseListener(this);58 layer.removeMouseMotionListener(this);57 mv.removeMouseListener(this); 58 mv.removeMouseMotionListener(this); 59 59 } 60 60 … … 86 86 87 87 for (Node n : movingNodes) { 88 Point pos = layer.getScreenPoint(n.coor);88 Point pos = mv.getScreenPoint(n.coor); 89 89 pos.x += dx; 90 90 pos.y += dy; 91 n.coor = layer.getPoint(pos.x, pos.y, true);91 n.coor = mv.getPoint(pos.x, pos.y, true); 92 92 } 93 layer.repaint();93 mv.repaint(); 94 94 95 95 mousePos = e.getPoint(); … … 111 111 112 112 if (ds.getSelected().size() == 0) { 113 OsmPrimitive osm = layer.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);113 OsmPrimitive osm = mv.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 layer.repaint();117 mv.repaint(); 118 118 } else 119 119 singleOsmPrimitive = null; 120 120 121 121 mousePos = e.getPoint(); 122 oldCursor = layer.getCursor();123 layer.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));122 oldCursor = mv.getCursor(); 123 mv.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 124 124 } 125 125 … … 129 129 @Override 130 130 public void mouseReleased(MouseEvent e) { 131 layer.setCursor(oldCursor);131 mv.setCursor(oldCursor); 132 132 if (singleOsmPrimitive != null) { 133 133 singleOsmPrimitive.setSelected(false, ds); 134 layer.repaint();134 mv.repaint(); 135 135 } 136 136 } -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r15 r16 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 Layer#getNearest(Point, boolean)48 * this as usual. For more, @see MapView#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, layer);65 this.selectionManager = new SelectionManager(this, false, mv); 66 66 } 67 67 … … 69 69 public void registerListener() { 70 70 super.registerListener(); 71 selectionManager.register( layer);71 selectionManager.register(mv); 72 72 } 73 73 … … 75 75 public void unregisterListener() { 76 76 super.unregisterListener(); 77 selectionManager.unregister( layer);77 selectionManager.unregister(mv); 78 78 } 79 79 … … 92 92 for (OsmPrimitive osm : selectionList) 93 93 osm.setSelected(!ctrl, ds); 94 layer.repaint();94 mv.repaint(); 95 95 } 96 96 } -
src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r15 r16 6 6 import org.openstreetmap.josm.data.GeoPoint; 7 7 import org.openstreetmap.josm.gui.MapFrame; 8 import org.openstreetmap.josm.gui. Layer;8 import org.openstreetmap.josm.gui.MapView; 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 layer.16 * ratio than the current map view. 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 Layermv;30 private final MapView mv; 31 31 /** 32 32 * Manager that manages the selection rectangle with the aspect ratio of the 33 * Layer.33 * MapView. 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. layer;44 mv = mapFrame.mapView; 45 45 selectionManager = new SelectionManager(this, true, mv); 46 46 } -
src/org/openstreetmap/josm/data/Preferences.java
r15 r16 1 1 package org.openstreetmap.josm.data; 2 2 3 import java.beans.PropertyChangeEvent;4 import java.beans.PropertyChangeListener;5 3 import java.io.File; 6 4 import java.io.FileReader; 7 5 import java.io.FileWriter; 6 import java.util.Collection; 8 7 import java.util.LinkedList; 9 8 import java.util.List; … … 28 27 public class Preferences { 29 28 30 31 29 /** 32 30 * The look and feel. Classname of the look and feel class to use. 33 31 */ 34 private LookAndFeelInfo laf = UIManager.getInstalledLookAndFeels()[0]; 32 public LookAndFeelInfo laf = UIManager.getInstalledLookAndFeels()[0]; 33 35 34 /** 36 35 * The convertor used to translate lat/lon points to screen points. 37 36 */ 38 37 private Projection projection = new UTM(); 38 39 39 40 /** 40 41 * Whether nodes on the same place should be considered identical. 41 42 */ 42 private boolean mergeNodes = true; 43 public boolean mergeNodes = true; 44 45 43 46 47 /** 48 * List of all available Projections. 49 */ 50 public static final Projection[] allProjections = new Projection[]{ 51 new UTM(), 52 new LatitudeLongitude() 53 }; 44 54 45 55 /** 56 * Return the location of the preferences file 57 */ 58 public static String getPreferencesFile() { 59 return System.getProperty("user.home")+"/.josm-preferences"; 60 } 61 46 62 /** 47 63 * Exception thrown in case of any loading/saving error (including parse errors). … … 53 69 } 54 70 } 55 56 /**57 * List of all available Projections.58 */59 public static final Projection[] allProjections = new Projection[]{60 new UTM(),61 new LatitudeLongitude()62 };63 64 65 66 67 // listener stuff68 69 /**70 * The event listener list71 */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 101 /**102 * Return the location of the preferences file103 */104 public static String getPreferencesFile() {105 return System.getProperty("user.home")+"/.josm-preferences";106 }107 108 71 /** 109 72 * Load from disk. … … 120 83 for (LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) 121 84 if (lafInfo.getClassName().equals(lafClassName)) { 122 setLaf(lafInfo);85 laf = lafInfo; 123 86 break; 124 87 } 125 if ( getLaf()== null)88 if (laf == null) 126 89 throw new PreferencesException("Look and Feel not found.", null); 127 128 // setprojection90 91 // projection 129 92 Class<?> projectionClass = Class.forName(root.getChildText("projection")); 130 93 projection = allProjections[0]; // defaults to UTM … … 136 99 } 137 100 138 setMergeNodes(root.getChild("mergeNodes") != null);101 mergeNodes = root.getChild("mergeNodes") != null; 139 102 } catch (Exception e) { 140 103 if (e instanceof PreferencesException) … … 153 116 154 117 List children = root.getChildren(); 155 children.add(new Element("laf").setText( getLaf().getClassName()));118 children.add(new Element("laf").setText(laf.getClassName())); 156 119 children.add(new Element("projection").setText(getProjection().getClass().getName())); 157 if ( isMergeNodes())120 if (mergeNodes) 158 121 children.add(new Element("mergeNodes")); 159 122 … … 167 130 } 168 131 169 // getter / setter 170 132 133 // projection change listener stuff 134 135 /** 136 * This interface notifies any interested about changes in the projection 137 * @author imi 138 */ 139 public interface ProjectionChangeListener { 140 void projectionChanged(Projection oldProjection, Projection newProjection); 141 } 142 /** 143 * The list of all listeners to projection changes. 144 */ 145 private Collection<ProjectionChangeListener> listener = new LinkedList<ProjectionChangeListener>(); 146 /** 147 * Add a listener of projection changes to the list of listeners. 148 * @param listener The listerner to add. 149 */ 150 public void addProjectionChangeListener(ProjectionChangeListener listener) { 151 if (listener != null) 152 this.listener.add(listener); 153 } 154 /** 155 * Remove the listener from the list. 156 */ 157 public void removeProjectionChangeListener(ProjectionChangeListener listener) { 158 this.listener.remove(listener); 159 } 160 /** 161 * Set the projection and fire an event to all ProjectionChangeListener 162 * @param projection The new Projection. 163 */ 171 164 public void setProjection(Projection projection) { 172 165 Projection old = this.projection; 173 166 this.projection = projection; 174 firePropertyChanged("projection", old, projection); 167 if (old != projection) 168 for (ProjectionChangeListener l : listener) 169 l.projectionChanged(old, projection); 175 170 } 171 /** 172 * Get the current projection. 173 * @return The current projection set. 174 */ 176 175 public Projection getProjection() { 177 176 return projection; 178 177 } 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 }195 178 } -
src/org/openstreetmap/josm/data/osm/DataSet.java
r15 r16 113 113 Node first = nodes.iterator().next(); 114 114 Bounds b = new Bounds(first.coor.clone(), first.coor.clone()); 115 for (Node n: nodes)115 for (Node w : nodes) 116 116 { 117 if (Double.isNaN( n.coor.x) || Double.isNaN(n.coor.y))117 if (Double.isNaN(w.coor.x) || Double.isNaN(w.coor.y)) 118 118 return null; 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;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; 127 127 } 128 128 return b; -
src/org/openstreetmap/josm/data/projection/LatitudeLongitude.java
r1 r16 1 1 package org.openstreetmap.josm.data.projection; 2 2 3 import javax.swing.J Panel;3 import javax.swing.JComponent; 4 4 5 5 import org.openstreetmap.josm.data.GeoPoint; … … 30 30 31 31 @Override 32 public String description() {33 return "Use lat/lon values directly.";32 public JComponent getConfigurationPanel() { 33 return null; 34 34 } 35 35 36 36 @Override 37 public JPanel getConfigurationPanel() { 38 return null; 37 public void commitConfigurationPanel() { 39 38 } 40 39 } -
src/org/openstreetmap/josm/data/projection/Projection.java
r15 r16 47 47 abstract public String toString(); 48 48 49 /**50 * Describe the projection converter. Give examples, where it is best to use51 * and maybe a reference link to more information about the converter.52 */53 abstract public String description();54 55 56 57 49 // miscellous functions 58 50 59 51 /** 60 52 * If the projection supports any configuration, this function return 61 * the configuration panel. If no configuration needed, return null. 53 * the configuration panel. If no configuration needed, 54 * return <code>null</code>. 62 55 * 63 * The items on the configuration panel should update the configuration 64 * directly, so the changes are instantly visible on screen. 56 * The items on the configuration panel should not update the configuration 57 * directly, but remember changed settings so a call to commitConfigurationPanel 58 * can set them. 59 * 60 * This function also rolls back all changes to the configuration panel interna 61 * components. 65 62 */ 66 63 abstract public JComponent getConfigurationPanel(); 64 /** 65 * Commits any changes from components created by addToConfigurationPanel. 66 * The projection should now obtain the new settings. If any setting has 67 * changed, the implementation have to call to fireStateChanged to inform 68 * the listeners. 69 */ 70 abstract public void commitConfigurationPanel(); 67 71 68 72 /** -
src/org/openstreetmap/josm/data/projection/UTM.java
r15 r16 1 1 package org.openstreetmap.josm.data.projection; 2 2 3 import java.awt.Font; 4 import java.awt.GridBagLayout; 3 5 import java.awt.event.ActionEvent; 4 6 import java.awt.event.ActionListener; 5 7 6 import javax.swing.BorderFactory; 7 import javax.swing.Box; 8 import javax.swing.JButton; 8 9 import javax.swing.JComboBox; 9 10 import javax.swing.JComponent; 10 11 import javax.swing.JLabel; 12 import javax.swing.JOptionPane; 13 import javax.swing.JPanel; 11 14 import javax.swing.JSpinner; 12 15 import javax.swing.SpinnerNumberModel; 13 import javax.swing.border.Border;14 import javax.swing.event.ChangeEvent;15 import javax.swing.event.ChangeListener;16 16 17 17 import org.openstreetmap.josm.data.Bounds; 18 18 import org.openstreetmap.josm.data.GeoPoint; 19 19 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.gui.GBC; 21 import org.openstreetmap.josm.gui.Main; 20 22 21 23 /** … … 93 95 protected Ellipsoid ellipsoid = allEllipsoids[allEllipsoids.length-1]; 94 96 97 /** 98 * Combobox with all ellipsoids for the configuration panel 99 */ 100 private JComboBox ellipsoidCombo = new JComboBox(allEllipsoids); 101 /** 102 * Spinner with all possible zones for the configuration panel 103 */ 104 private JSpinner zoneSpinner = new JSpinner(new SpinnerNumberModel(1,1,60,1)); 105 /** 106 * Hemisphere combo for the configuration panel 107 */ 108 private JComboBox hemisphereCombo = new JComboBox(Hemisphere.values()); 109 95 110 96 111 @Override … … 168 183 } 169 184 170 @Override 171 public String description() { 172 return "UTM projection ported from Ben Gimpert's ruby port.\n" + 173 "http://www.openstreetmap.org/websvn/filedetails.php?repname=" + 174 "OpenStreetMap&path=%2Futils%2Ftiger_import%2Ftiger%2Futm.rb"; 175 } 176 185 /** 186 * Helper class for the zone detection 187 * @author imi 188 */ 189 private class ZoneData { 190 int zone = 0; 191 Hemisphere hemisphere = Hemisphere.north; 192 } 193 /** 194 * Try to autodetect the zone and hemisphere from the dataset. 195 * @param dataSet The dataset to extrakt zone information from. 196 * @return The zone data extrakted from the dataset. 197 */ 198 private ZoneData autoDetect(DataSet dataSet) { 199 ZoneData zd = new ZoneData(); 200 201 Bounds b = dataSet.getBoundsLatLon(); 202 if (b == null) 203 return zd; 204 GeoPoint center = b.centerLatLon(); 205 double lat = center.lat; 206 double lon = center.lon; 207 // make sure the longitude is between -180.00 .. 179.9 208 double long_temp = (lon + 180) - (Math.floor((lon + 180) / 360) * 360) - 180; 209 210 zd.zone = (int)((long_temp + 180) / 6) + 1; 211 if ((lat >= 56.0) && (lat < 64.0) && (long_temp >= 3.0) && (long_temp < 12.0)) 212 zd.zone = 32; 213 // special zones for Svalbard 214 if ((lat >= 72.0) && (lat < 84.0)) 215 { 216 if ((long_temp >= 0.0) && (long_temp < 9.0)) 217 zd.zone = 31; 218 else if ((long_temp >= 9.0) && (long_temp < 21.0)) 219 zd.zone = 33; 220 else if ((long_temp >= 21.0) && (long_temp < 33.0)) 221 zd.zone = 35; 222 else if ((long_temp >= 33.0) && (long_temp < 42.0)) 223 zd.zone = 37; 224 } 225 zd.hemisphere = lat > 0 ? Hemisphere.north : Hemisphere.south; 226 return zd; 227 } 228 177 229 /** 178 230 * If the zone is not already set, calculate it from this dataset. … … 184 236 public void init(DataSet dataSet) { 185 237 if (zone == 0) { 186 Bounds b = dataSet.getBoundsLatLon(); 187 if (b == null) 188 return; 189 GeoPoint center = b.centerLatLon(); 190 double lat = center.lat; 191 double lon = center.lon; 192 // make sure the longitude is between -180.00 .. 179.9 193 double long_temp = (lon + 180) - (Math.floor((lon + 180) / 360) * 360) - 180; 194 195 zone = (int)((long_temp + 180) / 6) + 1; 196 if ((lat >= 56.0) && (lat < 64.0) && (long_temp >= 3.0) && (long_temp < 12.0)) 197 zone = 32; 198 // special zones for Svalbard 199 if ((lat >= 72.0) && (lat < 84.0)) 200 { 201 if ((long_temp >= 0.0) && (long_temp < 9.0)) 202 zone = 31; 203 else if ((long_temp >= 9.0) && (long_temp < 21.0)) 204 zone = 33; 205 else if ((long_temp >= 21.0) && (long_temp < 33.0)) 206 zone = 35; 207 else if ((long_temp >= 33.0) && (long_temp < 42.0)) 208 zone = 37; 209 } 210 hemisphere = lat > 0 ? Hemisphere.north : Hemisphere.south; 238 ZoneData zd = autoDetect(dataSet); 239 zone = zd.zone; 240 hemisphere = zd.hemisphere; 211 241 } 212 242 } … … 214 244 @Override 215 245 public JComponent getConfigurationPanel() { 216 Border border = BorderFactory.createEmptyBorder(5,0,0,0);217 Box panel = Box.createVerticalBox();218 246 JPanel panel = new JPanel(new GridBagLayout()); 247 GBC gbc = GBC.std().insets(0,0,5,0); 248 219 249 // ellipsoid 220 Box ellipsoidPanel = Box.createHorizontalBox(); 221 ellipsoidPanel.add(new JLabel("Ellipsoid")); 222 final JComboBox ellipsoidCombo = new JComboBox(allEllipsoids); 223 ellipsoidPanel.add(ellipsoidCombo); 250 panel.add(new JLabel("Ellipsoid"), gbc); 251 panel.add(ellipsoidCombo, GBC.eol()); 224 252 ellipsoidCombo.setSelectedItem(ellipsoid); 225 ellipsoidCombo.addActionListener(new ActionListener(){ 253 254 // zone 255 panel.add(new JLabel("Zone"), gbc); 256 panel.add(zoneSpinner, GBC.eol().insets(0,5,0,5)); 257 if (zone != 0) 258 zoneSpinner.setValue(zone); 259 260 // hemisphere 261 panel.add(new JLabel("Hemisphere"), gbc); 262 panel.add(hemisphereCombo, GBC.eop()); 263 hemisphereCombo.setSelectedItem(hemisphere); 264 265 // Autodetect 266 JButton autoDetect = new JButton("Detect"); 267 autoDetect.addActionListener(new ActionListener(){ 226 268 public void actionPerformed(ActionEvent e) { 227 ellipsoid = (Ellipsoid)ellipsoidCombo.getSelectedItem(); 228 fireStateChanged(); 269 if (Main.main.getMapFrame() != null) { 270 DataSet ds = Main.main.getMapFrame().mapView.dataSet; 271 ZoneData zd = autoDetect(ds); 272 if (zd.zone == 0) 273 JOptionPane.showMessageDialog(Main.main, "Autodetection failed. Maybe the data set contain too few information."); 274 else { 275 zoneSpinner.setValue(zd.zone); 276 hemisphereCombo.setSelectedItem(zd.hemisphere); 277 } 278 } else { 279 JOptionPane.showMessageDialog(Main.main, "No data loaded. Please open a data set first."); 280 } 229 281 } 230 282 }); 231 ellipsoidPanel.setBorder(border); 232 panel.add(ellipsoidPanel); 233 234 // zone 235 Box zonePanel = Box.createHorizontalBox(); 236 zonePanel.add(new JLabel("Zone")); 237 final JSpinner zoneSpinner = new JSpinner(new SpinnerNumberModel(zone,1,60,1)); 238 zonePanel.add(zoneSpinner); 239 zoneSpinner.addChangeListener(new ChangeListener(){ 240 public void stateChanged(ChangeEvent e) { 241 zone = (Integer)zoneSpinner.getValue(); 242 fireStateChanged(); 243 } 244 }); 245 zonePanel.setBorder(border); 246 panel.add(zonePanel); 247 248 // hemisphere 249 Box hemispherePanel = Box.createHorizontalBox(); 250 hemispherePanel.add(new JLabel("Hemisphere")); 251 final JComboBox hemisphereCombo = new JComboBox(Hemisphere.values()); 252 hemispherePanel.add(hemisphereCombo); 253 hemisphereCombo.setSelectedItem(hemisphere); 254 hemisphereCombo.addActionListener(new ActionListener(){ 255 public void actionPerformed(ActionEvent e) { 256 hemisphere = (Hemisphere)hemisphereCombo.getSelectedItem(); 257 fireStateChanged(); 258 } 259 }); 260 hemispherePanel.setBorder(border); 261 panel.add(hemispherePanel); 262 283 JLabel descLabel = new JLabel("Autodetect parameter based on loaded data"); 284 descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC)); 285 panel.add(descLabel, GBC.eol().fill(GBC.HORIZONTAL)); 286 panel.add(autoDetect, GBC.eol().anchor(GBC.CENTER)); 287 263 288 return panel; 264 289 } 290 291 @Override 292 public void commitConfigurationPanel() { 293 ellipsoid = (Ellipsoid)ellipsoidCombo.getSelectedItem(); 294 zone = (Integer)zoneSpinner.getValue(); 295 hemisphere = (Hemisphere)hemisphereCombo.getSelectedItem(); 296 fireStateChanged(); 297 } 265 298 } -
src/org/openstreetmap/josm/gui/GBC.java
r6 r16 41 41 } 42 42 43 /** 44 * Create the constraint for the last elements on a line and on a paragraph. 45 * This is merely a shortcut for eol().insets(0,0,0,10) 46 * @return A constraint which indicates the last item on a line. 47 */ 48 public static GBC eop() { 49 return eol().insets(0,0,0,10); 50 } 51 43 52 /** 44 53 * Try to fill both, horizontal and vertical -
src/org/openstreetmap/josm/gui/Main.java
r15 r16 5 5 import java.awt.Container; 6 6 7 import javax.swing.ImageIcon; 7 8 import javax.swing.JFrame; 8 9 import javax.swing.JMenu; … … 19 20 import org.openstreetmap.josm.data.Preferences; 20 21 import org.openstreetmap.josm.data.Preferences.PreferencesException; 21 import org.openstreetmap.josm.data.osm.DataSet;22 import org.openstreetmap.josm.data.projection.Projection;23 22 24 23 /** … … 103 102 */ 104 103 public static void main(String[] args) { 104 setupUiDefaults(); 105 105 106 // load preferences 106 107 String errMsg = null; … … 121 122 122 123 try { 123 UIManager.setLookAndFeel(pref. getLaf().getClassName());124 UIManager.setLookAndFeel(pref.laf.getClassName()); 124 125 } catch (Exception e) { 125 126 e.printStackTrace(); … … 133 134 134 135 /** 135 * Create and set the main's mapframe. If a changed old mapFrame is already136 * set,ask the user whether he want to save, discard or abort. If the user136 * Set the main's mapframe. If a changed old mapFrame is already set, 137 * ask the user whether he want to save, discard or abort. If the user 137 138 * aborts, nothing happens. 138 139 */ 139 public void setMapFrame(String name, DataSet dataSet) {140 public void setMapFrame(String name, MapFrame mapFrame) { 140 141 //TODO: Check for changes and ask user 141 MapFrame mapFrame = new MapFrame(dataSet);142 142 this.name = name; 143 143 this.mapFrame = mapFrame; … … 147 147 panel.add(mapFrame.toolBarActions, BorderLayout.WEST); 148 148 panel.add(mapFrame.statusLine, BorderLayout.SOUTH); 149 for (Projection p : Preferences.allProjections)150 p.init(dataSet);151 mapFrame.layer.initDataSet();152 149 panel.setVisible(true); 153 150 } … … 165 162 } 166 163 164 165 /** 166 * Sets some icons to the ui. 167 */ 168 private static void setupUiDefaults() { 169 UIManager.put("OptionPane.okIcon", new ImageIcon(Main.class.getResource("/images/ok.png"))); 170 UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon")); 171 UIManager.put("OptionPane.cancelIcon", new ImageIcon(Main.class.getResource("/images/cancel.png"))); 172 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); 173 } 167 174 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r15 r16 14 14 import javax.swing.JToolBar; 15 15 16 import org.openstreetmap.josm.actions.AutoScaleAction;17 16 import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction; 18 17 import org.openstreetmap.josm.actions.mapmode.AddNodeAction; … … 26 25 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 27 26 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 Layer layer;45 public MapView mapView; 46 46 /** 47 47 * The toolbar with the action icons … … 61 61 setLayout(new BorderLayout()); 62 62 63 add( layer= newLayer(dataSet), BorderLayout.CENTER);63 add(mapView = new MapView(dataSet), BorderLayout.CENTER); 64 64 65 65 // toolbar … … 84 84 // autoScale 85 85 toolBarActions.addSeparator(); 86 final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction( layer));86 final JToggleButton autoScaleButton = new IconToggleButton(this, mapView.new AutoScaleAction()); 87 87 toolBarActions.add(autoScaleButton); 88 88 autoScaleButton.setText(null); 89 autoScaleButton.setSelected( layer.isAutoScale());90 layer.addPropertyChangeListener(new PropertyChangeListener(){89 autoScaleButton.setSelected(mapView.isAutoScale()); 90 mapView.addPropertyChangeListener(new PropertyChangeListener(){ 91 91 public void propertyChange(PropertyChangeEvent evt) { 92 92 if (evt.getPropertyName().equals("autoScale")) 93 autoScaleButton.setSelected( layer.isAutoScale());93 autoScaleButton.setSelected(mapView.isAutoScale()); 94 94 } 95 95 }); 96 97 // properties 98 toolBarActions.add(new IconToggleButton(this, new PropertiesDialog(this))); 96 99 97 100 // selection dialog … … 107 110 108 111 // status line below the map 109 statusLine = new MapStatus( layer);112 statusLine = new MapStatus(mapView); 110 113 } 111 114 -
src/org/openstreetmap/josm/gui/MapMover.java
r15 r16 26 26 * The map to move around. 27 27 */ 28 private final Layermv;28 private final MapView 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 layerThe map that should be moved.36 * @param mapView The map that should be moved. 37 37 */ 38 public MapMover( Layer layer) {39 this.mv = layer;38 public MapMover(MapView mapView) { 39 this.mv = mapView; 40 40 mv.addMouseListener(this); 41 41 mv.addMouseMotionListener(this); -
src/org/openstreetmap/josm/gui/MapStatus.java
r15 r16 39 39 40 40 /** 41 * The Layerthis status belongs.41 * The MapView this status belongs. 42 42 */ 43 final Layermv;43 final MapView 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 Layer.148 * @param mv The Layerthe status line is part of.147 * Construct a new MapStatus and attach it to the map view. 148 * @param mv The MapView the status line is part of. 149 149 */ 150 public MapStatus(final Layermv) {150 public MapStatus(final MapView mv) { 151 151 this.mv = mv; 152 152 -
src/org/openstreetmap/josm/gui/MapView.java
r14 r16 16 16 import org.openstreetmap.josm.data.Bounds; 17 17 import org.openstreetmap.josm.data.GeoPoint; 18 import org.openstreetmap.josm.data.Preferences.ProjectionChangeListener; 18 19 import org.openstreetmap.josm.data.osm.DataSet; 19 20 import org.openstreetmap.josm.data.osm.LineSegment; … … 37 38 * @author imi 38 39 */ 39 public class MapView extends JComponent implements ComponentListener, ChangeListener { 40 public class MapView extends JComponent implements ComponentListener, ChangeListener, ProjectionChangeListener { 40 41 41 42 /** … … 69 70 70 71 /** 71 * Used projection method in this map72 */73 private Projection projection = Main.pref.projection.clone();74 75 /**76 72 * The underlying DataSet. 77 73 */ … … 94 90 95 91 // initialize the projection 96 setProjection(Main.pref.projection.clone()); 97 92 projectionChanged(null, Main.pref.getProjection()); 93 Main.pref.addProjectionChangeListener(this); 94 98 95 // initialize the drawing engine 99 96 engine = new SimpleEngine(this); … … 120 117 p.y = (getHeight()/2.0 - y)*scale + center.y; 121 118 if (latlon) 122 getProjection().xy2latlon(p); 119 Main.pref.getProjection().xy2latlon(p); 123 120 return p; 124 121 } … … 138 135 throw new IllegalArgumentException("point: Either lat/lon or x/y must be set."); 139 136 p = point.clone(); 140 projection.latlon2xy(p);137 Main.pref.getProjection().latlon2xy(p); 141 138 } 142 139 int x = ((int)Math.round((p.x-center.x) / scale + getWidth()/2)); … … 236 233 autoScale = false; 237 234 center = newCenter.clone(); 238 projection.xy2latlon(center);235 Main.pref.getProjection().xy2latlon(center); 239 236 this.scale = scale; 240 237 recalculateCenterScale(); … … 268 265 */ 269 266 public void stateChanged(ChangeEvent e) { 270 projection.init(dataSet); 267 for (Node n : dataSet.nodes) 268 Main.pref.getProjection().latlon2xy(n.coor); 271 269 recalculateCenterScale(); 272 }273 274 /**275 * Set a new projection method. This call is not cheap, as it will276 * 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;301 270 } 302 271 … … 334 303 335 304 305 306 /** 307 * Change to the new projection. Recalculate the dataset and zoom, if autoZoom 308 * is active. 309 * @param oldProjection The old projection. Unregister from this. 310 * @param newProjection The new projection. Register as state change listener. 311 */ 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(); 322 } 336 323 337 324 /** … … 357 344 // no bounds means standard scale and center 358 345 center = new GeoPoint(51.526447, -0.14746371); 359 getProjection().latlon2xy(center); 346 Main.pref.getProjection().latlon2xy(center); 360 347 scale = 10; 361 348 } else { 362 349 center = bounds.centerXY(); 363 getProjection().xy2latlon(center); 350 Main.pref.getProjection().xy2latlon(center); 364 351 double scaleX = (bounds.max.x-bounds.min.x)/w; 365 352 double scaleY = (bounds.max.y-bounds.min.y)/h; -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r15 r16 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.ActionListener; 9 import java.awt.event.KeyEvent;10 9 import java.io.File; 11 10 12 11 import javax.swing.AbstractAction; 12 import javax.swing.BorderFactory; 13 13 import javax.swing.Box; 14 14 import javax.swing.DefaultListCellRenderer; … … 17 17 import javax.swing.JCheckBox; 18 18 import javax.swing.JComboBox; 19 import javax.swing.JComponent; 19 20 import javax.swing.JDialog; 20 21 import javax.swing.JLabel; … … 43 44 class OkAction extends AbstractAction { 44 45 public OkAction() { 45 super("Ok", new ImageIcon(Main.class.getResource("/images/ok.png"))); 46 putValue(MNEMONIC_KEY, KeyEvent.VK_ENTER); 46 super(UIManager.getString("OptionPane.okButtonText"), 47 UIManager.getIcon("OptionPane.okIcon")); 48 putValue(MNEMONIC_KEY, new Integer((String)UIManager.get("OptionPane.okButtonMnemonic"))); 47 49 } 48 50 public void actionPerformed(ActionEvent e) { 49 Preferences pref = new Preferences();50 pref.setLaf((LookAndFeelInfo)lafCombo.getSelectedItem());51 pr ef.setProjection((Projection)projectionCombo.getSelectedItem());52 pref.set MergeNodes(mergeNodes.isSelected());53 Main.pref. setProjection(pref.getProjection());51 Main.pref.laf = (LookAndFeelInfo)lafCombo.getSelectedItem(); 52 Projection projection = (Projection)projectionCombo.getSelectedItem(); 53 projection.commitConfigurationPanel(); 54 Main.pref.setProjection(projection); 55 Main.pref.mergeNodes = mergeNodes.isSelected(); 54 56 try { 55 pref.save(); 57 Main.pref.save(); 56 58 } catch (PreferencesException x) { 57 59 x.printStackTrace(); … … 69 71 class CancelAction extends AbstractAction { 70 72 public CancelAction() { 71 super("Cancel", new ImageIcon("images/cancel.png")); 72 putValue(MNEMONIC_KEY, KeyEvent.VK_ESCAPE); 73 super(UIManager.getString("OptionPane.cancelButtonText"), 74 UIManager.getIcon("OptionPane.cancelIcon")); 75 putValue(MNEMONIC_KEY, new Integer((String)UIManager.get("OptionPane.cancelButtonMnemonic"))); 73 76 } 74 77 public void actionPerformed(ActionEvent e) { … … 125 128 return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus); 126 129 }}); 127 lafCombo.setSelectedItem(pref. getLaf());130 lafCombo.setSelectedItem(pref.laf); 128 131 lafCombo.addActionListener(new ActionListener(){ 129 132 public void actionPerformed(ActionEvent e) { … … 131 134 }}); 132 135 133 // projection methodcombo box136 // projection combo box 134 137 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 135 138 if (projectionCombo.getItemAt(i).getClass().equals(pref.getProjection().getClass())) { … … 138 141 } 139 142 } 143 JButton projectionDetail = new JButton("Configure"); 144 projectionDetail.addActionListener(new ActionListener(){ 145 public void actionPerformed(ActionEvent e) { 146 Projection p = (Projection)projectionCombo.getSelectedItem(); 147 JComponent configurationPanel = p.getConfigurationPanel(); 148 if (configurationPanel == null) { 149 JOptionPane.showMessageDialog(PreferenceDialog.this, 150 "This projection does not need any configuration."); 151 return; 152 } 153 JPanel detail = new JPanel(new GridBagLayout()); 154 detail.setLayout(new GridBagLayout()); 155 detail.add(configurationPanel, GBC.eop().fill()); 156 int result = JOptionPane.showConfirmDialog( 157 PreferenceDialog.this, detail, "Configuration of "+p, 158 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 159 if (result != JOptionPane.OK_OPTION) 160 p.getConfigurationPanel(); // rollback 161 } 162 }); 163 140 164 141 165 // Display tab 142 JPanel display = createPreferenceTab("display", "Display Settings", "Various settings tha ninfluence the visual representation of the wholeProgram.");166 JPanel display = createPreferenceTab("display", "Display Settings", "Various settings that influence the visual representation of the whole program."); 143 167 display.add(new JLabel("Look and Feel"), GBC.std()); 144 168 display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); … … 150 174 map.add(new JLabel("Projection method"), GBC.std()); 151 175 map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 152 map.add(projectionCombo, GBC.eol().fill(GBC.HORIZONTAL)); 153 JLabel labelNoteProjection = new JLabel( 154 "<html>Note: This is the default projection method used for files, " + 155 "where the correct projection could not be determined. " + 156 "The actual used projection can be changed in the property " + 157 "settings of each map.</html>"); 158 labelNoteProjection.setMinimumSize(new Dimension(550, 50)); 159 labelNoteProjection.setPreferredSize(new Dimension(550, 50)); 160 map.add(labelNoteProjection, GBC.eol().insets(0,5,0,20)); 176 map.add(projectionCombo, GBC.eol().fill(GBC.HORIZONTAL).insets(0,0,0,5)); 177 map.add(new JLabel("Projection details:"), GBC.std()); 178 map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 179 map.add(projectionDetail, GBC.eop()); 180 161 181 map.add(new JLabel("GPX import / export"), GBC.eol()); 162 mergeNodes.setSelected(pref. isMergeNodes());182 mergeNodes.setSelected(pref.mergeNodes); 163 183 map.add(mergeNodes, GBC.eol()); 164 184 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); … … 172 192 okPanel.add(new JButton(new OkAction()), GBC.std()); 173 193 okPanel.add(new JButton(new CancelAction()), GBC.std()); 194 okPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 174 195 175 196 // merging all in the content pane … … 196 217 JPanel p = new JPanel(new GridBagLayout()); 197 218 p.add(new JLabel(title), GBC.eol().anchor(GBC.CENTER).insets(0,5,0,10)); 198 JLabel descLabel = new JLabel(desc); 219 220 JLabel descLabel = new JLabel("<html>"+desc+"</html>"); 199 221 descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC)); 200 p.add(descLabel, GBC.eol().insets(5,0,5,20)); 222 p.add(descLabel, GBC.eol().insets(5,0,5,20).fill(GBC.HORIZONTAL)); 201 223 202 224 tabPane.addTab(null, new ImageIcon("images/preferences/"+icon+".png"), p); -
src/org/openstreetmap/josm/gui/SelectionManager.java
r15 r16 88 88 private Point mousePos; 89 89 /** 90 * The Layer, the selection rectangle is drawn onto.91 */ 92 private final Layermv;90 * The MapView, the selection rectangle is drawn onto. 91 */ 92 private final MapView 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 layerThe view, the rectangle is drawn onto.107 */ 108 public SelectionManager(SelectionEnded selectionEndedListener, boolean aspectRatio, Layer layer) {106 * @param mapView The view, the rectangle is drawn onto. 107 */ 108 public SelectionManager(SelectionEnded selectionEndedListener, boolean aspectRatio, MapView mapView) { 109 109 this.selectionEndedListener = selectionEndedListener; 110 110 this.aspectRatio = aspectRatio; 111 this.mv = layer;111 this.mv = mapView; 112 112 } 113 113 -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r15 r16 5 5 import javax.swing.BorderFactory; 6 6 import javax.swing.Box; 7 import javax.swing.JLabel; 8 import javax.swing.border.Border; 7 9 8 10 import org.openstreetmap.josm.gui.Main; … … 25 27 putValue(MNEMONIC_KEY, KeyEvent.VK_P); 26 28 27 //final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0);29 final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0); 28 30 Box panel = Box.createVerticalBox(); 29 30 // making an array of all projections and the current one within 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()); 31 32 JLabel todo = new JLabel("Nothing implemented yet."); 33 todo.setBorder(panelBorder); 34 panel.add(todo); 61 35 62 36 panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r15 r16 2 2 3 3 import java.awt.event.ActionEvent; 4 import java.awt.event.KeyEvent; 4 5 import java.util.HashMap; 5 6 import java.util.Map; … … 30 31 putValue(NAME, name); 31 32 putValue(MNEMONIC_KEY, mnemonic); 32 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke( mnemonic,0));33 putValue(LONG_DESCRIPTION, tooltip);33 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E,0)); 34 putValue(LONG_DESCRIPTION, "Open a selection list window."); 34 35 } 35 36 -
src/org/openstreetmap/josm/gui/engine/Engine.java
r15 r16 2 2 3 3 import java.awt.Graphics; 4 import java.beans.PropertyChangeEvent; 5 import java.beans.PropertyChangeListener; 4 6 5 7 import org.openstreetmap.josm.data.GeoPoint; … … 7 9 import org.openstreetmap.josm.data.osm.Node; 8 10 import org.openstreetmap.josm.data.osm.Track; 9 import org.openstreetmap.josm.gui.Layer; 11 import org.openstreetmap.josm.data.projection.Projection; 12 import org.openstreetmap.josm.gui.MapView; 10 13 11 14 /** … … 15 18 * @author imi 16 19 */ 17 abstract public class Engine { 20 abstract public class Engine implements PropertyChangeListener { 18 21 22 /** 23 * The projection method, this engine uses to render the graphics. 24 */ 25 protected Projection projection; 19 26 /** 20 27 * The Graphics surface to draw on. This should be set before each painting … … 23 30 protected Graphics g; 24 31 /** 25 * The layer, this engine was created for.32 * The mapView, this engine was created for. 26 33 */ 27 protected final Layer layer;34 protected final MapView mv; 28 35 29 36 30 37 /** 31 * Creates an Engine from an Layerit belongs to.32 * @param layerThe mapview this engine belongs to.38 * Creates an Engine from an MapView it belongs to. 39 * @param mapView The mapview this engine belongs to. 33 40 */ 34 public Engine(Layer layer) { 35 this.layer = layer; 41 public Engine(MapView mapView) { 42 mv = mapView; 43 mv.addPropertyChangeListener(this); 36 44 } 37 45 … … 65 73 */ 66 74 abstract public void drawPendingLineSegment(LineSegment ls); 75 76 /** 77 * Called when the projection method for the map changed. Subclasses with 78 * 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 } 67 84 } -
src/org/openstreetmap/josm/gui/engine/SimpleEngine.java
r15 r16 10 10 import org.openstreetmap.josm.data.osm.Node; 11 11 import org.openstreetmap.josm.data.osm.Track; 12 import org.openstreetmap.josm.gui. Layer;12 import org.openstreetmap.josm.gui.MapView; 13 13 14 14 /** … … 23 23 private final static Color darkgreen = new Color(0,128,0); 24 24 25 public SimpleEngine( Layer layer) {26 super( layer);25 public SimpleEngine(MapView mapView) { 26 super(mapView); 27 27 } 28 28 … … 33 33 public void drawBackground(GeoPoint ulGeo, GeoPoint lrGeo) { 34 34 g.setColor(Color.BLACK); 35 g.fillRect(0,0, layer.getWidth(),layer.getHeight());35 g.fillRect(0,0,mv.getWidth(),mv.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 = layer.getScreenPoint(ls.getStart().coor);112 Point p2 = layer.getScreenPoint(ls.getEnd().coor);111 Point p1 = mv.getScreenPoint(ls.getStart().coor); 112 Point p2 = mv.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 = layer.getScreenPoint(n.coor);123 Point p = mv.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
r15 r16 161 161 */ 162 162 private Node addNode (DataSet data, Node node) { 163 if (Main.pref. isMergeNodes())163 if (Main.pref.mergeNodes) 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.