- Timestamp:
- 2012-05-07T15:05:27+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapView.java
r5054 r5219 238 238 } 239 239 }); 240 240 241 241 // Add Multipolygon cache to layer listeners 242 242 addLayerChangeListener(MultipolygonCache.getInstance()); … … 730 730 AbstractButton button = e.nextElement(); 731 731 MapMode mode = (MapMode)button.getAction(); 732 boolean isLayerSupported = mode.layerIsSupported(layer); 732 boolean isLayerSupported = mode.layerIsSupported(layer); 733 733 button.setEnabled(isLayerSupported); 734 734 // Also update associated shortcut (fix #6876) -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r5200 r5219 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn; 5 6 6 7 import java.awt.Component; … … 11 12 import java.awt.Point; 12 13 import java.awt.Rectangle; 14 import java.awt.Window; 13 15 import java.awt.event.ActionEvent; 14 16 import java.awt.event.ActionListener; 15 17 import java.awt.event.KeyEvent; 16 18 import java.awt.event.MouseEvent; 19 import java.awt.event.WindowAdapter; 20 import java.awt.event.WindowEvent; 17 21 import java.io.BufferedInputStream; 18 22 import java.io.BufferedOutputStream; … … 61 65 import org.openstreetmap.josm.gui.SideButton; 62 66 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 67 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintStyleLoader; 63 68 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 64 69 import org.openstreetmap.josm.gui.mappaint.StyleSource; … … 143 148 selectionModel.addListSelectionListener(upAction); 144 149 selectionModel.addListSelectionListener(downAction); 145 150 146 151 // Toggle style on Enter and Spacebar 147 152 InputMapUtils.addEnterAction(tblStyles, onoffAction); 148 153 InputMapUtils.addSpacebarAction(tblStyles, onoffAction); 149 154 150 155 createLayout(p, true, Arrays.asList(new SideButton[] { 151 156 new SideButton(onoffAction, false), … … 173 178 } 174 179 180 /** 181 * Reload local styles when they have been changed in an external editor. 182 * 183 * Checks file modification time when an WindowEvent is invoked. Because 184 * any dialog window can get activated, when switching to another app and back, 185 * we have to register listeners to all windows in JOSM. 186 */ 187 protected static class ReloadWindowListener extends WindowAdapter { 188 189 private static ReloadWindowListener INSTANCE; 190 191 public static ReloadWindowListener getInstance() { 192 if (INSTANCE == null) { 193 INSTANCE = new ReloadWindowListener(); 194 } 195 return INSTANCE; 196 } 197 198 public static void setup() { 199 for (Window w : Window.getWindows()) { 200 if (w.isShowing()) { 201 w.addWindowListener(getInstance()); 202 } 203 } 204 } 205 206 public static void teardown() { 207 for (Window w : Window.getWindows()) { 208 w.removeWindowListener(getInstance()); 209 } 210 } 211 212 @Override 213 public void windowActivated(WindowEvent e) { 214 if (e.getOppositeWindow() == null) { // we come from a native window, e.g. editor 215 // reload local styles, if necessary 216 List<StyleSource> toReload = new ArrayList<StyleSource>(); 217 for (StyleSource s : MapPaintStyles.getStyles().getStyleSources()) { 218 if (s.isLocal()) { 219 File f = new File(s.url); 220 long mtime = f.lastModified(); 221 if (mtime > s.getLastMTime()) { 222 toReload.add(s); 223 s.setLastMTime(mtime); 224 } 225 } 226 } 227 if (!toReload.isEmpty()) { 228 System.out.println(trn("Reloading {0} map style.", "Reloading {0} map styles.", toReload.size(), toReload.size())); 229 Main.worker.submit(new MapPaintStyleLoader(toReload)); 230 } 231 } 232 } 233 234 @Override 235 public void windowDeactivated(WindowEvent e) { 236 // set up windows that have been created in the meantime 237 for (Window w : Window.getWindows()) { 238 w.removeWindowListener(getInstance()); 239 if (w.isShowing()) { 240 w.addWindowListener(getInstance()); 241 } 242 } 243 } 244 } 245 175 246 @Override 176 247 public void showNotify() { 177 248 MapPaintStyles.addMapPaintSylesUpdateListener(model); 178 249 Main.main.menu.wireFrameToggleAction.addButtonModel(cbWireframe.getModel()); 250 if (Main.pref.getBoolean("mappaint.auto_reload_local_styles", true)) { 251 ReloadWindowListener.setup(); 252 } 179 253 } 180 254 … … 183 257 Main.main.menu.wireFrameToggleAction.removeButtonModel(cbWireframe.getModel()); 184 258 MapPaintStyles.removeMapPaintSylesUpdateListener(model); 259 if (Main.pref.getBoolean("mappaint.auto_reload_local_styles", true)) { 260 ReloadWindowListener.teardown(); 261 } 185 262 } 186 263 -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java
r5217 r5219 50 50 return text.hashCode(); 51 51 } 52 53 @Override 54 public String toString() { 55 return "LineTextElemStyle{" + super.toString() + "text=" + text + "}"; 56 } 57 52 58 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r5054 r5219 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.File; 6 7 import java.io.IOException; 7 8 import java.io.InputStream; … … 21 22 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 22 23 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource; 24 import org.openstreetmap.josm.gui.preferences.SourceEntry; 23 25 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference.MapPaintPrefHelper; 24 import org.openstreetmap.josm.gui.preferences.SourceEntry;25 26 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 26 27 import org.openstreetmap.josm.io.MirroredInputStream; … … 165 166 for (StyleSource source : styles.getStyleSources()) { 166 167 source.loadStyleSource(); 167 } 168 168 if (Main.pref.getBoolean("mappaint.auto_reload_local_styles", true)) { 169 if (source.isLocal()) { 170 File f = new File(source.url); 171 source.setLastMTime(f.lastModified()); 172 } 173 } 174 } 169 175 fireMapPaintSylesUpdated(); 170 176 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r4820 r5219 26 26 27 27 private ImageIcon imageIcon; 28 private long lastMTime = 0l; 28 29 29 30 /****** … … 31 32 * of the source file. 32 33 */ 33 34 34 35 public String icon; 35 36 … … 104 105 return null; 105 106 } 107 108 public long getLastMTime() { 109 return lastMTime; 110 } 111 112 public void setLastMTime(long lastMTime) { 113 this.lastMTime = lastMTime; 114 } 115 116 106 117 }
Note:
See TracChangeset
for help on using the changeset viewer.