Changeset 33462 in osm for applications
- Timestamp:
- 2017-07-20T11:11:39+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/PTAssistantPlugin.java
r33461 r33462 2 2 package org.openstreetmap.josm.plugins.pt_assistant; 3 3 4 import java.awt.KeyboardFocusManager; 4 5 import java.util.ArrayList; 5 6 import java.util.List; … … 9 10 10 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.osm.DataSet; 11 13 import org.openstreetmap.josm.data.osm.Relation; 12 14 import org.openstreetmap.josm.data.validation.OsmValidator; … … 25 27 import org.openstreetmap.josm.plugins.pt_assistant.actions.SplitRoundaboutAction; 26 28 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment; 29 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayerManager; 27 30 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantPreferenceSetting; 28 31 import org.openstreetmap.josm.plugins.pt_assistant.validation.PTAssistantValidatorTest; … … 60 63 public PTAssistantPlugin(PluginInformation info) { 61 64 super(info); 62 Main.info("whatever you want");63 65 OsmValidator.addTest(PTAssistantValidatorTest.class); 64 66 67 DataSet.addSelectionListener(PTAssistantLayerManager.PTLM); 68 KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(PTAssistantLayerManager.PTLM); 65 69 RepeatLastFixAction repeatLastFixAction = new RepeatLastFixAction(); 66 70 EditHighlightedRelationsAction editHighlightedRelationsAction = new EditHighlightedRelationsAction(); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r33429 r33462 4 4 import java.awt.Graphics; 5 5 import java.awt.Graphics2D; 6 import java.awt.KeyboardFocusManager;7 import java.beans.PropertyChangeEvent;8 import java.beans.PropertyChangeListener;9 6 import java.util.ArrayList; 10 7 import java.util.Collections; 11 8 import java.util.HashMap; 12 9 import java.util.List; 10 import java.util.Map.Entry; 13 11 14 12 import javax.swing.Action; … … 25 23 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 26 24 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 27 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;28 25 import org.openstreetmap.josm.gui.layer.Layer; 29 26 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; … … 35 32 import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin; 36 33 import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay; 37 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;38 34 import org.openstreetmap.josm.tools.ImageProvider; 39 35 … … 45 41 */ 46 42 public final class PTAssistantLayer extends Layer 47 implements PropertyChangeListener,LayerChangeListener {43 implements LayerChangeListener { 48 44 49 45 private List<OsmPrimitive> primitives = new ArrayList<>(); … … 54 50 public PTAssistantLayer() { 55 51 super("pt_assistant layer"); 56 KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this);57 52 Main.getLayerManager().addLayerChangeListener(this); 58 53 Main.getLayerManager().addLayer(this); … … 97 92 } 98 93 99 for (Character currentFixVariantLetter : this.fixVariants.keySet()) { 100 List<PTWay> fixVariant = this.fixVariants.get(currentFixVariantLetter); 94 for (Entry<Character, List<PTWay>> entry : this.fixVariants.entrySet()) { 95 Character currentFixVariantLetter = entry.getKey(); 96 List<PTWay> fixVariant = entry.getValue(); 101 97 for (PTWay ptway : fixVariant) { 102 98 for (Way way : ptway.getWays()) { … … 123 119 */ 124 120 public List<PTWay> getFixVariant(char c) { 125 return this.fixVariants.get(Character.toUpperCase(c)); 126 } 127 128 public void setPrimitives(List<OsmPrimitive> primitives) { 129 this.primitives.clear(); 130 this.primitives.addAll(primitives); 121 return fixVariants.get(Character.toUpperCase(c)); 122 } 123 124 public void setPrimitives(List<OsmPrimitive> newPrimitives) { 125 primitives = new ArrayList<>(newPrimitives); 131 126 } 132 127 … … 140 135 } 141 136 142 paintVisitor.visitFixVariants( this.fixVariants, this.wayColoring);137 paintVisitor.visitFixVariants(fixVariants, wayColoring); 143 138 144 139 } … … 188 183 } 189 184 190 /** 191 * Listens to a focus change, sets the primitives attribute to the route 192 * relation in the top Relation Editor and repaints the map 193 */ 194 @Override 195 public void propertyChange(PropertyChangeEvent evt) { 196 197 if ("focusedWindow".equals(evt.getPropertyName())) { 198 199 if (evt.getNewValue() == null) { 200 return; 201 } 202 203 if (evt.getNewValue().getClass().equals(GenericRelationEditor.class)) { 204 205 GenericRelationEditor editor = (GenericRelationEditor) evt.getNewValue(); 206 Relation relation = editor.getRelation(); 207 208 if (RouteUtils.isVersionTwoPTRoute(relation)) { 209 this.repaint(relation); 210 211 } 212 } 213 } 214 } 185 215 186 216 187 /** … … 220 191 */ 221 192 public void repaint(Relation relation) { 222 this.primitives.clear();223 this.primitives.add(relation);193 primitives.clear(); 194 primitives.add(relation); 224 195 if (!Main.getLayerManager().containsLayer(this)) { 225 196 Main.getLayerManager().addLayer(this); … … 236 207 } 237 208 238 paintVisitor.visitFixVariants( this.fixVariants, this.wayColoring);209 paintVisitor.visitFixVariants(fixVariants, wayColoring); 239 210 240 211 Main.map.mapView.repaint(); … … 256 227 257 228 if (event.getRemovedLayer() instanceof OsmDataLayer) { 258 this.primitives.clear();259 this.fixVariants.clear();260 this.wayColoring.clear();229 primitives.clear(); 230 fixVariants.clear(); 231 wayColoring.clear(); 261 232 Main.map.mapView.repaint(); 262 233 } … … 274 245 @Override 275 246 public synchronized void destroy() { 276 KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(this);277 247 Main.getLayerManager().removeLayerChangeListener(this); 278 248 super.destroy(); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayerManager.java
r33429 r33462 2 2 package org.openstreetmap.josm.plugins.pt_assistant.gui; 3 3 4 import java.beans.PropertyChangeEvent; 5 import java.beans.PropertyChangeListener; 4 6 import java.util.ArrayList; 5 7 import java.util.Collection; … … 9 11 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 10 12 import org.openstreetmap.josm.data.osm.Relation; 13 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 11 14 import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin; 12 15 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 13 16 14 public class PTAssistantLayerManager implements SelectionChangedListener { 17 public class PTAssistantLayerManager 18 implements SelectionChangedListener, PropertyChangeListener { 15 19 16 20 public static final PTAssistantLayerManager PTLM = new PTAssistantLayerManager(); … … 51 55 } 52 56 } 57 58 /** 59 * Listens to a focus change, sets the primitives attribute to the route 60 * relation in the top Relation Editor and repaints the map 61 */ 62 @Override 63 public void propertyChange(PropertyChangeEvent evt) { 64 65 if ("focusedWindow".equals(evt.getPropertyName()) 66 && evt.getNewValue() != null 67 && GenericRelationEditor.class.equals(evt.getNewValue().getClass())) { 68 69 GenericRelationEditor editor = (GenericRelationEditor) evt.getNewValue(); 70 Relation relation = editor.getRelation(); 71 72 if (RouteUtils.isVersionTwoPTRoute(relation)) { 73 getLayer().repaint(relation); 74 } 75 } 76 } 53 77 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r33452 r33462 17 17 import org.openstreetmap.josm.command.SelectCommand; 18 18 import org.openstreetmap.josm.command.SequenceCommand; 19 import org.openstreetmap.josm.data.osm.DataSet;20 19 import org.openstreetmap.josm.data.osm.Node; 21 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 64 63 super(tr("Public Transport Assistant tests"), 65 64 tr("Check if route relations are compatible with public transport version 2")); 66 67 DataSet.addSelectionListener(PTAssistantLayerManager.PTLM);68 69 65 } 70 66
Note:
See TracChangeset
for help on using the changeset viewer.