Changeset 26318 in osm for applications/editors
- Timestamp:
- 2011-07-13T12:15:18+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 1 added
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r26174 r26318 30 30 <project name="utilsplugin2" default="dist" basedir="."> 31 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value=" extend selection"/>32 <property name="commit.message" value="Utilsplugin2: added ExtractNode tool Alt-J"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 <property name="plugin.main.version" value="4 064"/>34 <property name="plugin.main.version" value="4201"/> 35 35 <!-- 36 36 ************************************************ -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/ExtractPointAction.java
r26315 r26318 1 1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila 2 package utilsplugin2 .selection;2 package utilsplugin2; 3 3 4 import java.awt.MouseInfo; 5 import java.awt.Point; 4 6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 7 import static org.openstreetmap.josm.tools.I18n.tr; … … 8 10 import java.awt.event.KeyEvent; 9 11 import java.util.Collection; 10 import java.util.Set; 12 import java.util.LinkedList; 13 import java.util.List; 14 import javax.swing.JOptionPane; 15 import org.openstreetmap.josm.Main; 11 16 import org.openstreetmap.josm.actions.JosmAction; 17 import org.openstreetmap.josm.command.AddCommand; 18 import org.openstreetmap.josm.command.ChangeNodesCommand; 19 import org.openstreetmap.josm.command.Command; 20 import org.openstreetmap.josm.command.MoveCommand; 21 import org.openstreetmap.josm.command.SequenceCommand; 12 22 import org.openstreetmap.josm.data.osm.*; 13 23 … … 17 27 * Unselects all nodes 18 28 */ 19 public class UnselectNodesAction extends JosmAction {29 public class ExtractPointAction extends JosmAction { 20 30 21 31 22 public UnselectNodesAction() {23 super(tr(" Unselect nodes"), "unsnodes",24 tr(" Removes all nodes from selection"),25 Shortcut.registerShortcut("tools: unsnodes", tr("Tool: {0}","Unselect nodes"),26 KeyEvent.VK_ U, Shortcut.GROUP_MNEMONIC,KeyEvent.ALT_MASK ), true);27 putValue("help", ht("/Action/ UnselectNodes"));32 public ExtractPointAction() { 33 super(tr("Extract node"), "extpoint", 34 tr("Extracts node from a way"), 35 Shortcut.registerShortcut("tools:extnode", tr("Tool: {0}","Extract node"), 36 KeyEvent.VK_J, Shortcut.GROUP_MNEMONIC,KeyEvent.ALT_MASK ), true); 37 putValue("help", ht("/Action/ExtractNode")); 28 38 } 29 39 30 40 public void actionPerformed(ActionEvent e) { 31 41 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 32 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 33 getCurrentDataSet().clearSelection(selectedNodes); 42 List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class); 43 if (selectedNodes.size()!=1) { 44 JOptionPane.showMessageDialog(Main.parent, 45 tr("This tool extracts node from its ways and requires single node to be selected."), 46 tr("Extract node"), JOptionPane.INFORMATION_MESSAGE); 47 return; 48 } 49 Node nd = selectedNodes.get(0); 50 Node ndCopy = new Node(nd.getCoor()); 51 List<Command> cmds = new LinkedList<Command>(); 52 53 Point p = Main.map.mapView.getMousePosition(); 54 if (p!=null) cmds.add(new MoveCommand(nd,Main.map.mapView.getLatLon(p.x, p.y))); 55 List<OsmPrimitive> refs = nd.getReferrers(); 56 cmds.add(new AddCommand(ndCopy)); 57 58 for (OsmPrimitive pr: refs) { 59 if (pr instanceof Way) { 60 Way w=(Way)pr; 61 List<Node> nodes = w.getNodes(); 62 int idx=nodes.indexOf(nd); 63 nodes.set(idx, ndCopy); // replace node with its copy 64 cmds.add(new ChangeNodesCommand(w, nodes)); 65 } 66 } 67 if (cmds.size()>1) Main.main.undoRedo.add(new SequenceCommand(tr("Extract node from line"),cmds)); 34 68 } 35 69 … … 49 83 return; 50 84 } 51 setEnabled( !selection.isEmpty());85 setEnabled(selection.size()==1); 52 86 } 53 87 } -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java
r26293 r26318 28 28 JMenuItem intWaysR; 29 29 JMenuItem undoSelection; 30 JMenuItem extractPoint; 30 31 31 32 JMenuItem replaceGeometry; … … 37 38 JMenuItem selModifiedNodes; 38 39 JMenuItem selModifiedWays; 39 40 40 41 public UtilsPlugin2(PluginInformation info) { 41 42 super(info); … … 53 54 alignWayNodes = MainMenu.add(toolsMenu, new AlignWayNodesAction()); 54 55 splitOnIntersections = MainMenu.add(toolsMenu, new SplitOnIntersectionsAction()); 56 extractPoint = MainMenu.add(toolsMenu, new ExtractPointAction()); 55 57 56 58 JMenu selectionMenu = Main.main.menu.addMenu(marktr("Selection"), KeyEvent.VK_N, Main.main.menu.defaultMenuPos, "help");
Note:
See TracChangeset
for help on using the changeset viewer.