Changeset 32438 in osm for applications
- Timestamp:
- 2016-06-29T17:44:03+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r32436 r32438 26 26 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 27 27 import org.openstreetmap.josm.gui.layer.Layer; 28 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 29 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 30 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 31 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 28 32 import org.openstreetmap.josm.gui.layer.LayerPositionStrategy; 33 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 29 34 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 30 35 import org.openstreetmap.josm.tools.ImageProvider; 31 36 32 public class PTAssistantLayer extends Layer implements SelectionChangedListener, PropertyChangeListener { 37 public class PTAssistantLayer extends Layer 38 implements SelectionChangedListener, PropertyChangeListener, LayerChangeListener { 33 39 34 40 private List<OsmPrimitive> primitives = new ArrayList<>(); … … 37 43 public PTAssistantLayer() { 38 44 super("pt_assistant layer"); 39 KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this); 40 41 } 42 45 KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this); 46 Main.getLayerManager().addLayerChangeListener(this); 47 48 } 49 43 50 public void addPrimitive(OsmPrimitive primitive) { 44 51 this.primitives.add(primitive); … … 105 112 106 113 /** 107 * Listens to a selection change 114 * Listens to a selection change 108 115 */ 109 116 @Override 110 117 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 111 118 112 119 ArrayList<Relation> routes = new ArrayList<>(); 113 120 … … 131 138 132 139 } 133 134 140 135 141 /** 136 * Listens to a focus change 142 * Listens to a focus change, sets the primitives attribute to the route 143 * relation in the top Relation Editor and repaints the map 137 144 */ 138 145 @Override … … 146 153 147 154 if (evt.getNewValue().getClass().equals(GenericRelationEditor.class)) { 148 149 GenericRelationEditor editor = (GenericRelationEditor) evt.getNewValue(); 155 156 GenericRelationEditor editor = (GenericRelationEditor) evt.getNewValue(); 150 157 Relation relation = editor.getRelation(); 151 158 152 159 if (RouteUtils.isTwoDirectionRoute(relation)) { 153 160 … … 169 176 } 170 177 } 178 179 @Override 180 public void layerAdded(LayerAddEvent arg0) { 181 // do nothing 182 } 183 184 @Override 185 public void layerOrderChanged(LayerOrderChangeEvent arg0) { 186 // do nothing 187 188 } 189 190 @Override 191 public void layerRemoving(LayerRemoveEvent event) { 192 193 if (event.getRemovedLayer() instanceof OsmDataLayer) { 194 195 this.primitives.clear(); 196 Main.map.repaint(); 197 } 198 199 } 171 200 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java
r32436 r32438 22 22 private final MapView mv; 23 23 24 25 24 public PTAssistantPaintVisitor(Graphics g, MapView mv) { 26 25 super(g, mv); … … 42 41 } 43 42 label = label + "." + stopCount; 44 drawStop(rm.getMember(), Color.BLUE, Color.BLACK,label);43 drawStop(rm.getMember(), label); 45 44 stopCount++; 46 45 } else if (RouteUtils.isPTWay(rm)) { … … 58 57 } 59 58 } 60 61 59 62 60 } … … 103 101 double cosT = 8 * Math.cos(t); 104 102 double sinT = 8 * Math.sin(t); 105 106 107 int[] xPoints = {(int)(p1.x+cosT), (int)(p2.x+cosT), (int)(p2.x-cosT), (int)(p1.x-cosT)}; 108 int[] yPoints = {(int)(p1.y-sinT), (int)(p2.y-sinT), (int)(p2.y+sinT), (int)(p1.y+sinT)}; 103 104 int[] xPoints = { (int) (p1.x + cosT), (int) (p2.x + cosT), (int) (p2.x - cosT), (int) (p1.x - cosT) }; 105 int[] yPoints = { (int) (p1.y - sinT), (int) (p2.y - sinT), (int) (p2.y + sinT), (int) (p1.y + sinT) }; 109 106 g.setColor(color); 110 107 g.fillPolygon(xPoints, yPoints, 4); 111 g.fillOval((int)(p1.x-8), (int)(p1.y-8), 16, 16); 112 g.fillOval((int)(p2.x-8), (int)(p2.y-8), 16, 16); 113 108 g.fillOval((int) (p1.x - 8), (int) (p1.y - 8), 16, 16); 109 g.fillOval((int) (p2.x - 8), (int) (p2.y - 8), 16, 16); 114 110 115 // g.drawLine((int) (p1.x - cosT), (int) (p1.y - sinT), (int) (p2.x + cosT), (int) (p2.y - sinT)); 116 // g.drawLine((int) (p1.x - cosT), (int) (p1.y + sinT), (int) (p2.x - cosT), (int) (p2.y + sinT)); 111 // g.drawLine((int) (p1.x - cosT), (int) (p1.y - sinT), (int) (p2.x + 112 // cosT), (int) (p2.y - sinT)); 113 // g.drawLine((int) (p1.x - cosT), (int) (p1.y + sinT), (int) (p2.x - 114 // cosT), (int) (p2.y + sinT)); 117 115 118 116 } … … 135 133 } 136 134 137 protected void drawStop(OsmPrimitive primitive, Color fillColor, Color outlineColor,String label) {135 protected void drawStop(OsmPrimitive primitive, String label) { 138 136 139 137 // find the point to which the stop visualization will be linked: … … 141 139 142 140 Point p = mv.getPoint(n); 141 142 g.setColor(Color.WHITE); 143 Font stringFont = new Font("SansSerif", Font.PLAIN, 24); 144 g.setFont(stringFont); 145 g.drawString(label, p.x + 20, p.y - 20); 143 146 147 Color fillColor = null; 148 149 if (primitive.hasTag("bus", "yes")) { 150 fillColor = Color.BLUE; 151 } else if (primitive.hasTag("tram", "yes")) { 152 fillColor = Color.RED; 153 } // TODO: add more options 144 154 g.setColor(fillColor); 145 g.fillOval(p.x - 5, p.y - 5, 10, 10);146 g.setColor(outlineColor);147 g.drawOval(p.x - 5, p.y - 5, 10, 10);148 155 149 g.setColor(Color.WHITE); 150 Font stringFont = new Font( "SansSerif", Font.PLAIN, 18 ); 151 g.setFont(stringFont); 152 g.drawString(label, p.x - 20, p.y - 20); 156 if (primitive.hasTag("public_transport", "stop_position")) { 157 g.fillOval(p.x - 8, p.y - 8, 16, 16); 158 } else { 159 g.fillRect(p.x - 8, p.y - 8, 16, 16); 160 } 161 162 153 163 } 154 164 155 165 protected Graphics getGraphics() { 156 166 return this.g; 157 167 } 158 168 159 169 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java
r32430 r32438 68 68 return; 69 69 } 70 70 71 71 // if (!Main.getLayerManager().containsLayer(layer)) { 72 72 // Main.getLayerManager().addLayer(layer);
Note:
See TracChangeset
for help on using the changeset viewer.