Changeset 4956 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-02-16T18:17:02+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r4954 r4956 99 99 private SnapHelper snapHelper = new SnapHelper(); 100 100 101 private Shortcut extraShortcut;102 101 private Shortcut backspaceShortcut; 103 private int snappingKeyCode;104 102 private Shortcut snappingShortcut; 103 105 104 private JCheckBoxMenuItem snapCheckboxMenuItem; 106 107 105 108 106 public DrawAction(MapFrame mapFrame) { 109 107 super(tr("Draw"), "node/autonode", tr("Draw nodes"), 110 Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.GROUP_EDIT), 111 mapFrame, ImageProvider.getCursor("crosshair", null)); 112 113 // Add extra shortcut N 114 extraShortcut = Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT); 115 Main.registerActionShortcut(this, extraShortcut); 116 117 snappingKeyCode = Shortcut.registerShortcut("mapmode:drawanglesnapping", tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.GROUP_EDIT) 118 .getKeyStroke().getKeyCode(); 108 Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.GROUP_EDIT), 109 mapFrame, ImageProvider.getCursor("crosshair", null)); 110 111 snappingShortcut = Shortcut.registerShortcut("mapmode:drawanglesnapping", 112 tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.GROUP_EDIT); 119 113 addMenuItem(); 120 114 snapHelper.setMenuCheckBox(snapCheckboxMenuItem); … … 128 122 JMenuItem item = Main.main.menu.editMenu.getItem(i); 129 123 if (item!=null && item.getAction() !=null && item.getAction() instanceof SnapChangeAction) { 130 Main.main.menu.editMenu.remove(i); 124 Main.main.menu.editMenu.remove(i); 131 125 } 132 126 } … … 139 133 private void redrawIfRequired() { 140 134 updateStatusLine(); 141 if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight) return; 135 if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight) 136 return; 142 137 // update selection to reflect which way being modified 143 138 if (currentBaseNode != null && getCurrentDataSet().getSelected().isEmpty() == false) { … … 155 150 } 156 151 157 @Override public void enterMode() { 152 @Override 153 public void enterMode() { 158 154 if (!isEnabled()) 159 155 return; … … 165 161 snapHelper.init(); 166 162 snapCheckboxMenuItem.getAction().setEnabled(true); 167 163 168 164 timer = new Timer(0, new ActionListener() { 169 165 @Override 170 166 public void actionPerformed(ActionEvent ae) { 171 172 173 doKeyReleaseEvent(releaseEvent);174 167 timer.stop(); 168 if (set.remove(releaseEvent.getKeyCode())) { 169 doKeyReleaseEvent(releaseEvent); 170 } 175 171 } 176 172 177 173 }); 178 Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener); 179 backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace", tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.GROUP_EDIT); 174 Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener); 175 backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace", 176 tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.GROUP_EDIT); 180 177 Main.registerActionShortcut(new BackSpaceAction(), backspaceShortcut); 181 178 … … 193 190 } 194 191 195 @Override public void exitMode() { 192 @Override 193 public void exitMode() { 196 194 super.exitMode(); 197 195 Main.map.mapView.removeMouseListener(this); … … 203 201 snapCheckboxMenuItem.getAction().setEnabled(false); 204 202 Main.map.statusLine.getAnglePanel().removeMouseListener(snapHelper.anglePopupListener); 205 203 206 204 removeHighlighting(); 207 205 try { … … 226 224 return; 227 225 if (event instanceof KeyEvent) { 228 226 processKeyEvent((KeyEvent) event); 229 227 } // toggle angle snapping 230 228 updateKeyModifiers((InputEvent) event); … … 233 231 redrawIfRequired(); 234 232 } 235 236 237 // events for crossplatform key holding processing 238 // thanks to http://www.arco.in-berlin.de/keyevent.html 233 234 // events for crossplatform key holding processing 235 // thanks to http://www.arco.in-berlin.de/keyevent.html 239 236 private final TreeSet<Integer> set = new TreeSet<Integer>(); 240 237 private KeyEvent releaseEvent; 241 238 private Timer timer; 242 239 void processKeyEvent(KeyEvent e) { 243 if ( e.getKeyCode() != snappingKeyCode) return;244 //e.consume(); // ticket #7250 - TAB should work in other windows240 if (!snappingShortcut.isEvent(e)) 241 return; 245 242 246 243 if (e.getID() == KeyEvent.KEY_PRESSED) { 247 if (timer.isRunning()) {248 timer.stop();249 } else {250 if (set.add((e.getKeyCode()))) doKeyPressEvent(e);251 }252 253 }254 if (e.getID() == KeyEvent.KEY_RELEASED) {255 244 if (timer.isRunning()) { 256 timer.stop(); 257 if (set.remove(e.getKeyCode())) { 258 doKeyReleaseEvent(e); 259 } 245 timer.stop(); 246 } else if (set.add((e.getKeyCode()))) { 247 doKeyPressEvent(e); 248 } 249 } else if (e.getID() == KeyEvent.KEY_RELEASED) { 250 if (timer.isRunning()) { 251 timer.stop(); 252 if (set.remove(e.getKeyCode())) { 253 doKeyReleaseEvent(e); 254 } 260 255 } else { 261 releaseEvent = e; 262 timer.restart(); 263 } 264 } 265 266 } 267 256 releaseEvent = e; 257 timer.restart(); 258 } 259 } 260 } 261 268 262 private void doKeyPressEvent(KeyEvent e) { 269 if (e.getKeyCode() != snappingKeyCode) return; 263 if (!snappingShortcut.isEvent(e)) 264 return; 270 265 snapHelper.setFixedMode(); 271 computeHelperLine(); redrawIfRequired(); 266 computeHelperLine(); 267 redrawIfRequired(); 272 268 } 273 269 private void doKeyReleaseEvent(KeyEvent e) { 274 if (e.getKeyCode() != snappingKeyCode) return; 270 if (!snappingShortcut.isEvent(e)) 271 return; 275 272 snapHelper.unFixOrTurnOff(); 276 computeHelperLine(); redrawIfRequired(); 273 computeHelperLine(); 274 redrawIfRequired(); 277 275 } 278 276 … … 306 304 Main.map.selectSelectTool(true); 307 305 snapHelper.noSnapNow(); 308 306 309 307 // Redraw to remove the helper line stub 310 308 computeHelperLine(); … … 321 319 } 322 320 } 323 321 324 322 /** 325 323 * If user clicked with the left button, add a node at the current mouse … … 348 346 // 349 347 Main.map.mapView.requestFocus(); 350 348 351 349 if(e.getClickCount() > 1 && mousePos != null && mousePos.equals(oldMousePos)) { 352 350 // A double click equals "user clicked last node again, finish way" … … 357 355 } 358 356 oldMousePos = mousePos; 359 357 360 358 // we copy ctrl/alt/shift from the event just in case our global 361 359 // AWTEvent didn't make it through the security manager. Unclear … … 401 399 EastNorth foundPoint = n.getEastNorth(); 402 400 // project found node to snapping line 403 newEN = snapHelper.getSnapPoint(foundPoint); 401 newEN = snapHelper.getSnapPoint(foundPoint); 404 402 if (foundPoint.distance(newEN) > 1e-4) { 405 403 n = new Node(newEN); // point != projected, so we create new node … … 418 416 if (n.getCoor().isOutSideWorld()) { 419 417 JOptionPane.showMessageDialog( 420 421 422 423 418 Main.parent, 419 tr("Cannot add a node outside of the world."), 420 tr("Warning"), 421 JOptionPane.WARNING_MESSAGE 424 422 ); 425 423 return; … … 428 426 429 427 if (!ctrl) { 430 431 432 433 if (snapHelper.isActive()) { //434 435 436 437 428 // Insert the node into all the nearby way segments 429 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments( 430 Main.map.mapView.getPoint(n), OsmPrimitive.isSelectablePredicate); 431 if (snapHelper.isActive()) { 432 tryToMoveNodeOnIntersection(wss,n); 433 } 434 insertNodeIntoAllNearbySegments(wss, n, newSelection, cmds, replacedWays, reuseWays); 435 } 438 436 } 439 437 // now "n" is newly created or reused node that shoud be added to some way 440 438 441 439 // This part decides whether or not a "segment" (i.e. a connection) is made to an 442 440 // existing node. … … 588 586 redrawIfRequired(); 589 587 } 590 588 591 589 private void insertNodeIntoAllNearbySegments(List<WaySegment> wss, Node n, Collection<OsmPrimitive> newSelection, Collection<Command> cmds, ArrayList<Way> replacedWays, ArrayList<Way> reuseWays) { 592 590 Map<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); … … 613 611 pruneSuccsAndReverse(is); 614 612 for (int i : is) { 615 segSet.add( 616 Pair.sort(new Pair<Node,Node>(w.getNode(i), w.getNode(i+1)))); 613 segSet.add(Pair.sort(new Pair<Node,Node>(w.getNode(i), w.getNode(i+1)))); 617 614 } 618 615 for (int i : is) { … … 636 633 adjustNode(segSet, n); 637 634 } 638 639 635 640 636 /** … … 698 694 } 699 695 700 @Override public void mouseDragged(MouseEvent e) { 696 @Override 697 public void mouseDragged(MouseEvent e) { 701 698 mouseMoved(e); 702 699 } 703 700 704 @Override public void mouseMoved(MouseEvent e) { 701 @Override 702 public void mouseMoved(MouseEvent e) { 705 703 if(!Main.map.mapView.isActiveLayerDrawable()) 706 704 return; … … 767 765 determineCurrentBaseNodeAndPreviousNode(selection); 768 766 if (previousNode == null) snapHelper.noSnapNow(); 769 767 770 768 if (currentBaseNode == null || currentBaseNode == currentMouseNode) 771 769 return; // Don't create zero length way segments. … … 773 771 774 772 double curHdg = Math.toDegrees(currentBaseNode.getEastNorth() 775 773 .heading(currentMouseEastNorth)); 776 774 double baseHdg=-1; 777 775 if (previousNode != null) { 778 776 baseHdg = Math.toDegrees(previousNode.getEastNorth() 779 780 } 781 777 .heading(currentBaseNode.getEastNorth())); 778 } 779 782 780 snapHelper.checkAngleSnapping(currentMouseEastNorth,baseHdg, curHdg); 783 781 784 782 // status bar was filled by snapHelper 785 786 // Now done in redrawIfRequired()787 //updateStatusLine();788 783 } 789 784 … … 794 789 } 795 790 796 /** 797 * Helper function that sets fields currentBaseNode and previousNode 798 * @param selection 791 /** 792 * Helper function that sets fields currentBaseNode and previousNode 793 * @param selection 799 794 * uses also lastUsedNode field 800 795 */ … … 804 799 for (OsmPrimitive p : selection) { 805 800 if (p instanceof Node) { 806 if (selectedNode != null) return; 801 if (selectedNode != null) 802 return; 807 803 selectedNode = (Node) p; 808 804 } else if (p instanceof Way) { 809 if (selectedWay != null) return; 805 if (selectedWay != null) 806 return; 810 807 selectedWay = (Way) p; 811 808 } … … 835 832 if (selectedNode == selectedWay.lastNode()) { 836 833 currentBaseNode = selectedNode; 837 if (selectedWay.getNodesCount()>1) 834 if (selectedWay.getNodesCount()>1) 838 835 previousNode = selectedWay.getNode(selectedWay.getNodesCount()-2); 839 836 } … … 879 876 880 877 private static void pruneSuccsAndReverse(List<Integer> is) { 881 //if (is.size() < 2) return;882 883 878 HashSet<Integer> is2 = new HashSet<Integer>(); 884 879 for (int i : is) { … … 929 924 // In practice this will probably only happen when a way has been duplicated 930 925 931 if (u == 0) return; 926 if (u == 0) 927 return; 932 928 933 929 // q is a number between 0 and 1 … … 950 946 return; 951 947 } 952 953 948 default: 954 949 EastNorth P = n.getEastNorth(); … … 970 965 971 966 private void tryToMoveNodeOnIntersection(List<WaySegment> wss, Node n) { 972 if (wss.isEmpty()) return; 967 if (wss.isEmpty()) 968 return; 973 969 WaySegment ws = wss.get(0); 974 970 EastNorth p1=ws.getFirstNode().getEastNorth(); 975 971 EastNorth p2=ws.getSecondNode().getEastNorth(); 976 972 if (snapHelper.dir2!=null && currentBaseNode!=null) { 977 973 EastNorth xPoint = Geometry.getSegmentSegmentIntersection(p1, p2, snapHelper.dir2, currentBaseNode.getEastNorth()); 978 974 if (xPoint!=null) n.setEastNorth(xPoint); 979 975 } 980 976 } 981 /**977 /** 982 978 * Takes the data from computeHelperLine to determine which ways/nodes should be highlighted 983 979 * (if feature enabled). Also sets the target cursor if appropriate. … … 1011 1007 Main.map.mapView.setNewCursor(cursor, this); 1012 1008 return; 1013 }1009 } 1014 1010 1015 1011 Main.map.mapView.setNewCursor(cursorJoinWay, this); … … 1032 1028 oldHighlights = new HashSet<OsmPrimitive>(); 1033 1029 } 1034 1030 1035 1031 public void paint(Graphics2D g, MapView mv, Bounds box) { 1036 1032 // sanity checks 1037 if (Main.map.mapView == null) return; 1038 if (mousePos == null) return; 1039 1033 if (Main.map.mapView == null || mousePos == null 1040 1034 // don't draw line if we don't know where from or where to 1041 if (currentBaseNode == null || currentMouseEastNorth == null) return; 1042 1035 || currentBaseNode == null || currentMouseEastNorth == null 1043 1036 // don't draw line if mouse is outside window 1044 if (!Main.map.mapView.getBounds().contains(mousePos)) return; 1045 1037 || !Main.map.mapView.getBounds().contains(mousePos)) 1038 return; 1039 1046 1040 Graphics2D g2 = g; 1047 1041 snapHelper.drawIfNeeded(g2,mv); 1048 if (!drawHelperLine || wayIsFinished || shift) return; 1049 1042 if (!drawHelperLine || wayIsFinished || shift) 1043 return; 1044 1050 1045 if (!snapHelper.isActive()) { // else use color and stoke from snapHelper.draw 1051 1046 g2.setColor(selectedColor); 1052 1047 g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); 1053 } else {1054 if (!snapHelper.drawConstructionGeometry)return;1048 } else if (!snapHelper.drawConstructionGeometry) { 1049 return; 1055 1050 } 1056 1051 GeneralPath b = new GeneralPath(); … … 1072 1067 } 1073 1068 1074 @Override public String getModeHelpText() { 1069 @Override 1070 public String getModeHelpText() { 1075 1071 String rv = ""; 1076 1072 /* … … 1149 1145 } 1150 1146 1151 @Override public boolean layerIsSupported(Layer l) { 1147 @Override 1148 public boolean layerIsSupported(Layer l) { 1152 1149 return l instanceof OsmDataLayer; 1153 1150 } … … 1161 1158 public void destroy() { 1162 1159 super.destroy(); 1163 Main.unregisterActionShortcut(extraShortcut);1164 1160 } 1165 1161 … … 1170 1166 Main.main.undoRedo.undo(); 1171 1167 Node n=null; 1172 Command lastCmd=Main.main.undoRedo.commands.peekLast(); 1168 Command lastCmd=Main.main.undoRedo.commands.peekLast(); 1173 1169 if (lastCmd==null) return; 1174 1170 for (OsmPrimitive p: lastCmd.getParticipatingPrimitives()) { … … 1181 1177 // we have no way to continue, so we forget about found node 1182 1178 n=null; 1183 break; 1179 break; 1184 1180 } 1185 1181 } 1186 1182 } 1187 // select last added node - maybe we will continue drawing from it 1183 // select last added node - maybe we will continue drawing from it 1188 1184 if (n!=null) getCurrentDataSet().addSelected(n); 1189 1185 } 1190 }1186 } 1191 1187 1192 1188 private class SnapHelper { 1193 1189 boolean snapOn; // snapping is turned on 1194 1190 1195 1191 private boolean active; // snapping is active for current mouse position 1196 1192 private boolean fixed; // snap angle is fixed 1197 private boolean absoluteFix; // snap angle is absolute 1198 1199 private boolean drawConstructionGeometry; 1200 private boolean showProjectedPoint; 1201 private boolean showAngle; 1193 private boolean absoluteFix; // snap angle is absolute 1194 1195 private boolean drawConstructionGeometry; 1196 private boolean showProjectedPoint; 1197 private boolean showAngle; 1202 1198 1203 1199 private boolean snapToProjections; 1204 1200 1205 1201 EastNorth dir2; 1206 1202 EastNorth projected; 1207 1203 String labelText; 1208 1204 double lastAngle; 1205 1209 1206 double customBaseHeading=-1; // angle of base line, if not last segment) 1210 1207 private EastNorth segmentPoint1; // remembered first point of base segment 1211 1208 private EastNorth segmentPoint2; // remembered second point of base segment 1212 1209 private EastNorth projectionSource; // point that we are projecting to the line 1213 1214 double snapAngles[]; 1215 double snapAngleTolerance; 1216 1210 1211 double snapAngles[]; 1212 double snapAngleTolerance; 1213 1217 1214 double pe,pn; // (pe,pn) - direction of snapping line 1218 1215 double e0,n0; // (e0,n0) - origin of snapping line 1219 1216 1220 1217 final String fixFmt="%d "+tr("FIX"); 1221 1218 Color snapHelperColor; … … 1225 1222 private Stroke helperStroke; 1226 1223 private Stroke highlightStroke; 1227 1224 1228 1225 JCheckBoxMenuItem checkBox; 1229 1226 1230 1227 public void init() { 1231 1228 snapOn=false; 1232 1229 checkBox.setState(snapOn); 1233 1230 fixed=false; absoluteFix=false; 1234 1235 Collection<String> angles = Main.pref.getCollection("draw.anglesnap.angles", 1236 1237 1231 1232 Collection<String> angles = Main.pref.getCollection("draw.anglesnap.angles", 1233 Arrays.asList("0","30","45","60","90","120","135","150","180")); 1234 1238 1235 snapAngles = new double[2*angles.size()]; 1239 1236 int i=0; … … 1246 1243 snapAngles[i]=0;i++; 1247 1244 snapAngles[i]=0;i++; 1248 } 1245 } 1249 1246 } 1250 1247 snapAngleTolerance = Main.pref.getDouble("draw.anglesnap.tolerance", 5.0); … … 1258 1255 snapHelperColor = Main.pref.getColor(marktr("draw angle snap"), Color.ORANGE); 1259 1256 1260 highlightColor = Main.pref.getColor(marktr("draw angle snap highlight"), new Color(Color.ORANGE.getRed(),Color.ORANGE.getGreen(),Color.ORANGE.getBlue(),128)); 1257 highlightColor = Main.pref.getColor(marktr("draw angle snap highlight"), 1258 new Color(Color.ORANGE.getRed(),Color.ORANGE.getGreen(),Color.ORANGE.getBlue(),128)); 1261 1259 highlightStroke = new BasicStroke(10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); 1262 1260 1263 1261 float dash1[] = { 4.0f }; 1264 1262 helperStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, 1265 BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f); 1266 1267 } 1268 1263 BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f); 1264 } 1265 1269 1266 public void saveAngles(String ... angles) { 1270 1267 Main.pref.putCollection("draw.anglesnap.angles", Arrays.asList(angles)); 1271 1268 } 1272 1269 1273 1270 public void setMenuCheckBox(JCheckBoxMenuItem checkBox) { 1274 1271 this.checkBox = checkBox; 1275 1272 } 1276 1277 1273 1278 1274 public void drawIfNeeded(Graphics2D g2, MapView mv) { 1279 if (!snapOn ) return;1280 if (!active)return;1275 if (!snapOn || !active) 1276 return; 1281 1277 Point p1=mv.getPoint(currentBaseNode); 1282 1278 Point p2=mv.getPoint(dir2); … … 1289 1285 b = new GeneralPath(); 1290 1286 if (absoluteFix) { 1291 b.moveTo(p2.x,p2.y); 1287 b.moveTo(p2.x,p2.y); 1292 1288 b.lineTo(2*p1.x-p2.x,2*p1.y-p2.y); // bi-directional line 1293 1289 } else { 1294 1290 b.moveTo(p2.x,p2.y); 1295 1291 b.lineTo(p3.x,p3.y); 1296 } 1292 } 1297 1293 g2.draw(b); 1298 1294 } 1299 if (projectionSource !=null) {1295 if (projectionSource != null) { 1300 1296 g2.setColor(snapHelperColor); 1301 1297 g2.setStroke(helperStroke); … … 1303 1299 b.moveTo(p3.x,p3.y); 1304 1300 Point pp=mv.getPoint(projectionSource); 1305 b.lineTo(pp.x,pp.y); 1301 b.lineTo(pp.x,pp.y); 1306 1302 g2.draw(b); 1307 1303 } 1308 1309 1310 if (customBaseHeading>=0) { 1304 1305 if (customBaseHeading >= 0) { 1311 1306 g2.setColor(highlightColor); 1312 1307 g2.setStroke(highlightStroke); … … 1314 1309 Point pp1=mv.getPoint(segmentPoint1); 1315 1310 Point pp2=mv.getPoint(segmentPoint2); 1316 b.moveTo(pp1.x,pp1.y); 1311 b.moveTo(pp1.x,pp1.y); 1317 1312 b.lineTo(pp2.x,pp2.y); 1318 1313 g2.draw(b); 1319 1314 } 1320 1321 1315 1322 1316 g2.setColor(selectedColor); 1323 1317 g2.setStroke(normalStroke); 1324 1318 b = new GeneralPath(); 1325 b.moveTo(p1.x,p1.y); 1319 b.moveTo(p1.x,p1.y); 1326 1320 b.lineTo(p3.x,p3.y); 1327 1321 g2.draw(b); 1328 1322 1329 1323 g2.drawString(labelText, p3.x-5, p3.y+20); 1330 1324 if (showProjectedPoint) { … … 1332 1326 g2.drawOval(p3.x-5, p3.y-5, 10, 10); // projected point 1333 1327 } 1334 1328 1335 1329 g2.setColor(snapHelperColor); 1336 1330 g2.setStroke(helperStroke); 1337 1338 } 1339 1331 } 1332 1340 1333 /* If mouse position is close to line at 15-30-45-... angle, remembers this direction 1341 1334 */ … … 1344 1337 EastNorth snapPoint = currentEN; 1345 1338 double angle = -1; 1346 1347 double activeBaseHeading = (customBaseHeading>=0)? customBaseHeading : baseHeading; 1348 1339 1340 double activeBaseHeading = (customBaseHeading>=0)? customBaseHeading : baseHeading; 1341 1349 1342 if (snapOn && (activeBaseHeading>=0)) { 1350 1343 angle = curHeading - activeBaseHeading; 1351 1344 if (angle < 0) angle+=360; 1352 1345 if (angle > 360) angle=0; 1353 1346 1354 1347 double nearestAngle; 1355 1348 if (fixed) { … … 1362 1355 // if angle is to previous segment, exclude 180 degrees 1363 1356 lastAngle = nearestAngle; 1364 } else active=false; 1357 } else { 1358 active=false; 1359 } 1365 1360 } 1366 1361 … … 1388 1383 double hdg = Math.toDegrees(p0.heading(snapPoint)); 1389 1384 // heading of segment from current to calculated point, not to mouse position 1390 1385 1391 1386 if (baseHeading >=0 ) { // there is previous line segment with some heading 1392 1387 angle = hdg - baseHeading; … … 1420 1415 } 1421 1416 } 1422 1417 1423 1418 public EastNorth getSnapPoint(EastNorth p) { 1424 if (!active) return p; 1419 if (!active) 1420 return p; 1425 1421 double de=p.east()-e0; 1426 1422 double dn=p.north()-n0; 1427 1423 double l = de*pe+dn*pn; 1428 1424 double delta = Main.map.mapView.getDist100Pixel()/20; 1429 if (!absoluteFix && l<delta) {active=false; return p; } // do not go backward! 1430 1425 if (!absoluteFix && l<delta) { 1426 active=false; 1427 return p; 1428 } // do not go backward! 1429 1431 1430 projectionSource=null; 1432 1431 if (snapToProjections) { … … 1440 1439 if (Math.abs(l1-l) < delta) { 1441 1440 l=l1; 1442 projectionSource = en; 1441 projectionSource = en; 1443 1442 break; 1444 1443 } … … 1448 1447 return projected = new EastNorth(e0+l*pe, n0+l*pn); 1449 1448 } 1450 1451 1449 1450 1452 1451 public void noSnapNow() { 1453 active=false; 1452 active=false; 1454 1453 dir2=null; projected=null; 1455 1454 labelText=null; … … 1460 1459 segmentPoint1=seg.getFirstNode().getEastNorth(); 1461 1460 segmentPoint2=seg.getSecondNode().getEastNorth(); 1462 1461 1463 1462 double hdg = segmentPoint1.heading(segmentPoint2); 1464 1463 hdg=Math.toDegrees(hdg); … … 1473 1472 if (snapOn) { 1474 1473 // turn off snapping if we are in fixed mode or no actile snapping line exist 1475 if (fixed || !active) { snapOn=false; unsetFixedMode(); } 1474 if (fixed || !active) { snapOn=false; unsetFixedMode(); } 1476 1475 else setFixedMode(); 1477 1476 } else { … … 1482 1481 customBaseHeading=-1; 1483 1482 } 1484 1483 1485 1484 private void enableSnapping() { 1486 1485 snapOn = true; … … 1489 1488 unsetFixedMode(); 1490 1489 } 1491 1490 1492 1491 private void toggleSnapping() { 1493 1492 snapOn = !snapOn; … … 1496 1495 unsetFixedMode(); 1497 1496 } 1498 1497 1499 1498 public void setFixedMode() { 1500 if (active) { fixed=true; } 1501 } 1502 1503 1499 if (active) { 1500 fixed=true; 1501 } 1502 } 1503 1504 1504 1505 public void unsetFixedMode() { 1505 fixed=false; absoluteFix=false; 1506 fixed=false; 1507 absoluteFix=false; 1506 1508 lastAngle=0; 1507 1509 active=false; 1508 1510 } 1509 1511 1510 1512 public boolean isActive() { 1511 1513 return active; 1512 1514 } 1513 1515 1514 1516 public boolean isSnapOn() { 1515 1517 return snapOn; … … 1518 1520 private double getNearestAngle(double angle) { 1519 1521 double delta,minDelta=1e5, bestAngle=0.0; 1520 for (int i=0; i <snapAngles.length; i++) {1522 for (int i=0; i < snapAngles.length; i++) { 1521 1523 delta = getAngleDelta(angle,snapAngles[i]); 1522 if (delta <minDelta) {1524 if (delta < minDelta) { 1523 1525 minDelta=delta; 1524 1526 bestAngle=snapAngles[i]; 1525 1527 } 1526 1528 } 1527 if (Math.abs(bestAngle-360)<1e-3) bestAngle=0; 1529 if (Math.abs(bestAngle-360) < 1e-3) 1530 bestAngle=0; 1528 1531 return bestAngle; 1529 1532 } … … 1531 1534 private double getAngleDelta(double a, double b) { 1532 1535 double delta = Math.abs(a-b); 1533 if (delta>180) return 360-delta; else return delta; 1536 if (delta>180) 1537 return 360-delta; 1538 else 1539 return delta; 1534 1540 } 1535 1541 1536 1542 private void unFixOrTurnOff() { 1537 if (absoluteFix) unsetFixedMode(); else toggleSnapping(); 1538 } 1539 1543 if (absoluteFix) 1544 unsetFixedMode(); 1545 else 1546 toggleSnapping(); 1547 } 1548 1540 1549 MouseListener anglePopupListener = new PopupMenuLauncher( new JPopupMenu() { 1541 JCheckBoxMenuItem helperCb = new JCheckBoxMenuItem(new AbstractAction(tr("Show helper geometry")){ 1550 JCheckBoxMenuItem helperCb = new JCheckBoxMenuItem(new AbstractAction(tr("Show helper geometry")){ 1551 public void actionPerformed(ActionEvent e) { 1552 boolean sel=((JCheckBoxMenuItem) e.getSource()).getState(); 1553 Main.pref.put("draw.anglesnap.drawConstructionGeometry", sel); 1554 Main.pref.put("draw.anglesnap.drawProjectedPoint", sel); 1555 Main.pref.put("draw.anglesnap.showAngle", sel); 1556 init(); 1557 enableSnapping(); 1558 } 1559 }); 1560 JCheckBoxMenuItem projectionCb = new JCheckBoxMenuItem(new AbstractAction(tr("Snap to node projections")){ 1561 public void actionPerformed(ActionEvent e) { 1562 boolean sel=((JCheckBoxMenuItem) e.getSource()).getState(); 1563 Main.pref.put("draw.anglesnap.projectionsnap", sel); 1564 init(); 1565 enableSnapping(); 1566 } 1567 }); 1568 { 1569 helperCb.setState(Main.pref.getBoolean("draw.anglesnap.drawConstructionGeometry",true)); 1570 projectionCb.setState(Main.pref.getBoolean("draw.anglesnap.projectionsnapgvff",true)); 1571 add(helperCb); 1572 add(projectionCb);; 1573 add(new AbstractAction(tr("Disable")) { 1542 1574 public void actionPerformed(ActionEvent e) { 1543 boolean sel=((JCheckBoxMenuItem) e.getSource()).getState(); 1544 Main.pref.put("draw.anglesnap.drawConstructionGeometry", sel); 1545 Main.pref.put("draw.anglesnap.drawProjectedPoint", sel); 1546 Main.pref.put("draw.anglesnap.showAngle", sel); 1547 init(); enableSnapping(); 1575 saveAngles("180"); 1576 init(); 1577 enableSnapping(); 1548 1578 } 1549 });1550 JCheckBoxMenuItem projectionCb = new JCheckBoxMenuItem(new AbstractAction(tr("Snap to node projections")){1579 }); 1580 add(new AbstractAction(tr("0,90,...")) { 1551 1581 public void actionPerformed(ActionEvent e) { 1552 boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();1553 Main.pref.put("draw.anglesnap.projectionsnap", sel);1554 init();enableSnapping();1582 saveAngles("0","90","180"); 1583 init(); 1584 enableSnapping(); 1555 1585 } 1556 }); 1557 { 1558 helperCb.setState(Main.pref.getBoolean("draw.anglesnap.drawConstructionGeometry",true)); 1559 projectionCb.setState(Main.pref.getBoolean("draw.anglesnap.projectionsnapgvff",true)); 1560 add(helperCb); 1561 add(projectionCb);; 1562 add(new AbstractAction(tr("Disable")) { 1563 public void actionPerformed(ActionEvent e) { 1564 saveAngles("180"); 1565 init(); enableSnapping(); 1566 } 1567 }); 1568 add(new AbstractAction(tr("0,90,...")) { 1569 public void actionPerformed(ActionEvent e) { 1570 saveAngles("0","90","180"); 1571 init(); enableSnapping(); 1572 } 1573 }); 1574 add(new AbstractAction(tr("0,45,90,...")) { 1575 public void actionPerformed(ActionEvent e) { 1576 saveAngles("0","45","90","135","180"); 1577 init(); enableSnapping(); 1578 } 1579 }); 1580 add(new AbstractAction(tr("0,30,45,60,90,...")) { 1581 public void actionPerformed(ActionEvent e) { 1582 saveAngles("0","30","45","60","90","120","135","150","180"); 1583 init(); enableSnapping(); 1584 } 1585 }); 1586 } 1587 }) { 1586 }); 1587 add(new AbstractAction(tr("0,45,90,...")) { 1588 public void actionPerformed(ActionEvent e) { 1589 saveAngles("0","45","90","135","180"); 1590 init(); 1591 enableSnapping(); 1592 } 1593 }); 1594 add(new AbstractAction(tr("0,30,45,60,90,...")) { 1595 public void actionPerformed(ActionEvent e) { 1596 saveAngles("0","30","45","60","90","120","135","150","180"); 1597 init(); 1598 enableSnapping(); 1599 } 1600 }); 1601 } 1602 }) { 1588 1603 @Override 1589 1604 public void mouseClicked(MouseEvent e) { 1590 1605 super.mouseClicked(e); 1591 if (e.getButton() ==MouseEvent.BUTTON1) {1606 if (e.getButton() == MouseEvent.BUTTON1) { 1592 1607 toggleSnapping(); 1593 1608 updateStatusLine(); 1594 1609 } 1595 1610 } 1596 };1597 } 1598 1611 }; 1612 } 1613 1599 1614 private class SnapChangeAction extends JosmAction { 1600 1615 public SnapChangeAction() { 1601 super(tr("Angle snapping"), "anglesnap",1602 tr("Switch angle snapping mode while drawing"),1603 null, false);1604 putValue("help", ht("/Action/Draw/AngleSnap"));1605 } 1606 @Override 1616 super(tr("Angle snapping"), "anglesnap", 1617 tr("Switch angle snapping mode while drawing"), null, false); 1618 putValue("help", ht("/Action/Draw/AngleSnap")); 1619 } 1620 1621 @Override 1607 1622 public void actionPerformed(ActionEvent e) { 1608 if (snapHelper!=null) snapHelper.toggleSnapping(); 1609 } 1610 1623 if (snapHelper!=null) snapHelper.toggleSnapping(); 1624 } 1611 1625 } 1612 1626 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
r4836 r4956 126 126 super(tr("Parallel"), "parallel", tr("Make parallel copies of ways"), 127 127 Shortcut.registerShortcut("mapmode:parallel", tr("Mode: {0}", 128 tr("Parallel")), KeyEvent.VK_P, Shortcut.GROUP_EDIT ,129 Shortcut. SHIFT_DEFAULT), mapFrame, ImageProvider.getCursor("normal",128 tr("Parallel")), KeyEvent.VK_P, Shortcut.GROUP_EDIT+ 129 Shortcut.GROUPS_ALT1), mapFrame, ImageProvider.getCursor("normal", 130 130 "parallel")); 131 131 putValue("help", ht("/Action/Parallel")); -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r4912 r4956 86 86 public MapPaintDialog() { 87 87 super(tr("Map Paint Styles"), "mapstyle", tr("configure the map painting style"), 88 Shortcut.registerShortcut("subwindow:mappaint", tr("Toggle: {0}", tr("MapPaint")), KeyEvent.VK_M, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 88 Shortcut.registerShortcut("subwindow:mappaint", tr("Toggle: {0}", tr("MapPaint")), 89 KeyEvent.VK_M, Shortcut.GROUP_LAYER+Shortcut.GROUPS_ALT1), 150); 89 90 build(); 90 91 } -
trunk/src/org/openstreetmap/josm/gui/preferences/PrefJPanel.java
r4930 r4956 103 103 // not a list of real physical keys. If someone knows how to get that list? 104 104 private static Map<Integer, String> keyList = setKeyList(); 105 105 106 106 private static Map<Integer, String> setKeyList() { 107 107 Map<Integer, String> list = new LinkedHashMap<Integer, String>(); … … 125 125 return list; 126 126 } 127 127 128 128 private JComboBox bxPrim1 = new JComboBox(); 129 129 private JComboBox bxPrim2 = new JComboBox(); … … 145 145 private JCheckBox cbDisable = new JCheckBox(); 146 146 private JComboBox tfKey = new JComboBox(); 147 147 148 148 JTable shortcutTable = new JTable(); 149 149 150 150 private JTextField filterField = new JTextField(); 151 151 … … 219 219 220 220 listPane.add(listScrollPane); 221 221 222 222 shortcutTab.add(listPane); 223 223 … … 239 239 cbMeta.setAction(action); 240 240 cbMeta.setText(META); // see above for why no tr() 241 242 241 242 243 243 shortcutEditPane.add(cbDefault); 244 244 shortcutEditPane.add(new JLabel()); … … 266 266 editGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Edit Shortcuts"))); 267 267 editGroupPane.setLayout(new java.awt.GridLayout(3, 5)); 268 268 269 269 JComboBox[] bxArray = new JComboBox[] { 270 270 bxPrim1,bxSec1,bxTer1,bxPrim2,bxSec2,bxTer2, 271 271 bxPrim3,bxSec3,bxTer3,bxPrim4,bxSec4,bxTer4}; 272 for (JComboBox bxi: bxArray) bxi.setModel(new DefaultComboBoxModel(modifList)); 273 272 for (JComboBox bxi: bxArray) bxi.setModel(new DefaultComboBoxModel(modifList)); 273 274 274 editGroupPane.add(new JLabel(tr("Primary modifier:"))); 275 275 editGroupPane.add(bxPrim1); … … 310 310 311 311 initbx(); 312 for (JComboBox bxi: bxArray) bxi.setAction(action2); 312 for (JComboBox bxi: bxArray) bxi.setAction(action2); 313 313 314 314 modifierTab.add(subwindowGroupPane); … … 340 340 return pnl; 341 341 } 342 342 343 343 private void disableAllModifierCheckboxes() { 344 344 cbDefault.setEnabled(false); … … 481 481 } 482 482 483 483 484 484 class FilterFieldAdapter implements DocumentListener { 485 485 public void filter() { … … 492 492 sorter.setRowFilter(null); 493 493 } else { 494 // split search string on whitespace, do case-insensitive AND search 494 // split search string on whitespace, do case-insensitive AND search 495 495 ArrayList<RowFilter<Object, Object>> andFilters = new ArrayList<RowFilter<Object, Object>>(); 496 496 for (String word : expr.split("\\s+")) { … … 508 508 public void removeUpdate(DocumentEvent arg0) { filter(); } 509 509 } 510 510 511 511 } -
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r4928 r4956 571 571 return sc.getKeyStroke(); 572 572 } 573 574 public boolean isEvent(KeyEvent e) { 575 return getKeyStroke() != null && getKeyStroke().equals( 576 KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers())); 577 } 573 578 }
Note:
See TracChangeset
for help on using the changeset viewer.