Changeset 3128 in josm for trunk/src


Ignore:
Timestamp:
2010-03-13T10:45:19+01:00 (10 years ago)
Author:
jttt
Message:

Different fix for #4728 - discard offscreen buffer for all layer in MapView

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r3125 r3128  
    3939import org.openstreetmap.josm.data.Bounds;
    4040import org.openstreetmap.josm.data.SelectionChangedListener;
     41import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
     42import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    4143import org.openstreetmap.josm.data.coor.LatLon;
    4244import org.openstreetmap.josm.data.osm.DataSet;
     
    6567 * @author imi
    6668 */
    67 public class MapView extends NavigatableComponent implements PropertyChangeListener {
     69public class MapView extends NavigatableComponent implements PropertyChangeListener, PreferenceChangedListener {
    6870
    6971    /**
     
    183185    private final List<Layer> nonChangedLayers = new ArrayList<Layer>();
    184186    private int lastViewID;
     187    private boolean paintPreferencesChanged = true;
    185188
    186189    public MapView() {
     190        Main.pref.addPreferenceChangeListener(this);
    187191        addComponentListener(new ComponentAdapter(){
    188192            @Override public void componentResized(ComponentEvent e) {
     
    472476        }
    473477
    474         boolean canUseBuffer = nonChangedLayers.size() <= nonChangedLayersCount && lastViewID == getViewID();
     478        boolean canUseBuffer = !paintPreferencesChanged && nonChangedLayers.size() <= nonChangedLayersCount && lastViewID == getViewID();
    475479        if (canUseBuffer) {
    476480            for (int i=0; i<nonChangedLayers.size(); i++) {
     
    513517        }
    514518        lastViewID = getViewID();
     519        paintPreferencesChanged = false;
    515520
    516521        tempG.drawImage(offscreenBuffer, 0, 0, null);
     
    799804    }
    800805
     806    public void preferenceChanged(PreferenceChangeEvent e) {
     807        paintPreferencesChanged = true;
     808    }
     809
    801810}
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r3127 r3128  
    8787    private final List<GpxTrack> lastTracks = new ArrayList<GpxTrack>(); // List of tracks at last paint
    8888    private int lastUpdateCount;
    89     private PaintSettings lastPaintSettings;
    9089
    9190    private static class Markers {
     
    464463    @Override
    465464    public boolean isChanged() {
    466         if (data.tracks.equals(lastTracks) && new PaintSettings(isLocalFile).equals(lastPaintSettings))
     465        if (data.tracks.equals(lastTracks))
    467466            return sumUpdateCount() != lastUpdateCount;
    468467        else
     
    497496    }
    498497
    499     private class PaintSettings {
    500         final Color neutralColor;
    501         final boolean forceLines;
    502         final boolean direction;
    503         final int lineWidth;
    504         final int maxLineLength;
    505         final boolean lines;
    506         final boolean large;
    507         final boolean hdopcircle;
    508         final colorModes colored;
    509         final boolean alternatedirection;
    510         final int delta;
    511         final int colorTracksTune;
    512 
    513         public PaintSettings(boolean isLocalFile) {
    514             neutralColor = getColor(getName());
    515             // also draw lines between points belonging to different segments
    516             forceLines = Main.pref.getBoolean("draw.rawgps.lines.force");
    517             // draw direction arrows on the lines
    518             direction = Main.pref.getBoolean("draw.rawgps.direction");
    519             // don't draw lines if longer than x meters
    520             lineWidth = Main.pref.getInteger("draw.rawgps.linewidth",0);
    521 
    522             if (isLocalFile) {
    523                 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length.local", -1);
    524             } else {
    525                 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", 200);
    526             }
    527 
    528             // draw line between points, global setting
    529             boolean lines = (Main.pref.getBoolean("draw.rawgps.lines", true) || (Main.pref
    530                     .getBoolean("draw.rawgps.lines.localfiles") && isLocalFile));
    531             String linesKey = "draw.rawgps.lines.layer " + getName();
    532             // draw lines, per-layer setting
    533             if (Main.pref.hasKey(linesKey)) {
    534                 lines = Main.pref.getBoolean(linesKey);
    535             }
    536             this.lines = lines;
    537 
    538             // paint large dots for points
    539             large = Main.pref.getBoolean("draw.rawgps.large");
    540             hdopcircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", true);
    541             // color the lines
    542             int colorIndex = Main.pref.getInteger("draw.rawgps.colors", 0);
    543             colored = colorIndex >= 0 && colorIndex < colorModes.values().length?colorModes.values()[colorIndex]:colorModes.none;
    544             // paint direction arrow with alternate math. may be faster
    545             alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection");
    546             // don't draw arrows nearer to each other than this
    547             delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", 0);
    548             // allows to tweak line coloring for different speed levels.
    549             colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45);
    550         }
    551 
    552         @Override
    553         public int hashCode() {
    554             final int prime = 31;
    555             int result = 1;
    556             result = prime * result + getOuterType().hashCode();
    557             result = prime * result + (alternatedirection ? 1231 : 1237);
    558             result = prime * result + colorTracksTune;
    559             result = prime * result + ((colored == null) ? 0 : colored.hashCode());
    560             result = prime * result + delta;
    561             result = prime * result + (direction ? 1231 : 1237);
    562             result = prime * result + (forceLines ? 1231 : 1237);
    563             result = prime * result + (hdopcircle ? 1231 : 1237);
    564             result = prime * result + (large ? 1231 : 1237);
    565             result = prime * result + lineWidth;
    566             result = prime * result + (lines ? 1231 : 1237);
    567             result = prime * result + maxLineLength;
    568             result = prime * result + ((neutralColor == null) ? 0 : neutralColor.hashCode());
    569             return result;
    570         }
    571 
    572         @Override
    573         public boolean equals(Object obj) {
    574             if (this == obj)
    575                 return true;
    576             if (obj == null)
    577                 return false;
    578             if (getClass() != obj.getClass())
    579                 return false;
    580             PaintSettings other = (PaintSettings) obj;
    581             if (!getOuterType().equals(other.getOuterType()))
    582                 return false;
    583             if (alternatedirection != other.alternatedirection)
    584                 return false;
    585             if (colorTracksTune != other.colorTracksTune)
    586                 return false;
    587             if (colored == null) {
    588                 if (other.colored != null)
    589                     return false;
    590             } else if (!colored.equals(other.colored))
    591                 return false;
    592             if (delta != other.delta)
    593                 return false;
    594             if (direction != other.direction)
    595                 return false;
    596             if (forceLines != other.forceLines)
    597                 return false;
    598             if (hdopcircle != other.hdopcircle)
    599                 return false;
    600             if (large != other.large)
    601                 return false;
    602             if (lineWidth != other.lineWidth)
    603                 return false;
    604             if (lines != other.lines)
    605                 return false;
    606             if (maxLineLength != other.maxLineLength)
    607                 return false;
    608             if (neutralColor == null) {
    609                 if (other.neutralColor != null)
    610                     return false;
    611             } else if (!neutralColor.equals(other.neutralColor))
    612                 return false;
    613             return true;
    614         }
    615 
    616         private GpxLayer getOuterType() {
    617             return GpxLayer.this;
    618         }
    619     }
    620 
    621498    @Override
    622499    public void paint(Graphics2D g, MapView mv, Bounds box) {
     
    624501        lastTracks.clear();
    625502        lastTracks.addAll(data.tracks);
    626         lastPaintSettings = new PaintSettings(isLocalFile);
    627 
    628503
    629504        /****************************************************************
    630505         ********** STEP 1 - GET CONFIG VALUES **************************
    631506         ****************************************************************/
    632         PaintSettings ps =lastPaintSettings;
    633 
    634         if(ps.lineWidth != 0)
     507        // Long startTime = System.currentTimeMillis();
     508        Color neutralColor = getColor(getName());
     509        // also draw lines between points belonging to different segments
     510        boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force");
     511        // draw direction arrows on the lines
     512        boolean direction = Main.pref.getBoolean("draw.rawgps.direction");
     513        // don't draw lines if longer than x meters
     514        int lineWidth = Main.pref.getInteger("draw.rawgps.linewidth",0);
     515
     516        int maxLineLength;
     517        if (this.isLocalFile) {
     518            maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length.local", -1);
     519        } else {
     520            maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", 200);
     521        }
     522        // draw line between points, global setting
     523        boolean lines = (Main.pref.getBoolean("draw.rawgps.lines", true) || (Main.pref
     524                .getBoolean("draw.rawgps.lines.localfiles") && this.isLocalFile));
     525        String linesKey = "draw.rawgps.lines.layer " + getName();
     526        // draw lines, per-layer setting
     527        if (Main.pref.hasKey(linesKey)) {
     528            lines = Main.pref.getBoolean(linesKey);
     529        }
     530        // paint large dots for points
     531        boolean large = Main.pref.getBoolean("draw.rawgps.large");
     532        boolean hdopcircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", true);
     533        // color the lines
     534        colorModes colored = colorModes.none;
     535        try {
     536            colored = colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", 0)];
     537        } catch (Exception e) {
     538        }
     539        // paint direction arrow with alternate math. may be faster
     540        boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection");
     541        // don't draw arrows nearer to each other than this
     542        int delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", 0);
     543        // allows to tweak line coloring for different speed levels.
     544        int colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45);
     545
     546        if(lineWidth != 0)
    635547        {
    636             g.setStroke(new BasicStroke(ps.lineWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
     548            g.setStroke(new BasicStroke(lineWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    637549        }
    638550
     
    640552         ********** STEP 2a - CHECK CACHE VALIDITY **********************
    641553         ****************************************************************/
    642         if ((computeCacheMaxLineLengthUsed != ps.maxLineLength) || (!ps.neutralColor.equals(computeCacheColorUsed))
    643                 || (computeCacheColored != ps.colored) || (computeCacheColorTracksTune != ps.colorTracksTune)) {
     554        if ((computeCacheMaxLineLengthUsed != maxLineLength) || (!neutralColor.equals(computeCacheColorUsed))
     555                || (computeCacheColored != colored) || (computeCacheColorTracksTune != colorTracksTune)) {
    644556            // System.out.println("(re-)computing gpx line styles, reason: CCIS=" +
    645557            // computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) +
    646558            // " CCCU=" + (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" +
    647559            // (computeCacheColored != colored));
    648             computeCacheMaxLineLengthUsed = ps.maxLineLength;
     560            computeCacheMaxLineLengthUsed = maxLineLength;
    649561            computeCacheInSync = false;
    650             computeCacheColorUsed = ps.neutralColor;
    651             computeCacheColored = ps.colored;
    652             computeCacheColorTracksTune = ps.colorTracksTune;
     562            computeCacheColorUsed = neutralColor;
     563            computeCacheColored = colored;
     564            computeCacheColorTracksTune = colorTracksTune;
    653565        }
    654566
     
    660572            for (GpxTrack trk : data.tracks) {
    661573                for (GpxTrackSegment segment : trk.getSegments()) {
    662                     if (!ps.forceLines) { // don't draw lines between segments, unless forced to
     574                    if (!forceLines) { // don't draw lines between segments, unless forced to
    663575                        oldWp = null;
    664576                    }
     
    668580                            continue;
    669581                        }
    670                         trkPnt.customColoring = ps.neutralColor;
     582                        trkPnt.customColoring = neutralColor;
    671583                        if (oldWp != null) {
    672584                            double dist = c.greatCircleDistance(oldWp.getCoor());
    673585
    674                             switch (ps.colored) {
     586                            switch (colored) {
    675587                            case velocity:
    676588                                double dtime = trkPnt.time - oldWp.time;
    677589                                double vel = dist / dtime;
    678                                 double velColor = vel / ps.colorTracksTune * 255;
     590                                double velColor = vel / colorTracksTune * 255;
    679591                                // Bad case first
    680592                                if (dtime <= 0 || vel < 0 || velColor > 255) {
     
    700612                            }
    701613
    702                             if (ps.maxLineLength == -1 || dist <= ps.maxLineLength) {
     614                            if (maxLineLength == -1 || dist <= maxLineLength) {
    703615                                trkPnt.drawLine = true;
    704616                                trkPnt.dir = (int) oldWp.getCoor().heading(trkPnt.getCoor());
     
    728640         ********** STEP 3a - DRAW LINES ********************************
    729641         ****************************************************************/
    730         if (ps.lines) {
     642        if (lines) {
    731643            Point old = null;
    732644            for (Collection<WayPoint> segment : visibleSegments) {
     
    752664         ********** STEP 3b - DRAW NICE ARROWS **************************
    753665         ****************************************************************/
    754         if (ps.lines && ps.direction && !ps.alternatedirection) {
     666        if (lines && direction && !alternatedirection) {
    755667            Point old = null;
    756668            Point oldA = null; // last arrow painted
     
    765677                        // skip points that are on the same screenposition
    766678                        if (old != null
    767                                 && (oldA == null || screen.x < oldA.x - ps.delta || screen.x > oldA.x + ps.delta
    768                                         || screen.y < oldA.y - ps.delta || screen.y > oldA.y + ps.delta)) {
     679                                && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta
     680                                        || screen.y < oldA.y - delta || screen.y > oldA.y + delta)) {
    769681                            g.setColor(trkPnt.customColoring);
    770682                            double t = Math.atan2(screen.y - old.y, screen.x - old.x) + Math.PI;
     
    784696         ********** STEP 3c - DRAW FAST ARROWS **************************
    785697         ****************************************************************/
    786         if (ps.lines && ps.direction && ps.alternatedirection) {
     698        if (lines && direction && alternatedirection) {
    787699            Point old = null;
    788700            Point oldA = null; // last arrow painted
     
    797709                        // skip points that are on the same screenposition
    798710                        if (old != null
    799                                 && (oldA == null || screen.x < oldA.x - ps.delta || screen.x > oldA.x + ps.delta
    800                                         || screen.y < oldA.y - ps.delta || screen.y > oldA.y + ps.delta)) {
     711                                && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta
     712                                        || screen.y < oldA.y - delta || screen.y > oldA.y + delta)) {
    801713                            g.setColor(trkPnt.customColoring);
    802714                            g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y
     
    815727         ********** STEP 3d - DRAW LARGE POINTS AND HDOP CIRCLE *********
    816728         ****************************************************************/
    817         if (ps.large || ps.hdopcircle) {
    818             g.setColor(ps.neutralColor);
     729        if (large || hdopcircle) {
     730            g.setColor(neutralColor);
    819731            for (Collection<WayPoint> segment : visibleSegments) {
    820732                for (WayPoint trkPnt : segment) {
     
    825737                    Point screen = mv.getPoint(trkPnt.getEastNorth());
    826738                    g.setColor(trkPnt.customColoring);
    827                     if (ps.hdopcircle && trkPnt.attr.get("hdop") != null) {
     739                    if (hdopcircle && trkPnt.attr.get("hdop") != null) {
    828740                        // hdop value
    829741                        float hdop = ((Float)trkPnt.attr.get("hdop")).floatValue();
     
    835747                        g.drawArc(screen.x-hdopp/2, screen.y-hdopp/2, hdopp, hdopp, 0, 360);
    836748                    }
    837                     if (ps.large) {
     749                    if (large) {
    838750                        g.fillRect(screen.x-1, screen.y-1, 3, 3);
    839751                    }
     
    845757         ********** STEP 3e - DRAW SMALL POINTS FOR LINES ***************
    846758         ****************************************************************/
    847         if (!ps.large && ps.lines) {
    848             g.setColor(ps.neutralColor);
     759        if (!large && lines) {
     760            g.setColor(neutralColor);
    849761            for (Collection<WayPoint> segment : visibleSegments) {
    850762                for (WayPoint trkPnt : segment) {
     
    864776         ********** STEP 3f - DRAW SMALL POINTS INSTEAD OF LINES ********
    865777         ****************************************************************/
    866         if (!ps.large && !ps.lines) {
    867             g.setColor(ps.neutralColor);
     778        if (!large && !lines) {
     779            g.setColor(neutralColor);
    868780            for (Collection<WayPoint> segment : visibleSegments) {
    869781                for (WayPoint trkPnt : segment) {
Note: See TracChangeset for help on using the changeset viewer.