Changeset 3855 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint
- Timestamp:
- 2011-02-05T10:40:39+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3854 r3855 35 35 } 36 36 37 public void add(StyleSource style) { 38 styleSources.add(style); 39 } 40 41 public Collection<StyleSource> getStyleSources() { 42 return Collections.<StyleSource>unmodifiableCollection(styleSources); 37 public List<StyleSource> getStyleSources() { 38 return Collections.<StyleSource>unmodifiableList(styleSources); 43 39 } 44 40 … … 241 237 this.drawMultipolygon = drawMultipolygon; 242 238 } 239 240 /** 241 * remove all style sources; only accessed from MapPaintStyles 242 */ 243 void clear() { 244 styleSources.clear(); 245 } 246 247 /** 248 * add a style source; only accessed from MapPaintStyles 249 */ 250 void add(StyleSource style) { 251 styleSources.add(style); 252 } 253 254 /** 255 * set the style sources; only accessed from MapPaintStyles 256 */ 257 void setStyleSources(Collection<StyleSource> sources) { 258 styleSources.clear(); 259 styleSources.addAll(sources); 260 } 261 243 262 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3853 r3855 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.util.ArrayList; 9 import java.util.Arrays; 8 10 import java.util.Collection; 9 11 import java.util.Collections; 10 12 import java.util.LinkedList; 11 13 import java.util.List; 14 import java.util.concurrent.CopyOnWriteArrayList; 12 15 13 16 import javax.swing.ImageIcon; 17 import javax.swing.SwingUtilities; 14 18 15 19 import org.openstreetmap.josm.Main; … … 23 27 import org.openstreetmap.josm.tools.ImageProvider; 24 28 29 /** 30 * This class manages the ElemStyles instance. The object you get with 31 * getStyles() is read only, any manipulation happens via one of 32 * the wrapper methods here. (readFromPreferences, moveStyles, ...) 33 * 34 * On change, mapPaintSylesUpdated() is fired for all listeners. 35 */ 25 36 public class MapPaintStyles { 26 37 … … 71 82 } 72 83 73 @SuppressWarnings("null")74 84 public static void readFromPreferences() { 85 styles.clear(); 75 86 iconDirs = Main.pref.getCollection("mappaint.icon.sources", Collections.<String>emptySet()); 76 87 if(Main.pref.getBoolean("mappaint.icon.enable-defaults", true)) … … 83 94 } 84 95 85 Collection<? extends SourceEntry> sourceEntries = (new MapPaintPrefMigration()).get();96 Collection<? extends SourceEntry> sourceEntries = MapPaintPrefMigration.INSTANCE.get(); 86 97 87 98 for (SourceEntry entry : sourceEntries) { … … 120 131 s.loadStyleSource(); 121 132 } 133 fireMapPaintSylesUpdated(); 134 } 135 136 /** 137 * reload styles 138 * preferences are the same, but the file source may have changed 139 * @param sel the indices of styles to reload 140 */ 141 public static void reloadStyles(final int... sel) { 142 List<StyleSource> toReload = new ArrayList<StyleSource>(); 143 List<StyleSource> data = styles.getStyleSources(); 144 for (int i : sel) { 145 toReload.add(data.get(i)); 146 } 147 Main.worker.submit(new MapPaintStyleLoader(toReload)); 122 148 } 123 149 … … 138 164 @Override 139 165 protected void finish() { 166 SwingUtilities.invokeLater(new Runnable() { 167 @Override 168 public void run() { 169 fireMapPaintSylesUpdated(); 170 styles.clearCached(); 171 Main.map.mapView.preferenceChanged(null); 172 Main.map.mapView.repaint(); 173 } 174 }); 140 175 } 141 176 … … 154 189 } 155 190 191 /** 192 * Move position of entries in the current list of StyleSources 193 * @param sele The indices of styles to be moved. 194 * @param delta The number of lines it should move. positive int moves 195 * down and negative moves up. 196 */ 197 public static void moveStyles(int[] sel, int delta) { 198 if (!canMoveStyles(sel, delta)) 199 return; 200 int[] selSorted = Arrays.copyOf(sel, sel.length); 201 Arrays.sort(selSorted); 202 List<StyleSource> data = new ArrayList<StyleSource>(styles.getStyleSources()); 203 for (int row: selSorted) { 204 StyleSource t1 = data.get(row); 205 StyleSource t2 = data.get(row + delta); 206 data.set(row, t2); 207 data.set(row + delta, t1); 208 } 209 styles.setStyleSources(data); 210 MapPaintPrefMigration.INSTANCE.put(data); 211 fireMapPaintSylesUpdated(); 212 styles.clearCached(); 213 Main.map.mapView.repaint(); 214 } 215 216 public static boolean canMoveStyles(int[] sel, int i) { 217 if (sel.length == 0) 218 return false; 219 int[] selSorted = Arrays.copyOf(sel, sel.length); 220 Arrays.sort(selSorted); 221 222 if (i < 0) { // Up 223 return selSorted[0] >= -i; 224 } else 225 if (i > 0) { // Down 226 return selSorted[selSorted.length-1] <= styles.getStyleSources().size() - 1 - i; 227 } else 228 return true; 229 } 230 231 public static void toggleStyleActive(int... sel) { 232 List<StyleSource> data = styles.getStyleSources(); 233 for (int p : sel) { 234 StyleSource s = data.get(p); 235 s.active = !s.active; 236 } 237 MapPaintPrefMigration.INSTANCE.put(data); 238 if (sel.length == 1) { 239 fireMapPaintStyleEntryUpdated(sel[0]); 240 } else { 241 fireMapPaintSylesUpdated(); 242 } 243 styles.clearCached(); 244 Main.map.mapView.repaint(); 245 } 246 247 /*********************************** 248 * MapPaintSylesUpdateListener & related code 249 * (get informed when the list of MapPaint StyleSources changes) 250 */ 251 252 public interface MapPaintSylesUpdateListener { 253 public void mapPaintStylesUpdated(); 254 public void mapPaintStyleEntryUpdated(int idx); 255 } 256 257 protected static final CopyOnWriteArrayList<MapPaintSylesUpdateListener> listeners 258 = new CopyOnWriteArrayList<MapPaintSylesUpdateListener>(); 259 260 public static void addMapPaintSylesUpdateListener(MapPaintSylesUpdateListener listener) { 261 if (listener != null) { 262 listeners.addIfAbsent(listener); 263 } 264 } 265 266 public static void removeMapPaintSylesUpdateListener(MapPaintSylesUpdateListener listener) { 267 listeners.remove(listener); 268 } 269 270 public static void fireMapPaintSylesUpdated() { 271 for (MapPaintSylesUpdateListener l : listeners) { 272 l.mapPaintStylesUpdated(); 273 } 274 } 275 276 public static void fireMapPaintStyleEntryUpdated(int idx) { 277 for (MapPaintSylesUpdateListener l : listeners) { 278 l.mapPaintStyleEntryUpdated(idx); 279 } 280 } 156 281 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3836 r3855 97 97 } 98 98 } 99 } else if (primitive instanceof Relation ) {99 } else if (primitive instanceof Relation && icon != null) { 100 100 painter.drawRestriction((Relation) primitive, this); 101 101 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r3848 r3855 41 41 public void loadStyleSource() { 42 42 rules.clear(); 43 hasError = false; 43 44 try { 44 45 MirroredInputStream in = new MirroredInputStream(url); -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r3848 r3855 50 50 51 51 protected void init() { 52 hasError = false; 52 53 icons.clear(); 53 54 lines.clear();
Note:
See TracChangeset
for help on using the changeset viewer.