Changeset 32430 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-06-29T00:04:10+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r32415 r32430 2 2 3 3 import java.awt.Graphics2D; 4 import java.awt.KeyboardFocusManager; 5 import java.beans.PropertyChangeEvent; 6 import java.beans.PropertyChangeListener; 4 7 import java.util.ArrayList; 5 8 import java.util.Collection; … … 20 23 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 21 24 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 25 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 22 26 import org.openstreetmap.josm.gui.layer.Layer; 23 27 import org.openstreetmap.josm.gui.layer.LayerPositionStrategy; … … 25 29 import org.openstreetmap.josm.tools.ImageProvider; 26 30 27 public class PTAssistantLayer extends Layer implements SelectionChangedListener { 28 31 public class PTAssistantLayer extends Layer implements SelectionChangedListener, PropertyChangeListener { 32 29 33 private List<OsmPrimitive> primitives = new ArrayList<>(); 30 34 31 32 35 public PTAssistantLayer() { 33 36 super("pt_assistant layer"); 37 38 KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this); 39 34 40 } 35 41 36 42 public void addPrimitive(OsmPrimitive primitive) { 37 43 this.primitives.add(primitive); 38 44 } 39 45 40 46 public void clear() { 41 47 this.primitives.clear(); 42 48 } 43 49 44 45 @Override 46 public void paint(final Graphics2D g, final MapView mv, Bounds bounds) { 50 @Override 51 public void paint(final Graphics2D g, final MapView mv, Bounds bounds) { 47 52 48 49 50 53 PTAssistantPaintVisitor paintVisitor = new PTAssistantPaintVisitor(g, mv); 54 for (OsmPrimitive primitive : primitives) { 55 paintVisitor.visit(primitive); 51 56 52 53 54 57 } 58 59 } 55 60 56 61 @Override 57 62 public Icon getIcon() { 58 63 return ImageProvider.get("layer", "osmdata_small"); 59 64 } 60 65 … … 66 71 @Override 67 72 public Action[] getMenuEntries() { 68 return new Action[] { 69 LayerListDialog.getInstance().createShowHideLayerAction(), 70 LayerListDialog.getInstance().createDeleteLayerAction(), 71 SeparatorLayerAction.INSTANCE, 72 new RenameLayerAction(null, this), 73 SeparatorLayerAction.INSTANCE, 74 new LayerListPopup.InfoAction(this) }; 73 return new Action[] { LayerListDialog.getInstance().createShowHideLayerAction(), 74 LayerListDialog.getInstance().createDeleteLayerAction(), SeparatorLayerAction.INSTANCE, 75 new RenameLayerAction(null, this), SeparatorLayerAction.INSTANCE, new LayerListPopup.InfoAction(this) }; 75 76 } 76 77 … … 88 89 public void mergeFrom(Layer arg0) { 89 90 // do nothing 90 91 91 92 } 92 93 … … 94 95 public void visitBoundingBox(BoundingXYVisitor arg0) { 95 96 // do nothing 96 97 97 98 } 98 99 99 100 @Override 101 public LayerPositionStrategy getDefaultLayerPosition() { 102 return LayerPositionStrategy.IN_FRONT; 103 } 100 @Override 101 public LayerPositionStrategy getDefaultLayerPosition() { 102 return LayerPositionStrategy.IN_FRONT; 103 } 104 104 105 105 @Override 106 106 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 107 108 107 109 108 ArrayList<Relation> routes = new ArrayList<>(); 110 111 for (OsmPrimitive primitive: newSelection) { 109 110 for (OsmPrimitive primitive : newSelection) { 112 111 if (primitive.getType().equals(OsmPrimitiveType.RELATION)) { 113 112 Relation relation = (Relation) primitive; … … 115 114 routes.add(relation); 116 115 } 116 117 117 } 118 118 } 119 119 120 120 if (!routes.isEmpty()) { 121 121 this.primitives.clear(); … … 125 125 } 126 126 } 127 128 127 129 130 128 } 131 132 129 130 131 /** 132 * Listens to a focus change 133 */ 134 @Override 135 public void propertyChange(PropertyChangeEvent evt) { 136 137 if ("focusedWindow".equals(evt.getPropertyName())) { 138 139 if (evt.getNewValue() == null) { 140 return; 141 } 142 143 if (evt.getNewValue().getClass().equals(GenericRelationEditor.class)) { 144 145 GenericRelationEditor editor = (GenericRelationEditor) evt.getNewValue(); 146 Relation relation = editor.getRelation(); 147 148 if (RouteUtils.isTwoDirectionRoute(relation)) { 149 this.primitives.clear(); 150 this.primitives.add(relation); 151 if (!Main.getLayerManager().containsLayer(this)) { 152 Main.getLayerManager().addLayer(this); 153 } 154 // Main.map.repaint(); 155 } 156 157 } 158 159 // System.out.println("focusedWindow: "); 160 // System.out.println("GET NEW VALUE: " + evt.getNewValue().getClass()); 161 // System.out.println(""); 162 } 163 } 133 164 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java
r32427 r32430 47 47 layer = new PTAssistantLayer(); 48 48 DataSet.addSelectionListener(layer); 49 49 50 50 } 51 51
Note:
See TracChangeset
for help on using the changeset viewer.