Changeset 23190 in osm for applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/WMSRacer.java
- Timestamp:
- 2010-09-15T18:54:18+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wms-turbo-challenge2/src/wmsturbochallenge/WMSRacer.java
r21761 r23190 20 20 21 21 public class WMSRacer extends Plugin implements LayerChangeListener { 22 public WMSRacer(PluginInformation info) {23 super(info);24 driveAction.updateEnabledState();22 public WMSRacer(PluginInformation info) { 23 super(info); 24 driveAction.updateEnabledState(); 25 25 26 JMenu toolsMenu = Main.main.menu.toolsMenu;27 toolsMenu.addSeparator();28 toolsMenu.add(new JMenuItem(driveAction));29 }26 JMenu toolsMenu = Main.main.menu.toolsMenu; 27 toolsMenu.addSeparator(); 28 toolsMenu.add(new JMenuItem(driveAction)); 29 } 30 30 31 /* Rather than add an action or main menu entry we should add32 * an entry in the new layer's context menus in layerAdded33 * but there doesn't seem to be any way to do that :( */34 protected class DriveAction extends JosmAction {35 public MapFrame frame = null;36 public Layer currentLayer = null;37 protected Layer groundLayer = null;31 /* Rather than add an action or main menu entry we should add 32 * an entry in the new layer's context menus in layerAdded 33 * but there doesn't seem to be any way to do that :( */ 34 protected class DriveAction extends JosmAction { 35 public MapFrame frame = null; 36 public Layer currentLayer = null; 37 protected Layer groundLayer = null; 38 38 39 public DriveAction() {40 super("Go driving", "wmsracer",41 "Drive a race car on this layer",42 null, true);43 setEnabled(false);44 }39 public DriveAction() { 40 super("Go driving", "wmsracer", 41 "Drive a race car on this layer", 42 null, true); 43 setEnabled(false); 44 } 45 45 46 public void actionPerformed(ActionEvent ev) {47 if (groundLayer == null ||48 !groundLayer.isBackgroundLayer())49 return;46 public void actionPerformed(ActionEvent ev) { 47 if (groundLayer == null || 48 !groundLayer.isBackgroundLayer()) 49 return; 50 50 51 new GameWindow(groundLayer);52 }51 new GameWindow(groundLayer); 52 } 53 53 54 public void updateEnabledState() {55 if (frame == null) {56 groundLayer = null;57 setEnabled(false);58 return;59 }54 public void updateEnabledState() { 55 if (frame == null) { 56 groundLayer = null; 57 setEnabled(false); 58 return; 59 } 60 60 61 if (currentLayer != null &&62 currentLayer.isBackgroundLayer()) {63 groundLayer = currentLayer;64 setEnabled(true);65 return;66 }61 if (currentLayer != null && 62 currentLayer.isBackgroundLayer()) { 63 groundLayer = currentLayer; 64 setEnabled(true); 65 return; 66 } 67 67 68 /* TODO: should only iterate through visible layers?69 * or only wms layers? or perhaps we should allow70 * driving on data/gpx layers too, or the full layer71 * stack (by calling mapView.paint() instead of72 * layer.paint()? Nah.73 * (Note that for GPX or Data layers we could do74 * some clever rendering directly on our perspectivic75 * pseudo-3d surface by defining a strange projection76 * like that or rendering in "stripes" at different77 * horizontal scanlines (lines equidistant from78 * camera eye)) */79 for (Layer l : frame.mapView.getAllLayers())80 if (l.isBackgroundLayer()) {81 groundLayer = l;82 setEnabled(true);83 return;84 }68 /* TODO: should only iterate through visible layers? 69 * or only wms layers? or perhaps we should allow 70 * driving on data/gpx layers too, or the full layer 71 * stack (by calling mapView.paint() instead of 72 * layer.paint()? Nah. 73 * (Note that for GPX or Data layers we could do 74 * some clever rendering directly on our perspectivic 75 * pseudo-3d surface by defining a strange projection 76 * like that or rendering in "stripes" at different 77 * horizontal scanlines (lines equidistant from 78 * camera eye)) */ 79 for (Layer l : frame.mapView.getAllLayers()) 80 if (l.isBackgroundLayer()) { 81 groundLayer = l; 82 setEnabled(true); 83 return; 84 } 85 85 86 groundLayer = null;87 setEnabled(false);88 }89 }86 groundLayer = null; 87 setEnabled(false); 88 } 89 } 90 90 91 protected DriveAction driveAction = new DriveAction();91 protected DriveAction driveAction = new DriveAction(); 92 92 93 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {94 if (oldFrame != null)95 oldFrame.mapView.removeLayerChangeListener(this);93 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 94 if (oldFrame != null) 95 oldFrame.mapView.removeLayerChangeListener(this); 96 96 97 driveAction.frame = newFrame;98 driveAction.updateEnabledState();97 driveAction.frame = newFrame; 98 driveAction.updateEnabledState(); 99 99 100 if (newFrame != null)101 newFrame.mapView.addLayerChangeListener(this);102 }100 if (newFrame != null) 101 newFrame.mapView.addLayerChangeListener(this); 102 } 103 103 104 /* LayerChangeListener methods */105 public void activeLayerChange(Layer oldLayer, Layer newLayer) {106 driveAction.currentLayer = newLayer;107 driveAction.updateEnabledState();108 }104 /* LayerChangeListener methods */ 105 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 106 driveAction.currentLayer = newLayer; 107 driveAction.updateEnabledState(); 108 } 109 109 110 public void layerAdded(Layer newLayer) {111 driveAction.updateEnabledState();112 }110 public void layerAdded(Layer newLayer) { 111 driveAction.updateEnabledState(); 112 } 113 113 114 public void layerRemoved(Layer oldLayer) {115 driveAction.updateEnabledState();116 }114 public void layerRemoved(Layer oldLayer) { 115 driveAction.updateEnabledState(); 116 } 117 117 }
Note:
See TracChangeset
for help on using the changeset viewer.
