Changeset 1820 in josm
- Timestamp:
- 2009-07-21T19:52:53+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java
r1814 r1820 85 85 86 86 protected abstract String createInfoUrl(OsmPrimitive primitive); 87 88 @Override 89 protected void updateEnabledState() { 90 setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty()); 91 } 87 92 } -
trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java
r1814 r1820 15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.command.AddCommand; 17 import org.openstreetmap.josm.data.coor.LatLon; 17 18 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.coor.LatLon;19 import org.openstreetmap.josm.gui.layer.Layer;20 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;21 19 import org.openstreetmap.josm.tools.GBC; 22 20 import org.openstreetmap.josm.tools.Shortcut; … … 26 24 * and when ok is pressed, a new node is created at the specified position. 27 25 */ 28 public final class AddNodeAction extends JosmAction implements LayerChangeListener{26 public final class AddNodeAction extends JosmAction { 29 27 30 28 public AddNodeAction() { … … 32 30 Shortcut.registerShortcut("addnode", tr("Edit: {0}", tr("Add Node...")), KeyEvent.VK_D, Shortcut.GROUP_EDIT, 33 31 Shortcut.SHIFT_DEFAULT), true); 34 Layer.listeners.add(this);35 refreshEnabled();36 }37 38 protected void refreshEnabled() {39 setEnabled(Main.map != null40 && Main.map.mapView != null41 && Main.map.mapView.getEditLayer() != null);42 32 } 43 33 … … 83 73 } 84 74 85 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 86 refreshEnabled(); 75 @Override 76 protected void updateEnabledState() { 77 setEnabled(getEditLayer() != null); 87 78 } 88 79 89 public void layerAdded(Layer newLayer) { 90 refreshEnabled(); 80 } 91 81 92 }93 94 public void layerRemoved(Layer oldLayer) {95 refreshEnabled();96 }97 } -
trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
r1814 r1820 79 79 80 80 public void actionPerformed(ActionEvent e) { 81 if (!isEnabled()) 82 return; 83 81 84 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 82 85 Collection<Node> nodes = new LinkedList<Node>(); … … 208 211 Main.map.repaint(); 209 212 } 213 214 @Override 215 protected void updateEnabledState() { 216 setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty()); 217 } 210 218 } -
trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java
r1814 r1820 40 40 */ 41 41 public void actionPerformed(ActionEvent e) { 42 if (!isEnabled()) 43 return; 42 44 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 43 45 Collection<Node> nodes = new LinkedList<Node>(); … … 125 127 Main.map.repaint(); 126 128 } 129 130 @Override 131 protected void updateEnabledState() { 132 setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty()); 133 } 127 134 } -
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r1814 r1820 117 117 return v; 118 118 } 119 120 @Override 121 protected void updateEnabledState() { 122 setEnabled(Main.map != null); 123 } 124 119 125 } -
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r1817 r1820 30 30 import org.openstreetmap.josm.command.DeleteCommand; 31 31 import org.openstreetmap.josm.command.SequenceCommand; 32 import org.openstreetmap.josm.data.SelectionChangedListener;33 import org.openstreetmap.josm.data.osm.DataSet;34 32 import org.openstreetmap.josm.data.osm.Node; 35 33 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 39 37 import org.openstreetmap.josm.data.osm.Way; 40 38 import org.openstreetmap.josm.gui.ExtendedDialog; 41 import org.openstreetmap.josm.gui.layer.Layer;42 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;43 39 import org.openstreetmap.josm.tools.GBC; 44 40 import org.openstreetmap.josm.tools.Pair; … … 50 46 * @author Imi 51 47 */ 52 public class CombineWayAction extends JosmAction implements SelectionChangedListener,LayerChangeListener{48 public class CombineWayAction extends JosmAction { 53 49 54 50 public CombineWayAction() { 55 51 super(tr("Combine Way"), "combineway", tr("Combine several ways into one."), 56 52 Shortcut.registerShortcut("tools:combineway", tr("Tool: {0}", tr("Combine Way")), KeyEvent.VK_C, Shortcut.GROUP_EDIT), true); 57 DataSet.selListeners.add(this);58 Layer.listeners.add(this);59 refreshEnabled();60 53 } 61 54 … … 300 293 } 301 294 302 /** 303 * Enable the "Combine way" menu option if more then one way is selected 304 */ 305 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 306 refreshEnabled(); 307 } 308 309 protected void refreshEnabled() { 295 @Override 296 protected void updateEnabledState() { 310 297 if (getCurrentDataSet() == null) { 311 298 setEnabled(false); … … 321 308 setEnabled(numWays >= 2); 322 309 } 323 324 325 public void activeLayerChange(Layer oldLayer, Layer newLayer) {326 refreshEnabled();327 }328 329 public void layerAdded(Layer newLayer) {330 refreshEnabled();331 332 }333 334 public void layerRemoved(Layer oldLayer) {335 refreshEnabled();336 }337 338 310 } -
trunk/src/org/openstreetmap/josm/actions/CopyAction.java
r1814 r1820 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.SelectionChangedListener;19 18 import org.openstreetmap.josm.data.osm.DataSet; 20 19 import org.openstreetmap.josm.data.osm.DataSource; … … 27 26 import org.openstreetmap.josm.tools.Shortcut; 28 27 29 public final class CopyAction extends JosmAction implements SelectionChangedListener{28 public final class CopyAction extends JosmAction { 30 29 31 30 private LinkedList<JosmAction> listeners; … … 35 34 tr("Copy selected objects to paste buffer."), 36 35 Shortcut.registerShortcut("system:copy", tr("Edit: {0}", tr("Copy")), KeyEvent.VK_C, Shortcut.GROUP_MENU), true); 37 setEnabled(false);38 DataSet.selListeners.add(this);39 36 listeners = new LinkedList<JosmAction>(); 40 37 } … … 131 128 } 132 129 133 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 134 setEnabled(! newSelection.isEmpty()); 130 @Override 131 protected void updateEnabledState() { 132 setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty()); 135 133 } 136 134 -
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r1814 r1820 73 73 74 74 public void actionPerformed(ActionEvent e) { 75 if (!isEnabled()) 76 return; 77 75 78 int numberOfNodesInCircle = Main.pref.getInteger("createcircle.nodecount", 8); 76 79 if (numberOfNodesInCircle < 1) { … … 265 268 Main.map.repaint(); 266 269 } 270 271 @Override 272 protected void updateEnabledState() { 273 setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty()); 274 } 267 275 } -
trunk/src/org/openstreetmap/josm/actions/DeleteAction.java
r1750 r1820 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.util.Collection;7 5 8 6 import java.awt.event.ActionEvent; … … 11 9 import org.openstreetmap.josm.Main; 12 10 import org.openstreetmap.josm.tools.Shortcut; 13 import org.openstreetmap.josm.data.osm.DataSet;14 import org.openstreetmap.josm.data.osm.OsmPrimitive;15 import org.openstreetmap.josm.data.SelectionChangedListener;16 11 17 public final class DeleteAction extends JosmAction implements SelectionChangedListener{12 public final class DeleteAction extends JosmAction { 18 13 19 14 public DeleteAction() { 20 15 super(tr("Delete"), "dialogs/delete", tr("Delete selected objects."), 21 Shortcut.registerShortcut("system:delete", tr("Edit: {0}", tr("Delete")), KeyEvent.VK_DELETE, Shortcut.GROUP_DIRECT), true); 22 DataSet.selListeners.add(this); 23 setEnabled(false); 16 Shortcut.registerShortcut("system:delete", tr("Edit: {0}", tr("Delete")), KeyEvent.VK_DELETE, Shortcut.GROUP_DIRECT), true); 24 17 } 25 18 26 19 public void actionPerformed(ActionEvent e) { 20 if (!isEnabled()) 21 return; 27 22 if(!Main.map.mapView.isActiveLayerVisible()) 28 23 return; 29 24 new org.openstreetmap.josm.actions.mapmode.DeleteAction(Main.map) 30 25 .doActionPerformed(e); 31 26 } 32 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 33 setEnabled(! newSelection.isEmpty()); 27 28 @Override 29 protected void updateEnabledState() { 30 setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty()); 34 31 } 35 32 } -
trunk/src/org/openstreetmap/josm/actions/DistributeAction.java
r1814 r1820 38 38 */ 39 39 public void actionPerformed(ActionEvent e) { 40 if (!isEnabled()) 41 return; 40 42 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 41 43 Collection<Node> nodes = new LinkedList<Node>(); … … 126 128 Main.map.repaint(); 127 129 } 130 131 @Override 132 protected void updateEnabledState() { 133 setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty()); 134 } 128 135 } -
trunk/src/org/openstreetmap/josm/actions/DownloadReferrersAction.java
r1811 r1820 35 35 * 36 36 */ 37 public class DownloadReferrersAction extends JosmAction implements SelectionChangedListener, LayerChangeListener{37 public class DownloadReferrersAction extends JosmAction{ 38 38 39 39 public DownloadReferrersAction() { 40 40 super(tr("Download referrers from OSM..."), "downloadreferrers", tr("Download primitives referring to one of the selected primitives"), 41 41 Shortcut.registerShortcut("file:downloadreferrers", tr("File: {0}", tr("Download referrers...")), KeyEvent.VK_D, Shortcut.GROUPS_ALT2+Shortcut.GROUP_HOTKEY), true); 42 43 Layer.listeners.add(this);44 DataSet.selListeners.add(this);45 refreshEnabled();46 42 } 47 43 … … 168 164 * 169 165 */ 170 protected void refreshEnabled() { 171 setEnabled(Main.map != null 172 && Main.map.mapView !=null 173 && Main.map.mapView.getEditLayer() != null 174 && ! Main.map.mapView.getEditLayer().data.getSelected().isEmpty() 175 ); 176 } 177 178 /* ---------------------------------------------------------------------------------- */ 179 /* Interface SelectionChangeListener */ 180 /* ---------------------------------------------------------------------------------- */ 181 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 182 refreshEnabled(); 183 } 184 185 /* ---------------------------------------------------------------------------------- */ 186 /* Interface LayerChangeListener */ 187 /* ---------------------------------------------------------------------------------- */ 188 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 189 refreshEnabled(); 190 } 191 192 public void layerAdded(Layer newLayer) { 193 refreshEnabled(); 194 } 195 196 public void layerRemoved(Layer oldLayer) { 197 refreshEnabled(); 166 @Override 167 protected void updateEnabledState() { 168 setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty()); 198 169 } 199 170 } -
trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java
r1814 r1820 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.util.Collection;10 9 11 import org.openstreetmap.josm.data.SelectionChangedListener;12 import org.openstreetmap.josm.data.osm.DataSet;13 import org.openstreetmap.josm.data.osm.OsmPrimitive;14 import org.openstreetmap.josm.gui.layer.Layer;15 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;16 10 import org.openstreetmap.josm.tools.Shortcut; 17 11 18 public final class DuplicateAction extends JosmAction implements SelectionChangedListener, LayerChangeListener{12 public final class DuplicateAction extends JosmAction{ 19 13 20 14 public DuplicateAction() { … … 22 16 tr("Duplicate selection by copy and immediate paste."), 23 17 Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.GROUP_MENU), true); 24 setEnabled(false);25 DataSet.selListeners.add(this);26 Layer.listeners.add(this);27 18 } 28 19 … … 32 23 33 24 34 protected void refreshEnabled() { 35 setEnabled(getCurrentDataSet() != null 36 && ! getCurrentDataSet().getSelected().isEmpty() 37 ); 38 } 39 40 /* ---------------------------------------------------------------------------------- */ 41 /* Interface SelectionChangeListener */ 42 /* ---------------------------------------------------------------------------------- */ 43 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 44 refreshEnabled(); 45 } 46 47 /* ---------------------------------------------------------------------------------- */ 48 /* Interface LayerChangeListener */ 49 /* ---------------------------------------------------------------------------------- */ 50 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 51 refreshEnabled(); 52 } 53 54 public void layerAdded(Layer newLayer) { 55 refreshEnabled(); 56 } 57 58 public void layerRemoved(Layer oldLayer) { 59 refreshEnabled(); 25 @Override 26 protected void updateEnabledState() { 27 setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty()); 60 28 } 61 29 } -
trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java
r1814 r1820 32 32 import org.openstreetmap.josm.gui.layer.Layer; 33 33 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 34 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;35 34 import org.openstreetmap.josm.io.GpxWriter; 36 35 import org.openstreetmap.josm.tools.GBC; … … 40 39 * Exports data to gpx. 41 40 */ 42 public class GpxExportAction extends DiskAccessAction implements LayerChangeListener{41 public class GpxExportAction extends DiskAccessAction { 43 42 44 43 private final static String warningGpl = "<html><font color='red' size='-2'>"+tr("Note: GPL is not compatible with the OSM license. Do not upload GPL licensed tracks.")+"</html>"; … … 47 46 super(tr("Export to GPX..."), "exportgpx", tr("Export the data to GPX file."), 48 47 Shortcut.registerShortcut("file:exportgpx", tr("Export to GPX..."), KeyEvent.VK_E, Shortcut.GROUP_MENU)); 49 Layer.listeners.add(this);50 refreshEnabled();51 48 } 52 49 … … 333 330 * 334 331 */ 335 protected void refreshEnabled() { 332 @Override 333 protected void updateEnabledState() { 336 334 boolean check = Main.main != null 337 335 && Main.map != null … … 345 343 setEnabled(layer instanceof GpxLayer); 346 344 } 347 348 /* ---------------------------------------------------------------------------------- */349 /* Interface LayerChangeListener */350 /* ---------------------------------------------------------------------------------- */351 public void activeLayerChange(Layer oldLayer, Layer newLayer) {352 refreshEnabled();353 }354 355 public void layerAdded(Layer newLayer) {356 refreshEnabled();357 }358 359 public void layerRemoved(Layer oldLayer) {360 refreshEnabled();361 }362 345 } -
trunk/src/org/openstreetmap/josm/actions/HelpAction.java
r1755 r1820 12 12 import java.awt.event.WindowEvent; 13 13 import java.io.IOException; 14 import java.io.StringReader;15 14 16 15 import javax.swing.AbstractAction; … … 64 63 if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) 65 64 return; 66 if (e.getURL() == null) 65 if (e.getURL() == null) { 67 66 help.setText("<html>404 not found</html>"); 68 else if (e.getURL().toString().endsWith("action=edit"))67 } else if (e.getURL().toString().endsWith("action=edit")) { 69 68 OpenBrowser.displayUrl(e.getURL().toString()); 70 else69 } else { 71 70 setHelpUrl(e.getURL().toString()); 71 } 72 72 } 73 73 }); … … 119 119 String topic = null; 120 120 Point mouse = Main.parent.getMousePosition(); 121 if (mouse != null) 121 if (mouse != null) { 122 122 topic = contextSensitiveHelp(SwingUtilities.getDeepestComponentAt(Main.parent, mouse.x, mouse.y)); 123 } 123 124 if (topic == null) { 124 125 helpBrowser.setVisible(false); 125 126 setHelpUrl(baseurl+pathbase+"Help"); 126 } else 127 } else { 127 128 help(topic); 129 } 128 130 } else { 129 131 helpBrowser.setVisible(false); … … 176 178 int i = pathbase.length()+baseurl.length(); 177 179 String title = url.substring(i); 178 if(languageCode.length() != 0 && !title.startsWith(languageCode)) 180 if(languageCode.length() != 0 && !title.startsWith(languageCode)) { 179 181 title = languageCode + title; 182 } 180 183 langurl = url.substring(0, i) + title; 181 184 } … … 185 188 loaded = loadHelpUrl(url, langurl, true); 186 189 } 187 if(!loaded) 190 if(!loaded) { 188 191 loaded = loadHelpUrl(url, langurl, false); 189 if(!loaded) 192 } 193 if(!loaded) { 190 194 help.setText(tr("Error while loading page {0}",url)); 195 } 191 196 helpBrowser.setVisible(true); 192 197 } … … 194 199 private boolean loadHelpUrl(String url, String langurl, boolean lang) 195 200 { 196 this.url = lang ? langurl : url; 197 boolean loaded = false; 198 try { 199 String txt = reader.read(this.url); 200 if(txt.length() == 0) 201 { 202 if(lang) 203 throw new IOException(); 204 else 205 { 206 if(url.equals(langurl)) 207 { 208 txt = ("<HTML>"+tr("Help page missing. Create it in <A HREF=\"{0}\">english</A>.", 209 url+"?action=edit")+"</HTML>"); 210 } 201 this.url = lang ? langurl : url; 202 boolean loaded = false; 203 try { 204 String txt = reader.read(this.url); 205 if(txt.length() == 0) 206 { 207 if(lang) 208 throw new IOException(); 211 209 else 212 210 { 213 txt = ("<HTML>"+tr("Help page missing. Create it in <A HREF=\"{0}\">english</A> or <A HREF=\"{1}\">your language</A>.", 214 url+"?action=edit", langurl+"?action=edit")+"</HTML>"); 211 if(url.equals(langurl)) 212 { 213 txt = ("<HTML>"+tr("Help page missing. Create it in <A HREF=\"{0}\">english</A>.", 214 url+"?action=edit")+"</HTML>"); 215 } 216 else 217 { 218 txt = ("<HTML>"+tr("Help page missing. Create it in <A HREF=\"{0}\">english</A> or <A HREF=\"{1}\">your language</A>.", 219 url+"?action=edit", langurl+"?action=edit")+"</HTML>"); 220 } 215 221 } 216 } 217 } 218 help.setText(txt); 219 help.setCaretPosition(0); 220 loaded = true; 221 } catch (IOException ex) { 222 } 223 return loaded; 222 } 223 help.setText(txt); 224 help.setCaretPosition(0); 225 loaded = true; 226 } catch (IOException ex) { 227 } 228 return loaded; 224 229 } 225 230 -
trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
r1814 r1820 32 32 33 33 public void actionPerformed(ActionEvent e) { 34 if (!isEnabled()) 35 return; 34 36 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 35 37 if (sel.size() != 1 || !(sel.iterator().next() instanceof Node)) return; … … 84 86 Collections.reverse(is); 85 87 } 88 89 @Override 90 protected void updateEnabledState() { 91 setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty()); 92 } 86 93 } -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r1814 r1820 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Collection; 7 6 8 import javax.swing.AbstractAction; 7 9 import javax.swing.JComponent; 8 10 9 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.SelectionChangedListener; 10 13 import org.openstreetmap.josm.data.osm.DataSet; 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.gui.layer.Layer; 11 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 12 18 import org.openstreetmap.josm.tools.Destroyable; 13 19 import org.openstreetmap.josm.tools.ImageProvider; … … 16 22 /** 17 23 * Base class helper for all Actions in JOSM. Just to make the life easier. 18 * 24 * 25 * A JosmAction is a {@see LayerChangeListener} and a {@see SelectionChangedListener}. Upon 26 * a layer change event or a selection change event it invokes {@see #updateEnabled()}. 27 * Subclasses can override {@see #updateEnabled()} in order to update the {@see #isEnabled()}-state 28 * of a JosmAction depending on the {@see #getCurrentDataSet()} and the current layers 29 * (see also {@see #getEditLayer()}). 30 * 19 31 * destroy() from interface Destroyable is called e.g. for MapModes, when the last layer has 20 32 * been removed and so the mapframe will be destroyed. For other JosmActions, destroy() may never … … 26 38 27 39 protected Shortcut sc; 40 private LayerChangeAdapter layerChangeAdapter; 41 private SelectionChangeAdapter selectionChangeAdapter; 28 42 29 43 public Shortcut getShortcut() { … … 65 79 Main.toolbar.register(this); 66 80 } 81 installAdapters(); 82 } 83 84 public JosmAction() { 85 setHelpId(); 86 installAdapters(); 67 87 } 68 88 … … 72 92 Main.contentPane.getActionMap().remove(sc.getKeyStroke()); 73 93 } 94 if (Layer.listeners != null) { 95 Layer.listeners.remove(layerChangeAdapter); 96 } 97 if (DataSet.selListeners != null) { 98 DataSet.selListeners.remove(selectionChangeAdapter); 99 } 74 100 } 75 101 76 public JosmAction() { 77 setHelpId(); 78 } 102 79 103 80 104 /** … … 117 141 return Main.main.getCurrentDataSet(); 118 142 } 143 144 private void installAdapters() { 145 // make this action listen to layer change and selection change events 146 // 147 layerChangeAdapter = new LayerChangeAdapter(); 148 selectionChangeAdapter = new SelectionChangeAdapter(); 149 Layer.listeners.add(layerChangeAdapter); 150 DataSet.selListeners.add(selectionChangeAdapter); 151 updateEnabledState(); 152 } 153 154 /** 155 * This method is called when a layer change event or a selection update event 156 * occurs, see {@see LayerChangeListener} and {@see SelectionChangedListener}. 157 * 158 * The default implementation is empty. Subclasses can override the method 159 * in order to set the {@see #isEnabled()}-state of a JosmAction depending on 160 * the {@see #getCurrentDataSet()} and the current layers (see 161 * also {@see #getEditLayer()}). 162 * 163 */ 164 protected void updateEnabledState() { 165 // override in subclasses 166 } 167 168 /** 169 * Adapter for layer change events 170 * 171 */ 172 private class LayerChangeAdapter implements LayerChangeListener { 173 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 174 updateEnabledState(); 175 } 176 177 public void layerAdded(Layer newLayer) { 178 updateEnabledState(); 179 } 180 181 public void layerRemoved(Layer oldLayer) { 182 updateEnabledState(); 183 } 184 } 185 186 /** 187 * Adapter for selection change events 188 * 189 */ 190 private class SelectionChangeAdapter implements SelectionChangedListener { 191 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 192 updateEnabledState(); 193 } 194 } 119 195 } -
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r1814 r1820 29 29 import org.openstreetmap.josm.command.DeleteCommand; 30 30 import org.openstreetmap.josm.command.SequenceCommand; 31 import org.openstreetmap.josm.data.SelectionChangedListener;32 import org.openstreetmap.josm.data.osm.DataSet;33 31 import org.openstreetmap.josm.data.osm.Node; 34 32 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 51 49 * 52 50 */ 53 public class MergeNodesAction extends JosmAction implements SelectionChangedListener{51 public class MergeNodesAction extends JosmAction { 54 52 55 53 public MergeNodesAction() { 56 54 super(tr("Merge Nodes"), "mergenodes", tr("Merge nodes into the oldest one."), 57 55 Shortcut.registerShortcut("tools:mergenodes", tr("Tool: {0}", tr("Merge Nodes")), KeyEvent.VK_M, Shortcut.GROUP_EDIT), true); 58 DataSet.selListeners.add(this);59 56 } 60 57 61 58 public void actionPerformed(ActionEvent event) { 59 if (!isEnabled()) 60 return; 61 62 62 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 63 63 LinkedList<Node> selectedNodes = new LinkedList<Node>(); … … 295 295 * Enable the "Merge Nodes" menu option if more then one node is selected 296 296 */ 297 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {298 boolean ok = true;299 if ( newSelection.size() < 2) {297 @Override 298 public void updateEnabledState() { 299 if (getCurrentDataSet() == null || getCurrentDataSet().getSelected().isEmpty()) { 300 300 setEnabled(false); 301 301 return; 302 302 } 303 for (OsmPrimitive osm : newSelection) { 303 boolean ok = true; 304 if (getCurrentDataSet().getSelected().size() < 2) { 305 setEnabled(false); 306 return; 307 } 308 for (OsmPrimitive osm : getCurrentDataSet().getSelected()) { 304 309 if (!(osm instanceof Node)) { 305 310 ok = false; -
trunk/src/org/openstreetmap/josm/actions/MirrorAction.java
r1814 r1820 71 71 Main.map.repaint(); 72 72 } 73 74 @Override 75 protected void updateEnabledState() { 76 setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty()); 77 } 73 78 } -
trunk/src/org/openstreetmap/josm/actions/MoveAction.java
r1814 r1820 110 110 Main.map.mapView.repaint(); 111 111 } 112 113 @Override 114 protected void updateEnabledState() { 115 setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty()); 116 } 112 117 } -
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r1814 r1820 46 46 47 47 public void actionPerformed(ActionEvent e) { 48 48 if (!isEnabled()) 49 return; 49 50 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 50 51 … … 278 279 return heading_delta; 279 280 } 281 282 @Override 283 protected void updateEnabledState() { 284 setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty()); 285 } 280 286 } -
trunk/src/org/openstreetmap/josm/actions/PasteAction.java
r1814 r1820 32 32 super(tr("Paste"), "paste", tr("Paste contents of paste buffer."), 33 33 Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.GROUP_MENU), true); 34 setEnabled(false);35 34 } 36 35 37 36 public void actionPerformed(ActionEvent e) { 37 if (!isEnabled()) 38 return; 38 39 pasteData(Main.pasteBuffer, Main.pasteSource, e); 39 40 } … … 116 117 Main.map.mapView.repaint(); 117 118 } 119 120 @Override 121 protected void updateEnabledState() { 122 if (getCurrentDataSet() == null || getCurrentDataSet().getSelected().isEmpty()) { 123 setEnabled(false); 124 return; 125 } 126 if (Main.pasteBuffer == null) { 127 setEnabled(false); 128 } 129 setEnabled( 130 !Main.pasteBuffer.nodes.isEmpty() 131 || !Main.pasteBuffer.ways.isEmpty() 132 || !Main.pasteBuffer.relations.isEmpty() 133 ); 134 } 118 135 } -
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r1814 r1820 17 17 import org.openstreetmap.josm.command.Command; 18 18 import org.openstreetmap.josm.command.SequenceCommand; 19 import org.openstreetmap.josm.data.SelectionChangedListener;20 19 import org.openstreetmap.josm.data.osm.DataSet; 21 20 import org.openstreetmap.josm.data.osm.DataSource; … … 23 22 import org.openstreetmap.josm.tools.Shortcut; 24 23 25 public final class PasteTagsAction extends JosmAction implements SelectionChangedListener{24 public final class PasteTagsAction extends JosmAction { 26 25 27 26 public PasteTagsAction(JosmAction copyAction) { … … 29 28 tr("Apply tags of contents of paste buffer to all selected items."), 30 29 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true); 31 DataSet.selListeners.add(this);32 30 copyAction.addListener(this); 33 setEnabled(false);34 31 } 35 32 … … 125 122 } 126 123 127 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 128 possiblyEnable(newSelection, Main.pasteBuffer); 124 @Override 125 protected void updateEnabledState() { 126 if (getCurrentDataSet() == null || Main.pasteBuffer == null) { 127 setEnabled(false); 128 return; 129 } 130 possiblyEnable(getCurrentDataSet().getSelected(), Main.pasteBuffer); 129 131 } 130 132 } -
trunk/src/org/openstreetmap/josm/actions/RedoAction.java
r1169 r1820 22 22 public RedoAction() { 23 23 super(tr("Redo"), "redo", tr("Redo the last undone action."), 24 Shortcut.registerShortcut("system:redo", tr("Edit: {0}", tr("Redo")), KeyEvent.VK_Y, Shortcut.GROUP_MENU), true);24 Shortcut.registerShortcut("system:redo", tr("Edit: {0}", tr("Redo")), KeyEvent.VK_Y, Shortcut.GROUP_MENU), true); 25 25 setEnabled(false); 26 26 } … … 32 32 Main.main.undoRedo.redo(); 33 33 } 34 35 @Override 36 protected void updateEnabledState() { 37 setEnabled(Main.map != null); 38 } 34 39 } -
trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java
r1814 r1820 18 18 import org.openstreetmap.josm.corrector.ReverseWayTagCorrector; 19 19 import org.openstreetmap.josm.corrector.UserCancelException; 20 import org.openstreetmap.josm.data.SelectionChangedListener; 20 21 import org.openstreetmap.josm.data.osm.DataSet; 21 import org.openstreetmap.josm.data.osm.Node;22 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.Relation;24 23 import org.openstreetmap.josm.data.osm.Way; 25 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 24 import org.openstreetmap.josm.gui.layer.Layer; 25 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 26 26 import org.openstreetmap.josm.tools.Shortcut; 27 27 28 public final class ReverseWayAction extends JosmAction {28 public final class ReverseWayAction extends JosmAction implements SelectionChangedListener, LayerChangeListener { 29 29 30 30 public ReverseWayAction() { 31 31 super(tr("Reverse Ways"), "wayflip", tr("Reverse the direction of all selected ways."), 32 32 Shortcut.registerShortcut("tools:reverse", tr("Tool: {0}", tr("Reverse Ways")), KeyEvent.VK_R, Shortcut.GROUP_EDIT), true); 33 DataSet.selListeners.add(this); 34 Layer.listeners.add(this); 35 refreshEnabled(); 33 36 } 34 37 35 38 public void actionPerformed(ActionEvent e) { 39 if (! isEnabled()) 40 return; 41 if (getCurrentDataSet() == null) 42 return; 43 36 44 final Collection<Way> sel = new LinkedList<Way>(); 37 new AbstractVisitor() { 38 public void visit(Node n) { 45 for (OsmPrimitive primitive : getCurrentDataSet().getSelected()) { 46 if (primitive instanceof Way) { 47 sel.add((Way)primitive); 39 48 } 40 41 public void visit(Way w) { 42 sel.add(w); 43 } 44 45 public void visit(Relation e) { 46 } 47 48 public void visitAll() { 49 for (OsmPrimitive osm : getCurrentDataSet().getSelected()) { 50 osm.visit(this); 51 } 52 } 53 }.visitAll(); 54 49 } 55 50 if (sel.isEmpty()) { 56 51 JOptionPane.showMessageDialog(Main.parent, … … 86 81 Main.map.repaint(); 87 82 } 83 84 protected int getNumWaysInSelection() { 85 if (getCurrentDataSet() == null) return 0; 86 int ret = 0; 87 for (OsmPrimitive primitive : getCurrentDataSet().getSelected()) { 88 if (primitive instanceof Way) { 89 ret++; 90 } 91 } 92 return ret; 93 } 94 95 protected void refreshEnabled() { 96 setEnabled(getNumWaysInSelection() > 0); 97 } 98 99 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 100 refreshEnabled(); 101 } 102 103 public void layerAdded(Layer newLayer) { 104 refreshEnabled(); 105 106 } 107 108 public void layerRemoved(Layer oldLayer) { 109 refreshEnabled(); 110 } 111 112 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 113 refreshEnabled(); 114 } 88 115 } -
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r1814 r1820 26 26 import org.openstreetmap.josm.gui.layer.Layer; 27 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 28 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;29 28 import org.openstreetmap.josm.io.GpxImporter; 30 29 import org.openstreetmap.josm.io.GpxWriter; … … 35 34 import org.openstreetmap.josm.tools.Shortcut; 36 35 37 public abstract class SaveActionBase extends DiskAccessAction implements LayerChangeListener{36 public abstract class SaveActionBase extends DiskAccessAction { 38 37 39 38 public SaveActionBase(String name, String iconName, String tooltip, Shortcut shortcut) { 40 39 super(name, iconName, tooltip, shortcut); 41 Layer.listeners.add(this);42 refreshEnabled();43 40 } 44 41 … … 275 272 * 276 273 */ 277 protected void refreshEnabled() {278 boolean check = Main.main != null279 &&Main.map != null274 @Override 275 protected void updateEnabledState() { 276 boolean check = Main.map != null 280 277 && Main.map.mapView !=null 281 278 && Main.map.mapView.getActiveLayer() != null; … … 287 284 setEnabled(layer instanceof OsmDataLayer || layer instanceof GpxLayer); 288 285 } 289 290 291 /* ---------------------------------------------------------------------------------- */292 /* Interface LayerChangeListener */293 /* ---------------------------------------------------------------------------------- */294 public void activeLayerChange(Layer oldLayer, Layer newLayer) {295 refreshEnabled();296 }297 298 public void layerAdded(Layer newLayer) {299 refreshEnabled();300 }301 302 public void layerRemoved(Layer oldLayer) {303 refreshEnabled();304 }305 286 } -
trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java
r1814 r1820 11 11 import org.openstreetmap.josm.tools.Shortcut; 12 12 13 public class SelectAllAction extends JosmAction implements LayerChangeListener{13 public class SelectAllAction extends JosmAction { 14 14 15 15 public SelectAllAction() { 16 16 super(tr("Select All"),"selectall", tr("Select all undeleted objects in the data layer. This selects incomplete objects too."), 17 17 Shortcut.registerShortcut("system:selectall", tr("Edit: {0}", tr("Select All")), KeyEvent.VK_A, Shortcut.GROUP_MENU), true); 18 Layer.listeners.add(this);19 refreshEnabled();20 18 } 21 19 … … 30 28 * 31 29 */ 32 protected void refreshEnabled() { 30 @Override 31 protected void updateEnabledState() { 33 32 setEnabled(getEditLayer() != null); 34 33 } 35 36 /* ---------------------------------------------------------------------------------- */37 /* Interface LayerChangeListener */38 /* ---------------------------------------------------------------------------------- */39 public void activeLayerChange(Layer oldLayer, Layer newLayer) {40 refreshEnabled();41 }42 43 public void layerAdded(Layer newLayer) {44 refreshEnabled();45 }46 47 public void layerRemoved(Layer oldLayer) {48 refreshEnabled();49 }50 34 } -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r1814 r1820 34 34 import org.openstreetmap.josm.data.osm.visitor.Visitor; 35 35 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 36 import org.openstreetmap.josm.gui.layer.Layer; 37 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 36 38 import org.openstreetmap.josm.tools.Shortcut; 37 39 … … 43 45 */ 44 46 45 public class SplitWayAction extends JosmAction implements SelectionChangedListener{47 public class SplitWayAction extends JosmAction { 46 48 47 49 private Way selectedWay; … … 54 56 super(tr("Split Way"), "splitway", tr("Split a way at the selected node."), 55 57 Shortcut.registerShortcut("tools:splitway", tr("Tool: {0}", tr("Split Way")), KeyEvent.VK_P, Shortcut.GROUP_EDIT), true); 56 DataSet.selListeners.add(this);57 58 } 58 59 … … 337 338 } 338 339 339 /** 340 * Enable the "split way" menu option if the selection looks like we could use it. 341 */ 342 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 343 setEnabled(checkSelection(newSelection)); 340 @Override 341 protected void updateEnabledState() { 342 if (getCurrentDataSet() == null) { 343 setEnabled(false); 344 return; 345 } 346 setEnabled(checkSelection(getCurrentDataSet().getSelected())); 344 347 } 345 348 } -
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r1814 r1820 39 39 */ 40 40 41 public class UnGlueAction extends JosmAction { //implements SelectionChangedListener {41 public class UnGlueAction extends JosmAction { 42 42 43 43 private Node selectedNode; … … 51 51 super(tr("UnGlue Ways"), "unglueways", tr("Duplicate nodes that are used by multiple ways."), 52 52 Shortcut.registerShortcut("tools:unglue", tr("Tool: {0}", tr("UnGlue Ways")), KeyEvent.VK_G, Shortcut.GROUP_EDIT), true); 53 //DataSet.selListeners.add(this);54 53 } 55 54 … … 410 409 getCurrentDataSet().setSelected(allNewNodes); 411 410 } 411 412 @Override 413 protected void updateEnabledState() { 414 setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty()); 415 } 412 416 } -
trunk/src/org/openstreetmap/josm/actions/UndoAction.java
r1169 r1820 22 22 public UndoAction() { 23 23 super(tr("Undo"), "undo", tr("Undo the last action."), 24 Shortcut.registerShortcut("system:undo", tr("Edit: {0}", tr("Undo")), KeyEvent.VK_Z, Shortcut.GROUP_MENU), true);24 Shortcut.registerShortcut("system:undo", tr("Edit: {0}", tr("Undo")), KeyEvent.VK_Z, Shortcut.GROUP_MENU), true); 25 25 setEnabled(false); 26 26 } … … 32 32 Main.main.undoRedo.undo(); 33 33 } 34 35 @Override 36 protected void updateEnabledState() { 37 setEnabled(Main.map != null); 38 } 34 39 } -
trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java
r1814 r1820 13 13 import org.openstreetmap.josm.tools.Shortcut; 14 14 15 public class UnselectAllAction extends JosmAction implements LayerChangeListener{15 public class UnselectAllAction extends JosmAction { 16 16 17 17 public UnselectAllAction() { … … 37 37 KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT).getKeyStroke(), 38 38 tr("Unselect All")); 39 Layer.listeners.add(this);40 refreshEnabled();41 39 } 42 40 … … 50 48 * 51 49 */ 52 protected void refreshEnabled() { 50 @Override 51 protected void updateEnabledState() { 53 52 setEnabled(getEditLayer() != null); 54 53 } 55 56 /* ---------------------------------------------------------------------------------- */57 /* Interface LayerChangeListener */58 /* ---------------------------------------------------------------------------------- */59 public void activeLayerChange(Layer oldLayer, Layer newLayer) {60 refreshEnabled();61 }62 63 public void layerAdded(Layer newLayer) {64 refreshEnabled();65 }66 67 public void layerRemoved(Layer oldLayer) {68 refreshEnabled();69 }70 54 } -
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r1814 r1820 16 16 import org.openstreetmap.josm.data.osm.DataSource; 17 17 import org.openstreetmap.josm.gui.layer.Layer; 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;19 18 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 20 19 import org.openstreetmap.josm.tools.Shortcut; 21 20 22 public class UpdateDataAction extends JosmAction implements LayerChangeListener{21 public class UpdateDataAction extends JosmAction{ 23 22 public UpdateDataAction() { 24 23 super(tr("Update Data"), … … 30 29 Shortcut.GROUP_HOTKEY), 31 30 true); 32 refreshEnabled();33 Layer.listeners.add(this);34 31 } 35 32 … … 38 35 * 39 36 */ 40 protected void refreshEnabled() { 37 @Override 38 protected void updateEnabledState() { 41 39 setEnabled(getEditLayer() != null); 42 40 } … … 86 84 new DownloadOsmTaskList().download(false, areas); 87 85 } 88 89 /* ---------------------------------------------------------------------------------- */90 /* Interface LayerChangeListener */91 /* ---------------------------------------------------------------------------------- */92 public void activeLayerChange(Layer oldLayer, Layer newLayer) {93 refreshEnabled();94 }95 96 public void layerAdded(Layer newLayer) {97 refreshEnabled();98 }99 100 public void layerRemoved(Layer oldLayer) {101 refreshEnabled();102 }103 86 } -
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r1814 r1820 33 33 * 34 34 */ 35 public class UpdateSelectionAction extends JosmAction implements SelectionChangedListener, LayerChangeListener{35 public class UpdateSelectionAction extends JosmAction { 36 36 37 37 /** … … 184 184 Shortcut.GROUP_HOTKEY + Shortcut.GROUPS_ALT2), 185 185 true); 186 refreshEnabled();187 Layer.listeners.add(this);188 DataSet.selListeners.add(this);189 186 } 190 187 … … 193 190 * 194 191 */ 195 protected void refreshEnabled() { 192 @Override 193 protected void updateEnabledState() { 196 194 setEnabled(getCurrentDataSet() != null 197 195 && ! getCurrentDataSet().getSelected().isEmpty() … … 217 215 updatePrimitives(selection); 218 216 } 219 220 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {221 refreshEnabled();222 }223 224 public void activeLayerChange(Layer oldLayer, Layer newLayer) {225 refreshEnabled();226 }227 228 public void layerAdded(Layer newLayer) {229 refreshEnabled();230 }231 232 public void layerRemoved(Layer oldLayer) {233 refreshEnabled();234 }235 217 } -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1814 r1820 29 29 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 30 30 import org.openstreetmap.josm.gui.historycombobox.SuggestingJHistoryComboBox; 31 import org.openstreetmap.josm.gui.layer.Layer;32 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;33 31 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 34 32 import org.openstreetmap.josm.io.OsmApi; … … 51 49 * @author imi 52 50 */ 53 public class UploadAction extends JosmAction implements LayerChangeListener{51 public class UploadAction extends JosmAction{ 54 52 static private Logger logger = Logger.getLogger(UploadAction.class.getName()); 55 53 … … 155 153 } 156 154 }); 157 158 Layer.listeners.add(this);159 refreshEnabled();160 155 } 161 156 … … 164 159 * 165 160 */ 166 protected void refreshEnabled() { 167 setEnabled(Main.main != null 168 && Main.map != null 169 && Main.map.mapView !=null 170 && Main.map.mapView.getEditLayer() != null 171 ); 161 @Override 162 protected void updateEnabledState() { 163 setEnabled(getEditLayer() != null); 172 164 } 173 165 174 166 public void actionPerformed(ActionEvent e) { 167 if (!isEnabled()) 168 return; 175 169 if (Main.map == null) { 176 170 JOptionPane.showMessageDialog(Main.parent,tr("Nothing to upload. Get some data first.")); … … 600 594 e.printStackTrace(); 601 595 } 602 603 /* ---------------------------------------------------------------------------------- */604 /* Interface LayerChangeListener */605 /* ---------------------------------------------------------------------------------- */606 public void activeLayerChange(Layer oldLayer, Layer newLayer) {607 refreshEnabled();608 }609 610 public void layerAdded(Layer newLayer) {611 refreshEnabled();612 }613 614 public void layerRemoved(Layer oldLayer) {615 refreshEnabled();616 }617 596 } -
trunk/src/org/openstreetmap/josm/actions/ZoomInAction.java
r1722 r1820 14 14 public ZoomInAction() { 15 15 super(tr("Zoom In"), "dialogs/zoomin", tr("Zoom In"), 16 Shortcut.registerShortcut("view:zoomin", tr("View: {0}", tr("Zoom In")), KeyEvent.VK_PLUS, Shortcut.GROUP_DIRECT), true);16 Shortcut.registerShortcut("view:zoomin", tr("View: {0}", tr("Zoom In")), KeyEvent.VK_PLUS, Shortcut.GROUP_DIRECT), true); 17 17 setEnabled(true); 18 18 } -
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r1814 r1820 23 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 24 import org.openstreetmap.josm.gui.ExtendedDialog; 25 import org.openstreetmap.josm.gui.layer.Layer;26 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;27 25 import org.openstreetmap.josm.tools.GBC; 28 26 import org.openstreetmap.josm.tools.Shortcut; 29 27 30 public class SearchAction extends JosmAction implements LayerChangeListener{28 public class SearchAction extends JosmAction{ 31 29 32 30 public static final int SEARCH_HISTORY_SIZE = 10; … … 43 41 super(tr("Search..."), "dialogs/search", tr("Search for objects."), 44 42 Shortcut.registerShortcut("system:find", tr("Search..."), KeyEvent.VK_F, Shortcut.GROUP_HOTKEY), true); 45 Layer.listeners.add(this);46 refreshEnabled();47 43 } 48 44 … … 240 236 * 241 237 */ 242 protected void refreshEnabled() { 238 @Override 239 protected void updateEnabledState() { 243 240 setEnabled(getEditLayer() != null); 244 241 } 245 246 /* ---------------------------------------------------------------------------------- */247 /* Interface LayerChangeListener */248 /* ---------------------------------------------------------------------------------- */249 public void activeLayerChange(Layer oldLayer, Layer newLayer) {250 refreshEnabled();251 }252 253 public void layerAdded(Layer newLayer) {254 refreshEnabled();255 }256 257 public void layerRemoved(Layer oldLayer) {258 refreshEnabled();259 }260 242 } -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r1814 r1820 183 183 if(activeLayer != null && activeLayer instanceof OsmDataLayer) 184 184 return ((OsmDataLayer)activeLayer).data; 185 return n ew DataSet();185 return null; 186 186 } 187 187
Note:
See TracChangeset
for help on using the changeset viewer.