Ticket #1622: thepatch-withwhitespace.diff
| File thepatch-withwhitespace.diff, 154.0 KB (added by , 18 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/PreferencesAction.java
14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 16 16 import org.openstreetmap.josm.tools.GBC; 17 import org.openstreetmap.josm.tools.ShortCut; 17 18 18 19 /** 19 20 * Open the Preferences dialog. … … 26 27 * Create the preference action with "&Preferences" as label. 27 28 */ 28 29 public PreferencesAction() { 29 super(tr("Preferences ..."), "preference", tr("Open a preferences page for global settings."), KeyEvent.VK_F12, 0, true); 30 super(tr("Preferences ..."), "preference", tr("Open a preferences page for global settings."), 31 ShortCut.registerShortCut("system:preferences", tr("Preferences"), KeyEvent.VK_F12, ShortCut.GROUP_DIRECT), true); 30 32 } 31 33 32 34 /** -
src/org/openstreetmap/josm/actions/OpenAction.java
24 24 import org.openstreetmap.josm.io.NmeaReader; 25 25 import org.openstreetmap.josm.io.OsmReader; 26 26 import org.xml.sax.SAXException; 27 import org.openstreetmap.josm.tools.ShortCut; 27 28 28 29 /** 29 30 * Open a file chooser dialog and select an file to import. Then call the gpx-import 30 31 * driver. Finally open an internal frame into the main window with the gpx data shown. 31 * 32 * 32 33 * @author imi 33 34 */ 34 35 public class OpenAction extends DiskAccessAction { 35 36 36 37 /** 37 38 * Create an open action. The name is "Open a file". 38 39 */ 39 40 public OpenAction() { 40 super(tr("Open ..."), "open", tr("Open a file."), KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK); 41 super(tr("Open ..."), "open", tr("Open a file."), 42 ShortCut.registerShortCut("system:open", tr("File: Open..."), KeyEvent.VK_O, ShortCut.GROUP_MENU)); 41 43 } 42 44 43 45 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/AlignInCircleAction.java
19 19 import org.openstreetmap.josm.data.osm.Node; 20 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 21 import org.openstreetmap.josm.data.osm.Way; 22 import org.openstreetmap.josm.tools.ShortCut; 22 23 23 24 /** 24 25 * Aligns all selected nodes within a circle. (Useful for roundabouts) … … 28 29 public final class AlignInCircleAction extends JosmAction { 29 30 30 31 public AlignInCircleAction() { 31 super(tr("Align Nodes in Circle"), "aligncircle", tr("Move the selected nodes into a circle."), KeyEvent.VK_O, 0, true); 32 super(tr("Align Nodes in Circle"), "aligncircle", tr("Move the selected nodes into a circle."), 33 ShortCut.registerShortCut("tools:aligncircle", tr("Tool: Align in circle"), KeyEvent.VK_O, ShortCut.GROUP_EDIT), true); 32 34 } 33 35 34 36 public void actionPerformed(ActionEvent e) { … … 39 41 if (osm instanceof Node) 40 42 nodes.add((Node)osm); 41 43 42 // special case if no single nodes are selected and exactly one way is: 44 // special case if no single nodes are selected and exactly one way is: 43 45 // then use the way's nodes 44 46 if ((nodes.size() == 0) && (sel.size() == 1)) 45 47 for (OsmPrimitive osm : sel) … … 66 68 // Node "avn" now is central to all selected nodes. 67 69 68 70 // Now calculate the average distance to each node from the 69 // centre. This method is ok as long as distances are short 71 // centre. This method is ok as long as distances are short 70 72 // relative to the distance from the N or S poles. 71 73 double distances[] = new double[nodes.size()]; 72 74 double avdist = 0, latd, lond; -
src/org/openstreetmap/josm/actions/MoveAction.java
16 16 import org.openstreetmap.josm.data.osm.Node; 17 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 18 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 19 import org.openstreetmap.josm.tools.ShortCut; 19 20 20 21 /** 21 22 * Moves the selection 22 * 23 * 23 24 * @author Frederik Ramm 24 25 */ 25 26 public class MoveAction extends JosmAction { 26 27 27 28 public enum Direction { UP, LEFT, RIGHT, DOWN } 28 29 private Direction myDirection; 29 30 31 // any better idea? 32 private static Object calltosupermustbefirststatementinconstructor(Direction dir, boolean text) { 33 ShortCut sc; 34 String directiontext; 35 if (dir == Direction.UP) { 36 directiontext = tr("up"); 37 sc = ShortCut.registerShortCut("core:moveup", tr("Move objects {0}", directiontext), KeyEvent.VK_UP, ShortCut.GROUPS_ALT1+ShortCut.GROUP_DIRECT); 38 } else if (dir == Direction.DOWN) { 39 directiontext = tr("down"); 40 sc = ShortCut.registerShortCut("core:movedown", tr("Move objects {0}", directiontext), KeyEvent.VK_DOWN, ShortCut.GROUPS_ALT1+ShortCut.GROUP_DIRECT); 41 } else if (dir == Direction.LEFT) { 42 directiontext = tr("left"); 43 sc = ShortCut.registerShortCut("core:moveleft", tr("Move objects {0}", directiontext), KeyEvent.VK_LEFT, ShortCut.GROUPS_ALT1+ShortCut.GROUP_DIRECT); 44 } else { //dir == Direction.RIGHT) { 45 directiontext = tr("right"); 46 sc = ShortCut.registerShortCut("core:moveright", tr("Move objects {0}", directiontext), KeyEvent.VK_RIGHT, ShortCut.GROUPS_ALT1+ShortCut.GROUP_DIRECT); 47 } 48 if (text) { 49 return directiontext; 50 } else { 51 return sc; 52 } 53 } 54 30 55 public MoveAction(Direction dir) { 31 super(tr("Move"), null, tr("Moves Objects"), 32 (dir == Direction.UP) ? KeyEvent.VK_UP : 33 (dir == Direction.DOWN) ? KeyEvent.VK_DOWN : 34 (dir == Direction.LEFT) ? KeyEvent.VK_LEFT : 35 KeyEvent.VK_RIGHT, 0, true); 56 super(tr("Move {0}", calltosupermustbefirststatementinconstructor(dir, true)), null, 57 tr("Moves Objects {0}", calltosupermustbefirststatementinconstructor(dir, true)), 58 (ShortCut)calltosupermustbefirststatementinconstructor(dir, false), true); 36 59 myDirection = dir; 37 60 } 38 61 39 62 public void actionPerformed(ActionEvent event) { 40 63 41 64 // find out how many "real" units the objects have to be moved in order to 42 65 // achive an 1-pixel movement 43 66 44 67 EastNorth en1 = Main.map.mapView.getEastNorth(100, 100); 45 68 EastNorth en2 = Main.map.mapView.getEastNorth(101, 101); 46 69 47 70 double distx = en2.east() - en1.east(); 48 71 double disty = en2.north() - en1.north(); 49 72 50 73 switch (myDirection) { 51 case UP: 74 case UP: 52 75 distx = 0; 53 76 disty = -disty; 54 77 break; … … 61 84 default: 62 85 disty = 0; 63 86 } 64 87 65 88 Collection<OsmPrimitive> selection = Main.ds.getSelected(); 66 89 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 67 90 68 91 Command c = !Main.main.undoRedo.commands.isEmpty() 69 92 ? Main.main.undoRedo.commands.getLast() : null; 70 93 -
src/org/openstreetmap/josm/actions/JosmAction.java
1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.actions; 3 3 4 import java.awt.event.InputEvent; 4 5 5 6 import javax.swing.AbstractAction; 6 7 import javax.swing.JComponent; … … 10 11 import org.openstreetmap.josm.data.osm.DataSet; 11 12 import org.openstreetmap.josm.tools.Destroyable; 12 13 import org.openstreetmap.josm.tools.ImageProvider; 13 import org.openstreetmap.josm.tools.ShortCut Label;14 import org.openstreetmap.josm.tools.ShortCut; 14 15 15 16 /** 16 17 * Base class helper for all Actions in JOSM. Just to make the life easier. 17 * 18 * 18 19 * destroy() from interface Destroyable is called e.g. for MapModes, when the last layer has 19 20 * been removed and so the mapframe will be destroyed. For other JosmActions, destroy() may never 20 21 * be called (currently). 21 * 22 * 22 23 * @author imi 23 24 */ 24 25 abstract public class JosmAction extends AbstractAction implements Destroyable { 25 26 27 @Deprecated 26 28 public KeyStroke shortCut; 29 protected ShortCut sc; 27 30 31 public ShortCut getShortCut() { 32 if (sc == null) { 33 sc = ShortCut.registerShortCut("core:none", "No Shortcut", 0, ShortCut.GROUP_NONE); 34 sc.setAutomatic(); // as this shortcut is shared by all action that don't want to have a shortcut, 35 // we shouldn't allow the user to change it... 36 } 37 return sc; 38 } 39 40 @Deprecated 28 41 public JosmAction(String name, String iconName, String tooltip, int shortCut, int modifier, boolean register) { 29 42 super(name, iconName == null ? null : ImageProvider.get(iconName)); 30 43 setHelpId(); 31 String scl = ShortCutLabel.name(shortCut, modifier);32 putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+scl+"</font>"+(scl.equals("")?"":" ")+"</html>");33 44 if (shortCut != 0) { 34 this.shortCut = KeyStroke.getKeyStroke(shortCut, modifier); 35 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(this.shortCut, name); 45 int group = ShortCut.GROUP_LAYER; //GROUP_NONE; 46 if (((modifier & InputEvent.CTRL_MASK) != 0) || ((modifier & InputEvent.CTRL_DOWN_MASK) != 0)) { 47 group = ShortCut.GROUP_MENU; 48 } else if (modifier == 0) { 49 group = ShortCut.GROUP_EDIT; 50 } 51 sc = ShortCut.registerShortCut("auto:"+name, name, shortCut, group); 52 this.shortCut = sc.getKeyStroke(); 53 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), name); 36 54 Main.contentPane.getActionMap().put(name, this); 37 55 } 38 putValue("toolbar", iconName); 39 if (register) 40 Main.toolbar.register(this); 56 putValue(SHORT_DESCRIPTION, Main.platform.makeTooltip(tooltip, sc)); 57 putValue("toolbar", iconName); 58 if (register) 59 Main.toolbar.register(this); 41 60 } 42 61 62 /** 63 * The new super for all actions. 64 * 65 * Use this super constructor to setup your action. It takes 5 parameters: 66 * 67 * name - the action's text as displayed on the menu (if it is added to a menu) 68 * iconName - the filename of the icon to use 69 * tooltip - a longer description of the action that will be displayed in the tooltip. Please note 70 * that html is not supported for menu action on some platforms 71 * shortCut - a ready-created shortcut object or null if you don't want a shortcut. But you always 72 * do want a shortcut, remember you can alway register it with group=none, so you 73 * won't be assigned a shurtcut unless the user configures one. If you pass null here, 74 * the user CANNOT configure a shortcut for your action. 75 * register - register this action for the toolbar preferences? 76 */ 77 public JosmAction(String name, String iconName, String tooltip, ShortCut shortCut, boolean register) { 78 super(name, iconName == null ? null : ImageProvider.get(iconName)); 79 setHelpId(); 80 sc = shortCut; 81 if (sc != null) { 82 this.shortCut = sc.getKeyStroke(); 83 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), name); 84 Main.contentPane.getActionMap().put(name, this); 85 } 86 putValue(SHORT_DESCRIPTION, Main.platform.makeTooltip(tooltip, sc)); 87 putValue("toolbar", iconName); 88 if (register) 89 Main.toolbar.register(this); 90 } 91 43 92 public void destroy() { 44 93 if (shortCut != null) { 45 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(s hortCut);46 Main.contentPane.getActionMap().remove(s hortCut);94 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(sc.getKeyStroke()); 95 Main.contentPane.getActionMap().remove(sc.getKeyStroke()); 47 96 } 48 97 } 49 98 50 99 public JosmAction() { 51 100 setHelpId(); 52 101 } … … 57 106 public void pasteBufferChanged(DataSet newPasteBuffer) { 58 107 return; 59 108 } 60 109 61 110 /** 62 111 * needs to be overridden to be useful 63 112 */ 64 113 public void addListener(JosmAction a) { 65 114 return; 66 115 } 67 116 68 117 private void setHelpId() { 69 118 String helpId = "Action/"+getClass().getName().substring(getClass().getName().lastIndexOf('.')+1); 70 119 if (helpId.endsWith("Action")) -
src/org/openstreetmap/josm/actions/SelectAllAction.java
7 7 import java.awt.event.KeyEvent; 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.tools.ShortCut; 10 11 11 12 public class SelectAllAction extends JosmAction { 12 13 13 14 public SelectAllAction() { 14 super(tr("Select All"),"selectall", tr("Select all undeleted objects in the data layer. This selects incomplete objects too."), KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK, true); 15 } 15 super(tr("Select All"),"selectall", tr("Select all undeleted objects in the data layer. This selects incomplete objects too."), 16 ShortCut.registerShortCut("system:selectall", tr("Edit: Select all"), KeyEvent.VK_A, ShortCut.GROUP_MENU), true); 17 } 16 18 17 19 public void actionPerformed(ActionEvent e) { 18 20 Main.ds.setSelected(Main.ds.allNonDeletedPhysicalPrimitives()); -
src/org/openstreetmap/josm/actions/ExitAction.java
7 7 import java.awt.event.KeyEvent; 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.tools.ShortCut; 10 11 11 12 /** 12 13 * Exit the application. May ask for permission first (if something has changed). 13 * 14 * 14 15 * @author imi 15 16 */ 16 17 public class ExitAction extends JosmAction { … … 18 19 * Construct the action with "Exit" as label 19 20 */ 20 21 public ExitAction() { 21 super(tr("Exit"), "exit", tr("Exit the application."), KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK, true); 22 super(tr("Exit"), "exit", tr("Exit the application."), 23 ShortCut.registerShortCut("system:menuexit", tr("Quit JOSM"), KeyEvent.VK_Q, ShortCut.GROUP_MENU), true); 22 24 } 23 25 24 26 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/CopyAction.java
23 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 24 import org.openstreetmap.josm.data.osm.Way; 25 25 import org.openstreetmap.josm.data.osm.visitor.Visitor; 26 import org.openstreetmap.josm.tools.ShortCut; 26 27 27 28 public final class CopyAction extends JosmAction implements SelectionChangedListener { 28 29 29 30 private LinkedList<JosmAction> listeners; 30 31 31 32 public CopyAction() { 32 33 super(tr("Copy"), "copy", 33 34 tr("Copy selected objects to paste buffer."), 34 KeyEvent.VK_C, KeyEvent.CTRL_MASK, true);35 ShortCut.registerShortCut("system:copy", tr("Edit: Copy"), KeyEvent.VK_C, ShortCut.GROUP_MENU), true); 35 36 setEnabled(false); 36 37 DataSet.selListeners.add(this); 37 38 listeners = new LinkedList<JosmAction>(); … … 40 41 @Override public void addListener(JosmAction a) { 41 42 listeners.add(a); 42 43 } 43 44 44 45 public void actionPerformed(ActionEvent e) { 45 46 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 46 if (sel.isEmpty()) { 47 if (sel.isEmpty()) { 47 48 JOptionPane.showMessageDialog(Main.parent, 48 tr("Please select something to copy.")); 49 tr("Please select something to copy.")); 49 50 return; 50 51 } 51 52 … … 54 55 final HashMap<OsmPrimitive,OsmPrimitive> map = new HashMap<OsmPrimitive,OsmPrimitive>(); 55 56 /* temporarily maps old nodes to new so we can do a true deep copy */ 56 57 57 /* scan the selected objects, mapping them to copies; when copying a way or relation, 58 /* scan the selected objects, mapping them to copies; when copying a way or relation, 58 59 * the copy references the copies of their child objects */ 59 60 new Visitor(){ 60 61 public void visit(Node n) { 61 /* check if already in pasteBuffer - e.g. two ways are selected which share a node; 62 * or a way and a node in that way is selected, we'll see it twice, once via the 62 /* check if already in pasteBuffer - e.g. two ways are selected which share a node; 63 * or a way and a node in that way is selected, we'll see it twice, once via the 63 64 * way and once directly; and so on. */ 64 65 if (map.containsKey(n)) { return; } 65 66 Node nnew = new Node(n); … … 106 107 107 108 Main.pasteBuffer = pasteBuffer; 108 109 Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */ 109 110 110 111 for(JosmAction a : listeners) { 111 112 a.pasteBufferChanged(Main.pasteBuffer); 112 113 } -
src/org/openstreetmap/josm/actions/UnselectAllAction.java
9 9 import javax.swing.JComponent; 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.tools.ShortCut; 12 13 13 14 public class UnselectAllAction extends JosmAction { 14 15 15 16 public UnselectAllAction() { 16 17 super(tr("Unselect All"), "unselectall", tr("Unselect all objects."), 17 KeyEvent.VK_U, 0, true); 18 ShortCut.registerShortCut("edit:unselectall", tr("Edit: Unselect all"), KeyEvent.VK_U, ShortCut.GROUP_EDIT), true); 19 // this is not really GROUP_EDIT, but users really would complain if the yhad to reconfigure because we put 20 // the correct group in 18 21 19 22 // Add extra shortcut C-S-a 20 23 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 21 KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK22 | KeyEvent.SHIFT_DOWN_MASK),tr("Unselect All"));24 ShortCut.registerShortCut("edit:unselectall2", tr("Edit: Unselect all (2)"), KeyEvent.VK_A, ShortCut.GROUP_MENU).getKeyStroke(), 25 tr("Unselect All")); 23 26 24 27 // Add extra shortcut ESCAPE 25 28 /* … … 28 31 * for now this is a reasonable approximation. 29 32 */ 30 33 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 31 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),32 tr("Unselect All"));34 ShortCut.registerShortCut("edit:unselectall3", tr("Edit: Unselect all (3)"), KeyEvent.VK_ESCAPE, ShortCut.GROUP_DIRECT).getKeyStroke(), 35 tr("Unselect All")); 33 36 } 34 37 35 38 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/ZoomInAction.java
7 7 import java.awt.event.KeyEvent; 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.tools.ShortCut; 10 11 11 12 public final class ZoomInAction extends JosmAction { 12 13 13 14 public ZoomInAction() { 14 15 super(tr("Zoom in"), "dialogs/zoomin", tr("Zoom in"), 15 KeyEvent.VK_PLUS, 0, true);16 ShortCut.registerShortCut("view:zoomin", tr("View: Zoom in"), KeyEvent.VK_PLUS, ShortCut.GROUP_DIRECT), true); 16 17 setEnabled(true); 17 18 } 18 19 -
src/org/openstreetmap/josm/actions/SplitWayAction.java
32 32 import org.openstreetmap.josm.data.osm.Way; 33 33 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 34 34 import org.openstreetmap.josm.data.osm.visitor.Visitor; 35 import org.openstreetmap.josm.tools.ShortCut; 35 36 36 37 /** 37 38 * Splits a way into multiple ways (all identical except for their node list). 38 * 39 * 39 40 * Ways are just split at the selected nodes. The nodes remain in their 40 41 * original order. Selected nodes at the end of a way are ignored. 41 42 */ … … 49 50 * Create a new SplitWayAction. 50 51 */ 51 52 public SplitWayAction() { 52 super(tr("Split Way"), "splitway", tr("Split a way at the selected node."), KeyEvent.VK_P, 0, true); 53 super(tr("Split Way"), "splitway", tr("Split a way at the selected node."), 54 ShortCut.registerShortCut("tools:splitway", tr("Tool: Split way"), KeyEvent.VK_P, ShortCut.GROUP_EDIT), true); 53 55 DataSet.selListeners.add(this); 54 56 } 55 57 56 58 /** 57 59 * Called when the action is executed. 58 * 60 * 59 61 * This method performs an expensive check whether the selection clearly defines one 60 62 * of the split actions outlined above, and if yes, calls the splitWay method. 61 63 */ … … 84 86 // enties are not considered 85 87 } 86 88 }; 87 89 88 90 for (OsmPrimitive p : selection) 89 91 p.visit(splitVisitor); 90 92 … … 110 112 } 111 113 } 112 114 if (wayOccurenceCounter.isEmpty()) { 113 JOptionPane.showMessageDialog(Main.parent, 115 JOptionPane.showMessageDialog(Main.parent, 114 116 trn("The selected node is no inner part of any way.", 115 117 "The selected nodes are no inner part of any way.", selectedNodes.size())); 116 118 return; … … 139 141 nds.remove(n); 140 142 } 141 143 if (!nds.isEmpty()) { 142 JOptionPane.showMessageDialog(Main.parent, 144 JOptionPane.showMessageDialog(Main.parent, 143 145 trn("The selected way does not contain the selected node.", 144 146 "The selected way does not contain all the selected nodes.", selectedNodes.size())); 145 147 return; … … 150 152 splitWay(); 151 153 } 152 154 153 /** 155 /** 154 156 * Checks if the selection consists of something we can work with. 155 157 * Checks only if the number and type of items selected looks good; 156 * does not check whether the selected items are really a valid 158 * does not check whether the selected items are really a valid 157 159 * input for splitting (this would be too expensive to be carried 158 160 * out from the selectionChanged listener). 159 */ 161 */ 160 162 private boolean checkSelection(Collection<? extends OsmPrimitive> selection) { 161 163 boolean way = false; 162 164 boolean node = false; … … 229 231 // build a list of commands, and also a new selection list 230 232 Collection<Command> commandList = new ArrayList<Command>(wayChunks.size()); 231 233 Collection<Way> newSelection = new ArrayList<Way>(wayChunks.size()); 232 234 233 235 Iterator<List<Node>> chunkIt = wayChunks.iterator(); 234 236 235 237 // First, change the original way 236 238 Way changedWay = new Way(selectedWay); 237 239 changedWay.nodes.clear(); -
src/org/openstreetmap/josm/actions/ZoomOutAction.java
7 7 import java.awt.event.KeyEvent; 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.tools.ShortCut; 10 11 11 12 public final class ZoomOutAction extends JosmAction { 12 13 13 14 public ZoomOutAction() { 14 15 super(tr("Zoom out"), "dialogs/zoomout", tr("Zoom out"), 15 KeyEvent.VK_MINUS, 0, true);16 ShortCut.registerShortCut("view:zoomout", tr("View: Zoom out"), KeyEvent.VK_MINUS, ShortCut.GROUP_DIRECT), true); 16 17 setEnabled(true); 17 18 } 18 19 -
src/org/openstreetmap/josm/actions/SaveAsAction.java
8 8 import java.io.File; 9 9 10 10 import org.openstreetmap.josm.gui.layer.Layer; 11 import org.openstreetmap.josm.tools.ShortCut; 11 12 12 13 /** 13 14 * Export the data. 14 * 15 * 15 16 * @author imi 16 17 */ 17 18 public class SaveAsAction extends SaveActionBase { 18 19 19 20 /** 20 21 * Construct the action with "Save" as label. 21 22 * @param layer Save this layer. 22 23 */ 23 24 public SaveAsAction(Layer layer) { 24 super(tr("Save as ..."), "save_as", tr("Save the current data to a new file."), KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, layer); 25 super(tr("Save as ..."), "save_as", tr("Save the current data to a new file."), 26 ShortCut.registerShortCut("system:saveas", tr("File: Save as..."), KeyEvent.VK_S, ShortCut.GROUP_MENU), layer); 25 27 } 26 28 27 29 @Override protected File getFile(Layer layer) { 28 30 return openFileDialog(layer); 29 31 } -
src/org/openstreetmap/josm/actions/audio/AudioBackAction.java
10 10 import org.openstreetmap.josm.actions.JosmAction; 11 11 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 12 12 import org.openstreetmap.josm.tools.AudioPlayer; 13 import org.openstreetmap.josm.tools.ShortCut; 13 14 14 15 public class AudioBackAction extends JosmAction { 15 16 16 17 private double amount; // note, normally negative, i.e. jump backwards in time 17 18 18 19 public AudioBackAction() { 19 super(tr("Back"), "audio-back", tr("Jump back."), KeyEvent.VK_F6, 0, true); 20 super(tr("Back"), "audio-back", tr("Jump back."), 21 ShortCut.registerShortCut("audio:back", tr("Audio: Back"), KeyEvent.VK_F6, ShortCut.GROUP_DIRECT), true); 20 22 try { 21 23 amount = - Double.parseDouble(Main.pref.get("audio.forwardbackamount","10.0")); 22 24 } catch (NumberFormatException e) { -
src/org/openstreetmap/josm/actions/audio/AudioFwdAction.java
10 10 import org.openstreetmap.josm.actions.JosmAction; 11 11 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 12 12 import org.openstreetmap.josm.tools.AudioPlayer; 13 import org.openstreetmap.josm.tools.ShortCut; 13 14 14 15 public class AudioFwdAction extends JosmAction { 15 16 16 17 private double amount; 17 18 18 19 public AudioFwdAction() { 19 super(tr("Forward"), "audio-fwd", tr("Jump forward"), KeyEvent.VK_F7, 0, true); 20 super(tr("Forward"), "audio-fwd", tr("Jump forward"), 21 ShortCut.registerShortCut("audio:forward", tr("Audio: Forward"), KeyEvent.VK_F7, ShortCut.GROUP_DIRECT), true); 20 22 try { 21 23 amount = Double.parseDouble(Main.pref.get("audio.forwardbackamount","10.0")); 22 24 } catch (NumberFormatException e) { -
src/org/openstreetmap/josm/actions/audio/AudioFastSlowAction.java
6 6 import org.openstreetmap.josm.Main; 7 7 import org.openstreetmap.josm.actions.JosmAction; 8 8 import org.openstreetmap.josm.tools.AudioPlayer; 9 import org.openstreetmap.josm.tools.ShortCut; 9 10 10 11 abstract public class AudioFastSlowAction extends JosmAction { 11 12 12 13 private double multiplier; 13 14 15 public AudioFastSlowAction(String name, String iconName, String tooltip, ShortCut shortcut, boolean fast) { 16 super(name, iconName, tooltip, shortcut, true); 17 try { 18 multiplier = Double.parseDouble(Main.pref.get("audio.fastfwdmultiplier","1.3")); 19 } catch (NumberFormatException e) { 20 multiplier = 1.3; 21 } 22 if (! fast) 23 multiplier = 1.0 / multiplier; 24 } 25 26 @Deprecated 14 27 public AudioFastSlowAction(String name, String iconName, String tooltip, int shortcut, int modifier, boolean fast) { 15 28 super(name, iconName, tooltip, shortcut, modifier, true); 16 29 try { … … 18 31 } catch (NumberFormatException e) { 19 32 multiplier = 1.3; 20 33 } 21 if (! fast) 34 if (! fast) 22 35 multiplier = 1.0 / multiplier; 23 36 } 24 37 25 38 public void actionPerformed(ActionEvent e) { 26 39 double speed = AudioPlayer.speed(); 27 if (speed * multiplier <= 0.1) 40 if (speed * multiplier <= 0.1) 28 41 return; 29 42 try { 30 43 if (AudioPlayer.playing() || AudioPlayer.paused()) -
src/org/openstreetmap/josm/actions/audio/AudioPlayPauseAction.java
10 10 import org.openstreetmap.josm.actions.JosmAction; 11 11 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 12 12 import org.openstreetmap.josm.tools.AudioPlayer; 13 import org.openstreetmap.josm.tools.ShortCut; 13 14 14 15 public class AudioPlayPauseAction extends JosmAction { 15 16 16 17 public AudioPlayPauseAction() { 17 super(tr("Play/pause"), "audio-playpause", tr("Play/pause audio."), KeyEvent.VK_PERIOD, 0, true); 18 super(tr("Play/pause"), "audio-playpause", tr("Play/pause audio."), 19 ShortCut.registerShortCut("audio:pause", tr("Audio: Play/Pause"), KeyEvent.VK_PERIOD, ShortCut.GROUP_DIRECT), true); 18 20 } 19 21 20 22 public void actionPerformed(ActionEvent e) { … … 34 36 } catch (Exception ex) { 35 37 AudioPlayer.audioMalfunction(ex); 36 38 } 37 } 39 } 38 40 } -
src/org/openstreetmap/josm/actions/audio/AudioFasterAction.java
2 2 package org.openstreetmap.josm.actions.audio; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import org.openstreetmap.josm.tools.ShortCut; 5 6 6 7 import java.awt.event.KeyEvent; 7 8 8 9 public class AudioFasterAction extends AudioFastSlowAction { 9 10 10 11 public AudioFasterAction() { 11 super(tr("Faster"), "audio-faster", tr("Faster Forward"), KeyEvent.VK_F9, 0, true); 12 super(tr("Faster"), "audio-faster", tr("Faster Forward"), 13 ShortCut.registerShortCut("audio:faster", tr("Audio: Faster"), KeyEvent.VK_F9, ShortCut.GROUP_DIRECT), true); 12 14 } 13 15 } -
src/org/openstreetmap/josm/actions/audio/AudioSlowerAction.java
4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.awt.event.KeyEvent; 7 import org.openstreetmap.josm.tools.ShortCut; 7 8 8 9 public class AudioSlowerAction extends AudioFastSlowAction { 9 10 10 11 public AudioSlowerAction() { 11 super(tr("Slower"), "audio-slower", tr("Slower Forward"), KeyEvent.VK_F9, KeyEvent.SHIFT_MASK, false); 12 super(tr("Slower"), "audio-slower", tr("Slower Forward"), 13 ShortCut.registerShortCut("audio:slower", tr("Audio: Slower"), KeyEvent.VK_F9, ShortCut.GROUP_DIRECT), true); 12 14 } 13 15 } -
src/org/openstreetmap/josm/actions/audio/AudioPrevAction.java
8 8 9 9 import org.openstreetmap.josm.actions.JosmAction; 10 10 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 11 import org.openstreetmap.josm.tools.ShortCut; 11 12 12 13 public class AudioPrevAction extends JosmAction { 13 14 14 15 public AudioPrevAction() { 15 super(tr("Previous Marker"), "audio-prev", tr("Play previous marker."), KeyEvent.VK_F5, 0, true); 16 super(tr("Previous Marker"), "audio-prev", tr("Play previous marker."), 17 ShortCut.registerShortCut("audio:prev", tr("Audio: Previous"), KeyEvent.VK_F5, ShortCut.GROUP_DIRECT), true); 16 18 } 17 19 18 20 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/audio/AudioNextAction.java
8 8 9 9 import org.openstreetmap.josm.actions.JosmAction; 10 10 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 11 import org.openstreetmap.josm.tools.ShortCut; 11 12 12 13 public class AudioNextAction extends JosmAction { 13 14 14 15 public AudioNextAction() { 15 super(tr("Next Marker"), "audio-next", tr("Play next marker."), KeyEvent.VK_F8, 0, true); 16 super(tr("Next Marker"), "audio-next", tr("Play next marker."), 17 ShortCut.registerShortCut("audio:next", tr("Audio: Next"), KeyEvent.VK_F8, ShortCut.GROUP_DIRECT), true); 16 18 } 17 19 18 20 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
22 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 23 import org.openstreetmap.josm.data.osm.Way; 24 24 import org.openstreetmap.josm.data.osm.WaySegment; 25 import org.openstreetmap.josm.tools.ShortCut; 25 26 26 27 public class JoinNodeWayAction extends JosmAction { 27 28 public JoinNodeWayAction() { 28 super(tr("Join node to way"), "joinnodeway", 29 tr("Join a node into the nearest way segments"), KeyEvent.VK_J, 0, true);29 super(tr("Join node to way"), "joinnodeway", tr("Join a node into the nearest way segments"), 30 ShortCut.registerShortCut("tools:joinnodeway", tr("Tool: Join node to way"), KeyEvent.VK_J, ShortCut.GROUP_EDIT), true); 30 31 } 31 32 32 33 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/search/SearchAction.java
21 21 import org.openstreetmap.josm.actions.JosmAction; 22 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 23 import org.openstreetmap.josm.tools.GBC; 24 import org.openstreetmap.josm.tools.ShortCut; 24 25 25 26 public class SearchAction extends JosmAction { 26 27 … … 35 36 private static SearchSetting lastSearch = null; 36 37 37 38 public SearchAction() { 38 super(tr("Search ..."), "dialogs/search", tr("Search for objects."), KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK,39 true);39 super(tr("Search ..."), "dialogs/search", tr("Search for objects."), 40 ShortCut.registerShortCut("system:find", tr("Search..."), KeyEvent.VK_F, ShortCut.GROUP_HOTKEY), true); 40 41 } 41 42 42 43 public void actionPerformed(ActionEvent e) { … … 104 105 } 105 106 106 107 /** 107 * Adds the search specified by the settings in <code>s</code> to the 108 * Adds the search specified by the settings in <code>s</code> to the 108 109 * search history and performs the search. 109 * 110 * 110 111 * @param s 111 112 */ 112 113 public static void searchWithHistory(SearchSetting s) { -
src/org/openstreetmap/josm/actions/AlignInLineAction.java
17 17 import org.openstreetmap.josm.data.osm.Node; 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 19 import org.openstreetmap.josm.data.osm.Way; 20 import org.openstreetmap.josm.tools.ShortCut; 20 21 21 22 /** 22 23 * Aligns all selected nodes into a straight line (useful for 23 24 * roads that should be straight, but have side roads and 24 25 * therefore need multiple nodes) 25 * 26 * 26 27 * @author Matthew Newton 27 28 */ 28 29 public final class AlignInLineAction extends JosmAction { 29 30 30 31 public AlignInLineAction() { 31 super(tr("Align Nodes in Line"), "alignline", tr("Move the selected nodes onto a line."), KeyEvent.VK_L, 0, true); 32 super(tr("Align Nodes in Line"), "alignline", tr("Move the selected nodes onto a line."), 33 ShortCut.registerShortCut("tools:alignline", tr("Tool: Align in line"), KeyEvent.VK_L, ShortCut.GROUP_EDIT), true); 32 34 } 33 35 34 36 /** … … 45 47 nodes.add((Node)osm); 46 48 itnodes.add((Node)osm); 47 49 } 48 // special case if no single nodes are selected and exactly one way is: 50 // special case if no single nodes are selected and exactly one way is: 49 51 // then use the way's nodes 50 52 if ((nodes.size() == 0) && (sel.size() == 1)) 51 53 for (OsmPrimitive osm : sel) -
src/org/openstreetmap/josm/actions/ReverseWayAction.java
24 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 25 import org.openstreetmap.josm.data.osm.Way; 26 26 import org.openstreetmap.josm.data.osm.visitor.Visitor; 27 import org.openstreetmap.josm.tools.ShortCut; 27 28 28 29 public final class ReverseWayAction extends JosmAction { 29 30 30 31 public ReverseWayAction() { 31 super(tr("Reverse ways"), "wayflip", 32 tr("Reverse the direction of all selected ways."), 33 KeyEvent.VK_R, 0, true); 32 super(tr("Reverse ways"), "wayflip", tr("Reverse the direction of all selected ways."), 33 ShortCut.registerShortCut("tools:reverse", tr("Tool: Reverse way"), KeyEvent.VK_R, ShortCut.GROUP_EDIT), true); 34 34 } 35 35 36 36 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/UnGlueAction.java
25 25 import org.openstreetmap.josm.data.osm.Relation; 26 26 import org.openstreetmap.josm.data.osm.RelationMember; 27 27 import org.openstreetmap.josm.data.osm.Way; 28 import org.openstreetmap.josm.tools.ShortCut; 28 29 29 30 /** 30 31 * Dupe a node that is used my multiple ways, so each way has its own node. … … 43 44 * Create a new SplitWayAction. 44 45 */ 45 46 public UnGlueAction() { 46 super(tr("UnGlue Ways"), "unglueways", tr("Duplicate the selected node so each way using it has its own copy."), KeyEvent.VK_G, 0, true); 47 super(tr("UnGlue Ways"), "unglueways", tr("Duplicate the selected node so each way using it has its own copy."), 48 ShortCut.registerShortCut("tools:unglue", tr("Tool: Unglue"), KeyEvent.VK_G, ShortCut.GROUP_EDIT), true); 47 49 DataSet.selListeners.add(this); 48 50 } 49 51 … … 84 86 * out from the selectionChanged listener). 85 87 */ 86 88 private boolean checkSelection(Collection<? extends OsmPrimitive> selection) { 87 89 88 90 int size = selection.size(); 89 91 if (size < 1 || size > 2) 90 92 return false; 91 93 92 94 selectedNode = null; 93 95 selectedWay = null; 94 96 95 97 for (OsmPrimitive p : selection) { 96 98 if (p instanceof Node) { 97 99 selectedNode = (Node) p; … … 99 101 return size == 1 || selectedWay.nodes.contains(selectedNode); 100 102 } else if (p instanceof Way) { 101 103 selectedWay = (Way) p; 102 if (size == 2 && selectedNode != null) 104 if (size == 2 && selectedNode != null) 103 105 return selectedWay.nodes.contains(selectedNode); 104 106 } 105 107 } 106 108 107 109 return false; 108 110 } 109 111 … … 132 134 133 135 return firstway; 134 136 } 135 137 136 138 /** 137 139 * see above 138 140 */ … … 142 144 List<Node> newNodes = new LinkedList<Node>(); 143 145 144 146 if (selectedWay == null) { 145 147 146 148 boolean firstway = true; 147 149 // modify all ways containing the nodes 148 150 for (Way w : Main.ds.ways) { 149 151 if (w.deleted || w.incomplete || w.nodes.size() < 1) continue; 150 152 if (!w.nodes.contains(selectedNode)) continue; 151 153 152 154 firstway = modifyWay(firstway, w, cmds, newNodes); 153 155 } 154 156 } else { -
src/org/openstreetmap/josm/actions/GpxExportAction.java
33 33 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 34 34 import org.openstreetmap.josm.io.GpxWriter; 35 35 import org.openstreetmap.josm.tools.GBC; 36 import org.openstreetmap.josm.tools.ShortCut; 36 37 37 38 /** 38 39 * Exports data to gpx. … … 44 45 private final Layer layer; 45 46 46 47 public GpxExportAction(Layer layer) { 47 super(tr("Export to GPX ..."), "exportgpx", tr("Export the data to GPX file."), KeyEvent.VK_E, InputEvent.CTRL_DOWN_MASK); 48 super(tr("Export to GPX ..."), "exportgpx", tr("Export the data to GPX file."), 49 ShortCut.registerShortCut("file:exportgpx", tr("Export to GPX"), KeyEvent.VK_E, ShortCut.GROUP_MENU)); 48 50 this.layer = layer; 49 51 } 50 52 … … 70 72 fn += ".gpx"; 71 73 file = new File(fn); 72 74 } 73 75 74 76 // open the dialog asking for options 75 77 JPanel p = new JPanel(new GridBagLayout()); 76 78 … … 79 81 desc.setWrapStyleWord(true); 80 82 desc.setLineWrap(true); 81 83 p.add(new JScrollPane(desc), GBC.eop().fill(GBC.BOTH)); 82 84 83 85 JCheckBox author = new JCheckBox(tr("Add author information"), Main.pref.getBoolean("lastAddAuthor", true)); 84 86 author.setSelected(true); 85 87 p.add(author, GBC.eol()); … … 104 106 JLabel warning = new JLabel("<html><font size='-2'> </html"); 105 107 p.add(warning, GBC.eol().fill(GBC.HORIZONTAL).insets(15,0,0,0)); 106 108 addDependencies(author, authorName, email, copyright, predefined, copyrightYear, nameLabel, emailLabel, copyrightLabel, copyrightYearLabel, warning); 107 109 108 110 p.add(new JLabel(tr("Keywords")), GBC.eol()); 109 111 JTextField keywords = new JTextField(); 110 112 p.add(keywords, GBC.eop().fill(GBC.HORIZONTAL)); … … 112 114 int answer = JOptionPane.showConfirmDialog(Main.parent, p, tr("Export options"), JOptionPane.OK_CANCEL_OPTION); 113 115 if (answer != JOptionPane.OK_OPTION) 114 116 return; 115 117 116 118 Main.pref.put("lastAddAuthor", author.isSelected()); 117 119 if (authorName.getText().length() != 0) 118 120 Main.pref.put("lastAuthorName", authorName.getText()); … … 135 137 } catch (IOException x) { 136 138 x.printStackTrace(); 137 139 JOptionPane.showMessageDialog(Main.parent, tr("Error while exporting {0}", fn)+":\n"+x.getMessage(), tr("Error"), JOptionPane.ERROR_MESSAGE); 138 } 140 } 139 141 } 140 142 141 143 /** 142 144 * Add all those listeners to handle the enable state of the fields. 143 * @param copyrightYearLabel 144 * @param copyrightLabel 145 * @param emailLabel 146 * @param nameLabel 147 * @param warning 145 * @param copyrightYearLabel 146 * @param copyrightLabel 147 * @param emailLabel 148 * @param nameLabel 149 * @param warning 148 150 */ 149 151 private static void addDependencies( 150 final JCheckBox author, 152 final JCheckBox author, 151 153 final JTextField authorName, 152 154 final JTextField email, 153 155 final JTextField copyright, … … 158 160 final JLabel copyrightLabel, 159 161 final JLabel copyrightYearLabel, 160 162 final JLabel warning) { 161 163 162 164 ActionListener authorActionListener = new ActionListener(){ 163 165 public void actionPerformed(ActionEvent e) { 164 166 boolean b = author.isSelected(); … … 182 184 } 183 185 }; 184 186 authorName.addKeyListener(authorNameListener); 185 187 186 188 predefined.addActionListener(new ActionListener(){ 187 189 public void actionPerformed(ActionEvent e) { 188 190 JList l = new JList(new String[]{"Creative Commons By-SA", "public domain", "GNU Lesser Public License (LGPL)", "BSD License (MIT/X11)"}); -
src/org/openstreetmap/josm/actions/DeleteAction.java
7 7 import java.awt.event.KeyEvent; 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.tools.ShortCut; 10 11 11 12 public final class DeleteAction extends JosmAction { 12 13 13 14 public DeleteAction() { 14 15 super(tr("Delete"), "dialogs/delete", tr("Delete selected objects."), 15 KeyEvent.VK_DELETE, 0, true);16 ShortCut.registerShortCut("system:delete", tr("Edit: Delete"), KeyEvent.VK_DELETE, ShortCut.GROUP_DIRECT), true); 16 17 setEnabled(true); 17 18 } 18 19 -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
15 15 import org.openstreetmap.josm.data.osm.WaySegment; 16 16 import org.openstreetmap.josm.gui.MapFrame; 17 17 import org.openstreetmap.josm.tools.ImageProvider; 18 import org.openstreetmap.josm.tools.ShortCut; 18 19 19 20 /** 20 21 * An action that enables the user to delete nodes and other objects. 21 22 * 22 * The user can click on an object, which gets deleted if possible. When Ctrl is 23 * pressed when releasing the button, the objects and all its references are 23 * The user can click on an object, which gets deleted if possible. When Ctrl is 24 * pressed when releasing the button, the objects and all its references are 24 25 * deleted. The exact definition of "all its references" are in 25 26 * {@link #deleteWithReferences deleteWithReferences}. 26 27 * … … 29 30 * 30 31 * If the user enters the mapmode and any object is selected, all selected 31 32 * objects that can be deleted will. 32 * 33 * 33 34 * @author imi 34 35 */ 35 36 public class DeleteAction extends MapMode { … … 40 41 */ 41 42 public DeleteAction(MapFrame mapFrame) { 42 43 super(tr("Delete Mode"), 43 "delete", 44 tr("Delete nodes or ways."), 45 KeyEvent.VK_D,46 mapFrame, 44 "delete", 45 tr("Delete nodes or ways."), 46 ShortCut.registerShortCut("mapmode:delete", tr("Delete mode"), KeyEvent.VK_D, ShortCut.GROUP_EDIT), 47 mapFrame, 47 48 ImageProvider.getCursor("normal", "delete")); 48 49 } 49 50 … … 57 58 Main.map.mapView.removeMouseListener(this); 58 59 } 59 60 60 61 61 62 @Override public void actionPerformed(ActionEvent e) { 62 63 super.actionPerformed(e); 63 64 if(!Main.map.mapView.isDrawableLayer()) … … 96 97 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 97 98 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 98 99 boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 99 100 100 101 OsmPrimitive sel = Main.map.mapView.getNearestNode(e.getPoint()); 101 102 Command c = null; 102 103 if (sel == null) { 103 104 WaySegment ws = Main.map.mapView.getNearestWaySegment(e.getPoint()); 104 105 if (ws != null) { 105 106 if (shift) { 106 c = DeleteCommand.deleteWaySegment(ws); 107 c = DeleteCommand.deleteWaySegment(ws); 107 108 } else if (ctrl) { 108 109 c = DeleteCommand.deleteWithReferences(Collections.singleton((OsmPrimitive)ws.way)); 109 110 } else { … … 121 122 122 123 Main.map.mapView.repaint(); 123 124 } 124 125 125 126 @Override public String getModeHelpText() { 126 127 return tr("Click to delete. Shift: delete way segment. Alt: don't delete unused nodes when deleting a way. Ctrl: delete referring objects."); 127 128 } -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
11 11 import org.openstreetmap.josm.actions.JosmAction; 12 12 import org.openstreetmap.josm.gui.MapFrame; 13 13 import org.openstreetmap.josm.tools.ImageProvider; 14 import org.openstreetmap.josm.tools.ShortCut; 14 15 15 16 /** 16 17 * A class implementing MapMode is able to be selected as an mode for map editing. 17 18 * As example scrolling the map is a MapMode, connecting Nodes to new Ways 18 19 * is another. 19 * 20 * 20 21 * MapModes should register/deregister all necessary listeners on the map's view 21 * control. 22 * control. 22 23 */ 23 24 abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener { 24 25 private final Cursor cursor; … … 27 28 /** 28 29 * Constructor for mapmodes without an menu 29 30 */ 31 public MapMode(String name, String iconName, String tooltip, ShortCut shortCut, MapFrame mapFrame, Cursor cursor) { 32 super(name, "mapmode/"+iconName, tooltip, shortCut, false); 33 this.cursor = cursor; 34 putValue("active", false); 35 } 36 37 /** 38 * Constructor for mapmodes without an menu 39 */ 40 @Deprecated 30 41 public MapMode(String name, String iconName, String tooltip, int keystroke, MapFrame mapFrame, Cursor cursor) { 31 42 super(name, "mapmode/"+iconName, tooltip, keystroke, 0, false); 32 43 this.cursor = cursor; … … 58 69 Main.map.statusLine.setHelpText(getModeHelpText()); 59 70 Main.map.statusLine.repaint(); 60 71 } 61 72 62 73 public String getModeHelpText() { 63 74 return ""; 64 75 } -
src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
12 12 import org.openstreetmap.josm.gui.SelectionManager; 13 13 import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; 14 14 import org.openstreetmap.josm.tools.ImageProvider; 15 import org.openstreetmap.josm.tools.ShortCut; 15 16 16 17 /** 17 * Enable the zoom mode within the MapFrame. 18 * 19 * Holding down the left mouse button select a rectangle with the same aspect 18 * Enable the zoom mode within the MapFrame. 19 * 20 * Holding down the left mouse button select a rectangle with the same aspect 20 21 * ratio than the current map view. 21 22 * Holding down left and right let the user move the former selected rectangle. 22 23 * Releasing the left button zoom to the selection. 23 * 24 * Rectangle selections with either height or width smaller than 3 pixels 24 * 25 * Rectangle selections with either height or width smaller than 3 pixels 25 26 * are ignored. 26 * 27 * 27 28 * @author imi 28 29 */ 29 30 public class ZoomAction extends MapMode implements SelectionEnded { … … 44 45 * @param mapFrame The MapFrame, whose zoom mode should be enabled. 45 46 */ 46 47 public ZoomAction(MapFrame mapFrame) { 47 super(tr("Zoom"), "zoom", tr("Zoom and move map"), KeyEvent.VK_Z, mapFrame, ImageProvider.getCursor("normal", "zoom")); 48 super(tr("Zoom"), "zoom", tr("Zoom and move map"), 49 ShortCut.registerShortCut("mapmode:zoom", tr("Zoom mode"), KeyEvent.VK_Z, ShortCut.GROUP_EDIT), 50 mapFrame, ImageProvider.getCursor("normal", "zoom")); 48 51 mv = mapFrame.mapView; 49 52 selectionManager = new SelectionManager(this, true, mv); 50 53 } … … 69 72 super.exitMode(); 70 73 selectionManager.unregister(mv); 71 74 } 72 75 73 76 @Override public String getModeHelpText() { 74 77 return tr("Zoom by dragging or Ctrl+. or Ctrl+,; move with Ctrl+up,left,down,right; move zoom with right button"); 75 78 } -
src/org/openstreetmap/josm/actions/mapmode/PlayHeadDragMode.java
11 11 import org.openstreetmap.josm.Main; 12 12 import org.openstreetmap.josm.data.coor.EastNorth; 13 13 import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker; 14 import org.openstreetmap.josm.tools.ShortCut; 14 15 15 16 /** 16 17 * Singleton marker class to track position of audio. 17 * 18 * 18 19 * @author david.earl 19 20 * 20 21 */ … … 24 25 private Point mousePos = null; 25 26 private Point mouseStart = null; 26 27 private PlayHeadMarker playHeadMarker = null; 27 28 28 29 public PlayHeadDragMode(PlayHeadMarker m) { 29 super("play head drag", "playheaddrag", "play head trag", 0, Main.map, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 30 super("play head drag", "playheaddrag", "play head drag", null, 31 Main.map, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 30 32 playHeadMarker = m; 31 33 } 32 34 33 35 @Override public void enterMode() { 34 36 super.enterMode(); 35 37 Main.map.mapView.addMouseListener(this); … … 73 75 } else { 74 76 playHeadMarker.synchronize(en); 75 77 } 76 mousePos = null; 78 mousePos = null; 77 79 dragging = false; 78 80 79 81 /* -
src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
51 51 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 52 52 import org.openstreetmap.josm.tools.ImageProvider; 53 53 import org.openstreetmap.josm.tools.Pair; 54 import org.openstreetmap.josm.tools.ShortCut; 54 55 55 56 /** 56 57 * 57 */ 58 */ 58 59 public class DrawAction extends MapMode implements MapViewPaintable, SelectionChangedListener, AWTEventListener { 59 60 60 61 private static Node lastUsedNode = null; 61 62 private double PHI=Math.toRadians(90); 62 63 … … 67 68 private boolean drawHelperLine; 68 69 private Point mousePos; 69 70 private Color selectedColor; 70 71 71 72 private Node currentBaseNode; 72 73 private EastNorth currentMouseEastNorth; 73 74 74 75 public DrawAction(MapFrame mapFrame) { 75 76 super(tr("Draw"), "node/autonode", tr("Draw nodes"), 76 KeyEvent.VK_A, mapFrame, getCursor()); 77 ShortCut.registerShortCut("mapmode:draw", tr("Draw mode"), KeyEvent.VK_A, ShortCut.GROUP_EDIT), 78 mapFrame, getCursor()); 77 79 78 80 // Add extra shortcut N 79 81 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 80 KeyStroke.getKeyStroke(KeyEvent.VK_N, 0), tr("Draw"));81 82 ShortCut.registerShortCut("mapmode:draw2", tr("Draw mode (2)"), KeyEvent.VK_N, ShortCut.GROUP_EDIT).getKeyStroke(), tr("Draw")); 83 82 84 //putValue("help", "Action/AddNode/Autnode"); 83 85 selectedColor = Main.pref.getColor(marktr("selected"), Color.YELLOW); 84 86 85 87 drawHelperLine = Main.pref.getBoolean("draw.helper-line", true); 86 88 } 87 89 … … 117 119 } catch (SecurityException ex) { 118 120 } 119 121 } 120 122 121 123 /** 122 124 * redraw to (possibly) get rid of helper line if selection changes. 123 125 */ … … 143 145 * If user clicked with the left button, add a node at the current mouse 144 146 * position. 145 147 * 146 * If in nodeway mode, insert the node into the way. 148 * If in nodeway mode, insert the node into the way. 147 149 */ 148 150 @Override public void mouseClicked(MouseEvent e) { 149 151 … … 159 161 alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 160 162 shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 161 163 mousePos = e.getPoint(); 162 164 163 165 Collection<OsmPrimitive> selection = Main.ds.getSelected(); 164 166 Collection<Command> cmds = new LinkedList<Command>(); 165 167 … … 167 169 replacedWays = new ArrayList<Way>(); 168 170 boolean newNode = false; 169 171 Node n = null; 170 172 171 173 if (!ctrl) { 172 174 n = Main.map.mapView.getNearestNode(mousePos); 173 175 } 174 176 175 177 if (n != null) { 176 178 // user clicked on node 177 179 if (shift || selection.isEmpty()) { … … 181 183 Main.ds.setSelected(n); 182 184 return; 183 185 } 184 186 185 187 } else { 186 188 // no node found in clicked area 187 189 n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY())); … … 231 233 adjustNode(segSet, n); 232 234 } 233 235 } 234 236 235 237 // This part decides whether or not a "segment" (i.e. a connection) is made to an 236 238 // existing node. 237 239 238 240 // For a connection to be made, the user must either have a node selected (connection 239 241 // is made to that node), or he must have a way selected *and* one of the endpoints 240 242 // of that way must be the last used node (connection is made to last used node), or 241 243 // he must have a way and a node selected (connection is made to the selected node). 242 244 243 245 boolean extendedWay = false; 244 246 245 247 if (!shift && selection.size() > 0 && selection.size() < 3) { 246 248 247 249 Node selectedNode = null; 248 250 Way selectedWay = null; 249 251 250 252 for (OsmPrimitive p : selection) { 251 253 if (p instanceof Node) { 252 254 if (selectedNode != null) return; … … 256 258 selectedWay = (Way) p; 257 259 } 258 260 } 259 261 260 262 // the node from which we make a connection 261 263 Node n0 = null; 262 264 263 265 if (selectedNode == null) { 264 266 if (selectedWay == null) return; 265 267 if (lastUsedNode == selectedWay.nodes.get(0) || lastUsedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) { … … 270 272 } else { 271 273 if (selectedNode == selectedWay.nodes.get(0) || selectedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) { 272 274 n0 = selectedNode; 273 } 275 } 274 276 } 275 277 276 278 if (n0 == null || n0 == n) { 277 279 return; // Don't create zero length way segments. 278 280 } 279 281 280 // Ok we know now that we'll insert a line segment, but will it connect to an 282 // Ok we know now that we'll insert a line segment, but will it connect to an 281 283 // existing way or make a new way of its own? The "alt" modifier means that the 282 284 // user wants a new way. 283 285 284 286 Way way = alt ? null : (selectedWay != null) ? selectedWay : getWayForNode(n0); 285 287 if (way == null) { 286 288 way = new Way(); … … 327 329 } 328 330 329 331 Command c = new SequenceCommand(title, cmds); 330 332 331 333 Main.main.undoRedo.add(c); 332 334 lastUsedNode = n; 333 335 computeHelperLine(); 334 336 Main.map.mapView.repaint(); 335 337 } 336 338 337 339 @Override public void mouseMoved(MouseEvent e) { 338 340 if(!Main.map.mapView.isDrawableLayer()) 339 341 return; … … 341 343 // we copy ctrl/alt/shift from the event just in case our global 342 344 // AWTEvent didn't make it through the security manager. Unclear 343 345 // if that can ever happen but better be safe. 344 346 345 347 ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 346 348 alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 347 349 shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 348 350 mousePos = e.getPoint(); 349 351 350 352 computeHelperLine(); 351 353 } 352 354 353 355 /** 354 356 * This method prepares data required for painting the "helper line" from 355 357 * the last used position to the mouse cursor. It duplicates some code from … … 362 364 currentBaseNode = null; 363 365 return; 364 366 } 365 367 366 368 double distance = -1; 367 369 double angle = -1; 368 370 … … 380 382 if (!ctrl && mousePos != null) { 381 383 currentMouseNode = Main.map.mapView.getNearestNode(mousePos); 382 384 } 383 385 384 386 if (currentMouseNode != null) { 385 387 // user clicked on node 386 388 if (selection.isEmpty()) return; … … 390 392 // no node found in clicked area 391 393 currentMouseEastNorth = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y); 392 394 } 393 395 394 396 for (OsmPrimitive p : selection) { 395 397 if (p instanceof Node) { 396 398 if (selectedNode != null) return; … … 400 402 selectedWay = (Way) p; 401 403 } 402 404 } 403 405 404 406 // the node from which we make a connection 405 407 currentBaseNode = null; 406 408 Node previousNode = null; 407 409 408 410 if (selectedNode == null) { 409 411 if (selectedWay == null) return; 410 412 if (lastUsedNode == selectedWay.nodes.get(0) || lastUsedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) { … … 418 420 } else { 419 421 if (selectedNode == selectedWay.nodes.get(0) || selectedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) { 420 422 currentBaseNode = selectedNode; 421 } 423 } 422 424 } 423 425 424 426 if (currentBaseNode == null || currentBaseNode == currentMouseNode) { 425 427 return; // Don't create zero length way segments. 426 428 } … … 442 444 443 445 Main.map.mapView.repaint(); 444 446 } 445 447 446 448 /** 447 449 * Repaint on mouse exit so that the helper line goes away. 448 450 */ … … 452 454 mousePos = e.getPoint(); 453 455 Main.map.mapView.repaint(); 454 456 } 455 457 456 458 /** 457 * @return If the node is the end of exactly one way, return this. 459 * @return If the node is the end of exactly one way, return this. 458 460 * <code>null</code> otherwise. 459 461 */ 460 462 public static Way getWayForNode(Node n) { … … 490 492 /** 491 493 * Adjusts the position of a node to lie on a segment (or a segment 492 494 * intersection). 493 * 495 * 494 496 * If one or more than two segments are passed, the node is adjusted 495 497 * to lie on the first segment that is passed. 496 * 498 * 497 499 * If two segments are passed, the node is adjusted to be at their 498 500 * intersection. 499 * 501 * 500 502 * No action is taken if no segments are passed. 501 * 503 * 502 504 * @param segs the segments to use as a reference when adjusting 503 505 * @param n the node to adjust 504 506 */ 505 507 private static void adjustNode(Collection<Pair<Node,Node>> segs, Node n) { 506 508 507 509 switch (segs.size()) { 508 510 case 0: 509 511 return; 510 512 case 2: 511 513 // algorithm used here is a bit clumsy, anyone's welcome to replace 512 514 // it by something else. All it does it compute the intersection between 513 // the two segments and adjust the node position. The code doesnt 515 // the two segments and adjust the node position. The code doesnt 514 516 Iterator<Pair<Node,Node>> i = segs.iterator(); 515 517 Pair<Node,Node> seg = i.next(); 516 518 EastNorth A = seg.a.eastNorth; … … 527 529 det(C.east(), C.north(), D.east(), D.north()), C.north() - D.north())/ 528 530 det(A.east() - B.east(), A.north() - B.north(), C.east() - D.east(), C.north() - D.north()) 529 531 ); 530 532 531 533 // only adjust to intersection if within 10 pixel of mouse click; otherwise 532 534 // fall through to default action. 533 535 // (for semi-parallel lines, intersection might be miles away!) … … 535 537 n.eastNorth = intersection; 536 538 return; 537 539 } 538 540 539 541 default: 540 542 EastNorth P = n.eastNorth; 541 543 seg = segs.iterator().next(); … … 550 552 B.north() + q * (A.north() - B.north())); 551 553 } 552 554 } 553 555 554 556 // helper for adjustNode 555 557 static double det(double a, double b, double c, double d) 556 558 { 557 559 return a * d - b * c; 558 560 } 559 561 560 562 public void paint(Graphics g, MapView mv) { 561 563 562 564 // don't draw line if disabled in prefs 563 565 if (!drawHelperLine) return; 564 566 565 567 // sanity checks 566 568 if (Main.map.mapView == null) return; 567 569 if (mousePos == null) return; 568 570 569 571 // if shift key is held ("no auto-connect"), don't draw a line 570 572 if (shift) return; 571 573 572 574 // don't draw line if we don't know where from or where to 573 575 if (currentBaseNode == null) return; 574 576 if (currentMouseEastNorth == null) return; 575 577 576 578 // don't draw line if mouse is outside window 577 579 if (!Main.map.mapView.getBounds().contains(mousePos)) return; 578 580 579 581 Graphics2D g2 = (Graphics2D) g; 580 582 g2.setColor(selectedColor); 581 583 g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); … … 584 586 Point p2=mv.getPoint(currentMouseEastNorth); 585 587 586 588 double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI; 587 589 588 590 b.moveTo(p1.x,p1.y); b.lineTo(p2.x, p2.y); 589 591 590 592 // if alt key is held ("start new way"), draw a little perpendicular line 591 593 if (alt) { 592 594 b.moveTo((int)(p1.x + 8*Math.cos(t+PHI)), (int)(p1.y + 8*Math.sin(t+PHI))); 593 595 b.lineTo((int)(p1.x + 8*Math.cos(t-PHI)), (int)(p1.y + 8*Math.sin(t-PHI))); 594 596 } 595 597 596 598 g2.draw(b); 597 g2.setStroke(new BasicStroke(1)); 599 g2.setStroke(new BasicStroke(1)); 598 600 599 601 } 600 602 601 603 @Override public String getModeHelpText() { 602 604 String rv; 603 605 604 606 if (currentBaseNode != null && !shift) { 605 607 if (mouseOnExistingNode) { 606 608 if (alt && /* FIXME: way exists */true) 607 609 rv = tr("Click to create a new way to the existing node."); 608 else 610 else 609 611 rv =tr("Click to make a connection to the existing node."); 610 612 } else { 611 613 if (alt && /* FIXME: way exists */true) 612 614 rv = tr("Click to insert a node and create a new way."); 613 else 615 else 614 616 rv = tr("Click to insert a new node and make a connection."); 615 617 } 616 618 } -
src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
35 35 import org.openstreetmap.josm.gui.SelectionManager; 36 36 import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; 37 37 import org.openstreetmap.josm.tools.ImageProvider; 38 import org.openstreetmap.josm.tools.ShortCut; 39 38 40 /** 39 41 * Move is an action that can move all kind of OsmPrimitives (except keys for now). 40 42 * … … 42 44 * If an unselected object is under the mouse when dragging, it becomes selected 43 45 * and will be moved. 44 46 * If no object is under the mouse, move all selected objects (if any) 45 * 47 * 46 48 * @author imi 47 49 */ 48 50 public class SelectAction extends MapMode implements SelectionEnded { … … 64 66 */ 65 67 private Point mousePos; 66 68 private SelectionManager selectionManager; 67 69 68 70 /** 69 71 * The time which needs to pass between click and release before something 70 72 * counts as a move, in milliseconds … … 83 85 */ 84 86 public SelectAction(MapFrame mapFrame) { 85 87 super(tr("Select"), "move/move", tr("Select, move and rotate objects"), 86 KeyEvent.VK_S, mapFrame, 88 ShortCut.registerShortCut("mapmode:select", tr("Select mode"), KeyEvent.VK_S, ShortCut.GROUP_EDIT), 89 mapFrame, 87 90 getCursor("normal", "selection", Cursor.DEFAULT_CURSOR)); 88 91 putValue("help", "Action/Move/Move"); 89 selectionManager = new SelectionManager(this, false, mapFrame.mapView); 92 selectionManager = new SelectionManager(this, false, mapFrame.mapView); 90 93 try { initialMoveDelay = Integer.parseInt(Main.pref.get("edit.initial-move-delay","200")); } catch (NumberFormatException x) {} 91 94 try { initialMoveThreshold = Integer.parseInt(Main.pref.get("edit.initial-move-threshold","5")); } catch (NumberFormatException x) {} 92 95 93 96 } 94 97 95 98 private static Cursor getCursor(String name, String mod, int def) { … … 113 116 oldCursor = null; 114 117 } 115 118 } 116 119 117 120 @Override public void enterMode() { 118 121 super.enterMode(); 119 122 Main.map.mapView.addMouseListener(this); … … 152 155 mousePos = e.getPoint(); 153 156 return; 154 157 } 155 158 156 159 if (!initialMoveThresholdExceeded) { 157 160 int dxp = mousePos.x - e.getX(); 158 161 int dyp = mousePos.y - e.getY(); … … 160 163 if (dp < initialMoveThreshold) return; 161 164 initialMoveThresholdExceeded = true; 162 165 } 163 166 164 167 EastNorth mouseEN = Main.map.mapView.getEastNorth(e.getX(), e.getY()); 165 168 EastNorth mouseStartEN = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y); 166 169 double dx = mouseEN.east() - mouseStartEN.east(); … … 183 186 } else { 184 187 Collection<OsmPrimitive> selection = Main.ds.getSelected(); 185 188 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 186 189 187 190 // when rotating, having only one node makes no sense - quit silently 188 if (mode == Mode.rotate && affectedNodes.size() < 2) 191 if (mode == Mode.rotate && affectedNodes.size() < 2) 189 192 return; 190 193 191 194 Command c = !Main.main.undoRedo.commands.isEmpty() … … 231 234 OsmPrimitive osm = c.getNearestNode(p); 232 235 virtualWay = null; 233 236 virtualNode = null; 234 237 235 238 if (osm == null) 236 239 { 237 240 WaySegment nearestWaySeg = c.getNearestWaySegment(p); … … 256 259 } 257 260 } 258 261 } 259 if (osm == null) 262 if (osm == null) 260 263 return Collections.emptySet(); 261 264 return Collections.singleton(osm); 262 265 } … … 264 267 /** 265 268 * Look, whether any object is selected. If not, select the nearest node. 266 269 * If there are no nodes in the dataset, do nothing. 267 * 270 * 268 271 * If the user did not press the left mouse button, do nothing. 269 * 270 * Also remember the starting position of the movement and change the mouse 272 * 273 * Also remember the starting position of the movement and change the mouse 271 274 * cursor to movement. 272 275 */ 273 276 @Override public void mousePressed(MouseEvent e) { … … 277 280 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 278 281 // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 279 282 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 280 283 281 284 mouseDownTime = System.currentTimeMillis(); 282 285 didMove = false; 283 286 initialMoveThresholdExceeded = false; … … 376 379 Main.ds.setSelected(curSel); 377 380 Main.map.mapView.repaint(); 378 381 } 379 382 380 383 @Override public String getModeHelpText() { 381 384 if (mode == Mode.select) { 382 385 return tr("Release the mouse button to select the objects in the rectangle."); -
src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
29 29 import org.openstreetmap.josm.gui.MapView; 30 30 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 31 31 import org.openstreetmap.josm.tools.ImageProvider; 32 import org.openstreetmap.josm.tools.ShortCut; 33 32 34 /** 33 35 * Makes a rectangle from a line, or modifies a rectangle. 34 * 36 * 35 37 * This class currently contains some "sleeping" code copied from DrawAction (move and rotate) 36 38 * which can eventually be removed, but it may also get activated here and removed in DrawAction. 37 39 */ … … 46 48 double xoff; 47 49 double yoff; 48 50 double distance; 49 51 50 52 /** 51 53 * The old cursor before the user pressed the mouse button. 52 54 */ 53 55 private Cursor oldCursor; 54 56 /** 55 * The current position of the mouse 57 * The current position of the mouse 56 58 */ 57 59 private Point mousePos; 58 /** 60 /** 59 61 * The position of the mouse cursor when the drag action was initiated. 60 62 */ 61 63 private Point initialMousePos; … … 71 73 */ 72 74 public ExtrudeAction(MapFrame mapFrame) { 73 75 super(tr("Extrude"), "extrude/extrude", tr("Create areas"), 74 KeyEvent.VK_X, mapFrame, 76 ShortCut.registerShortCut("mapmode:extrude", tr("Extrude mode"), KeyEvent.VK_X, ShortCut.GROUP_EDIT), 77 mapFrame, 75 78 getCursor("normal", "selection", Cursor.DEFAULT_CURSOR)); 76 79 putValue("help", "Action/Extrude/Extrude"); 77 80 initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay",200); … … 99 102 oldCursor = null; 100 103 } 101 104 } 102 105 103 106 @Override public void enterMode() { 104 107 super.enterMode(); 105 108 Main.map.mapView.addMouseListener(this); … … 121 124 */ 122 125 @Override public void mouseDragged(MouseEvent e) { 123 126 if (mode == Mode.select) return; 124 127 125 128 // do not count anything as a move if it lasts less than 100 milliseconds. 126 129 if ((mode == Mode.EXTRUDE) && (System.currentTimeMillis() - mouseDownTime < initialMoveDelay)) return; 127 130 … … 136 139 mousePos = e.getPoint(); 137 140 return; 138 141 } 139 142 140 143 Main.map.mapView.repaint(); 141 144 mousePos = e.getPoint(); 142 145 … … 146 149 if (selectedSegment != null) { 147 150 Node n1 = selectedSegment.way.nodes.get(selectedSegment.lowerIndex); 148 151 Node n2 = selectedSegment.way.nodes.get(selectedSegment.lowerIndex+1); 149 152 150 153 EastNorth en1 = n1.eastNorth; 151 154 EastNorth en2 = n2.eastNorth; 152 155 if (en1.east() < en2.east()) { en2 = en1; en1 = n2.eastNorth; } 153 156 EastNorth en3 = mv.getEastNorth(mousePos.x, mousePos.y); 154 157 155 158 double u = ((en3.east()-en1.east())*(en2.east()-en1.east()) + (en3.north()-en1.north())*(en2.north()-en1.north()))/en2.distanceSq(en1); 156 159 // the point on the segment from which the distance to mouse pos is shortest 157 160 EastNorth base = new EastNorth(en1.east()+u*(en2.east()-en1.east()), en1.north()+u*(en2.north()-en1.north())); 158 161 159 162 // the distance, in projection units, between the base point and the mouse cursor 160 163 double len = base.distance(en3); 161 164 162 165 // find out the distance, in metres, between the base point and the mouse cursor 163 166 distance = Main.proj.eastNorth2latlon(base).greatCircleDistance(Main.proj.eastNorth2latlon(en3)); 164 167 Main.map.statusLine.setDist(distance); 165 168 updateStatusLine(); 166 169 167 170 // compute the angle at which the segment is drawn 168 171 // and use it to compute the x and y offsets for the 169 // corner points. 172 // corner points. 170 173 double sin_alpha = (en2.north()-en1.north())/en2.distance(en1); 171 174 172 175 // this is a kludge because sometimes extrusion just goes the wrong direction 173 176 if ((en3.east()>base.east()) ^ (sin_alpha < 0)) len=-len; 174 177 xoff = sin_alpha * len; 175 178 yoff = Math.sqrt(1-sin_alpha*sin_alpha) * len; 176 179 177 180 Graphics2D g2 = (Graphics2D) g; 178 181 g2.setColor(selectedColor); 179 182 g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); … … 182 185 Point p2=mv.getPoint(en2); 183 186 Point p3=mv.getPoint(en1.add(-xoff, -yoff)); 184 187 Point p4=mv.getPoint(en2.add(-xoff, -yoff)); 185 188 186 189 b.moveTo(p1.x,p1.y); b.lineTo(p3.x, p3.y); 187 190 b.lineTo(p4.x, p4.y); b.lineTo(p2.x, p2.y); 188 191 b.lineTo(p1.x,p1.y); 189 192 g2.draw(b); 190 g2.setStroke(new BasicStroke(1)); 193 g2.setStroke(new BasicStroke(1)); 191 194 } 192 195 } 193 196 194 197 /** 195 198 */ 196 199 @Override public void mousePressed(MouseEvent e) { … … 200 203 // boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 201 204 // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 202 205 // boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 203 206 204 207 mouseDownTime = System.currentTimeMillis(); 205 208 206 209 selectedSegment = 207 210 Main.map.mapView.getNearestWaySegment(e.getPoint()); 208 211 … … 241 244 Command c = new SequenceCommand(tr("Extrude Way"), cmds); 242 245 Main.main.undoRedo.add(c); 243 246 } 244 247 245 248 Main.map.mapView.removeTemporaryLayer(this); 246 249 mode = null; 247 250 updateStatusLine(); 248 Main.map.mapView.repaint(); 251 Main.map.mapView.repaint(); 249 252 } 250 253 251 254 @Override public String getModeHelpText() { -
src/org/openstreetmap/josm/actions/UndoAction.java
8 8 import java.awt.event.KeyEvent; 9 9 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.tools.ShortCut; 11 12 12 13 13 /** 14 14 * Undoes the last command. 15 * 15 * 16 16 * @author imi 17 17 */ 18 18 public class UndoAction extends JosmAction { … … 21 21 * Construct the action with "Undo" as label. 22 22 */ 23 23 public UndoAction() { 24 super(tr("Undo"), "undo", tr("Undo the last action."), KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK, true); 24 super(tr("Undo"), "undo", tr("Undo the last action."), 25 ShortCut.registerShortCut("system:undo", tr("Edit: Undo"), KeyEvent.VK_Z, ShortCut.GROUP_MENU), true); 25 26 setEnabled(false); 26 27 } 27 28 -
src/org/openstreetmap/josm/actions/AlignInRectangleAction.java
19 19 import org.openstreetmap.josm.data.osm.Node; 20 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 21 import org.openstreetmap.josm.data.osm.Way; 22 import org.openstreetmap.josm.tools.ShortCut; 22 23 23 24 /** 24 * Aligns all selected nodes within a rectangle. 25 * 25 * Aligns all selected nodes within a rectangle. 26 * 26 27 * There are many ways this could be done, for example: 27 28 * - find smallest rectangle to contain all points (rectangular hull) OR 28 29 * - find largest rectangle to fit inside OR 29 30 * - find both and compute the average 30 * 31 * 31 32 * Also, it would be possible to let the user specify more input, e.g. 32 33 * two nodes that should remain where they are. 33 * 34 * 34 35 * This method uses the following algorithm: 35 36 * 1. compute "heading" of all four edges 36 37 * 2. select the edge that is oriented closest to the average of all headings … … 39 40 public final class AlignInRectangleAction extends JosmAction { 40 41 41 42 public AlignInRectangleAction() { 42 super(tr("Align Nodes in Rectangle"), "alignrect", tr("Move the selected nodes into a rectangle."), KeyEvent.VK_Q, 0, true); 43 super(tr("Align Nodes in Rectangle"), "alignrect", tr("Move the selected nodes into a rectangle."), 44 ShortCut.registerShortCut("tools:alignrect", tr("Tool: Align in rectangle"), KeyEvent.VK_Q, ShortCut.GROUP_EDIT), true); 43 45 } 44 46 45 47 public void actionPerformed(ActionEvent e) { 46 48 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 47 49 Way myWay = null; 48 if (sel.size() == 1) 50 if (sel.size() == 1) 49 51 for (OsmPrimitive osm : sel) 50 52 if (osm instanceof Way) 51 53 myWay = (Way) osm; 52 54 53 55 if ((myWay == null) || (myWay.nodes.size() != 5) || (!myWay.nodes.get(0).equals(myWay.nodes.get(4)))) { 54 56 JOptionPane.showMessageDialog(Main.parent, tr("Please select one circular way of exactly four nodes.")); 55 57 return; … … 66 68 avg_angle += angle[i]; 67 69 } 68 70 avg_angle /= 4; 69 71 70 72 // select edge that is closest to average, and use it as the base for the following 71 double best_dist = 0; 73 double best_dist = 0; 72 74 int base = 0; 73 75 for (int i=0; i<4; i++) 74 76 { … … 85 87 EastNorth end = en[(base+1)%4]; // second node of base segment 86 88 EastNorth next = en[(base+2)%4]; // node following the second node of the base seg 87 89 EastNorth prev= en[(base+3)%4]; // node before the first node of the base seg 88 90 89 91 // find a parallel to the base segment 90 92 double base_slope = (end.north() - begin.north()) / (end.east() - begin.east()); 91 93 // base intercept of parallels that go through "next" and "prev" points … … 101 103 // same for "prev" 102 104 u = ((prev.east()-begin.east())*(end.east()-begin.east()) + (prev.north()-begin.north())*(end.north()-begin.north()))/end.distanceSq(begin); 103 105 EastNorth begin2 = new EastNorth(begin.east()+u*(end.east()-begin.east()), begin.north()+u*(end.north()-begin.north())); 104 105 // new "begin" and "end" points are halfway between their old position and 106 107 // new "begin" and "end" points are halfway between their old position and 106 108 // the base points found above 107 109 end = new EastNorth((end2.east()+end.east())/2, (end2.north()+end.north())/2); 108 110 begin = new EastNorth((begin2.east()+begin.east())/2, (begin2.north()+begin.north())/2); 109 111 110 112 double other_slope = -1 / base_slope; 111 113 double next_b = end.north() - other_slope * end.east(); 112 114 double prev_b = begin.north() - other_slope * begin.east(); 113 115 114 116 double x = (opposite_b-next_b)/(other_slope-base_slope); 115 117 double y = opposite_b + base_slope * x; 116 118 next = new EastNorth(x, y); 117 119 118 120 x = (opposite_b-prev_b)/(other_slope-base_slope); 119 121 y = opposite_b + base_slope * x; 120 122 prev = new EastNorth(x, y); 121 123 122 124 Collection<Command> cmds = new LinkedList<Command>(); 123 125 for (int i=0; i<4; i++) { 124 126 Node n = myWay.nodes.get(i); -
src/org/openstreetmap/josm/actions/DownloadAction.java
16 16 import org.openstreetmap.josm.gui.download.DownloadDialog; 17 17 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 18 18 import org.openstreetmap.josm.tools.GBC; 19 import org.openstreetmap.josm.tools.ShortCut; 19 20 20 21 /** 21 22 * Action that opens a connection to the osm server and downloads map data. … … 26 27 * @author imi 27 28 */ 28 29 public class DownloadAction extends JosmAction { 29 30 30 31 public DownloadDialog dialog; 31 32 32 33 public DownloadAction() { 33 super(tr("Download from OSM ..."), "download", tr("Download map data from the OSM server."), KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true); 34 super(tr("Download from OSM ..."), "download", tr("Download map data from the OSM server."), 35 ShortCut.registerShortCut("file:download", tr("File: Download"), KeyEvent.VK_D, ShortCut.GROUPS_ALT1+ShortCut.GROUP_HOTKEY), true); 34 36 } 35 37 36 38 public void actionPerformed(ActionEvent e) { 37 39 dialog = new DownloadDialog(); 38 40 39 41 JPanel downPanel = new JPanel(new GridBagLayout()); 40 42 downPanel.add(dialog, GBC.eol().fill(GBC.BOTH)); 41 43 -
src/org/openstreetmap/josm/actions/DuplicateAction.java
12 12 import org.openstreetmap.josm.data.SelectionChangedListener; 13 13 import org.openstreetmap.josm.data.osm.DataSet; 14 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.tools.ShortCut; 15 16 16 17 public final class DuplicateAction extends JosmAction implements SelectionChangedListener { 17 18 18 19 public DuplicateAction() { 19 20 super(tr("Duplicate"), "duplicate", 20 21 tr("Duplicate selection by copy and immediate paste."), 21 KeyEvent.VK_D, KeyEvent.CTRL_MASK, true);22 ShortCut.registerShortCut("system:duplicate", tr("Edit: Duplicate selection"), KeyEvent.VK_D, ShortCut.GROUP_MENU), true); 22 23 setEnabled(false); 23 DataSet.selListeners.add(this);24 DataSet.selListeners.add(this); 24 25 } 25 26 26 27 public void actionPerformed(ActionEvent e) { 27 28 Main.main.menu.copy.actionPerformed(e); 28 29 Main.main.menu.paste.actionPerformed(e); 29 30 } 30 31 31 32 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 32 33 setEnabled(! newSelection.isEmpty()); 33 34 } -
src/org/openstreetmap/josm/actions/AboutAction.java
33 33 import org.openstreetmap.josm.tools.GBC; 34 34 import org.openstreetmap.josm.tools.ImageProvider; 35 35 import org.openstreetmap.josm.tools.UrlLabel; 36 import org.openstreetmap.josm.tools.ShortCut; 36 37 37 38 /** 38 39 * Nice about screen. I guess every application need one these days.. *sigh* 39 * 40 * The REVISION resource is read and if present, it shows the revision 40 * 41 * The REVISION resource is read and if present, it shows the revision 41 42 * information of the jar-file. 42 * 43 * 43 44 * @author imi 44 45 */ 45 46 public class AboutAction extends JosmAction { … … 64 65 static public String getVersion() { 65 66 return version; 66 67 } 67 68 68 69 public AboutAction() { 69 super(tr("About"), "about", tr("Display the about screen."), KeyEvent.VK_F1, KeyEvent.SHIFT_DOWN_MASK, true);70 super(tr("About"), "about", tr("Display the about screen."), ShortCut.registerShortCut("system:about", tr("About..."), KeyEvent.VK_F1, ShortCut.GROUP_DIRECT), true); 70 71 } 71 72 72 73 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/PasteAction.java
23 23 import org.openstreetmap.josm.data.osm.RelationMember; 24 24 import org.openstreetmap.josm.data.osm.Way; 25 25 import org.openstreetmap.josm.data.coor.EastNorth; 26 import org.openstreetmap.josm.tools.ShortCut; 26 27 27 28 public final class PasteAction extends JosmAction { 28 29 29 30 public PasteAction() { 30 super(tr("Paste"), "paste", 31 tr("Paste contents of paste buffer."), 32 KeyEvent.VK_V, KeyEvent.CTRL_MASK, true); 33 setEnabled(false); 31 super(tr("Paste"), "paste", tr("Paste contents of paste buffer."), 32 ShortCut.registerShortCut("system:paste", tr("Edit: Paste"), KeyEvent.VK_V, ShortCut.GROUP_MENU), true); 33 setEnabled(false); 34 34 } 35 35 36 36 public void actionPerformed(ActionEvent e) { 37 37 DataSet pasteBuffer = Main.pasteBuffer; 38 38 39 /* Find the middle of the pasteBuffer area */ 39 /* Find the middle of the pasteBuffer area */ 40 40 double maxEast = -1E100, minEast = 1E100, maxNorth = -1E100, minNorth = 1E100; 41 41 for (Node n : pasteBuffer.nodes) { 42 42 double east = n.eastNorth.east(); 43 43 double north = n.eastNorth.north(); 44 if (east > maxEast) { maxEast = east; } 45 if (east < minEast) { minEast = east; } 46 if (north > maxNorth) { maxNorth = north; } 47 if (north < minNorth) { minNorth = north; } 44 if (east > maxEast) { maxEast = east; } 45 if (east < minEast) { minEast = east; } 46 if (north > maxNorth) { maxNorth = north; } 47 if (north < minNorth) { minNorth = north; } 48 48 } 49 49 50 50 EastNorth mPosition; … … 56 56 57 57 double offsetEast = mPosition.east() - (maxEast + minEast)/2.0; 58 58 double offsetNorth = mPosition.north() - (maxNorth + minNorth)/2.0; 59 60 HashMap<OsmPrimitive,OsmPrimitive> map = new HashMap<OsmPrimitive,OsmPrimitive>(); 59 60 HashMap<OsmPrimitive,OsmPrimitive> map = new HashMap<OsmPrimitive,OsmPrimitive>(); 61 61 /* temporarily maps old nodes to new so we can do a true deep copy */ 62 62 63 63 /* do the deep copy of the paste buffer contents, leaving the pasteBuffer unchanged */ 64 64 for (Node n : pasteBuffer.nodes) { 65 65 Node nnew = new Node(n); … … 95 95 rnew.members.addAll(members); 96 96 map.put(r, rnew); 97 97 } 98 98 99 99 /* Now execute the commands to add the dupicated contents of the paste buffer to the map */ 100 100 Collection<OsmPrimitive> osms = map.values(); 101 101 Collection<Command> clist = new LinkedList<Command>(); -
src/org/openstreetmap/josm/actions/DiskAccessAction.java
9 9 import javax.swing.JOptionPane; 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.tools.ShortCut; 12 13 13 14 /** 14 15 * Helper class for all actions that access the disk 15 16 */ 16 17 abstract public class DiskAccessAction extends JosmAction { 17 18 19 public DiskAccessAction(String name, String iconName, String tooltip, ShortCut shortCut) { 20 super(name, iconName, tooltip, shortCut, true); 21 } 22 23 @Deprecated 18 24 public DiskAccessAction(String name, String iconName, String tooltip, int shortCut, int modifiers) { 19 25 super(name, iconName, tooltip, shortCut, modifiers, true); 20 26 } 21 27 22 28 protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) { 23 29 String curDir = Main.pref.get("lastDirectory"); 24 30 if (curDir.equals("")) … … 31 37 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i) 32 38 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]); 33 39 fc.setAcceptAllFileFilterUsed(true); 34 40 35 41 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent); 36 42 if (answer != JFileChooser.APPROVE_OPTION) 37 43 return null; 38 44 39 45 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) 40 46 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 41 47 42 48 if (!open) { 43 49 File file = fc.getSelectedFile(); 44 if (file == null || (file.exists() && JOptionPane.YES_OPTION != 50 if (file == null || (file.exists() && JOptionPane.YES_OPTION != 45 51 JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION))) 46 52 return null; 47 53 } 48 54 49 55 return fc; 50 56 } 51 57 } -
src/org/openstreetmap/josm/actions/HistoryInfoAction.java
13 13 import org.openstreetmap.josm.data.osm.Way; 14 14 import org.openstreetmap.josm.data.osm.visitor.Visitor; 15 15 import org.openstreetmap.josm.tools.OpenBrowser; 16 import org.openstreetmap.josm.tools.ShortCut; 16 17 17 18 public class HistoryInfoAction extends JosmAction { 18 19 19 20 public HistoryInfoAction() { 20 super(tr("OSM History Information"), "about",tr("Display history information about OSM ways or nodes."), KeyEvent.VK_H, KeyEvent.SHIFT_DOWN_MASK, true); 21 super(tr("OSM History Information"), "about",tr("Display history information about OSM ways or nodes."), 22 ShortCut.registerShortCut("core:history", tr("Display history"), KeyEvent.VK_H, ShortCut.GROUP_HOTKEY), true); 21 23 } 22 24 23 25 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/AutoScaleAction.java
14 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 15 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 16 16 import org.openstreetmap.josm.gui.layer.Layer; 17 import org.openstreetmap.josm.tools.ShortCut; 17 18 18 19 /** 19 20 * Toggles the autoScale feature of the mapView … … 45 46 46 47 public AutoScaleAction(String mode) { 47 48 super(tr("Zoom to {0}", tr(mode)), "dialogs/autoscale/" + mode, tr("Zoom the view to {0}.", tr(mode)), 48 AutoScaleAction.getModeShortcut(mode), 0, true);49 ShortCut.registerShortCut("view:zoom"+mode, tr("View: Zoom to {0}", tr(mode)), getModeShortcut(mode), ShortCut.GROUP_EDIT), true); 49 50 String modeHelp = Character.toUpperCase(mode.charAt(0)) + mode.substring(1); 50 51 putValue("help", "Action/AutoScale/" + modeHelp); 51 52 this.mode = mode; … … 78 79 } 79 80 for (OsmPrimitive osm : sel) 80 81 osm.visit(v); 81 // increase bbox by 0.001 degrees on each side. this is required 82 // especially if the bbox contains one single node, but helpful 82 // increase bbox by 0.001 degrees on each side. this is required 83 // especially if the bbox contains one single node, but helpful 83 84 // in most other cases as well. 84 85 v.enlargeBoundingBox(); 85 86 } -
src/org/openstreetmap/josm/actions/UploadAction.java
23 23 import org.openstreetmap.josm.io.OsmServerWriter; 24 24 import org.openstreetmap.josm.tools.GBC; 25 25 import org.xml.sax.SAXException; 26 import org.openstreetmap.josm.tools.ShortCut; 26 27 27 28 /** 28 29 * Action that opens a connection to the osm server and uploads all changes. … … 33 34 * @author imi 34 35 */ 35 36 public class UploadAction extends JosmAction { 36 37 37 38 /** Upload Hook */ 38 39 public interface UploadHook { 39 40 /** … … 45 46 */ 46 47 public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete); 47 48 } 48 49 49 50 /** 50 51 * The list of upload hooks. These hooks will be called one after the other 51 52 * when the user wants to upload data. Plugins can insert their own hooks here 52 53 * if they want to be able to veto an upload. 53 * 54 * 54 55 * Be default, the standard upload dialog is the only element in the list. 55 56 * Plugins should normally insert their code before that, so that the upload 56 57 * dialog is the last thing shown before upload really starts; on occasion … … 59 60 public final LinkedList<UploadHook> uploadHooks = new LinkedList<UploadHook>(); 60 61 61 62 public UploadAction() { 62 super(tr("Upload to OSM ..."), "upload", tr("Upload all changes to the OSM server."), KeyEvent.VK_U, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true); 63 super(tr("Upload to OSM ..."), "upload", tr("Upload all changes to the OSM server."), 64 ShortCut.registerShortCut("file:upload", tr("File: Upload"), KeyEvent.VK_U, ShortCut.GROUPS_ALT1+ShortCut.GROUP_HOTKEY), true); 63 65 64 66 /** 65 67 * Displays a screen where the actions that would be taken are displayed and … … 128 130 else if (osm.deleted && osm.id != 0) 129 131 delete.addFirst(osm); 130 132 } 131 133 132 134 if (add.isEmpty() && update.isEmpty() && delete.isEmpty()) { 133 135 JOptionPane.showMessageDialog(Main.parent,tr("No changes to upload.")); 134 136 return; … … 139 141 for(UploadHook hook : uploadHooks) 140 142 if(!hook.checkUpload(add, update, delete)) 141 143 return; 142 144 143 145 final OsmServerWriter server = new OsmServerWriter(); 144 146 final Collection<OsmPrimitive> all = new LinkedList<OsmPrimitive>(); 145 147 all.addAll(add); -
src/org/openstreetmap/josm/actions/CreateCircleAction.java
19 19 import org.openstreetmap.josm.data.osm.Node; 20 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 21 import org.openstreetmap.josm.data.osm.Way; 22 import org.openstreetmap.josm.tools.ShortCut; 22 23 23 24 /** 24 25 * Create a new circle from three selected nodes--or a way with 3 nodes. (Useful for roundabouts) 26 * 25 27 * Note: If a way is selected, it is changed. If nodes are selected a new way is created. 26 28 * So if you've got a way with 3 nodes it makes a difference between running this on the way or the nodes! 29 * 27 30 * BTW: Someone might want to implement projection corrections for this... 28 31 * 29 32 * @author Henry Loenwind, based on much copy&Paste from other Actions. … … 31 34 public final class CreateCircleAction extends JosmAction { 32 35 33 36 public CreateCircleAction() { 34 super(tr("Create Circle"), "createcircle", tr("Create a circle from three selected nodes."), KeyEvent.VK_O, KeyEvent.CTRL_MASK, true); 37 super(tr("Create Circle"), "createcircle", tr("Create a circle from three selected nodes."), 38 ShortCut.registerShortCut("tools:createcircle", tr("Tool: Create circle"), KeyEvent.VK_O, ShortCut.GROUP_EDIT), true); 35 39 } 36 40 37 41 private double calcang(double xc, double yc, double x, double y) { -
src/org/openstreetmap/josm/actions/MergeNodesAction.java
39 39 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 40 40 import org.openstreetmap.josm.tools.GBC; 41 41 import org.openstreetmap.josm.tools.Pair; 42 import org.openstreetmap.josm.tools.ShortCut; 42 43 43 44 44 45 /** 45 46 * Merge two or more nodes into one node. 46 47 * (based on Combine ways) 47 * 48 * 48 49 * @author Matthew Newton 49 50 * 50 51 */ 51 52 public class MergeNodesAction extends JosmAction implements SelectionChangedListener { 52 53 53 54 public MergeNodesAction() { 54 super(tr("Merge Nodes"), "mergenodes", tr("Merge nodes into one."), KeyEvent.VK_M, 0, true); 55 super(tr("Merge Nodes"), "mergenodes", tr("Merge nodes into the oldest one."), 56 ShortCut.registerShortCut("tools:mergenodes", tr("Tool: Merge nodes"), KeyEvent.VK_M, ShortCut.GROUP_EDIT), true); 55 57 DataSet.selListeners.add(this); 56 58 } 57 59 -
src/org/openstreetmap/josm/actions/SaveActionBase.java
21 21 import org.openstreetmap.josm.gui.layer.GpxLayer; 22 22 import org.openstreetmap.josm.io.OsmWriter; 23 23 import org.openstreetmap.josm.io.GpxWriter; 24 import org.openstreetmap.josm.tools.ShortCut; 24 25 25 26 public abstract class SaveActionBase extends DiskAccessAction { 26 27 27 28 private Layer layer; 28 29 30 public SaveActionBase(String name, String iconName, String tooltip, ShortCut shortCut, Layer layer) { 31 super(name, iconName, tooltip, shortCut); 32 this.layer = layer; 33 } 34 35 @Deprecated 29 36 public SaveActionBase(String name, String iconName, String tooltip, int shortCut, int modifiers, Layer layer) { 30 37 super(name, iconName, tooltip, shortCut, modifiers); 31 38 this.layer = layer; … … 78 85 return false; 79 86 } 80 87 if (!Main.map.conflictDialog.conflicts.isEmpty()) { 81 int answer = JOptionPane.showConfirmDialog(Main.parent, 88 int answer = JOptionPane.showConfirmDialog(Main.parent, 82 89 tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"),tr("Conflicts"), JOptionPane.YES_NO_OPTION); 83 90 if (answer != JOptionPane.YES_OPTION) 84 91 return false; … … 215 222 216 223 /** 217 224 * Check the data set if it would be empty on save. It is empty, if it contains 218 * no objects (after all objects that are created and deleted without being 225 * no objects (after all objects that are created and deleted without being 219 226 * transfered to the server have been removed). 220 * 227 * 221 228 * @return <code>true</code>, if a save result in an empty data set. 222 229 */ 223 230 private boolean isDataSetEmpty(OsmDataLayer layer) { -
src/org/openstreetmap/josm/actions/RedoAction.java
8 8 import java.awt.event.KeyEvent; 9 9 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.tools.ShortCut; 11 12 12 13 13 /** 14 14 * Redoes the last command. 15 * 15 * 16 16 * @author imi 17 17 */ 18 18 public class RedoAction extends JosmAction { … … 21 21 * Construct the action with "Redo" as label. 22 22 */ 23 23 public RedoAction() { 24 super(tr("Redo"), "redo", tr("Redo the last undone action."), KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK, true); 24 super(tr("Redo"), "redo", tr("Redo the last undone action."), 25 ShortCut.registerShortCut("system:redo", tr("Edit: Redo"), KeyEvent.VK_Y, ShortCut.GROUP_MENU), true); 25 26 setEnabled(false); 26 27 } 27 28 -
src/org/openstreetmap/josm/actions/NewAction.java
10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.data.osm.DataSet; 12 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 13 import org.openstreetmap.josm.tools.ShortCut; 13 14 14 15 public class NewAction extends JosmAction { 15 16 16 17 public NewAction() { 17 super(tr("New"), "new", tr("Create a new map."), KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK, true); 18 super(tr("New"), "new", tr("Create a new map."), 19 ShortCut.registerShortCut("system:new", tr("File: New"), KeyEvent.VK_N, ShortCut.GROUP_MENU), true); 18 20 } 19 21 20 22 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/actions/PasteTagsAction.java
19 19 import org.openstreetmap.josm.data.SelectionChangedListener; 20 20 import org.openstreetmap.josm.data.osm.DataSet; 21 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.tools.ShortCut; 22 23 23 24 public final class PasteTagsAction extends JosmAction implements SelectionChangedListener { 24 25 25 26 public PasteTagsAction(JosmAction copyAction) { 26 27 super(tr("Paste Tags"), "pastetags", 27 28 tr("Apply tags of contents of paste buffer to all selected items."), 28 KeyEvent.VK_V, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK, true);29 ShortCut.registerShortCut("system:pastestyle", tr("Edit: Paste tags"), KeyEvent.VK_V, ShortCut.GROUP_MENU), true); 29 30 DataSet.selListeners.add(this); 30 31 copyAction.addListener(this); 31 32 setEnabled(false); -
src/org/openstreetmap/josm/actions/CombineWayAction.java
39 39 import org.openstreetmap.josm.data.osm.Way; 40 40 import org.openstreetmap.josm.tools.GBC; 41 41 import org.openstreetmap.josm.tools.Pair; 42 import org.openstreetmap.josm.tools.ShortCut; 42 43 43 44 /** 44 45 * Combines multiple ways into one. 45 * 46 * 46 47 * @author Imi 47 48 */ 48 49 public class CombineWayAction extends JosmAction implements SelectionChangedListener { 49 50 50 51 public CombineWayAction() { 51 super(tr("Combine Way"), "combineway", tr("Combine several ways into one."), KeyEvent.VK_C, 0, true); 52 super(tr("Combine Way"), "combineway", tr("Combine several ways into one."), 53 ShortCut.registerShortCut("tools:combineway", tr("Tool: Combine ways"), KeyEvent.VK_C, ShortCut.GROUP_EDIT), true); 52 54 DataSet.selListeners.add(this); 53 55 } 54 56 -
src/org/openstreetmap/josm/actions/SaveAction.java
10 10 import org.openstreetmap.josm.gui.layer.Layer; 11 11 import org.openstreetmap.josm.gui.layer.GpxLayer; 12 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 13 import org.openstreetmap.josm.tools.ShortCut; 13 14 14 15 /** 15 16 * Export the data as an OSM xml file. 16 * 17 * 17 18 * @author imi 18 19 */ 19 20 public class SaveAction extends SaveActionBase { 20 21 21 22 /** 22 23 * Construct the action with "Save" as label. 23 24 * @param layer Save this layer. 24 25 */ 25 26 public SaveAction(Layer layer) { 26 super(tr("Save"), "save", tr("Save the current data."), KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK, layer); 27 super(tr("Save"), "save", tr("Save the current data."), 28 ShortCut.registerShortCut("system:save", tr("File: Save"), KeyEvent.VK_S, ShortCut.GROUP_MENU), layer); 27 29 } 28 30 29 31 @Override public File getFile(Layer layer) { 30 32 if (layer instanceof OsmDataLayer) { 31 33 File f = ((OsmDataLayer)layer).associatedFile; -
src/org/openstreetmap/josm/tools/OpenBrowser.java
11 11 12 12 /** 13 13 * Helper to open platform web browser on different platforms 14 * 15 * This now delegates the real work to a platform specific class. 16 * 14 17 * @author Imi 15 18 */ 16 19 public class OpenBrowser { … … 29 32 } 30 33 } 31 34 32 String os = System.getProperty("os.name");33 if (os == null)34 return "unknown operating system";35 35 try { 36 if (os != null && os.startsWith("Windows")) 37 windows(url); 38 else if (os.equals("Linux") || os.equals("Solaris") || os.equals("SunOS") || os.equals("AIX") || os.equals("FreeBSD")) 39 linux(url); 40 else if (os.equals("Mac OS") || os.equals("Mac OS X")) 41 mac(url); 42 else 43 return "unknown operating system"; 36 Main.platform.openUrl(url); 44 37 } catch (IOException e) { 45 38 return e.getMessage(); 46 39 } 47 40 return null; 48 41 } 49 42 50 private static void windows(String url) throws IOException {51 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);52 }53 54 private static void linux(String url) {55 String[] programs = {"gnome-open", "kfmclient openURL", "firefox"};56 for (String program : programs) {57 try {58 Runtime.getRuntime().exec(program+" "+url);59 return;60 } catch (IOException e) {61 }62 }63 }64 65 private static void mac(String url) throws IOException {66 Runtime.getRuntime().exec("open " + url);67 }68 43 } -
src/org/openstreetmap/josm/tools/ShortCutLabel.java
5 5 6 6 import java.awt.event.KeyEvent; 7 7 8 8 @Deprecated 9 9 public class ShortCutLabel { 10 @Deprecated 10 11 public static String name(int shortCut, int modifiers) { 11 12 if (shortCut == 0 && modifiers == 0) 12 13 return ""; -
src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
42 42 import org.openstreetmap.josm.gui.NavigatableComponent; 43 43 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 44 44 import org.openstreetmap.josm.gui.SideButton; 45 import org.openstreetmap.josm.tools.ShortCut; 45 46 46 47 public final class ConflictDialog extends ToggleDialog { 47 48 … … 50 51 private final JList displaylist = new JList(model); 51 52 52 53 public ConflictDialog() { 53 super(tr("Conflict"), "conflict", tr("Merging conflicts."), KeyEvent.VK_C, 100); 54 super(tr("Conflict"), "conflict", tr("Merging conflicts."), 55 ShortCut.registerShortCut("subwindow:conflict", tr("Toggle conflict window"), KeyEvent.VK_C, ShortCut.GROUP_LAYER), 100); 54 56 displaylist.setCellRenderer(new OsmPrimitivRenderer()); 55 57 displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 56 58 displaylist.addMouseListener(new MouseAdapter(){ -
src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
37 37 import org.openstreetmap.josm.gui.SideButton; 38 38 import org.openstreetmap.josm.tools.GBC; 39 39 import org.openstreetmap.josm.tools.ImageProvider; 40 import org.openstreetmap.josm.tools.ShortCut; 40 41 41 42 /** 42 43 * History dialog works like follows: … … 86 87 private JLabel notLoaded = new JLabel("<html><i>"+tr("Click Reload to refresh list")+"</i></html>"); 87 88 88 89 public HistoryDialog() { 89 super(tr("History"), "history", tr("Display the history of all selected items."), KeyEvent.VK_H, 150); 90 super(tr("History"), "history", tr("Display the history of all selected items."), 91 ShortCut.registerShortCut("subwindow:history", tr("Toggle history window"), KeyEvent.VK_H, ShortCut.GROUP_LAYER), 150); 90 92 historyPane.setVisible(false); 91 93 notLoaded.setVisible(true); 92 94 notLoaded.setHorizontalAlignment(JLabel.CENTER); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
40 40 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 41 41 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 42 42 import org.openstreetmap.josm.gui.SideButton; 43 import org.openstreetmap.josm.tools.ShortCut; 43 44 44 45 /** 45 46 * A small tool dialog for displaying the current selection. The selection manager … … 69 70 private JMenuItem zoomToElement; 70 71 71 72 /** 72 * If the selection changed event is triggered with newSelection equals 73 * this element, the newSelection will not be added to the selection history 73 * If the selection changed event is triggered with newSelection equals 74 * this element, the newSelection will not be added to the selection history 74 75 */ 75 76 private Collection<? extends OsmPrimitive> historyIgnoreSelection = null; 76 77 77 78 public SelectionListDialog() { 78 super(tr("Current Selection"), "selectionlist", tr("Open a selection list window."), KeyEvent.VK_T, 150); 79 super(tr("Current Selection"), "selectionlist", tr("Open a selection list window."), 80 ShortCut.registerShortCut("subwindow:selection", tr("Toggle selection window"), KeyEvent.VK_T, ShortCut.GROUP_LAYER), 150); 79 81 80 82 selectionHistory = new LinkedList<Collection<? extends OsmPrimitive>>(); 81 83 popupMenu = new JPopupMenu(); … … 190 192 } 191 193 192 194 /** 193 * Zooms to the element(s) selected in {@link #displaylist} 195 * Zooms to the element(s) selected in {@link #displaylist} 194 196 */ 195 197 public void zoomToSelectedElement() { 196 198 BoundingXYVisitor box = new BoundingXYVisitor(); … … 247 249 if (selectionHistory != null && newSelection.size() > 0 && !newSelection.equals(historyIgnoreSelection)) { 248 250 historyIgnoreSelection = null; 249 251 try { 250 // Check if the newSelection has already been added to the history 252 // Check if the newSelection has already been added to the history 251 253 Collection<? extends OsmPrimitive> first = selectionHistory.getFirst(); 252 254 if (first.equals(newSelection)) 253 255 return; … … 272 274 273 275 /** 274 276 * A specialized {@link JMenuItem} for presenting one entry of the selection history 275 * 277 * 276 278 * @author Jan Peter Stotz 277 279 */ 278 280 protected class SelectionMenuItem extends JMenuItem implements ActionListener { … … 302 304 303 305 /** 304 306 * A specialized {@link JMenuItem} for presenting one entry of the search history 305 * 307 * 306 308 * @author Jan Peter Stotz 307 309 */ 308 310 protected class SearchMenuItem extends JMenuItem implements ActionListener { -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
26 26 import org.openstreetmap.josm.actions.HelpAction.Helpful; 27 27 import org.openstreetmap.josm.tools.GBC; 28 28 import org.openstreetmap.josm.tools.ImageProvider; 29 import org.openstreetmap.josm.tools.ShortCut; 29 30 30 31 /** 31 32 * This class is a toggle dialog that can be turned on and off. It is attached … … 39 40 public final String prefname; 40 41 public AbstractButton button; 41 42 42 private ToggleDialogAction(String name, String iconName, String tooltip, int shortCut, int modifier, String prefname) {43 super(name, iconName, tooltip, shortCut, modifier,false);43 private ToggleDialogAction(String name, String iconName, String tooltip, ShortCut shortCut, String prefname) { 44 super(name, iconName, tooltip, shortCut, false); 44 45 this.prefname = prefname; 45 46 } 46 47 … … 61 62 public JPanel parent; 62 63 private final JPanel titleBar = new JPanel(new GridBagLayout()); 63 64 65 @Deprecated 64 66 public ToggleDialog(final String name, String iconName, String tooltip, int shortCut, int preferredHeight) { 65 67 super(new BorderLayout()); 66 68 this.prefName = iconName; 69 ToggleDialogInit(name, iconName, tooltip, ShortCut.registerShortCut("auto:"+name, tooltip, shortCut, ShortCut.GROUP_LAYER), preferredHeight); 70 } 71 72 public ToggleDialog(final String name, String iconName, String tooltip, ShortCut shortCut, int preferredHeight) { 73 super(new BorderLayout()); 74 this.prefName = iconName; 75 ToggleDialogInit(name, iconName, tooltip, shortCut, preferredHeight); 76 } 77 78 private void ToggleDialogInit(final String name, String iconName, String tooltip, ShortCut shortCut, int preferredHeight) { 67 79 setPreferredSize(new Dimension(330,preferredHeight)); 68 action = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, shortCut, KeyEvent.ALT_MASK,iconName);80 action = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, shortCut, iconName); 69 81 String helpId = "Dialog/"+getClass().getName().substring(getClass().getName().lastIndexOf('.')+1); 70 82 action.putValue("help", helpId.substring(0, helpId.length()-6)); 71 83 setLayout(new BorderLayout()); -
src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
19 19 import org.openstreetmap.josm.command.Command; 20 20 import org.openstreetmap.josm.gui.MapFrame; 21 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener; 22 import org.openstreetmap.josm.tools.ShortCut; 22 23 23 24 public class CommandStackDialog extends ToggleDialog implements CommandQueueListener { 24 25 … … 26 27 private JTree tree = new JTree(treeModel); 27 28 28 29 public CommandStackDialog(final MapFrame mapFrame) { 29 super(tr("Command Stack"), "commandstack", tr("Open a list of all commands (undo buffer)."), KeyEvent.VK_O, 100); 30 super(tr("Command Stack"), "commandstack", tr("Open a list of all commands (undo buffer)."), 31 ShortCut.registerShortCut("subwindow:commandstack", tr("Toggle command stack"), KeyEvent.VK_O, ShortCut.GROUP_LAYER), 100); 30 32 Main.main.undoRedo.listenerCommands.add(this); 31 33 32 34 tree.setRootVisible(false); 33 35 tree.setShowsRootHandles(true); 34 36 tree.expandRow(0); -
src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
39 39 import org.openstreetmap.josm.tools.DontShowAgainInfo; 40 40 import org.openstreetmap.josm.tools.ImageProvider; 41 41 import org.openstreetmap.josm.tools.ImageProvider.OverlayPosition; 42 import org.openstreetmap.josm.tools.ShortCut; 42 43 43 44 /** 44 45 * A component that manages the list of all layers and react to selection changes … … 157 158 * Create an layerlist and attach it to the given mapView. 158 159 */ 159 160 public LayerListDialog(MapFrame mapFrame) { 160 super(tr("Layers"), "layerlist", tr("Open a list of all loaded layers."), KeyEvent.VK_L, 100); 161 super(tr("Layers"), "layerlist", tr("Open a list of all loaded layers."), 162 ShortCut.registerShortCut("subwindow:layers", tr("Toggle layer window"), KeyEvent.VK_L, ShortCut.GROUP_LAYER), 100); 161 163 instance = new JList(model); 162 164 listScrollPane = new JScrollPane(instance); 163 165 add(listScrollPane, BorderLayout.CENTER); -
src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
31 31 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 32 32 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 33 33 import org.openstreetmap.josm.tools.GBC; 34 import org.openstreetmap.josm.tools.ShortCut; 34 35 35 36 /** 36 37 * A dialog showing all known relations, with buttons to add, edit, and 37 * delete them. 38 * 38 * delete them. 39 * 39 40 * We don't have such dialogs for nodes, segments, and ways, becaus those 40 41 * objects are visible on the map and can be selected there. Relations are not. 41 42 * … … 54 55 private JList displaylist = new JList(list); 55 56 56 57 public RelationListDialog() { 57 super(tr("Relations"), "relationlist", tr("Open a list of all relations."), KeyEvent.VK_R, 150); 58 super(tr("Relations"), "relationlist", tr("Open a list of all relations."), 59 ShortCut.registerShortCut("subwindow:relations", tr("Toggle relations window"), KeyEvent.VK_R, ShortCut.GROUP_LAYER), 150); 58 60 displaylist.setCellRenderer(new OsmPrimitivRenderer()); 59 61 displaylist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 60 62 displaylist.addMouseListener(new MouseAdapter(){ … … 70 72 add(new JScrollPane(displaylist), BorderLayout.CENTER); 71 73 72 74 JPanel buttonPanel = new JPanel(new GridLayout(1,4)); 73 75 74 76 buttonPanel.add(new SideButton(marktr("New"), "addrelation", "Selection", tr("Create a new relation"), new ActionListener() { 75 77 public void actionPerformed(ActionEvent e) { 76 78 // call relation editor with null argument to create new relation 77 79 new RelationEditor(null).setVisible(true); 78 80 } 79 81 }), GBC.std()); 80 82 81 83 buttonPanel.add(new SideButton(marktr("Select"), "select", "Selection", tr("Select this relation"), new ActionListener() { 82 84 public void actionPerformed(ActionEvent e) { 83 85 // replace selection with the relation from the list 84 86 Main.ds.setSelected((Relation)displaylist.getSelectedValue()); 85 87 } 86 88 }), GBC.std()); 87 89 88 90 buttonPanel.add(new SideButton(marktr("Edit"), "edit", "Selection", tr( "Open an editor for the selected relation"), new ActionListener() { 89 91 public void actionPerformed(ActionEvent e) { 90 92 Relation toEdit = (Relation) displaylist.getSelectedValue(); 91 93 if (toEdit != null) 92 new RelationEditor(toEdit).setVisible(true); 94 new RelationEditor(toEdit).setVisible(true); 93 95 } 94 96 }), GBC.std()); 95 97 96 98 buttonPanel.add(new SideButton(marktr("Delete"), "delete", "Selection", tr("Delete the selected relation"), new ActionListener() { 97 99 public void actionPerformed(ActionEvent e) { 98 100 Relation toDelete = (Relation) displaylist.getSelectedValue(); … … 110 112 super.setVisible(b); 111 113 if (b) updateList(); 112 114 } 113 115 114 116 public void updateList() { 115 117 list.setSize(Main.ds.relations.size()); 116 118 int i = 0; … … 120 122 } 121 123 list.setSize(i); 122 124 } 123 125 124 126 public void activeLayerChange(Layer a, Layer b) { 125 127 if ((a == null || a instanceof OsmDataLayer) && b instanceof OsmDataLayer) { 126 128 if (a != null) ((OsmDataLayer)a).listenerDataChanged.remove(this); … … 129 131 repaint(); 130 132 } 131 133 } 132 134 133 135 public void layerRemoved(Layer a) { 134 136 if (a instanceof OsmDataLayer) { 135 137 ((OsmDataLayer)a).listenerDataChanged.remove(this); … … 139 141 if (a instanceof OsmDataLayer) { 140 142 ((OsmDataLayer)a).listenerDataChanged.add(this); 141 143 } 142 } 144 } 143 145 public void dataChanged(OsmDataLayer l) { 144 146 updateList(); 145 147 repaint(); 146 148 } 147 149 148 150 /** 149 151 * Returns the currently selected relation, or null. 150 * 152 * 151 153 * @return the currently selected relation, or null 152 154 */ 153 155 public Relation getCurrentRelation() { … … 156 158 157 159 /** 158 160 * Adds a selection listener to the relation list. 159 * 161 * 160 162 * @param listener the listener to add 161 163 */ 162 164 public void addListSelectionListener(ListSelectionListener listener) { … … 165 167 166 168 /** 167 169 * Removes a selection listener from the relation list. 168 * 170 * 169 171 * @param listener the listener to remove 170 172 */ 171 173 public void removeListSelectionListener(ListSelectionListener listener) { -
src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
20 20 import org.openstreetmap.josm.data.osm.DataSet; 21 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 22 import org.openstreetmap.josm.data.osm.User; 23 import org.openstreetmap.josm.tools.ShortCut; 23 24 24 25 /** 25 * Displays a dialog with all users who have last edited something in the 26 * Displays a dialog with all users who have last edited something in the 26 27 * selection area, along with the number of objects. 27 * 28 * 28 29 * @author Frederik Ramm <frederik@remote.org> 29 30 */ 30 31 public class UserListDialog extends ToggleDialog implements SelectionChangedListener { … … 44 45 private JTable userTable = new JTable(data); 45 46 46 47 private static User anonymousUser = User.get("(anonymous users)"); 47 48 48 49 public UserListDialog() { 49 super(tr("Authors"), "userlist", tr("Open a list of people working on the selected objects."), KeyEvent.VK_A, 150); 50 50 super(tr("Authors"), "userlist", tr("Open a list of people working on the selected objects."), 51 ShortCut.registerShortCut("subwindow:authors", tr("Toggle authors window"), KeyEvent.VK_A, ShortCut.GROUP_LAYER), 150); 52 51 53 data.setColumnIdentifiers(new String[]{tr("Author"),tr("# Objects"),"%"}); 52 54 userTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 53 55 add(new JScrollPane(userTable), BorderLayout.CENTER); 54 56 selectionChanged(Main.ds.getSelected()); 55 57 56 58 DataSet.selListeners.add(this); 57 59 } 58 60 … … 69 71 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 70 72 if (!isVisible()) 71 73 return; 72 74 73 75 class UserCount { 74 76 User user; 75 77 int count; 76 78 UserCount(User user, int count) { this.user=user; this.count=count; } 77 79 } 78 80 79 81 if (data == null) 80 82 return; // selection changed may be received in base class constructor before init 81 83 82 84 data.setRowCount(0); 83 85 84 86 HashMap<User,UserCount> counters = new HashMap<User,UserCount>(); 85 87 int all = 0; 86 88 for (OsmPrimitive p : newSelection) { 87 89 User u = p.user; 88 90 if (u == null) u = anonymousUser; 89 91 UserCount uc = counters.get(u); 90 if (uc == null) 92 if (uc == null) 91 93 counters.put(u, uc = new UserCount(u, 0)); 92 94 uc.count++; 93 95 all++; … … 95 97 UserCount[] ucArr = new UserCount[counters.size()]; 96 98 counters.values().toArray(ucArr); 97 99 Arrays.sort(ucArr, new Comparator<UserCount>() { 98 public int compare(UserCount a, UserCount b) { 100 public int compare(UserCount a, UserCount b) { 99 101 return (a.count<b.count) ? 1 : (a.count>b.count) ? -1 : 0; 100 102 } 101 103 }); 102 104 103 105 for (UserCount uc : ucArr) { 104 106 data.addRow(new Object[] { uc.user.name, uc.count, uc.count * 100 / all }); 105 107 } -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
63 63 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 64 64 import org.openstreetmap.josm.tools.AutoCompleteComboBox; 65 65 import org.openstreetmap.josm.tools.GBC; 66 import org.openstreetmap.josm.tools.ShortCut; 66 67 67 68 /** 68 69 * This dialog displays the properties of the current selected primitives. … … 87 88 * Used to display relation names in the membership table 88 89 */ 89 90 private NameVisitor nameVisitor = new NameVisitor(); 90 91 91 92 /** 92 93 * Watches for double clicks and from editing or new property, depending on the 93 94 * location, the click was. … … 133 134 return; 134 135 } 135 136 String msg = "<html>"+trn("This will change up to {0} object.", "This will change up to {0} objects.", sel.size(), sel.size())+"<br><br>("+tr("An empty value deletes the key.", key)+")</html>"; 136 137 137 138 JPanel panel = new JPanel(new BorderLayout()); 138 139 panel.add(new JLabel(msg), BorderLayout.NORTH); 139 140 … … 158 159 if (c instanceof JLabel) { 159 160 String str = null; 160 161 str=(String) value; 161 if (valueCount.containsKey(objKey)){ 162 if (valueCount.containsKey(objKey)){ 162 163 Map<String, Integer> m=valueCount.get(objKey); 163 164 if (m.containsKey(str)) { 164 165 str+="("+m.get(str)+")"; … … 268 269 /** 269 270 * This simply fires up an relation editor for the relation shown; everything else 270 271 * is the editor's business. 271 * 272 * 272 273 * @param row 273 274 */ 274 void membershipEdit(int row) { 275 final RelationEditor editor = new RelationEditor((Relation)membershipData.getValueAt(row, 0), 275 void membershipEdit(int row) { 276 final RelationEditor editor = new RelationEditor((Relation)membershipData.getValueAt(row, 0), 276 277 (Collection<RelationMember>) membershipData.getValueAt(row, 1) ); 277 278 editor.setVisible(true); 278 279 } … … 295 296 final AutoCompleteComboBox keys = new AutoCompleteComboBox(); 296 297 keys.setPossibleItems(allData.keySet()); 297 298 keys.setEditable(true); 298 299 299 300 p.add(keys, BorderLayout.CENTER); 300 301 301 302 JPanel p2 = new JPanel(new BorderLayout()); … … 402 403 return String.class; 403 404 } 404 405 }; 405 406 406 407 /** 407 408 * The properties list. 408 409 */ … … 416 417 * Create a new PropertiesDialog 417 418 */ 418 419 public PropertiesDialog(MapFrame mapFrame) { 419 super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."), KeyEvent.VK_P, 150); 420 super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."), 421 ShortCut.registerShortCut("subwindow:properies", tr("Toggle properties window"), KeyEvent.VK_P, ShortCut.GROUP_LAYER), 150); 420 422 421 423 // --------------------------------------- 422 // This drop-down is really deprecated but we offer people a chance to 423 // activate it if they really want. Presets should be used from the 424 // This drop-down is really deprecated but we offer people a chance to 425 // activate it if they really want. Presets should be used from the 424 426 // menu. 425 if (TaggingPresetPreference.taggingPresets.size() > 0 && 427 if (TaggingPresetPreference.taggingPresets.size() > 0 && 426 428 Main.pref.getBoolean("taggingpreset.in-properties-dialog", false)) { 427 429 Vector<ActionListener> allPresets = new Vector<ActionListener>(); 428 430 for (final TaggingPreset p : TaggingPresetPreference.taggingPresets) … … 447 449 taggingPresets.setRenderer(new TaggingCellRenderer()); 448 450 449 451 // setting up the properties table 450 452 451 453 propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")}); 452 454 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 453 455 454 456 propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){ 455 457 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 456 458 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); … … 475 477 return c; 476 478 } 477 479 }); 478 480 479 481 // setting up the membership table 480 482 481 483 membershipData.setColumnIdentifiers(new String[]{tr("Member Of"),tr("Role")}); 482 484 membershipTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 483 485 484 486 membershipTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { 485 487 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 486 488 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); … … 491 493 return c; 492 494 } 493 495 }); 494 496 495 497 membershipTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() { 496 498 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 497 499 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 498 500 if (c instanceof JLabel) { 499 501 Collection<RelationMember> col = (Collection<RelationMember>) value; 500 502 501 503 String text = null; 502 504 for (RelationMember r : col) { 503 505 if (text == null) { … … 508 510 break; 509 511 } 510 512 } 511 513 512 514 ((JLabel)c).setText(text); 513 515 } 514 516 return c; 515 517 } 516 518 }); 517 519 518 520 // combine both tables and wrap them in a scrollPane 519 521 JPanel bothTables = new JPanel(); 520 522 bothTables.setLayout(new GridBagLayout()); … … 522 524 bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH)); 523 525 bothTables.add(membershipTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); 524 526 bothTables.add(membershipTable, GBC.eol().fill(GBC.BOTH)); 525 527 526 528 DblClickWatch dblClickWatch = new DblClickWatch(); 527 529 propertyTable.addMouseListener(dblClickWatch); 528 530 membershipTable.addMouseListener(dblClickWatch); … … 564 566 Main.main.undoRedo.add(new ChangeCommand(cur, rel)); 565 567 selectionChanged(sel); // update whole table 566 568 } 567 569 568 570 } 569 571 } 570 572 else … … 586 588 } 587 589 } 588 590 }; 589 591 590 592 buttonPanel.add(new SideButton(marktr("Add"),"add","Properties",tr("Add a new key/value pair to all objects"), KeyEvent.VK_A, buttonAction)); 591 593 buttonPanel.add(new SideButton(marktr("Edit"),"edit","Properties",tr("Edit the value of the selected key for all objects"), KeyEvent.VK_E, buttonAction)); 592 594 buttonPanel.add(new SideButton(marktr("Delete"),"delete","Properties",tr("Delete the selected key in all objects"), KeyEvent.VK_D, buttonAction)); … … 610 612 propertyTable.getCellEditor().cancelCellEditing(); 611 613 612 614 // re-load property data 613 615 614 616 propertyData.setRowCount(0); 615 617 616 618 Map<String, Integer> keyCount = new HashMap<String, Integer>(); … … 638 640 } 639 641 propertyData.addRow(new Object[]{e.getKey(), e.getValue()}); 640 642 } 641 643 642 644 // re-load membership data 643 645 // this is rather expensive since we have to walk through all members of all existing relationships. 644 646 // could use back references here for speed if necessary. 645 647 646 648 membershipData.setRowCount(0); 647 649 648 650 TreeMap<Relation, Collection<RelationMember>> roles = new TreeMap<Relation, Collection<RelationMember>>(); 649 651 for (Relation r : Main.ds.relations) { 650 652 if (!r.deleted && !r.incomplete) { … … 660 662 } 661 663 } 662 664 } 663 665 664 666 for (Entry<Relation, Collection<RelationMember>> e : roles.entrySet()) { 665 667 membershipData.addRow(new Object[]{e.getKey(), e.getValue()}); 666 668 } 667 669 668 670 membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0); 669 671 } 670 672 } -
src/org/openstreetmap/josm/gui/MainApplication.java
30 30 */ 31 31 public class MainApplication extends Main { 32 32 /** 33 * Allow subclassing (see JOSM.java) 34 */ 35 public MainApplication() {} 36 37 /** 33 38 * Construct an main frame, ready sized and operating. Does not 34 39 * display the frame. 35 40 */ … … 65 70 66 71 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler()); 67 72 73 // initialize the plaform hook, and 74 Main.determinePlatformHook(); 75 // call the really early hook before we anything else 76 Main.platform.preStartupHook(); 77 68 78 // construct argument table 69 79 List<String> argList = Arrays.asList(argArray); 70 80 final Map<String, Collection<String>> args = new HashMap<String, Collection<String>>(); … … 137 147 tr("Activating the updated plugins failed. Check if JOSM has the permission to overwrite the existing ones."), 138 148 tr("Plugins"), JOptionPane.ERROR_MESSAGE); 139 149 } 140 150 141 151 // load the early plugins 142 152 splash.setStatus(tr("Loading early plugins")); 143 153 Main.loadPlugins(true, language); 144 154 145 155 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) { 156 // TODO: put in a platformHook for system that have no console by default 146 157 System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+ 147 158 tr("usage")+":\n"+ 148 159 "\tjava -jar josm.jar <option> <option> <option>...\n\n"+ … … 191 202 } 192 203 }); 193 204 } 205 194 206 } -
src/org/openstreetmap/josm/gui/MapView.java
25 25 26 26 import org.openstreetmap.josm.Main; 27 27 import org.openstreetmap.josm.actions.AutoScaleAction; 28 import org.openstreetmap.josm.actions.JosmAction; 28 29 import org.openstreetmap.josm.actions.MoveAction; 29 30 import org.openstreetmap.josm.data.Bounds; 30 31 import org.openstreetmap.josm.data.SelectionChangedListener; … … 82 83 * The layer from the layers list that is currently active. 83 84 */ 84 85 private Layer activeLayer; 85 86 86 87 /** 87 88 * The last event performed by mouse. 88 89 */ 89 90 public MouseEvent lastMEvent; 90 91 91 92 private LinkedList<MapViewPaintable> temporaryLayers = new LinkedList<MapViewPaintable>(); 92 93 93 94 private BufferedImage offscreenBuffer; 94 95 95 96 /** 96 97 * The listener of the active layer changes. 97 98 * @deprecated Use Layer.listener instead. … … 106 107 new AutoScaleAction("data").actionPerformed(null); 107 108 108 109 new MapMover(MapView.this, Main.contentPane); 109 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, java.awt.event.InputEvent.SHIFT_MASK), "UP"); 110 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, java.awt.event.InputEvent.SHIFT_MASK), "DOWN"); 111 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, java.awt.event.InputEvent.SHIFT_MASK), "LEFT"); 112 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, java.awt.event.InputEvent.SHIFT_MASK), "RIGHT"); 110 JosmAction mv; 111 mv = new MoveAction(MoveAction.Direction.UP); 112 if (mv.getShortCut() != null) { 113 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortCut().getKeyStroke(), "UP"); 114 Main.contentPane.getActionMap().put("UP", mv); 115 } 116 mv = new MoveAction(MoveAction.Direction.DOWN); 117 if (mv.getShortCut() != null) { 118 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortCut().getKeyStroke(), "DOWN"); 119 Main.contentPane.getActionMap().put("DOWN", mv); 120 } 121 mv = new MoveAction(MoveAction.Direction.LEFT); 122 if (mv.getShortCut() != null) { 123 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortCut().getKeyStroke(), "LEFT"); 124 Main.contentPane.getActionMap().put("LEFT", mv); 125 } 126 mv = new MoveAction(MoveAction.Direction.RIGHT); 127 if (mv.getShortCut() != null) { 128 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortCut().getKeyStroke(), "RIGHT"); 129 Main.contentPane.getActionMap().put("RIGHT", mv); 130 } 113 131 114 Main.contentPane.getActionMap().put("UP", new MoveAction(MoveAction.Direction.UP));115 Main.contentPane.getActionMap().put("DOWN", new MoveAction(MoveAction.Direction.DOWN));116 Main.contentPane.getActionMap().put("LEFT", new MoveAction(MoveAction.Direction.LEFT));117 Main.contentPane.getActionMap().put("RIGHT", new MoveAction(MoveAction.Direction.RIGHT));118 119 120 132 MapSlider zoomSlider = new MapSlider(MapView.this); 121 133 add(zoomSlider); 122 134 zoomSlider.setBounds(3, 0, 114, 30); … … 275 287 for (MapViewPaintable mvp : temporaryLayers) { 276 288 mvp.paint(tempG, this); 277 289 } 278 290 279 291 // draw world borders 280 292 tempG.setColor(Color.WHITE); 281 293 Bounds b = new Bounds(); … … 287 299 int y2 = Math.max(min.y, max.y); 288 300 if (x1 > 0 || y1 > 0 || x2 < getWidth() || y2 < getHeight()) 289 301 tempG.drawRect(x1, y1, x2-x1+1, y2-y1+1); 290 302 291 303 if (playHeadMarker != null) 292 304 playHeadMarker.paint(tempG, this); 293 305 … … 403 415 if (oldScale != scale) 404 416 firePropertyChange("scale", oldScale, scale); 405 417 } 406 418 407 419 public boolean addTemporaryLayer(MapViewPaintable mvp) { 408 420 if (temporaryLayers.contains(mvp)) return false; 409 421 return temporaryLayers.add(mvp); 410 422 } 411 423 412 424 public boolean removeTemporaryLayer(MapViewPaintable mvp) { 413 425 return temporaryLayers.remove(mvp); 414 426 } -
src/org/openstreetmap/josm/gui/MainMenu.java
12 12 import javax.swing.JMenuBar; 13 13 import javax.swing.JMenuItem; 14 14 import javax.swing.KeyStroke; 15 import java.awt.event.KeyEvent; 15 16 16 17 import org.openstreetmap.josm.Main; 17 18 import org.openstreetmap.josm.actions.AboutAction; … … 58 59 import org.openstreetmap.josm.actions.audio.AudioSlowerAction; 59 60 import org.openstreetmap.josm.actions.search.SearchAction; 60 61 import org.openstreetmap.josm.data.DataSetChecker; 62 import org.openstreetmap.josm.tools.ShortCut; 61 63 62 64 /** 63 65 * This is the JOSM main menu bar. It is overwritten to initialize itself and provide … … 78 80 public final DownloadAction download = new DownloadAction(); 79 81 public final JosmAction upload = new UploadAction(); 80 82 public final JosmAction exit = new ExitAction(); 81 83 82 84 /* Edit menu */ 83 85 public final UndoAction undo = new UndoAction(); 84 86 public final RedoAction redo = new RedoAction(); 85 87 public final JosmAction copy = new CopyAction(); 86 88 public final JosmAction paste = new PasteAction(); 87 89 public final JosmAction delete = new DeleteAction(); 88 public final JosmAction pasteTags = new PasteTagsAction(copy); 89 public final JosmAction duplicate = new DuplicateAction(); 90 public final JosmAction pasteTags = new PasteTagsAction(copy); 91 public final JosmAction duplicate = new DuplicateAction(); 90 92 public final JosmAction selectAll = new SelectAllAction(); 91 93 public final JosmAction unselectAll = new UnselectAllAction(); 92 94 /* crashes when loading data, if using JosmAction for search */ 93 95 public final JosmAction search = new SearchAction(); 94 96 public final JosmAction preferences = new PreferencesAction(); 95 97 96 98 /* View menu */ 97 99 98 100 /* Tools menu */ 99 101 public final JosmAction splitWay = new SplitWayAction(); 100 102 public final JosmAction combineWay = new CombineWayAction(); … … 120 122 public final HelpAction help = new HelpAction(); 121 123 public final JosmAction about = new AboutAction(); 122 124 public final HistoryInfoAction historyinfo = new HistoryInfoAction(); 123 125 124 126 public final JMenu fileMenu = new JMenu(tr("File")); 125 127 public final JMenu editMenu = new JMenu(tr("Edit")); 126 128 public final JMenu viewMenu = new JMenu(tr("View")); … … 128 130 public final JMenu audioMenu = new JMenu(tr("Audio")); 129 131 public final JMenu presetsMenu = new JMenu(tr("Presets")); 130 132 public final JMenu helpMenu = new JMenu(tr("Help")); 131 132 133 134 /** 135 * Add a JosmAction to a menu. 136 * 137 * This method handles all the shortcut handling. 138 * It also makes sure that actions that are handled by the 139 * OS are not duplicated on the menu. 140 */ 141 public static void add(JMenu menu, JosmAction action) { 142 if (!action.getShortCut().getAutomatic()) { 143 JMenuItem menuitem = menu.add(action); 144 KeyStroke ks = action.getShortCut().getKeyStroke(); 145 if (ks != null) { 146 menuitem.setAccelerator(ks); 147 } 148 } 149 } 150 151 /** 152 * Add a menu to the main menu. 153 * 154 * This method handles all the shortcut handling. 155 */ 156 public void add(JMenu menu, int mnemonicKey, String shortName) { 157 ShortCut.registerShortCut("menu:"+shortName, shortName+" menu", mnemonicKey, ShortCut.GROUP_MNEMONIC).setMnemonic(menu); 158 add(menu); 159 } 160 133 161 public MainMenu() { 134 JMenuItem current; 135 136 fileMenu.setMnemonic('F'); 137 current = fileMenu.add(newAction); 138 current.setAccelerator(newAction.shortCut); 139 current = fileMenu.add(open); 140 current.setAccelerator(open.shortCut); 162 JMenuItem current; 163 164 add(fileMenu, newAction); 165 add(fileMenu, open); 141 166 fileMenu.addSeparator(); 142 current = fileMenu.add(save); 143 current.setAccelerator(save.shortCut); 144 current = fileMenu.add(saveAs); 145 current.setAccelerator(saveAs.shortCut); 146 current = fileMenu.add(gpxExport); 147 current.setAccelerator(gpxExport.shortCut); 167 add(fileMenu, save); 168 add(fileMenu, saveAs); 169 add(fileMenu, gpxExport); 148 170 fileMenu.addSeparator(); 149 current = fileMenu.add(download); 150 current.setAccelerator(download.shortCut); 151 current = fileMenu.add(upload); 152 current.setAccelerator(upload.shortCut); 153 fileMenu.addSeparator(); 154 current = fileMenu.add(exit); 155 current.setAccelerator(exit.shortCut); 156 add(fileMenu); 171 add(fileMenu, download); 172 add(fileMenu, upload); 173 add(fileMenu, exit); 174 add(fileMenu, KeyEvent.VK_F, "file"); 157 175 158 editMenu.setMnemonic('E'); 159 current = editMenu.add(undo); 160 current.setAccelerator(undo.shortCut); 161 current = editMenu.add(redo); 162 current.setAccelerator(redo.shortCut); 176 add(editMenu, undo); 177 add(editMenu, redo); 163 178 editMenu.addSeparator(); 164 current = editMenu.add(copy); 165 current.setAccelerator(copy.shortCut); 166 current = editMenu.add(delete); 167 current.setAccelerator(delete.shortCut); 168 current = editMenu.add(paste); 169 current.setAccelerator(paste.shortCut); 170 current = editMenu.add(pasteTags); 171 current.setAccelerator(pasteTags.shortCut); 172 current = editMenu.add(duplicate); 173 current.setAccelerator(duplicate.shortCut); 179 add(editMenu, copy); 180 add(editMenu, delete); 181 add(editMenu, paste); 182 add(editMenu, pasteTags); 183 add(editMenu, duplicate); 174 184 editMenu.addSeparator(); 175 current = editMenu.add(selectAll); 176 current.setAccelerator(selectAll.shortCut); 177 current = editMenu.add(unselectAll); 178 current.setAccelerator(unselectAll.shortCut); 185 add(editMenu, selectAll); 186 add(editMenu, unselectAll); 179 187 editMenu.addSeparator(); 180 current = editMenu.add(search); 181 current.setAccelerator(search.shortCut); 188 add(editMenu, search); 182 189 editMenu.addSeparator(); 183 current = editMenu.add(preferences); 184 current.setAccelerator(preferences.shortCut); 185 add(editMenu); 186 187 viewMenu.setMnemonic('V'); 188 for (String mode : AutoScaleAction.modes) { 189 JosmAction autoScaleAction = new AutoScaleAction(mode); 190 current = viewMenu.add(autoScaleAction); 191 current.setAccelerator(autoScaleAction.shortCut); 192 } 193 viewMenu.addSeparator(); 194 JosmAction a = new ZoomOutAction(); 195 viewMenu.add(a).setAccelerator(a.shortCut); 196 a = new ZoomInAction(); 197 viewMenu.add(a).setAccelerator(a.shortCut); 190 add(editMenu, preferences); 191 add(editMenu, KeyEvent.VK_E, "edit"); 198 192 193 for (String mode : AutoScaleAction.modes) { 194 JosmAction autoScaleAction = new AutoScaleAction(mode); 195 add(viewMenu, autoScaleAction); 196 } 199 197 viewMenu.addSeparator(); 200 198 add(viewMenu, new ZoomOutAction()); 199 add(viewMenu, new ZoomInAction()); 200 viewMenu.addSeparator(); 201 201 // TODO move code to an "action" like the others? 202 final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(tr("Wireframe view"));202 final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(tr("Wireframe view")); 203 203 wireframe.setSelected(Main.pref.getBoolean("draw.wireframe", false)); 204 wireframe.setAccelerator(KeyStroke.getKeyStroke("ctrl W"));205 wireframe.addActionListener(new ActionListener() {206 public void actionPerformed(ActionEvent ev) {207 Main.pref.put("draw.wireframe", wireframe.isSelected());208 if (Main.map != null) {204 wireframe.setAccelerator(ShortCut.registerShortCut("menu:view:wireframe", "Toggle Wireframe view", KeyEvent.VK_W, ShortCut.GROUP_MENU).getKeyStroke()); 205 wireframe.addActionListener(new ActionListener() { 206 public void actionPerformed(ActionEvent ev) { 207 Main.pref.put("draw.wireframe", wireframe.isSelected()); 208 if (Main.map != null) { 209 209 Main.map.mapView.repaint(); 210 210 } 211 } 212 }); 213 viewMenu.add(wireframe); 214 215 add(viewMenu); 211 } 212 }); 213 viewMenu.add(wireframe); 214 add(viewMenu, KeyEvent.VK_V, "view"); 216 215 217 toolsMenu.setMnemonic('T'); 218 current = toolsMenu.add(splitWay); 219 current.setAccelerator(splitWay.shortCut); 220 current = toolsMenu.add(combineWay); 221 current.setAccelerator(combineWay.shortCut); 216 add(toolsMenu, splitWay); 217 add(toolsMenu, combineWay); 222 218 toolsMenu.addSeparator(); 223 current = toolsMenu.add(reverseWay); 224 current.setAccelerator(reverseWay.shortCut); 219 add(toolsMenu, reverseWay); 225 220 toolsMenu.addSeparator(); 226 current = toolsMenu.add(alignInCircle); 227 current.setAccelerator(alignInCircle.shortCut); 228 current = toolsMenu.add(alignInLine); 229 current.setAccelerator(alignInLine.shortCut); 230 current = toolsMenu.add(alignInRect); 231 current.setAccelerator(alignInRect.shortCut); 221 add(toolsMenu, alignInCircle); 222 add(toolsMenu, alignInLine); 223 add(toolsMenu, alignInRect); 232 224 toolsMenu.addSeparator(); 233 current = toolsMenu.add(createCircle); 234 current.setAccelerator(createCircle.shortCut); 225 add(toolsMenu, createCircle); 235 226 toolsMenu.addSeparator(); 236 current = toolsMenu.add(mergeNodes); 237 current.setAccelerator(mergeNodes.shortCut); 238 current = toolsMenu.add(joinNodeWay); 239 current.setAccelerator(joinNodeWay.shortCut); 240 current = toolsMenu.add(unglueNodes); 241 current.setAccelerator(unglueNodes.shortCut); 242 add(toolsMenu); 227 add(toolsMenu, mergeNodes); 228 add(toolsMenu, joinNodeWay); 229 add(toolsMenu, unglueNodes); 230 add(toolsMenu, KeyEvent.VK_T, "tools"); 243 231 244 232 if (! Main.pref.getBoolean("audio.menuinvisible")) { 245 audioMenu.setMnemonic('A'); 246 current = audioMenu.add(audioPlayPause); 247 current.setAccelerator(audioPlayPause.shortCut); 248 current = audioMenu.add(audioNext); 249 current.setAccelerator(audioNext.shortCut); 250 current = audioMenu.add(audioPrev); 251 current.setAccelerator(audioPrev.shortCut); 252 current = audioMenu.add(audioFwd); 253 current.setAccelerator(audioFwd.shortCut); 254 current = audioMenu.add(audioBack); 255 current.setAccelerator(audioBack.shortCut); 256 current = audioMenu.add(audioSlower); 257 current.setAccelerator(audioSlower.shortCut); 258 current = audioMenu.add(audioFaster); 259 current.setAccelerator(audioFaster.shortCut); 260 add(audioMenu); 233 add(audioMenu, audioPlayPause); 234 add(audioMenu, audioNext); 235 add(audioMenu, audioPrev); 236 add(audioMenu, audioFwd); 237 add(audioMenu, audioBack); 238 add(audioMenu, audioSlower); 239 add(audioMenu, audioFaster); 240 add(audioMenu, KeyEvent.VK_A, "audio"); 261 241 } 262 242 263 add(presetsMenu); 264 presetsMenu.setMnemonic('P'); 265 266 helpMenu.setMnemonic('H'); 243 add(presetsMenu, KeyEvent.VK_P, "presets"); 244 267 245 JMenuItem check = new JMenuItem("DEBUG: Check Dataset"); 268 246 check.addActionListener(new ActionListener(){ 269 247 public void actionPerformed(ActionEvent e) { 270 248 DataSetChecker.check(); 271 }249 } 272 250 }); 273 current = helpMenu.add(check); 274 current = helpMenu.add(help); 275 //current.setAccelerator(help.shortCut); 276 current = helpMenu.add(about); 277 current.setAccelerator(about.shortCut); 278 current = helpMenu.add(historyinfo); 279 current.setAccelerator(historyinfo.shortCut); 280 add(helpMenu); 251 helpMenu.add(check); 252 current = helpMenu.add(help); // why is help not a JosmAction? 253 current.setAccelerator(ShortCut.registerShortCut("system:help", tr("Help"), KeyEvent.VK_F1, ShortCut.GROUP_DIRECT).getKeyStroke()); 254 add(helpMenu, about); 255 add(helpMenu, historyinfo); 256 add(helpMenu, KeyEvent.VK_H, "help"); 281 257 } 282 258 } -
src/org/openstreetmap/josm/gui/preferences/LafPreference.java
4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.awt.Component; 7 import java.lang.reflect.*; 7 8 8 9 import javax.swing.DefaultListCellRenderer; 9 10 import javax.swing.JComboBox; … … 25 26 26 27 public void addGui(PreferenceDialog gui) { 27 28 lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels()); 28 29 30 // let's try to load additional LookAndFeels and put them into the list 31 try { 32 Class Cquaqua = Class.forName("ch.randelshofer.quaqua.QuaquaLookAndFeel"); 33 Object Oquaqua = Cquaqua.getConstructor((Class[])null).newInstance((Object[])null); 34 // no exception? Then Go! 35 lafCombo.addItem( 36 new UIManager.LookAndFeelInfo(((javax.swing.LookAndFeel)Oquaqua).getName(), "ch.randelshofer.quaqua.QuaquaLookAndFeel") 37 ); 38 } catch (Exception ex) { 39 // just ignore, Quaqua may not even be installed... 40 //System.out.println("Failed to load Quaqua: " + ex); 41 } 42 29 43 String laf = Main.pref.get("laf"); 30 44 for (int i = 0; i < lafCombo.getItemCount(); ++i) { 31 45 if (((LookAndFeelInfo)lafCombo.getItemAt(i)).getClassName().equals(laf)) { -
src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java
40 40 public final JPanel connection = createPreferenceTab("connection", I18n.tr("Connection Settings"), I18n.tr("Connection Settings for the OSM server.")); 41 41 public final JPanel map = createPreferenceTab("map", I18n.tr("Map Settings"), I18n.tr("Settings for the map projection and data interpretation.")); 42 42 public final JPanel audio = createPreferenceTab("audio", I18n.tr("Audio Settings"), I18n.tr("Settings for the audio player and audio markers.")); 43 43 44 44 /** 45 45 * Construct a JPanel for the preference settings. Layout is GridBagLayout 46 46 * and a centered title label and the description are added. … … 110 110 settings.add(new PluginPreference()); 111 111 settings.add(Main.toolbar); 112 112 settings.add(new AudioPreference()); 113 113 settings.add(new ShortcutPreference()); 114 114 115 for (PluginProxy plugin : Main.plugins) { 115 116 PreferenceSetting p = plugin.getPreferenceSetting(); 116 117 if (p != null) -
src/org/openstreetmap/josm/gui/MapMover.java
15 15 import javax.swing.JComponent; 16 16 import javax.swing.JPanel; 17 17 import javax.swing.KeyStroke; 18 import org.openstreetmap.josm.tools.ShortCut; 19 import static org.openstreetmap.josm.tools.I18n.tr; 18 20 19 21 import org.openstreetmap.josm.data.coor.EastNorth; 20 22 … … 77 79 nc.addMouseListener(this); 78 80 nc.addMouseMotionListener(this); 79 81 nc.addMouseWheelListener(this); 80 81 String[] n = {",",".","up","right","down","left"};82 int[] k = {KeyEvent.VK_COMMA, KeyEvent.VK_PERIOD, KeyEvent.VK_UP, KeyEvent.VK_RIGHT, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT};83 82 84 83 if (contentPane != null) { 85 for (int i = 0; i < n.length; ++i) { 86 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(k[i], KeyEvent.CTRL_DOWN_MASK), "MapMover.Zoomer."+n[i]); 87 contentPane.getActionMap().put("MapMover.Zoomer."+n[i], new ZoomerAction(n[i])); 88 } 84 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 85 ShortCut.registerShortCut("system:movefocusright", tr("Map: Move right"), KeyEvent.VK_RIGHT, ShortCut.GROUP_HOTKEY).getKeyStroke(), 86 "MapMover.Zoomer.right"); 87 contentPane.getActionMap().put("MapMover.Zoomer.right", new ZoomerAction("right")); 88 89 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 90 ShortCut.registerShortCut("system:movefocusleft", tr("Map: Move left"), KeyEvent.VK_LEFT, ShortCut.GROUP_HOTKEY).getKeyStroke(), 91 "MapMover.Zoomer.left"); 92 contentPane.getActionMap().put("MapMover.Zoomer.left", new ZoomerAction("left")); 93 94 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 95 ShortCut.registerShortCut("system:movefocusup", tr("Map: Move up"), KeyEvent.VK_UP, ShortCut.GROUP_HOTKEY).getKeyStroke(), 96 "MapMover.Zoomer.up"); 97 contentPane.getActionMap().put("MapMover.Zoomer.up", new ZoomerAction("up")); 98 99 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 100 ShortCut.registerShortCut("system:movefocusdown", tr("Map: Move down"), KeyEvent.VK_DOWN, ShortCut.GROUP_HOTKEY).getKeyStroke(), 101 "MapMover.Zoomer.down"); 102 contentPane.getActionMap().put("MapMover.Zoomer.down", new ZoomerAction("down")); 103 104 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 105 ShortCut.registerShortCut("view:zoominalternate", tr("Map: Zoom in"), KeyEvent.VK_COMMA, ShortCut.GROUP_HOTKEY).getKeyStroke(), 106 "MapMover.Zoomer.in"); 107 contentPane.getActionMap().put("MapMover.Zoomer.in", new ZoomerAction(",")); 108 109 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 110 ShortCut.registerShortCut("view:zoomoutalternate", tr("Map: Zoom out"), KeyEvent.VK_PERIOD, ShortCut.GROUP_HOTKEY).getKeyStroke(), 111 "MapMover.Zoomer.out"); 112 contentPane.getActionMap().put("MapMover.Zoomer.out", new ZoomerAction(".")); 89 113 } 90 114 } 91 115 … … 168 192 double newHalfHeight = h*zoomfactor - h/2; 169 193 double centerx = e.getX() - (e.getX()-w/2)*newHalfWidth*2/w; 170 194 double centery = e.getY() - (e.getY()-h/2)*newHalfHeight*2/h; 171 EastNorth newCenter = nc.getEastNorth((int)centerx, (int)centery); 195 EastNorth newCenter = nc.getEastNorth((int)centerx, (int)centery); 172 196 173 197 nc.zoomTo(newCenter, nc.getScale()*zoom); 174 198 } -
src/org/openstreetmap/josm/gui/MainApplet.java
28 28 import org.openstreetmap.josm.actions.JosmAction; 29 29 import org.openstreetmap.josm.data.ServerSidePreferences; 30 30 import org.openstreetmap.josm.tools.GBC; 31 import org.openstreetmap.josm.tools.ShortCut; 31 32 32 33 public class MainApplet extends JApplet { 33 34 34 35 public static final class UploadPreferencesAction extends JosmAction { 35 36 public UploadPreferencesAction() { 36 super(tr("Upload Preferences"), "upload-preferences", tr("Upload the current preferences to the server"), KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK, true); 37 super(tr("Upload Preferences"), "upload-preferences", tr("Upload the current preferences to the server"), 38 ShortCut.registerShortCut("applet:uploadprefs", tr("Upload preferences"), KeyEvent.VK_U, ShortCut.GROUP_HOTKEY), true); 37 39 } 38 40 public void actionPerformed(ActionEvent e) { 39 41 ((ServerSidePreferences)Main.pref).upload(); … … 99 101 Main.preConstructorInit(args); 100 102 Main.parent = this; 101 103 new MainCaller().postConstructorProcessCmdLine(args); 102 104 103 105 MainMenu m = Main.main.menu; // shortcut 104 106 105 107 // remove offending stuff from JOSM (that would break the SecurityManager) -
src/org/openstreetmap/josm/Main.java
58 58 import org.openstreetmap.josm.plugins.PluginInformation; 59 59 import org.openstreetmap.josm.plugins.PluginProxy; 60 60 import org.openstreetmap.josm.tools.ImageProvider; 61 import org.openstreetmap.josm.tools.PlatformHook; 62 import org.openstreetmap.josm.tools.PlatformHookUnixoid; 63 import org.openstreetmap.josm.tools.PlatformHookWindows; 64 import org.openstreetmap.josm.tools.PlatformHookOsx; 65 import org.openstreetmap.josm.tools.ShortCut; 61 66 62 67 abstract public class Main { 63 68 /** … … 132 137 } 133 138 134 139 /** 140 * Platform specific code goes in here. 141 * Plugins may replace it, however, some hooks will be called before any plugins have been loeaded. 142 * So if you need to hook into those early ones, split your class and send the one with the early hooks 143 * to the JOSM team for inclusion. 144 */ 145 public static PlatformHook platform; 146 147 /** 135 148 * Set or clear (if passed <code>null</code>) the map. 136 149 */ 137 150 public final void setMapFrame(final MapFrame map) { … … 177 190 setMapFrame(null); 178 191 } 179 192 180 181 193 public Main() { 182 194 main = this; 195 // platform = determinePlatformHook(); 196 platform.startupHook(); 183 197 contentPane.add(panel, BorderLayout.CENTER); 184 198 panel.add(new GettingStarted(), BorderLayout.CENTER); 185 199 menu = new MainMenu(); 186 200 187 201 undoRedo.listenerCommands.add(redoUndoListener); 188 202 189 203 // creating toolbar 190 204 contentPane.add(toolbar.control, BorderLayout.NORTH); 191 205 192 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "Help");206 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ShortCut.registerShortCut("system:help", tr("Help"), KeyEvent.VK_F1, ShortCut.GROUP_DIRECT).getKeyStroke(), "Help"); 193 207 contentPane.getActionMap().put("Help", menu.help); 194 208 195 209 TaggingPresetPreference.initialize(); … … 234 248 if(!lang.equals("en")) 235 249 plugins.add("lang-"+lang); 236 250 } 237 251 238 252 if (plugins.isEmpty()) 239 253 return; 240 254 SortedMap<Integer, Collection<PluginInformation>> p = new TreeMap<Integer, Collection<PluginInformation>>(); … … 249 263 } else { 250 264 if (early) 251 265 System.out.println("Plugin not found: "+pluginName); // do not translate 252 else 266 else 253 267 JOptionPane.showMessageDialog(Main.parent, tr("Plugin not found: {0}.", pluginName)); 254 268 } 255 269 } 256 270 257 271 // iterate all plugins and collect all libraries of all plugins: 258 272 List<URL> allPluginLibraries = new ArrayList<URL>(); 259 273 for (Collection<PluginInformation> c : p.values()) … … 289 303 if (remove) { 290 304 plugins.remove(info.name); 291 305 String plist = null; 292 for (String pn : plugins) { 306 for (String pn : plugins) { 293 307 if (plist==null) plist=""; else plist=plist+","; 294 308 plist=plist+pn; 295 309 } … … 414 428 } 415 429 416 430 public static boolean breakBecauseUnsavedChanges() { 431 ShortCut.savePrefs(); 417 432 if (map != null) { 418 433 boolean modified = false; 419 434 boolean uploadedModified = false; … … 470 485 471 486 main.menu.open.openFile(new File(s)); 472 487 } 488 489 protected static void determinePlatformHook() { 490 String os = System.getProperty("os.name"); 491 if (os == null) { 492 System.err.println("Your operating system has no name, so I'm guessing its some kind of *nix."); 493 platform = new PlatformHookUnixoid(); 494 } else if (os.toLowerCase().startsWith("windows")) { 495 platform = new PlatformHookWindows(); 496 } else if (os.equals("Linux") || os.equals("Solaris") || os.equals("SunOS") || os.equals("AIX") || os.equals("FreeBSD")) { 497 platform = new PlatformHookUnixoid(); 498 } else if (os.toLowerCase().startsWith("mac os x")) { 499 platform = new PlatformHookOsx(); 500 } else { 501 System.err.println("I don't know your operating system '"+os+"', so I'm guessing its some kind of *nix."); 502 platform = new PlatformHookUnixoid(); 503 } 504 } 505 473 506 } -
build.xml
36 36 <delete file="dist/josm-custom.jar"/> 37 37 <jar destfile="dist/josm-custom.jar" basedir="build"> 38 38 <manifest> 39 <attribute name="Main-class" value=" org.openstreetmap.josm.gui.MainApplication" />39 <attribute name="Main-class" value="JOSM" /> 40 40 </manifest> 41 41 </jar> 42 42 </target>
