Skip to content

Commit

Permalink
fix #josm15612 + avoid repainting directly the mapview
Browse files Browse the repository at this point in the history
  • Loading branch information
don-vip committed Dec 1, 2017
1 parent fb75fdc commit 1fcdf2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- enter the SVN commit message -->
<property name="commit.message" value="Initial commit"/>
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
<property name="plugin.main.version" value="12987"/>
<property name="plugin.main.version" value="13150"/>

<!-- Configure these properties (replace "..." accordingly).
See https://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.openstreetmap.josm.gui.util.KeyPressReleaseListener;
import org.openstreetmap.josm.gui.util.ModifierExListener;
import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
import org.openstreetmap.josm.tools.Geometry;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.Logging;
Expand All @@ -69,7 +68,7 @@
*/
public class ImproveWayAccuracyAction extends MapMode implements MapViewPaintable,
SelectionChangedListener, ModifierExListener, KeyPressReleaseListener,
ExpertModeChangeListener, PreferenceChangedListener {
ExpertModeChangeListener {

enum State {
selecting, improving
Expand Down Expand Up @@ -137,9 +136,8 @@ enum State {

/**
* Constructs a new {@code ImproveWayAccuracyAction}.
* @param mapFrame Map frame
*/
public ImproveWayAccuracyAction(MapFrame mapFrame) {
public ImproveWayAccuracyAction() {
super(tr("Improve Way"), "improveway",
tr("Improve Way mode"),
Shortcut.registerShortcut("mapmode:ImproveWay",
Expand All @@ -158,7 +156,6 @@ public ImproveWayAccuracyAction(MapFrame mapFrame) {
"add_node_lock");
cursorImproveLock = ImageProvider.getCursor("crosshair", "lock");
ExpertToggleAction.addExpertModeChangeListener(this, true);
Main.pref.addPreferenceChangeListener(this);
readPreferences();
}

Expand Down Expand Up @@ -200,7 +197,7 @@ public void enterMode() {
public void run() {
helpersEnabled = true;
helpersUseOriginal = true;
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
}
}, longKeypressTime);
}
Expand Down Expand Up @@ -246,7 +243,7 @@ public void exitMode() {
DataSet.removeSelectionListener(this);

MainApplication.getMap().keyDetector.removeModifierExListener(this);
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
}

@Override
Expand Down Expand Up @@ -652,7 +649,7 @@ public void modifiersExChanged(int modifiers) {
updateCursorDependentObjectsIfNeeded();
updateCursor();
updateStatusLine();
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
}

@Override
Expand Down Expand Up @@ -681,7 +678,7 @@ public void mouseMoved(MouseEvent e) {
updateCursorDependentObjectsIfNeeded();
updateCursor();
updateStatusLine();
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
}

@Override
Expand Down Expand Up @@ -810,7 +807,7 @@ public void mouseReleased(MouseEvent e) {

updateCursor();
updateStatusLine();
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
}

@Override
Expand All @@ -822,7 +819,7 @@ public void mouseExited(MouseEvent e) {
if (!dragging) {
mousePos = null;
}
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
}

// -------------------------------------------------------------------------
Expand Down Expand Up @@ -896,7 +893,7 @@ public void startSelecting() {

targetWay = null;

mv.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
updateStatusLine();
}

Expand All @@ -921,7 +918,7 @@ public void startImproving(Way targetWay) {
this.candidateNode = null;
this.candidateSegment = null;

mv.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
updateStatusLine();
}

Expand Down Expand Up @@ -979,7 +976,7 @@ private void resetTimer() {
public void doKeyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_WINDOWS) {
mod4 = true;
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
return;
}
if (!helpersShortcut.isEvent(e) && !getShortcut().isEvent(e)) return;
Expand All @@ -988,14 +985,14 @@ public void doKeyPressed(KeyEvent e) {
helpersEnabledBeforeKeypressed = helpersEnabled;
if (!helpersEnabled) helpersEnabled = true;
helpersUseOriginal = true;
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
}

@Override
public void doKeyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_WINDOWS) {
mod4 = false;
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
return;
}
if (!helpersShortcut.isEvent(e) && !getShortcut().isEvent(e)) return;
Expand All @@ -1010,25 +1007,23 @@ public void doKeyReleased(KeyEvent e) {
helpersEnabled = !helpersEnabledBeforeKeypressed;
}
helpersUseOriginal = false;
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
}

@Override
public void expertChanged(boolean isExpert) {
this.isExpert = isExpert;
if (!isExpert && helpersEnabled) {
helpersEnabled = false;
MainApplication.getMap().mapView.repaint();
MainApplication.getLayerManager().invalidateEditLayer();
}
}

@Override
public void preferenceChanged(PreferenceChangeEvent e) {
if (!isEnabled()) return;
if (e.getKey().startsWith("improvewayaccuracy") ||
e.getKey().startsWith("color.improve.way.accuracy")) {
readPreferences();
MainApplication.getMap().mapView.repaint();
super.preferenceChanged(e);
if (isEnabled() && (e.getKey().startsWith("improvewayaccuracy") || e.getKey().startsWith("color.improve.way.accuracy"))) {
MainApplication.getLayerManager().invalidateEditLayer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public ImproveWayPlugin(final PluginInformation info) {
@Override
public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
if (oldFrame == null && newFrame != null) {
MainApplication.getMap().addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(MainApplication.getMap()), false));
MainApplication.getMap().addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(), false));
}
}

}

0 comments on commit 1fcdf2a

Please sign in to comment.