Changeset 15 in josm for src/org/openstreetmap/josm/gui


Ignore:
Timestamp:
2005-10-07T01:13:49+02:00 (19 years ago)
Author:
imi
Message:

renamed alot (Layer instead of MapView) and removed feature of having
projections on every Layer.

Location:
src/org/openstreetmap/josm/gui
Files:
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/Layer.java

    r14 r15  
    33import java.awt.Graphics;
    44import java.awt.Point;
    5 import java.awt.event.ActionEvent;
    65import java.awt.event.ComponentEvent;
    76import java.awt.event.ComponentListener;
    8 import java.awt.event.KeyEvent;
    9 
    10 import javax.swing.AbstractAction;
    11 import javax.swing.ImageIcon;
     7import java.beans.PropertyChangeEvent;
     8import java.beans.PropertyChangeListener;
     9
    1210import javax.swing.JComponent;
    1311import javax.swing.event.ChangeEvent;
     
    2725/**
    2826 * This is a component used in the MapFrame for browsing the map. It use is to
    29  * provide the MapMode's enough capabilities to operate. 
     27 * provide the MapMode's enough capabilities to operate.
    3028 *
    31  * MapView holds the map data, organize it, convert it, provide access to it.
     29 * Layer holds one dataset. There can be more than one Layer active.
    3230 *
    33  * MapView hold meta-data about the data set currently displayed, as scale level,
    34  * center point viewed, what scrolling mode or editing mode is selected or with
    35  * what projection the map is viewed etc..
    36  *
     31 * Layer hold data of the current displayed graphics as scale level and
     32 * center point view.
     33 *
    3734 * @author imi
    3835 */
    39 public class MapView extends JComponent implements ComponentListener, ChangeListener {
    40 
    41         /**
    42          * Toggles the autoScale feature of the mapView
    43          * @author imi
    44          */
    45         public class AutoScaleAction extends AbstractAction {
    46                 public AutoScaleAction() {
    47                         super("Auto Scale", new ImageIcon(Main.class.getResource("/images/autoscale.png")));
    48                         putValue(MNEMONIC_KEY, KeyEvent.VK_A);
    49                 }
    50                 public void actionPerformed(ActionEvent e) {
    51                         autoScale = !autoScale;
    52                         recalculateCenterScale();
    53                 }
    54         }
     36public class Layer extends JComponent implements ComponentListener, ChangeListener, PropertyChangeListener {
    5537
    5638        /**
     
    6951
    7052        /**
    71          * Used projection method in this map
    72          */
    73         private Projection projection = Main.pref.projection.clone();
    74 
    75         /**
    7653         * The underlying DataSet.
    7754         */
     
    8461       
    8562        /**
    86          * Construct a MapView.
    87          */
    88         public MapView(DataSet dataSet) {
     63         * Construct a Layer.
     64         */
     65        public Layer(DataSet dataSet) {
    8966                this.dataSet = dataSet;
    9067                addComponentListener(this);
     
    9370                new MapMover(this);
    9471
    95                 // initialize the projection
    96                 setProjection(Main.pref.projection.clone());
    97 
    9872                // initialize the drawing engine
    9973                engine = new SimpleEngine(this);
     74               
     75                // initialize on the preferences for projection changes.
     76                Main.pref.addPropertyChangeListener(this);
    10077        }
    10178
     
    12097                p.y = (getHeight()/2.0 - y)*scale + center.y;
    12198                if (latlon)
    122                         getProjection().xy2latlon(p);
     99                        Main.pref.getProjection().xy2latlon(p);
    123100                return p;
    124101        }
     
    138115                                throw new IllegalArgumentException("point: Either lat/lon or x/y must be set.");
    139116                        p = point.clone();
    140                         projection.latlon2xy(p);
     117                        Main.pref.getProjection().latlon2xy(p);
    141118                }
    142119                int x = ((int)Math.round((p.x-center.x) / scale + getWidth()/2));
     
    236213                autoScale = false;
    237214                center = newCenter.clone();
    238                 projection.xy2latlon(center);
     215                Main.pref.getProjection().xy2latlon(center);
    239216                this.scale = scale;
    240217                recalculateCenterScale();
     
    268245         */
    269246        public void stateChanged(ChangeEvent e) {
    270                 projection.init(dataSet);
    271                 recalculateCenterScale();
    272         }
    273 
    274         /**
    275          * Set a new projection method. This call is not cheap, as it will
    276          * transform the whole underlying dataSet and repaint itself.
    277          *
    278          * @param projection The new projection method to set.
    279          */
    280         public void setProjection(Projection projection) {
    281                 if (projection == this.projection)
    282                         return;
    283 
    284                 Projection oldProjection = this.projection;
    285                
    286                 if (this.projection != null)
    287                         this.projection.removeChangeListener(this);
    288                 this.projection = projection;
    289                 projection.addChangeListener(this);
    290                
    291                 stateChanged(new ChangeEvent(this));
    292                 firePropertyChange("projection", oldProjection, projection);
    293         }
    294 
    295         /**
    296          * Return the projection method for this map view.
    297          * @return The projection method.
    298          */
    299         public Projection getProjection() {
    300                 return projection;
     247                initDataSet();
     248        }
     249
     250        /**
     251         * Called when a property, as example the projection of the Main preferences
     252         * changes.
     253         */
     254        public void propertyChange(PropertyChangeEvent evt) {
     255                if (evt.getPropertyName().equals("projection")) {
     256                        Projection oldProjection = (Projection)evt.getOldValue();
     257                        if (oldProjection != null)
     258                                oldProjection.removeChangeListener(this);
     259
     260                        Projection newProjection = (Projection)evt.getNewValue();
     261                        if (newProjection != null)
     262                                newProjection.addChangeListener(this);
     263
     264                        initDataSet();
     265                }
    301266        }
    302267
     
    322287                if (this.autoScale != autoScale) {
    323288                        this.autoScale = autoScale;
     289                        if (autoScale)
     290                                recalculateCenterScale();
    324291                        firePropertyChange("autoScale", !autoScale, autoScale);
    325292                }
     
    333300        }
    334301
     302        /**
     303         * Initialize the DataSet with the projection taken from the preference
     304         * settings.
     305         */
     306        public void initDataSet() {
     307                for (Node n : dataSet.nodes)
     308                        Main.pref.getProjection().latlon2xy(n.coor);
     309                recalculateCenterScale();
     310        }
    335311       
    336312       
     
    357333                                // no bounds means standard scale and center
    358334                                center = new GeoPoint(51.526447, -0.14746371);
    359                                 getProjection().latlon2xy(center);
     335                                Main.pref.getProjection().latlon2xy(center);
    360336                                scale = 10;
    361337                        } else {
    362338                                center = bounds.centerXY();
    363                                 getProjection().xy2latlon(center);
     339                                Main.pref.getProjection().xy2latlon(center);
    364340                                double scaleX = (bounds.max.x-bounds.min.x)/w;
    365341                                double scaleY = (bounds.max.y-bounds.min.y)/h;
  • src/org/openstreetmap/josm/gui/Main.java

    r9 r15  
    1919import org.openstreetmap.josm.data.Preferences;
    2020import org.openstreetmap.josm.data.Preferences.PreferencesException;
     21import org.openstreetmap.josm.data.osm.DataSet;
     22import org.openstreetmap.josm.data.projection.Projection;
    2123
    2224/**
     
    119121               
    120122                try {
    121                         UIManager.setLookAndFeel(pref.laf.getClassName());
     123                        UIManager.setLookAndFeel(pref.getLaf().getClassName());
    122124                } catch (Exception e) {
    123125                        e.printStackTrace();
     
    131133
    132134        /**
    133          * Set the main's mapframe. If a changed old mapFrame is already set,
    134          * ask the user whether he want to save, discard or abort. If the user
     135         * Create and set the main's mapframe. If a changed old mapFrame is already
     136         * set, ask the user whether he want to save, discard or abort. If the user
    135137         * aborts, nothing happens.
    136138         */
    137         public void setMapFrame(String name, MapFrame mapFrame) {
     139        public void setMapFrame(String name, DataSet dataSet) {
    138140                //TODO: Check for changes and ask user
     141                MapFrame mapFrame = new MapFrame(dataSet);
    139142                this.name = name;
    140143                this.mapFrame = mapFrame;
     
    144147                panel.add(mapFrame.toolBarActions, BorderLayout.WEST);
    145148                panel.add(mapFrame.statusLine, BorderLayout.SOUTH);
     149                for (Projection p : Preferences.allProjections)
     150                        p.init(dataSet);
     151                mapFrame.layer.initDataSet();
    146152                panel.setVisible(true);
    147153        }
  • src/org/openstreetmap/josm/gui/MapFrame.java

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

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

    r9 r15  
    3939
    4040        /**
    41          * The MapView this status belongs.
     41         * The Layer this status belongs.
    4242         */
    43         final MapView mv;
     43        final Layer mv;
    4444        /**
    4545         * The position of the mouse cursor.
     
    145145       
    146146        /**
    147          * Construct a new MapStatus and attach it to the map view.
    148          * @param mv The MapView the status line is part of.
     147         * Construct a new MapStatus and attach it to the Layer.
     148         * @param mv The Layer the status line is part of.
    149149         */
    150         public MapStatus(final MapView mv) {
     150        public MapStatus(final Layer mv) {
    151151                this.mv = mv;
    152152               
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r11 r15  
    4848                public void actionPerformed(ActionEvent e) {
    4949                        Preferences pref = new Preferences();
    50                         pref.laf = (LookAndFeelInfo)lafCombo.getSelectedItem();
    51                         pref.projection = (Projection)projectionCombo.getSelectedItem();
    52                         pref.mergeNodes = mergeNodes.isSelected();
    53                         Main.pref.projection = pref.projection;
     50                        pref.setLaf((LookAndFeelInfo)lafCombo.getSelectedItem());
     51                        pref.setProjection((Projection)projectionCombo.getSelectedItem());
     52                        pref.setMergeNodes(mergeNodes.isSelected());
     53                        Main.pref.setProjection(pref.getProjection());
    5454                        try {
    5555                                pref.save();
     
    125125                                return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus);
    126126                        }});
    127                 lafCombo.setSelectedItem(pref.laf);
     127                lafCombo.setSelectedItem(pref.getLaf());
    128128                lafCombo.addActionListener(new ActionListener(){
    129129                        public void actionPerformed(ActionEvent e) {
     
    133133                // projection method combo box
    134134                for (int i = 0; i < projectionCombo.getItemCount(); ++i) {
    135                         if (projectionCombo.getItemAt(i).getClass().equals(pref.projection.getClass())) {
     135                        if (projectionCombo.getItemAt(i).getClass().equals(pref.getProjection().getClass())) {
    136136                                projectionCombo.setSelectedIndex(i);
    137137                                break;
     
    160160                map.add(labelNoteProjection, GBC.eol().insets(0,5,0,20));
    161161                map.add(new JLabel("GPX import / export"), GBC.eol());
    162                 mergeNodes.setSelected(pref.mergeNodes);
     162                mergeNodes.setSelected(pref.isMergeNodes());
    163163                map.add(mergeNodes, GBC.eol());
    164164                map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
  • src/org/openstreetmap/josm/gui/SelectionManager.java

    r8 r15  
    8888        private Point mousePos;
    8989        /**
    90          * The MapView, the selection rectangle is drawn onto.
    91          */
    92         private final MapView mv;
     90         * The Layer, the selection rectangle is drawn onto.
     91         */
     92        private final Layer 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 mapView The view, the rectangle is drawn onto.
    107          */
    108         public SelectionManager(SelectionEnded selectionEndedListener, boolean aspectRatio, MapView mapView) {
     106         * @param layer The view, the rectangle is drawn onto.
     107         */
     108        public SelectionManager(SelectionEnded selectionEndedListener, boolean aspectRatio, Layer layer) {
    109109                this.selectionEndedListener = selectionEndedListener;
    110110                this.aspectRatio = aspectRatio;
    111                 this.mv = mapView;
     111                this.mv = layer;
    112112        }
    113113       
  • src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r8 r15  
    11package org.openstreetmap.josm.gui.dialogs;
    22
    3 import java.awt.event.ActionEvent;
    4 import java.awt.event.ActionListener;
    53import java.awt.event.KeyEvent;
    64
    75import javax.swing.BorderFactory;
    86import javax.swing.Box;
    9 import javax.swing.BoxLayout;
    10 import javax.swing.JComboBox;
    11 import javax.swing.JComponent;
    12 import javax.swing.JLabel;
    13 import javax.swing.JPanel;
    14 import javax.swing.border.Border;
    157
    16 import org.openstreetmap.josm.data.Preferences;
    17 import org.openstreetmap.josm.data.projection.Projection;
    188import org.openstreetmap.josm.gui.Main;
    199import org.openstreetmap.josm.gui.MapFrame;
     
    3525                putValue(MNEMONIC_KEY, KeyEvent.VK_P);
    3626
    37                 final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0);
     27//              final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0);
    3828                Box panel = Box.createVerticalBox();
    3929
    4030                // making an array of all projections and the current one within
    41                 Projection[] allProjections = Preferences.allProjections.clone();
    42                 for (int i = 0; i < allProjections.length; ++i)
    43                         if (allProjections[i].getClass() == frame.mapView.getProjection().getClass())
    44                                 allProjections[i] = frame.mapView.getProjection();
    45                
    46                 // projection
    47                 Box projectionPanel = Box.createHorizontalBox();
    48                 projectionPanel.setBorder(panelBorder);
    49                 projectionPanel.add(new JLabel("Projection"));
    50                 final JComboBox projectionCombo = new JComboBox(allProjections);
    51                 projectionPanel.add(projectionCombo);
    52                 panel.add(projectionPanel);
    53                 final JPanel configurationPanel = new JPanel();
    54                 configurationPanel.setLayout(new BoxLayout(configurationPanel, BoxLayout.X_AXIS));
    55                
    56                 // projections details
    57                 projectionCombo.addActionListener(new ActionListener(){
    58                         public void actionPerformed(ActionEvent e) {
    59                                 configurationPanel.removeAll();
    60                                 frame.mapView.setProjection((Projection)projectionCombo.getSelectedItem());
    61                                 JComponent panel = frame.mapView.getProjection().getConfigurationPanel();
    62                                 if (panel != null) {
    63                                         panel.setBorder(panelBorder);
    64                                         configurationPanel.add(panel);
    65                                 }
    66                                 pack();
    67                         }
    68                 });
    69                 panel.add(configurationPanel);
    70                 projectionCombo.setSelectedItem(frame.mapView.getProjection());
     31//              Projection[] allProjections = Preferences.allProjections.clone();
     32//              for (int i = 0; i < allProjections.length; ++i)
     33//                      if (allProjections[i].getClass() == frame.layer.getProjection().getClass())
     34//                              allProjections[i] = frame.layer.getProjection();
     35//             
     36//              // projection
     37//              Box projectionPanel = Box.createHorizontalBox();
     38//              projectionPanel.setBorder(panelBorder);
     39//              projectionPanel.add(new JLabel("Projection"));
     40//              final JComboBox projectionCombo = new JComboBox(allProjections);
     41//              projectionPanel.add(projectionCombo);
     42//              panel.add(projectionPanel);
     43//              final JPanel configurationPanel = new JPanel();
     44//              configurationPanel.setLayout(new BoxLayout(configurationPanel, BoxLayout.X_AXIS));
     45//             
     46//              // projections details
     47//              projectionCombo.addActionListener(new ActionListener(){
     48//                      public void actionPerformed(ActionEvent e) {
     49//                              configurationPanel.removeAll();
     50//                              frame.layer.setProjection((Projection)projectionCombo.getSelectedItem());
     51//                              JComponent panel = frame.layer.getProjection().getConfigurationPanel();
     52//                              if (panel != null) {
     53//                                      panel.setBorder(panelBorder);
     54//                                      configurationPanel.add(panel);
     55//                              }
     56//                              pack();
     57//                      }
     58//              });
     59//              panel.add(configurationPanel);
     60//              projectionCombo.setSelectedItem(frame.layer.getProjection());
    7161               
    7262                panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
  • src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r11 r15  
    22
    33import java.awt.event.ActionEvent;
    4 import java.awt.event.KeyEvent;
    54import java.util.HashMap;
    65import java.util.Map;
     
    3130                putValue(NAME, name);
    3231                putValue(MNEMONIC_KEY, mnemonic);
    33                 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E,0));
    34                 putValue(LONG_DESCRIPTION, "Open a selection list window.");
     32                putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(mnemonic,0));
     33                putValue(LONG_DESCRIPTION, tooltip);
    3534        }
    3635
  • src/org/openstreetmap/josm/gui/engine/Engine.java

    r8 r15  
    22
    33import java.awt.Graphics;
    4 import java.beans.PropertyChangeEvent;
    5 import java.beans.PropertyChangeListener;
    64
    75import org.openstreetmap.josm.data.GeoPoint;
     
    97import org.openstreetmap.josm.data.osm.Node;
    108import org.openstreetmap.josm.data.osm.Track;
    11 import org.openstreetmap.josm.data.projection.Projection;
    12 import org.openstreetmap.josm.gui.MapView;
     9import org.openstreetmap.josm.gui.Layer;
    1310
    1411/**
     
    1815 * @author imi
    1916 */
    20 abstract public class Engine implements PropertyChangeListener {
     17abstract public class Engine {
    2118
    22         /**
    23          * The projection method, this engine uses to render the graphics.
    24          */
    25         protected Projection projection;
    2619        /**
    2720         * The Graphics surface to draw on. This should be set before each painting
     
    3023        protected Graphics g;
    3124        /**
    32          * The mapView, this engine was created for.
     25         * The layer, this engine was created for.
    3326         */
    34         protected final MapView mv;
     27        protected final Layer layer;
    3528
    3629       
    3730        /**
    38          * Creates an Engine from an MapView it belongs to.
    39          * @param mapView The mapview this engine belongs to.
     31         * Creates an Engine from an Layer it belongs to.
     32         * @param layer The mapview this engine belongs to.
    4033         */
    41         public Engine(MapView mapView) {
    42                 mv = mapView;
    43                 mv.addPropertyChangeListener(this);
     34        public Engine(Layer layer) {
     35                this.layer = layer;
    4436        }
    4537       
     
    7365         */
    7466        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         }
    8467}
  • src/org/openstreetmap/josm/gui/engine/SimpleEngine.java

    r8 r15  
    1010import org.openstreetmap.josm.data.osm.Node;
    1111import org.openstreetmap.josm.data.osm.Track;
    12 import org.openstreetmap.josm.gui.MapView;
     12import org.openstreetmap.josm.gui.Layer;
    1313
    1414/**
     
    2323        private final static Color darkgreen = new Color(0,128,0);
    2424
    25         public SimpleEngine(MapView mapView) {
    26                 super(mapView);
     25        public SimpleEngine(Layer layer) {
     26                super(layer);
    2727        }
    2828
     
    3333        public void drawBackground(GeoPoint ulGeo, GeoPoint lrGeo) {
    3434                g.setColor(Color.BLACK);
    35                 g.fillRect(0,0,mv.getWidth(),mv.getHeight());
     35                g.fillRect(0,0,layer.getWidth(),layer.getHeight());
    3636        }
    3737
     
    109109        private void drawLineSegment(LineSegment ls, Color color) {
    110110                g.setColor(ls.isSelected() ? Color.WHITE : color);
    111                 Point p1 = mv.getScreenPoint(ls.getStart().coor);
    112                 Point p2 = mv.getScreenPoint(ls.getEnd().coor);
     111                Point p1 = layer.getScreenPoint(ls.getStart().coor);
     112                Point p2 = layer.getScreenPoint(ls.getEnd().coor);
    113113                g.drawLine(p1.x, p1.y, p2.x, p2.y);
    114114        }
     
    121121         */
    122122        private void drawNode(Node n, Color color) {
    123                 Point p = mv.getScreenPoint(n.coor);
     123                Point p = layer.getScreenPoint(n.coor);
    124124                g.setColor(color);
    125125                g.drawRect(p.x-1, p.y-1, 2, 2);
Note: See TracChangeset for help on using the changeset viewer.