- Timestamp:
- 2014-05-29T00:58:29+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r7100 r7185 88 88 import org.openstreetmap.josm.gui.util.RedirectInputMap; 89 89 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; 90 import org.openstreetmap.josm.io.FileWatcher; 90 91 import org.openstreetmap.josm.io.OsmApi; 91 92 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 198 199 */ 199 200 public OsmValidator validator; 201 202 /** 203 * The file watcher service. 204 */ 205 public static final FileWatcher fileWatcher = new FileWatcher(); 200 206 201 207 /** -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r7082 r7185 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn;6 5 7 6 import java.awt.Component; … … 66 65 import org.openstreetmap.josm.gui.SideButton; 67 66 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 68 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintStyleLoader;69 67 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 70 68 import org.openstreetmap.josm.gui.mappaint.StyleSource; … … 83 81 import org.openstreetmap.josm.tools.Utils; 84 82 85 public class MapPaintDialog extends ToggleDialog implements Main.WindowSwitchListener{83 public class MapPaintDialog extends ToggleDialog { 86 84 87 85 protected StylesTable tblStyles; … … 191 189 192 190 @Override 193 public void toOtherApplication() {194 // nothing195 }196 197 @Override198 public void fromOtherApplication() {199 // Reload local styles when they have been changed in an external editor.200 // Checks file modification time.201 List<StyleSource> toReload = new ArrayList<>();202 for (StyleSource s : MapPaintStyles.getStyles().getStyleSources()) {203 if (s.isLocal()) {204 File f = new File(s.url);205 long mtime = f.lastModified();206 if (mtime > s.getLastMTime()) {207 toReload.add(s);208 s.setLastMTime(mtime);209 }210 }211 }212 if (!toReload.isEmpty()) {213 Main.info(trn("Reloading {0} map style.", "Reloading {0} map styles.", toReload.size(), toReload.size()));214 Main.worker.submit(new MapPaintStyleLoader(toReload));215 }216 }217 218 @Override219 191 public void showNotify() { 220 192 MapPaintStyles.addMapPaintSylesUpdateListener(model); 221 193 Main.main.menu.wireFrameToggleAction.addButtonModel(cbWireframe.getModel()); 222 if (Main.pref.getBoolean("mappaint.auto_reload_local_styles", true)) {223 Main.addWindowSwitchListener(this);224 }225 194 } 226 195 … … 229 198 Main.main.menu.wireFrameToggleAction.removeButtonModel(cbWireframe.getModel()); 230 199 MapPaintStyles.removeMapPaintSylesUpdateListener(model); 231 if (Main.pref.getBoolean("mappaint.auto_reload_local_styles", true)) {232 Main.removeWindowSwitchListener(this);233 }234 200 } 235 201 … … 296 262 tblStyles.repaint(); 297 263 } 298 299 /**300 * MapPaintSylesUpdateListener interface301 */302 264 303 265 @Override -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r7143 r7185 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.File;7 6 import java.io.IOException; 8 7 import java.io.InputStreamReader; … … 206 205 } 207 206 for (StyleSource source : styles.getStyleSources()) { 208 final long startTime = System.currentTimeMillis(); 209 source.loadStyleSource(); 210 if (Main.pref.getBoolean("mappaint.auto_reload_local_styles", true) && source.isLocal()) { 211 File f = new File(source.url); 212 source.setLastMTime(f.lastModified()); 213 } 214 if (Main.isDebugEnabled()) { 215 final long elapsedTime = System.currentTimeMillis() - startTime; 216 Main.debug("Initializing map style " + source.url + " completed in " + Utils.getDurationString(elapsedTime)); 217 } 207 loadStyleForFirstTime(source); 218 208 } 219 209 fireMapPaintSylesUpdated(); 210 } 211 212 private static void loadStyleForFirstTime(StyleSource source) { 213 final long startTime = System.currentTimeMillis(); 214 source.loadStyleSource(); 215 if (Main.pref.getBoolean("mappaint.auto_reload_local_styles", true) && source.isLocal()) { 216 try { 217 Main.fileWatcher.registerStyleSource(source); 218 } catch (IOException e) { 219 Main.error(e); 220 } 221 } 222 if (Main.isDebugEnabled()) { 223 final long elapsedTime = System.currentTimeMillis() - startTime; 224 Main.debug("Initializing map style " + source.url + " completed in " + Utils.getDurationString(elapsedTime)); 225 } 220 226 } 221 227 … … 287 293 public static class MapPaintStyleLoader extends PleaseWaitRunnable { 288 294 private boolean canceled; 289 private List<StyleSource> sources;290 291 public MapPaintStyleLoader( List<StyleSource> sources) {295 private Collection<StyleSource> sources; 296 297 public MapPaintStyleLoader(Collection<StyleSource> sources) { 292 298 super(tr("Reloading style sources")); 293 299 this.sources = sources; … … 385 391 if (source != null) { 386 392 styles.add(source); 387 source.loadStyleSource();393 loadStyleForFirstTime(source); 388 394 MapPaintPrefHelper.INSTANCE.put(styles.getStyleSources()); 389 395 fireMapPaintSylesUpdated(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r7081 r7185 34 34 35 35 private ImageIcon imageIcon; 36 private long lastMTime = 0L;37 36 38 37 /****** … … 81 80 */ 82 81 public abstract InputStream getSourceInputStream() throws IOException; 83 82 84 83 /** 85 84 * Returns a new {@code MirroredInputStream} to the local file containing style source (can be a text file or an archive). … … 156 155 return null; 157 156 } 158 159 public long getLastMTime() {160 return lastMTime;161 }162 163 public void setLastMTime(long lastMTime) {164 this.lastMTime = lastMTime;165 }166 157 }
Note:
See TracChangeset
for help on using the changeset viewer.