Changeset 16 in josm


Ignore:
Timestamp:
Oct 8, 2005 5:14:54 PM (8 years ago)
Author:
imi
Message:
  • reverted to 14, but kept the global Projection.
  • improved the preference settings for projections.
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  
    1515import org.openstreetmap.josm.data.osm.DataSet; 
    1616import org.openstreetmap.josm.gui.Main; 
     17import org.openstreetmap.josm.gui.MapFrame; 
    1718import org.openstreetmap.josm.io.GpxReader; 
    1819import org.openstreetmap.josm.io.DataReader.ConnectionException; 
     
    5455                try { 
    5556                        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); 
    5759                } catch (ParseException x) { 
    5860                        x.printStackTrace(); 
  • src/org/openstreetmap/josm/actions/SaveGpxAction.java

    r15 r16  
    4646                try { 
    4747                        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); 
    4949                        out.output(); 
    5050                        fileWriter.close(); 
  • src/org/openstreetmap/josm/actions/mapmode/AddLineSegmentAction.java

    r15 r16  
    5959        public void registerListener() { 
    6060                super.registerListener(); 
    61                 layer.addMouseListener(this); 
    62                 layer.addMouseMotionListener(this); 
     61                mv.addMouseListener(this); 
     62                mv.addMouseMotionListener(this); 
    6363        } 
    6464 
     
    6666        public void unregisterListener() { 
    6767                super.unregisterListener(); 
    68                 layer.removeMouseListener(this); 
    69                 layer.removeMouseMotionListener(this); 
     68                mv.removeMouseListener(this); 
     69                mv.removeMouseMotionListener(this); 
    7070                drawHint(false); 
    7171        } 
     
    7979                        return; 
    8080 
    81                 OsmPrimitive clicked = layer.getNearest(e.getPoint(), false); 
     81                OsmPrimitive clicked = mv.getNearest(e.getPoint(), false); 
    8282                if (clicked == null || !(clicked instanceof Node)) 
    8383                        return; 
     
    9696                        return; 
    9797 
    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); 
    9999                if (clicked == null || clicked == second || !(clicked instanceof Node)) 
    100100                        return; 
     
    161161                } 
    162162                 
    163                 layer.repaint(); 
     163                mv.repaint(); 
    164164        } 
    165165 
     
    175175                        return; 
    176176 
    177                 Graphics g = layer.getGraphics(); 
     177                Graphics g = mv.getGraphics(); 
    178178                g.setColor(Color.BLACK); 
    179179                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); 
    182182                g.drawLine(firstDrawn.x, firstDrawn.y, secondDrawn.x, secondDrawn.y); 
    183183                hintDrawn = !hintDrawn; 
  • src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java

    r15 r16  
    3030        public void registerListener() { 
    3131                super.registerListener(); 
    32                 layer.addMouseListener(this); 
     32                mv.addMouseListener(this); 
    3333        } 
    3434 
     
    3636        public void unregisterListener() { 
    3737                super.unregisterListener(); 
    38                 layer.removeMouseListener(this); 
     38                mv.removeMouseListener(this); 
    3939        } 
    4040 
     
    4747                if (e.getButton() == MouseEvent.BUTTON1) { 
    4848                        Node node = new Node(); 
    49                         node.coor = layer.getPoint(e.getX(), e.getY(), true); 
     49                        node.coor = mv.getPoint(e.getX(), e.getY(), true); 
    5050                        ds.nodes.add(node); 
    51                         layer.repaint(); 
     51                        mv.repaint(); 
    5252                } 
    5353        } 
  • src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java

    r15 r16  
    4343        public AddTrackAction(MapFrame mapFrame) { 
    4444                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); 
    4646        } 
    4747 
     
    4949        public void registerListener() { 
    5050                super.registerListener(); 
    51                 selectionManager.register(layer); 
     51                selectionManager.register(mv); 
    5252        } 
    5353 
     
    5555        public void unregisterListener() { 
    5656                super.unregisterListener(); 
    57                 selectionManager.unregister(layer); 
     57                selectionManager.unregister(mv); 
    5858        } 
    5959 
     
    8282                        osm.setSelected(!ctrl, ds); 
    8383 
    84                 layer.repaint(); // from now on, the map has to be repainted. 
     84                mv.repaint(); // from now on, the map has to be repainted. 
    8585 
    8686                if (ctrl || shift) 
  • src/org/openstreetmap/josm/actions/mapmode/CombineAction.java

    r15 r16  
    8080        public void registerListener() { 
    8181                super.registerListener(); 
    82                 layer.addMouseListener(this); 
    83                 layer.addMouseMotionListener(this); 
     82                mv.addMouseListener(this); 
     83                mv.addMouseMotionListener(this); 
    8484                ds.clearSelection(); 
    8585        } 
     
    8888        public void unregisterListener() { 
    8989                super.unregisterListener(); 
    90                 layer.removeMouseListener(this); 
    91                 layer.removeMouseMotionListener(this); 
     90                mv.removeMouseListener(this); 
     91                mv.removeMouseMotionListener(this); 
    9292                drawCombineHint(false); 
    9393        } 
     
    103103                        return; 
    104104 
    105                 OsmPrimitive clicked = layer.getNearest(e.getPoint(), true); 
     105                OsmPrimitive clicked = mv.getNearest(e.getPoint(), true); 
    106106                if (clicked == null || clicked instanceof Node) 
    107107                        return; 
     
    119119                        return; 
    120120                 
    121                 OsmPrimitive clicked = layer.getNearest(e.getPoint(), true); 
     121                OsmPrimitive clicked = mv.getNearest(e.getPoint(), true); 
    122122                if (clicked == null || clicked == second || clicked instanceof Node) 
    123123                        return; 
     
    168168                        } 
    169169                } 
    170                 layer.repaint(); 
     170                mv.repaint(); 
    171171        } 
    172172 
     
    198198                        return; 
    199199 
    200                 Graphics g = layer.getGraphics(); 
     200                Graphics g = mv.getGraphics(); 
    201201                g.setColor(Color.BLACK); 
    202202                g.setXORMode(Color.WHITE); 
     
    214214                if (osm instanceof LineSegment) { 
    215215                        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) 
    219219                                g.drawLine(start.x, start.y, end.x, end.y); 
    220220                        else 
  • src/org/openstreetmap/josm/actions/mapmode/DebugAction.java

    r15 r16  
    3131        public void registerListener() { 
    3232                super.registerListener(); 
    33                 layer.addMouseMotionListener(this); 
    34                 layer.addMouseListener(this); 
     33                mv.addMouseMotionListener(this); 
     34                mv.addMouseListener(this); 
    3535                mapFrame.add(label, BorderLayout.SOUTH); 
    3636        } 
     
    3939        public void unregisterListener() { 
    4040                super.unregisterListener(); 
    41                 layer.removeMouseMotionListener(this); 
    42                 layer.removeMouseListener(this); 
     41                mv.removeMouseMotionListener(this); 
     42                mv.removeMouseListener(this); 
    4343                mapFrame.remove(label); 
    4444        } 
     
    4646        @Override 
    4747        public void mouseClicked(MouseEvent e) { 
    48                 Graphics g = mapFrame.layer.getGraphics(); 
     48                Graphics g = mapFrame.mapView.getGraphics(); 
    4949                g.setColor(Color.WHITE); 
    50                 for (Track t :mapFrame.layer.dataSet.tracks()) 
     50                for (Track t :mapFrame.mapView.dataSet.tracks()) 
    5151                        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); 
    5454                                Point C = e.getPoint(); 
    5555                                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  
    7171        public void registerListener() { 
    7272                super.registerListener(); 
    73                 layer.addMouseListener(this); 
     73                mv.addMouseListener(this); 
    7474        } 
    7575 
     
    7777        public void unregisterListener() { 
    7878                super.unregisterListener(); 
    79                 layer.removeMouseListener(this); 
     79                mv.removeMouseListener(this); 
    8080        } 
    8181 
     
    8989                        return; 
    9090                 
    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); 
    9292                if (sel == null) 
    9393                        return; 
     
    9898                        delete(sel); 
    9999 
    100                 layer.repaint(); 
     100                mv.repaint(); 
    101101        } 
    102102 
  • src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r15 r16  
    1414import org.openstreetmap.josm.gui.Main; 
    1515import org.openstreetmap.josm.gui.MapFrame; 
    16 import org.openstreetmap.josm.gui.Layer; 
     16import org.openstreetmap.josm.gui.MapView; 
    1717 
    1818/** 
     
    3131        protected final MapFrame mapFrame; 
    3232        /** 
    33          * Shortcut to the Layer. 
     33         * Shortcut to the MapView. 
    3434         */ 
    35         protected final Layer layer; 
     35        protected final MapView mv; 
    3636        /** 
    3737         * Shortcut to the DataSet. 
     
    5353                mapFrame.getActionMap().put(this, this); 
    5454                this.mapFrame = mapFrame; 
    55                 layer = mapFrame.layer; 
    56                 ds = layer.dataSet; 
     55                mv = mapFrame.mapView; 
     56                ds = mv.dataSet; 
    5757        } 
    5858         
    5959        /** 
    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. 
    6162         */ 
    6263        public void registerListener() { 
     
    6667        /** 
    6768         * Unregister all listener previously registered.  
     69         * @param mapView       The view from which the listener should be deregistered. 
    6870         */ 
    6971        public void unregisterListener() { 
  • src/org/openstreetmap/josm/actions/mapmode/MoveAction.java

    r15 r16  
    4848        public void registerListener() { 
    4949                super.registerListener(); 
    50                 layer.addMouseListener(this); 
    51                 layer.addMouseMotionListener(this); 
     50                mv.addMouseListener(this); 
     51                mv.addMouseMotionListener(this); 
    5252        } 
    5353 
     
    5555        public void unregisterListener() { 
    5656                super.unregisterListener(); 
    57                 layer.removeMouseListener(this); 
    58                 layer.removeMouseMotionListener(this); 
     57                mv.removeMouseListener(this); 
     58                mv.removeMouseMotionListener(this); 
    5959        } 
    6060 
     
    8686 
    8787                for (Node n : movingNodes) { 
    88                         Point pos = layer.getScreenPoint(n.coor); 
     88                        Point pos = mv.getScreenPoint(n.coor); 
    8989                        pos.x += dx; 
    9090                        pos.y += dy; 
    91                         n.coor = layer.getPoint(pos.x, pos.y, true); 
     91                        n.coor = mv.getPoint(pos.x, pos.y, true); 
    9292                } 
    93                 layer.repaint(); 
     93                mv.repaint(); 
    9494                 
    9595                mousePos = e.getPoint(); 
     
    111111 
    112112                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); 
    114114                        if (osm != null) 
    115115                                osm.setSelected(true, ds); 
    116116                        singleOsmPrimitive = osm; 
    117                         layer.repaint(); 
     117                        mv.repaint(); 
    118118                } else 
    119119                        singleOsmPrimitive = null; 
    120120                 
    121121                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)); 
    124124        } 
    125125         
     
    129129        @Override 
    130130        public void mouseReleased(MouseEvent e) { 
    131                 layer.setCursor(oldCursor); 
     131                mv.setCursor(oldCursor); 
    132132                if (singleOsmPrimitive != null) { 
    133133                        singleOsmPrimitive.setSelected(false, ds); 
    134                         layer.repaint(); 
     134                        mv.repaint(); 
    135135                } 
    136136        } 
  • src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java

    r15 r16  
    4646 * and the user clicked in or 10 pixel away from an area, this area is selected.  
    4747 * 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) 
    4949 * 
    5050 * @author imi 
     
    6363        public SelectionAction(MapFrame mapFrame) { 
    6464                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); 
    6666        } 
    6767 
     
    6969        public void registerListener() { 
    7070                super.registerListener(); 
    71                 selectionManager.register(layer); 
     71                selectionManager.register(mv); 
    7272        } 
    7373 
     
    7575        public void unregisterListener() { 
    7676                super.unregisterListener(); 
    77                 selectionManager.unregister(layer); 
     77                selectionManager.unregister(mv); 
    7878        } 
    7979 
     
    9292                for (OsmPrimitive osm : selectionList) 
    9393                        osm.setSelected(!ctrl, ds); 
    94                 layer.repaint(); 
     94                mv.repaint(); 
    9595        } 
    9696} 
  • src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java

    r15 r16  
    66import org.openstreetmap.josm.data.GeoPoint; 
    77import org.openstreetmap.josm.gui.MapFrame; 
    8 import org.openstreetmap.josm.gui.Layer; 
     8import org.openstreetmap.josm.gui.MapView; 
    99import org.openstreetmap.josm.gui.SelectionManager; 
    1010import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; 
     
    1414 *  
    1515 * 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. 
    1717 * Holding down left and right let the user move the former selected rectangle. 
    1818 * Releasing the left button zoom to the selection. 
     
    2828         * Shortcut to the mapview. 
    2929         */ 
    30         private final Layer mv; 
     30        private final MapView mv; 
    3131        /** 
    3232         * Manager that manages the selection rectangle with the aspect ratio of the 
    33          * Layer. 
     33         * MapView. 
    3434         */ 
    3535        private final SelectionManager selectionManager; 
     
    4242        public ZoomAction(MapFrame mapFrame) { 
    4343                super("Zoom", "zoom", "Zoom in by dragging", KeyEvent.VK_Z, mapFrame); 
    44                 mv = mapFrame.layer; 
     44                mv = mapFrame.mapView; 
    4545                selectionManager = new SelectionManager(this, true, mv); 
    4646        } 
  • src/org/openstreetmap/josm/data/Preferences.java

    r15 r16  
    11package org.openstreetmap.josm.data; 
    22 
    3 import java.beans.PropertyChangeEvent; 
    4 import java.beans.PropertyChangeListener; 
    53import java.io.File; 
    64import java.io.FileReader; 
    75import java.io.FileWriter; 
     6import java.util.Collection; 
    87import java.util.LinkedList; 
    98import java.util.List; 
     
    2827public class Preferences { 
    2928 
    30          
    3129        /** 
    3230         * The look and feel. Classname of the look and feel class to use. 
    3331         */ 
    34         private LookAndFeelInfo laf = UIManager.getInstalledLookAndFeels()[0]; 
     32        public LookAndFeelInfo laf = UIManager.getInstalledLookAndFeels()[0]; 
     33 
    3534        /** 
    3635         * The convertor used to translate lat/lon points to screen points. 
    3736         */ 
    3837        private Projection projection = new UTM(); 
     38 
     39 
    3940        /** 
    4041         * Whether nodes on the same place should be considered identical. 
    4142         */ 
    42         private boolean mergeNodes = true; 
     43        public boolean mergeNodes = true; 
     44         
     45         
    4346 
     47        /** 
     48         * List of all available Projections. 
     49         */ 
     50        public static final Projection[] allProjections = new Projection[]{ 
     51                new UTM(), 
     52                new LatitudeLongitude() 
     53        }; 
    4454 
    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         
    4662        /** 
    4763         * Exception thrown in case of any loading/saving error (including parse errors). 
     
    5369                } 
    5470        } 
    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 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          
    101         /** 
    102          * Return the location of the preferences file 
    103          */ 
    104         public static String getPreferencesFile() { 
    105                 return System.getProperty("user.home")+"/.josm-preferences"; 
    106         } 
    107          
    10871        /** 
    10972         * Load from disk. 
     
    12083                        for (LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) 
    12184                                if (lafInfo.getClassName().equals(lafClassName)) { 
    122                                         setLaf(lafInfo); 
     85                                        laf = lafInfo; 
    12386                                        break; 
    12487                                } 
    125                         if (getLaf() == null) 
     88                        if (laf == null) 
    12689                                throw new PreferencesException("Look and Feel not found.", null); 
    127  
    128                         // set projection 
     90                         
     91                        // projection 
    12992                        Class<?> projectionClass = Class.forName(root.getChildText("projection")); 
    13093                        projection = allProjections[0]; // defaults to UTM 
     
    13699                        } 
    137100 
    138                         setMergeNodes(root.getChild("mergeNodes") != null); 
     101                        mergeNodes = root.getChild("mergeNodes") != null; 
    139102                } catch (Exception e) { 
    140103                        if (e instanceof PreferencesException) 
     
    153116                 
    154117                List children = root.getChildren(); 
    155                 children.add(new Element("laf").setText(getLaf().getClassName())); 
     118                children.add(new Element("laf").setText(laf.getClassName())); 
    156119                children.add(new Element("projection").setText(getProjection().getClass().getName())); 
    157                 if (isMergeNodes()) 
     120                if (mergeNodes) 
    158121                        children.add(new Element("mergeNodes")); 
    159122 
     
    167130        } 
    168131 
    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         */ 
    171164        public void setProjection(Projection projection) { 
    172165                Projection old = this.projection; 
    173166                this.projection = projection; 
    174                 firePropertyChanged("projection", old, projection); 
     167                if (old != projection) 
     168                        for (ProjectionChangeListener l : listener) 
     169                                l.projectionChanged(old, projection); 
    175170        } 
     171        /** 
     172         * Get the current projection. 
     173         * @return The current projection set. 
     174         */ 
    176175        public Projection getProjection() { 
    177176                return projection; 
    178177        } 
    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         } 
    195178} 
  • src/org/openstreetmap/josm/data/osm/DataSet.java

    r15 r16  
    113113                Node first = nodes.iterator().next(); 
    114114                Bounds b = new Bounds(first.coor.clone(), first.coor.clone()); 
    115                 for (Node n : nodes) 
     115                for (Node w : nodes) 
    116116                { 
    117                         if (Double.isNaN(n.coor.x) || Double.isNaN(n.coor.y)) 
     117                        if (Double.isNaN(w.coor.x) || Double.isNaN(w.coor.y)) 
    118118                                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; 
    127127                } 
    128128                return b; 
  • src/org/openstreetmap/josm/data/projection/LatitudeLongitude.java

    r1 r16  
    11package org.openstreetmap.josm.data.projection; 
    22 
    3 import javax.swing.JPanel; 
     3import javax.swing.JComponent; 
    44 
    55import org.openstreetmap.josm.data.GeoPoint; 
     
    3030 
    3131        @Override 
    32         public String description() { 
    33                 return "Use lat/lon values directly."; 
     32        public JComponent getConfigurationPanel() { 
     33                return null; 
    3434        } 
    3535 
    3636        @Override 
    37         public JPanel getConfigurationPanel() { 
    38                 return null; 
     37        public void commitConfigurationPanel() { 
    3938        } 
    4039} 
  • src/org/openstreetmap/josm/data/projection/Projection.java

    r15 r16  
    4747        abstract public String toString(); 
    4848         
    49         /** 
    50          * Describe the projection converter. Give examples, where it is best to use 
    51          * and maybe a reference link to more information about the converter.  
    52          */ 
    53         abstract public String description(); 
    54  
    55          
    56  
    5749        // miscellous functions 
    5850         
    5951        /** 
    6052         * 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>. 
    6255         *  
    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. 
    6562         */ 
    6663        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(); 
    6771 
    6872        /** 
  • src/org/openstreetmap/josm/data/projection/UTM.java

    r15 r16  
    11package org.openstreetmap.josm.data.projection; 
    22 
     3import java.awt.Font; 
     4import java.awt.GridBagLayout; 
    35import java.awt.event.ActionEvent; 
    46import java.awt.event.ActionListener; 
    57 
    6 import javax.swing.BorderFactory; 
    7 import javax.swing.Box; 
     8import javax.swing.JButton; 
    89import javax.swing.JComboBox; 
    910import javax.swing.JComponent; 
    1011import javax.swing.JLabel; 
     12import javax.swing.JOptionPane; 
     13import javax.swing.JPanel; 
    1114import javax.swing.JSpinner; 
    1215import javax.swing.SpinnerNumberModel; 
    13 import javax.swing.border.Border; 
    14 import javax.swing.event.ChangeEvent; 
    15 import javax.swing.event.ChangeListener; 
    1616 
    1717import org.openstreetmap.josm.data.Bounds; 
    1818import org.openstreetmap.josm.data.GeoPoint; 
    1919import org.openstreetmap.josm.data.osm.DataSet; 
     20import org.openstreetmap.josm.gui.GBC; 
     21import org.openstreetmap.josm.gui.Main; 
    2022 
    2123/** 
     
    9395        protected Ellipsoid ellipsoid = allEllipsoids[allEllipsoids.length-1]; 
    9496 
     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 
    95110         
    96111        @Override 
     
    168183        } 
    169184 
    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         
    177229        /** 
    178230         * If the zone is not already set, calculate it from this dataset.  
     
    184236        public void init(DataSet dataSet) { 
    185237                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; 
    211241                } 
    212242        } 
     
    214244        @Override 
    215245        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                 
    219249                // 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()); 
    224252                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(){ 
    226268                        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                                } 
    229281                        } 
    230282                }); 
    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                 
    263288                return panel; 
    264289        } 
     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        } 
    265298} 
  • src/org/openstreetmap/josm/gui/GBC.java

    r6 r16  
    4141        } 
    4242         
     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 
    4352        /** 
    4453         * Try to fill both, horizontal and vertical 
  • src/org/openstreetmap/josm/gui/Main.java

    r15 r16  
    55import java.awt.Container; 
    66 
     7import javax.swing.ImageIcon; 
    78import javax.swing.JFrame; 
    89import javax.swing.JMenu; 
     
    1920import org.openstreetmap.josm.data.Preferences; 
    2021import org.openstreetmap.josm.data.Preferences.PreferencesException; 
    21 import org.openstreetmap.josm.data.osm.DataSet; 
    22 import org.openstreetmap.josm.data.projection.Projection; 
    2322 
    2423/** 
     
    103102         */ 
    104103        public static void main(String[] args) { 
     104                setupUiDefaults(); 
     105                 
    105106                // load preferences 
    106107                String errMsg = null; 
     
    121122                 
    122123                try { 
    123                         UIManager.setLookAndFeel(pref.getLaf().getClassName()); 
     124                        UIManager.setLookAndFeel(pref.laf.getClassName()); 
    124125                } catch (Exception e) { 
    125126                        e.printStackTrace(); 
     
    133134 
    134135        /** 
    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 
     136         * 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 
    137138         * aborts, nothing happens.  
    138139         */ 
    139         public void setMapFrame(String name, DataSet dataSet) { 
     140        public void setMapFrame(String name, MapFrame mapFrame) { 
    140141                //TODO: Check for changes and ask user 
    141                 MapFrame mapFrame = new MapFrame(dataSet); 
    142142                this.name = name; 
    143143                this.mapFrame = mapFrame; 
     
    147147                panel.add(mapFrame.toolBarActions, BorderLayout.WEST); 
    148148                panel.add(mapFrame.statusLine, BorderLayout.SOUTH); 
    149                 for (Projection p : Preferences.allProjections) 
    150                         p.init(dataSet); 
    151                 mapFrame.layer.initDataSet(); 
    152149                panel.setVisible(true); 
    153150        } 
     
    165162        } 
    166163 
     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        } 
    167174} 
  • src/org/openstreetmap/josm/gui/MapFrame.java

    r15 r16  
    1414import javax.swing.JToolBar; 
    1515 
    16 import org.openstreetmap.josm.actions.AutoScaleAction; 
    1716import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction; 
    1817import org.openstreetmap.josm.actions.mapmode.AddNodeAction; 
     
    2625import org.openstreetmap.josm.actions.mapmode.ZoomAction; 
    2726import org.openstreetmap.josm.data.osm.DataSet; 
     27import org.openstreetmap.josm.gui.dialogs.PropertiesDialog; 
    2828import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; 
    2929 
     
    4343         * The view control displayed. 
    4444         */ 
    45         public Layer layer; 
     45        public MapView mapView; 
    4646        /** 
    4747         * The toolbar with the action icons 
     
    6161                setLayout(new BorderLayout()); 
    6262 
    63                 add(layer = new Layer(dataSet), BorderLayout.CENTER); 
     63                add(mapView = new MapView(dataSet), BorderLayout.CENTER); 
    6464 
    6565                // toolbar 
     
    8484                // autoScale 
    8585                toolBarActions.addSeparator(); 
    86                 final JToggleButton autoScaleButton = new IconToggleButton(this, new AutoScaleAction(layer)); 
     86                final JToggleButton autoScaleButton = new IconToggleButton(this, mapView.new AutoScaleAction()); 
    8787                toolBarActions.add(autoScaleButton); 
    8888                autoScaleButton.setText(null); 
    89                 autoScaleButton.setSelected(layer.isAutoScale()); 
    90                 layer.addPropertyChangeListener(new PropertyChangeListener(){ 
     89                autoScaleButton.setSelected(mapView.isAutoScale()); 
     90                mapView.addPropertyChangeListener(new PropertyChangeListener(){ 
    9191                        public void propertyChange(PropertyChangeEvent evt) { 
    9292                                if (evt.getPropertyName().equals("autoScale")) 
    93                                         autoScaleButton.setSelected(layer.isAutoScale()); 
     93                                        autoScaleButton.setSelected(mapView.isAutoScale()); 
    9494                        } 
    9595                }); 
     96 
     97                // properties 
     98                toolBarActions.add(new IconToggleButton(this, new PropertiesDialog(this))); 
    9699 
    97100                // selection dialog 
     
    107110 
    108111                // status line below the map 
    109                 statusLine = new MapStatus(layer); 
     112                statusLine = new MapStatus(mapView); 
    110113        } 
    111114 
  • src/org/openstreetmap/josm/gui/MapMover.java

    r15 r16  
    2626         * The map to move around. 
    2727         */ 
    28         private final Layer mv; 
     28        private final MapView mv; 
    2929        /** 
    3030         * The old cursor when we changed it to movement cursor. 
     
    3434        /** 
    3535         * Create a new MapMover 
    36          * @param layer The map that should be moved. 
     36         * @param mapView The map that should be moved. 
    3737         */ 
    38         public MapMover(Layer layer) { 
    39                 this.mv = layer; 
     38        public MapMover(MapView mapView) { 
     39                this.mv = mapView; 
    4040                mv.addMouseListener(this); 
    4141                mv.addMouseMotionListener(this); 
  • src/org/openstreetmap/josm/gui/MapStatus.java

    r15 r16  
    3939 
    4040        /** 
    41          * The Layer this status belongs.  
     41         * The MapView this status belongs.  
    4242         */ 
    43         final Layer mv; 
     43        final MapView mv; 
    4444        /** 
    4545         * The position of the mouse cursor. 
     
    145145         
    146146        /** 
    147          * Construct a new MapStatus and attach it to the Layer. 
    148          * @param mv The Layer the 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. 
    149149         */ 
    150         public MapStatus(final Layer mv) { 
     150        public MapStatus(final MapView mv) { 
    151151                this.mv = mv; 
    152152                 
  • src/org/openstreetmap/josm/gui/MapView.java

    r14 r16  
    1616import org.openstreetmap.josm.data.Bounds; 
    1717import org.openstreetmap.josm.data.GeoPoint; 
     18import org.openstreetmap.josm.data.Preferences.ProjectionChangeListener; 
    1819import org.openstreetmap.josm.data.osm.DataSet; 
    1920import org.openstreetmap.josm.data.osm.LineSegment; 
     
    3738 * @author imi 
    3839 */ 
    39 public class MapView extends JComponent implements ComponentListener, ChangeListener { 
     40public class MapView extends JComponent implements ComponentListener, ChangeListener, ProjectionChangeListener { 
    4041 
    4142        /** 
     
    6970 
    7071        /** 
    71          * Used projection method in this map 
    72          */ 
    73         private Projection projection = Main.pref.projection.clone(); 
    74  
    75         /** 
    7672         * The underlying DataSet. 
    7773         */ 
     
    9490 
    9591                // initialize the projection 
    96                 setProjection(Main.pref.projection.clone()); 
    97  
     92                projectionChanged(null, Main.pref.getProjection()); 
     93                Main.pref.addProjectionChangeListener(this); 
     94                 
    9895                // initialize the drawing engine 
    9996                engine = new SimpleEngine(this); 
     
    120117                p.y = (getHeight()/2.0 - y)*scale + center.y; 
    121118                if (latlon) 
    122                         getProjection().xy2latlon(p); 
     119                        Main.pref.getProjection().xy2latlon(p); 
    123120                return p; 
    124121        } 
     
    138135                                throw new IllegalArgumentException("point: Either lat/lon or x/y must be set."); 
    139136                        p = point.clone(); 
    140                         projection.latlon2xy(p); 
     137                        Main.pref.getProjection().latlon2xy(p); 
    141138                } 
    142139                int x = ((int)Math.round((p.x-center.x) / scale + getWidth()/2)); 
     
    236233                autoScale = false; 
    237234                center = newCenter.clone(); 
    238                 projection.xy2latlon(center); 
     235                Main.pref.getProjection().xy2latlon(center); 
    239236                this.scale = scale; 
    240237                recalculateCenterScale(); 
     
    268265         */ 
    269266        public void stateChanged(ChangeEvent e) { 
    270                 projection.init(dataSet); 
     267                for (Node n : dataSet.nodes) 
     268                        Main.pref.getProjection().latlon2xy(n.coor); 
    271269                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; 
    301270        } 
    302271 
     
    334303 
    335304         
     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        } 
    336323         
    337324        /** 
     
    357344                                // no bounds means standard scale and center  
    358345                                center = new GeoPoint(51.526447, -0.14746371); 
    359                                 getProjection().latlon2xy(center); 
     346                                Main.pref.getProjection().latlon2xy(center); 
    360347                                scale = 10; 
    361348                        } else { 
    362349                                center = bounds.centerXY(); 
    363                                 getProjection().xy2latlon(center); 
     350                                Main.pref.getProjection().xy2latlon(center); 
    364351                                double scaleX = (bounds.max.x-bounds.min.x)/w; 
    365352                                double scaleY = (bounds.max.y-bounds.min.y)/h; 
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r15 r16  
    77import java.awt.event.ActionEvent; 
    88import java.awt.event.ActionListener; 
    9 import java.awt.event.KeyEvent; 
    109import java.io.File; 
    1110 
    1211import javax.swing.AbstractAction; 
     12import javax.swing.BorderFactory; 
    1313import javax.swing.Box; 
    1414import javax.swing.DefaultListCellRenderer; 
     
    1717import javax.swing.JCheckBox; 
    1818import javax.swing.JComboBox; 
     19import javax.swing.JComponent; 
    1920import javax.swing.JDialog; 
    2021import javax.swing.JLabel; 
     
    4344        class OkAction extends AbstractAction { 
    4445                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"))); 
    4749                } 
    4850                public void actionPerformed(ActionEvent e) { 
    49                         Preferences pref = new Preferences(); 
    50                         pref.setLaf((LookAndFeelInfo)lafCombo.getSelectedItem()); 
    51                         pref.setProjection((Projection)projectionCombo.getSelectedItem()); 
    52                         pref.setMergeNodes(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(); 
    5456                        try { 
    55                                 pref.save(); 
     57                                Main.pref.save(); 
    5658                        } catch (PreferencesException x) { 
    5759                                x.printStackTrace(); 
     
    6971        class CancelAction extends AbstractAction { 
    7072                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"))); 
    7376                } 
    7477                public void actionPerformed(ActionEvent e) { 
     
    125128                                return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus); 
    126129                        }}); 
    127                 lafCombo.setSelectedItem(pref.getLaf()); 
     130                lafCombo.setSelectedItem(pref.laf); 
    128131                lafCombo.addActionListener(new ActionListener(){ 
    129132                        public void actionPerformed(ActionEvent e) { 
     
    131134                        }}); 
    132135 
    133                 // projection method combo box 
     136                // projection combo box 
    134137                for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 
    135138                        if (projectionCombo.getItemAt(i).getClass().equals(pref.getProjection().getClass())) { 
     
    138141                        } 
    139142                } 
     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                 
    140164                 
    141165                // Display tab 
    142                 JPanel display = createPreferenceTab("display", "Display Settings", "Various settings than influence the visual representation of the whole Program."); 
     166                JPanel display = createPreferenceTab("display", "Display Settings", "Various settings that influence the visual representation of the whole program."); 
    143167                display.add(new JLabel("Look and Feel"), GBC.std()); 
    144168                display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 
     
    150174                map.add(new JLabel("Projection method"), GBC.std()); 
    151175                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                 
    161181                map.add(new JLabel("GPX import / export"), GBC.eol()); 
    162                 mergeNodes.setSelected(pref.isMergeNodes()); 
     182                mergeNodes.setSelected(pref.mergeNodes); 
    163183                map.add(mergeNodes, GBC.eol()); 
    164184                map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 
     
    172192                okPanel.add(new JButton(new OkAction()), GBC.std()); 
    173193                okPanel.add(new JButton(new CancelAction()), GBC.std()); 
     194                okPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 
    174195 
    175196                // merging all in the content pane 
     
    196217                JPanel p = new JPanel(new GridBagLayout()); 
    197218                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>"); 
    199221                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)); 
    201223 
    202224                tabPane.addTab(null, new ImageIcon("images/preferences/"+icon+".png"), p); 
  • src/org/openstreetmap/josm/gui/SelectionManager.java

    r15 r16  
    8888        private Point mousePos; 
    8989        /** 
    90          * The Layer, the selection rectangle is drawn onto. 
    91          */ 
    92         private final Layer mv; 
     90         * The MapView, the selection rectangle is drawn onto. 
     91         */ 
     92        private final MapView mv; 
    9393        /** 
    9494         * Whether the selection rectangle must obtain the aspect ratio of the  
     
    104104         * @param aspectRatio If true, the selection window must obtain the aspect 
    105105         *              ratio of the drawComponent. 
    106          * @param layer The 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) { 
    109109                this.selectionEndedListener = selectionEndedListener; 
    110110                this.aspectRatio = aspectRatio; 
    111                 this.mv = layer; 
     111                this.mv = mapView; 
    112112        } 
    113113         
  • src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r15 r16  
    55import javax.swing.BorderFactory; 
    66import javax.swing.Box; 
     7import javax.swing.JLabel; 
     8import javax.swing.border.Border; 
    79 
    810import org.openstreetmap.josm.gui.Main; 
     
    2527                putValue(MNEMONIC_KEY, KeyEvent.VK_P); 
    2628 
    27 //              final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0); 
     29                final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0); 
    2830                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); 
    6135                 
    6236                panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 
  • src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r15 r16  
    22 
    33import java.awt.event.ActionEvent; 
     4import java.awt.event.KeyEvent; 
    45import java.util.HashMap; 
    56import java.util.Map; 
     
    3031                putValue(NAME, name); 
    3132                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."); 
    3435        } 
    3536 
  • src/org/openstreetmap/josm/gui/engine/Engine.java

    r15 r16  
    22 
    33import java.awt.Graphics; 
     4import java.beans.PropertyChangeEvent; 
     5import java.beans.PropertyChangeListener; 
    46 
    57import org.openstreetmap.josm.data.GeoPoint; 
     
    79import org.openstreetmap.josm.data.osm.Node; 
    810import org.openstreetmap.josm.data.osm.Track; 
    9 import org.openstreetmap.josm.gui.Layer; 
     11import org.openstreetmap.josm.data.projection.Projection; 
     12import org.openstreetmap.josm.gui.MapView; 
    1013 
    1114/** 
     
    1518 * @author imi 
    1619 */ 
    17 abstract public class Engine { 
     20abstract public class Engine implements PropertyChangeListener { 
    1821 
     22        /** 
     23         * The projection method, this engine uses to render the graphics. 
     24         */ 
     25        protected Projection projection; 
    1926        /** 
    2027         * The Graphics surface to draw on. This should be set before each painting 
     
    2330        protected Graphics g; 
    2431        /** 
    25          * The layer, this engine was created for. 
     32         * The mapView, this engine was created for. 
    2633         */ 
    27         protected final Layer layer; 
     34        protected final MapView mv; 
    2835 
    2936         
    3037        /** 
    31          * Creates an Engine from an Layer it belongs to. 
    32          * @param layer The mapview this engine belongs to. 
     38         * Creates an Engine from an MapView it belongs to. 
     39         * @param mapView The mapview this engine belongs to. 
    3340         */ 
    34         public Engine(Layer layer) { 
    35                 this.layer = layer; 
     41        public Engine(MapView mapView) { 
     42                mv = mapView; 
     43                mv.addPropertyChangeListener(this); 
    3644        } 
    3745         
     
    6573         */ 
    6674        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        } 
    6784} 
  • src/org/openstreetmap/josm/gui/engine/SimpleEngine.java

    r15 r16  
    1010import org.openstreetmap.josm.data.osm.Node; 
    1111import org.openstreetmap.josm.data.osm.Track; 
    12 import org.openstreetmap.josm.gui.Layer; 
     12import org.openstreetmap.josm.gui.MapView; 
    1313 
    1414/** 
     
    2323        private final static Color darkgreen = new Color(0,128,0); 
    2424 
    25         public SimpleEngine(Layer layer) { 
    26                 super(layer); 
     25        public SimpleEngine(MapView mapView) { 
     26                super(mapView); 
    2727        } 
    2828 
     
    3333        public void drawBackground(GeoPoint ulGeo, GeoPoint lrGeo) { 
    3434                g.setColor(Color.BLACK); 
    35                 g.fillRect(0,0,layer.getWidth(),layer.getHeight()); 
     35                g.fillRect(0,0,mv.getWidth(),mv.getHeight()); 
    3636        } 
    3737 
     
    109109        private void drawLineSegment(LineSegment ls, Color color) { 
    110110                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); 
    113113                g.drawLine(p1.x, p1.y, p2.x, p2.y); 
    114114        } 
     
    121121         */ 
    122122        private void drawNode(Node n, Color color) { 
    123                 Point p = layer.getScreenPoint(n.coor); 
     123                Point p = mv.getScreenPoint(n.coor); 
    124124                g.setColor(color); 
    125125                g.drawRect(p.x-1, p.y-1, 2, 2); 
  • src/org/openstreetmap/josm/io/GpxReader.java

    r15 r16  
    161161         */ 
    162162        private Node addNode (DataSet data, Node node) { 
    163                 if (Main.pref.isMergeNodes()) 
     163                if (Main.pref.mergeNodes) 
    164164                        for (Node n : data.nodes) 
    165165                                if (node.coor.lat == n.coor.lat && node.coor.lon == n.coor.lon) 
Note: See TracChangeset for help on using the changeset viewer.