Ignore:
Timestamp:
2005-10-04T00:09:32+02:00 (21 years ago)
Author:
imi
Message:
  • added support for DataReaders
  • added a nice status line and a tooltip when holding middle mouse button
File:
1 edited

Legend:

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

    r8 r9  
    8484       
    8585        /**
    86          * Construct a MapView and attach it to a frame.
     86         * Construct a MapView.
    8787         */
    8888        public MapView(DataSet dataSet) {
    8989                this.dataSet = dataSet;
    9090                addComponentListener(this);
    91                
     91
    9292                // initialize the movement listener
    9393                new MapMover(this);
    94                
     94
    9595                // initialize the projection
    9696                setProjection(Main.pref.projection.clone());
    97                
    98                 // initialize the engine
     97
     98                // initialize the drawing engine
    9999                engine = new SimpleEngine(this);
    100100        }
     
    222222        }
    223223
     224       
    224225        /**
    225226         * Zoom to the given coordinate.
     
    247248       
    248249        /**
     250         * Draw the component.
     251         */
     252        @Override
     253        public void paint(Graphics g) {
     254                engine.init(g);
     255                engine.drawBackground(getPoint(0,0,true), getPoint(getWidth(), getHeight(), true));
     256
     257                for (Track t : dataSet.tracks())
     258                        engine.drawTrack(t);
     259                for (LineSegment ls : dataSet.pendingLineSegments())
     260                        engine.drawPendingLineSegment(ls);
     261                for (Node n : dataSet.nodes)
     262                        engine.drawNode(n);
     263        }
     264
     265        /**
     266         * Notify from the projection, that something has changed.
     267         * @param e
     268         */
     269        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;
     301        }
     302
     303        /**
    249304         * Return the current scale value.
    250305         * @return The scale value currently used in display
     
    254309        }
    255310
     311        /**
     312         * @return Returns the autoScale.
     313         */
     314        public boolean isAutoScale() {
     315                return autoScale;
     316        }
     317
     318        /**
     319         * @param autoScale The autoScale to set.
     320         */
     321        public void setAutoScale(boolean autoScale) {
     322                if (this.autoScale != autoScale) {
     323                        this.autoScale = autoScale;
     324                        firePropertyChange("autoScale", !autoScale, autoScale);
     325                }
     326        }
     327        /**
     328         * @return Returns the center point. A copy is returned, so users cannot
     329         *              change the center by accessing the return value. Use zoomTo instead.
     330         */
     331        public GeoPoint getCenter() {
     332                return center.clone();
     333        }
     334
     335       
     336       
    256337        /**
    257338         * Set the new dimension to the projection class. Also adjust the components
     
    285366                                scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen
    286367                        }
    287 
     368       
    288369                        firePropertyChange("center", oldCenter, center);
    289370                        if (oldAutoScale != autoScale)
     
    303384
    304385        /**
    305          * Draw the component.
    306          */
    307         @Override
    308         public void paint(Graphics g) {
    309                 engine.init(g);
    310                 engine.drawBackground(getPoint(0,0,true), getPoint(getWidth(), getHeight(), true));
    311 
    312                 for (Track t : dataSet.tracks())
    313                         engine.drawTrack(t);
    314                 for (LineSegment ls : dataSet.pendingLineSegments())
    315                         engine.drawPendingLineSegment(ls);
    316                 for (Node n : dataSet.nodes)
    317                         engine.drawNode(n);
    318         }
    319 
    320         /**
    321          * Notify from the projection, that something has changed.
    322          * @param e
    323          */
    324         public void stateChanged(ChangeEvent e) {
    325                 projection.init(dataSet);
    326                 recalculateCenterScale();
    327         }
    328 
    329         /**
    330          * Set a new projection method. This call is not cheap, as it will
    331          * transform the whole underlying dataSet and repaint itself.
    332          *
    333          * @param projection The new projection method to set.
    334          */
    335         public void setProjection(Projection projection) {
    336                 if (projection == this.projection)
    337                         return;
    338 
    339                 Projection oldProjection = this.projection;
    340                
    341                 if (this.projection != null)
    342                         this.projection.removeChangeListener(this);
    343                 this.projection = projection;
    344                 projection.addChangeListener(this);
    345                
    346                 stateChanged(new ChangeEvent(this));
    347                 firePropertyChange("projection", oldProjection, projection);
    348         }
    349 
    350         /**
    351          * Return the projection method for this map view.
    352          * @return The projection method.
    353          */
    354         public Projection getProjection() {
    355                 return projection;
    356         }
    357 
    358         /**
    359          * @return Returns the autoScale.
    360          */
    361         public boolean isAutoScale() {
    362                 return autoScale;
    363         }
    364 
    365         /**
    366          * @param autoScale The autoScale to set.
    367          */
    368         public void setAutoScale(boolean autoScale) {
    369                 if (this.autoScale != autoScale) {
    370                         this.autoScale = autoScale;
    371                         firePropertyChange("autoScale", !autoScale, autoScale);
    372                 }
    373         }
    374         /**
    375          * @return Returns the center point. A copy is returned, so users cannot
    376          *              change the center by accessing the return value. Use zoomTo instead.
    377          */
    378         public GeoPoint getCenter() {
    379                 return center.clone();
    380         }
    381 
    382         /**
    383386         * Does nothing. Just to satisfy ComponentListener.
    384387         */
Note: See TracChangeset for help on using the changeset viewer.