Changeset 12651 in josm
- Timestamp:
- 2017-08-25T23:56:58+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapView.java
r12639 r12651 34 34 import javax.swing.JComponent; 35 35 import javax.swing.JPanel; 36 import javax.swing.SwingUtilities; 36 37 37 38 import org.openstreetmap.josm.Main; … … 70 71 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 71 72 import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker; 73 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 74 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 72 75 import org.openstreetmap.josm.io.audio.AudioPlayer; 73 76 import org.openstreetmap.josm.tools.JosmRuntimeException; … … 92 95 implements PropertyChangeListener, PreferenceChangedListener, 93 96 LayerManager.LayerChangeListener, MainLayerManager.ActiveLayerChangeListener { 97 98 static { 99 MapPaintStyles.addMapPaintSylesUpdateListener(new MapPaintSylesUpdateListener() { 100 @Override 101 public void mapPaintStylesUpdated() { 102 SwingUtilities.invokeLater(() -> { 103 // Trigger a repaint of all data layers 104 MainApplication.getLayerManager().getLayers() 105 .stream() 106 .filter(layer -> layer instanceof OsmDataLayer) 107 .forEach(Layer::invalidate); 108 }); 109 } 110 111 @Override 112 public void mapPaintStyleEntryUpdated(int index) { 113 mapPaintStylesUpdated(); 114 } 115 }); 116 } 94 117 95 118 /** -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r12649 r12651 65 65 import org.openstreetmap.josm.gui.mappaint.StyleSetting; 66 66 import org.openstreetmap.josm.gui.mappaint.StyleSource; 67 import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader; 67 68 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 68 69 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference; … … 417 418 public void actionPerformed(ActionEvent e) { 418 419 final int[] rows = tblStyles.getSelectedRows(); 419 MapPaintStyle s.reloadStyles(rows);420 MapPaintStyleLoader.reloadStyles(rows); 420 421 MainApplication.worker.submit(() -> SwingUtilities.invokeLater(() -> { 421 422 selectionModel.setValueIsAdjusting(true); -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r12649 r12651 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.io.File; … … 24 22 import org.openstreetmap.josm.data.preferences.sources.MapPaintPrefHelper; 25 23 import org.openstreetmap.josm.data.preferences.sources.SourceEntry; 26 import org.openstreetmap.josm.gui.MainApplication;27 import org.openstreetmap.josm.gui.PleaseWaitRunnable;28 import org.openstreetmap.josm.gui.layer.Layer;29 import org.openstreetmap.josm.gui.layer.OsmDataLayer;30 24 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 31 25 import org.openstreetmap.josm.gui.mappaint.styleelement.MapImage; 32 26 import org.openstreetmap.josm.gui.mappaint.styleelement.NodeElement; 33 27 import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement; 34 import org.openstreetmap.josm.gui.progress.ProgressMonitor;35 28 import org.openstreetmap.josm.io.CachedFile; 36 29 import org.openstreetmap.josm.tools.ImageProvider; … … 340 333 341 334 /** 342 * reload styles343 * preferences are the same, but the file source may have changed344 * @param sel the indices of styles to reload345 */346 public static void reloadStyles(final int... sel) {347 List<StyleSource> toReload = new ArrayList<>();348 List<StyleSource> data = styles.getStyleSources();349 for (int i : sel) {350 toReload.add(data.get(i));351 }352 MainApplication.worker.submit(new MapPaintStyleLoader(toReload));353 }354 355 /**356 * This class loads the map paint styles357 */358 public static class MapPaintStyleLoader extends PleaseWaitRunnable {359 private boolean canceled;360 private final Collection<StyleSource> sources;361 362 /**363 * Create a new {@link MapPaintStyleLoader}364 * @param sources The styles to load365 */366 public MapPaintStyleLoader(Collection<StyleSource> sources) {367 super(tr("Reloading style sources"));368 this.sources = sources;369 }370 371 @Override372 protected void cancel() {373 canceled = true;374 }375 376 @Override377 protected void finish() {378 fireMapPaintSylesUpdated();379 afterStyleUpdate();380 }381 382 @Override383 protected void realRun() {384 ProgressMonitor monitor = getProgressMonitor();385 monitor.setTicksCount(sources.size());386 for (StyleSource s : sources) {387 if (canceled)388 return;389 monitor.subTask(tr("loading style ''{0}''...", s.getDisplayString()));390 s.loadStyleSource();391 monitor.worked(1);392 }393 }394 }395 396 /**397 335 * Move position of entries in the current list of StyleSources 398 336 * @param sel The indices of styles to be moved. … … 415 353 MapPaintPrefHelper.INSTANCE.put(data); 416 354 fireMapPaintSylesUpdated(); 417 afterStyleUpdate();418 }419 420 /**421 * Manually trigger for now. TODO: Move this to a listener422 */423 private static void afterStyleUpdate() {424 SwingUtilities.invokeLater(() -> {425 styles.clearCached();426 427 // Trigger a repaint of all data layers428 MainApplication.getLayerManager().getLayers()429 .stream()430 .filter(layer -> layer instanceof OsmDataLayer)431 .forEach(Layer::invalidate);432 });433 355 } 434 356 … … 469 391 fireMapPaintSylesUpdated(); 470 392 } 471 afterStyleUpdate();472 393 } 473 394 … … 500 421 MapPaintPrefHelper.INSTANCE.put(styles.getStyleSources()); 501 422 fireMapPaintSylesUpdated(); 502 afterStyleUpdate();503 423 } 504 424 … … 522 442 private static final ListenerList<MapPaintSylesUpdateListener> listeners = ListenerList.createUnchecked(); 523 443 444 static { 445 listeners.addListener(new MapPaintSylesUpdateListener() { 446 @Override 447 public void mapPaintStylesUpdated() { 448 SwingUtilities.invokeLater(styles::clearCached); 449 } 450 451 @Override 452 public void mapPaintStyleEntryUpdated(int index) { 453 mapPaintStylesUpdated(); 454 } 455 }); 456 } 457 524 458 /** 525 459 * Add a listener that listens to global style changes. -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSetting.java
r12634 r12651 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.gui.MainApplication; 14 import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader; 14 15 import org.openstreetmap.josm.tools.Logging; 15 16 … … 71 72 public void actionPerformed(ActionEvent e) { 72 73 setValue(item.isSelected()); 73 MainApplication.worker.submit(new MapPaintStyle s.MapPaintStyleLoader(Arrays.asList(parentStyle)));74 MainApplication.worker.submit(new MapPaintStyleLoader(Arrays.asList(parentStyle))); 74 75 } 75 76 }; -
trunk/src/org/openstreetmap/josm/io/FileWatcher.java
r12649 r12651 19 19 import org.openstreetmap.josm.data.validation.OsmValidator; 20 20 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker; 21 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintStyleLoader;22 21 import org.openstreetmap.josm.gui.mappaint.StyleSource; 22 import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader; 23 23 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; 24 24 import org.openstreetmap.josm.tools.CheckParameterUtil; -
trunk/test/performance/org/openstreetmap/josm/gui/mappaint/MapRendererPerformanceTest.java
r12650 r12651 39 39 import org.openstreetmap.josm.gui.NavigatableComponent; 40 40 import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting; 41 import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader; 41 42 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 42 43 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; … … 142 143 Assert.assertNotNull(hideIconsSetting); 143 144 hideIconsSetting.setValue(false); 144 MapPaintStyle s.reloadStyles(defaultStyleIdx);145 MapPaintStyleLoader.reloadStyles(defaultStyleIdx); 145 146 146 147 try ( … … 157 158 hideIconsSetting.setValue(true); 158 159 } 159 MapPaintStyle s.reloadStyles(defaultStyleIdx);160 MapPaintStyleLoader.reloadStyles(defaultStyleIdx); 160 161 } 161 162 … … 290 291 setFilterStyleActive(false); 291 292 } 292 MapPaintStyle s.reloadStyles(filterStyleIdx);293 MapPaintStyleLoader.reloadStyles(filterStyleIdx); 293 294 test.run(); 294 295 } -
trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSPerformanceTest.java
r12650 r12651 68 68 69 69 void loadStyle() { 70 System.out.print ln("Loading style '"+STYLE_FILE+"' ...");70 System.out.print("Loading style '"+STYLE_FILE+"' ..."); 71 71 MapCSSStyleSource source = new MapCSSStyleSource( 72 72 new SourceEntry(
Note:
See TracChangeset
for help on using the changeset viewer.