- Timestamp:
- 2012-09-16T08:39:16+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r5459 r5512 110 110 111 111 private Shortcut backspaceShortcut; 112 private BackSpaceAction backspaceAction; 112 113 private final Shortcut snappingShortcut; 113 114 … … 118 119 public DrawAction(MapFrame mapFrame) { 119 120 super(tr("Draw"), "node/autonode", tr("Draw nodes"), 120 Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.DIRECT),121 mapFrame, ImageProvider.getCursor("crosshair", null));121 Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.DIRECT), 122 mapFrame, ImageProvider.getCursor("crosshair", null)); 122 123 123 124 snappingShortcut = Shortcut.registerShortcut("mapmode:drawanglesnapping", 124 tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.DIRECT);125 tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.DIRECT); 125 126 snapChangeAction = new SnapChangeAction(); 126 127 snapCheckboxMenuItem = addMenuItem(); 127 128 snapHelper.setMenuCheckBox(snapCheckboxMenuItem); 129 backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace", 130 tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.DIRECT); 131 backspaceAction = new BackSpaceAction(); 128 132 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); 129 133 cursorJoinWay = ImageProvider.getCursor("crosshair", "joinway"); … … 207 211 snapCheckboxMenuItem.getAction().setEnabled(true); 208 212 209 213 timer = new Timer(0, new ActionListener() { 210 214 @Override 211 215 public void actionPerformed(ActionEvent ae) { … … 218 222 }); 219 223 Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener); 220 backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace", 221 tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.DIRECT); 222 Main.registerActionShortcut(new BackSpaceAction(), backspaceShortcut); 224 Main.registerActionShortcut(backspaceAction, backspaceShortcut); 223 225 224 226 Main.map.mapView.addMouseListener(this); … … 242 244 Main.map.mapView.removeTemporaryLayer(this); 243 245 DataSet.removeSelectionListener(this); 244 Main.unregister Shortcut(backspaceShortcut);246 Main.unregisterActionShortcut(backspaceAction, backspaceShortcut); 245 247 snapHelper.unsetFixedMode(); 246 248 snapCheckboxMenuItem.getAction().setEnabled(false); 247 249 248 250 Main.map.statusLine.getAnglePanel().removeMouseListener(snapHelper.anglePopupListener); 249 251 Main.map.statusLine.activateAnglePanel(false); … … 274 276 if (snappingShortcut.isEvent(e) || (useRepeatedShortcut && getShortcut().isEvent(e))) { 275 277 Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); 276 if (SwingUtilities.getWindowAncestor(focused) instanceof JFrame) 278 if (SwingUtilities.getWindowAncestor(focused) instanceof JFrame) { 277 279 processKeyEvent(e); 280 } 278 281 } 279 282 } // toggle angle snapping … … 289 292 private Timer timer; 290 293 void processKeyEvent(KeyEvent e) { 291 if (!snappingShortcut.isEvent(e) && !(useRepeatedShortcut && getShortcut().isEvent(e))) 292 return; 293 294 if (!snappingShortcut.isEvent(e) && !(useRepeatedShortcut && getShortcut().isEvent(e))) 295 return; 296 294 297 if (e.getID() == KeyEvent.KEY_PRESSED) { 295 298 if (timer.isRunning()) { … … 413 416 414 417 ArrayList<Way> reuseWays = new ArrayList<Way>(), 415 replacedWays = new ArrayList<Way>();418 replacedWays = new ArrayList<Way>(); 416 419 boolean newNode = false; 417 420 Node n = null; … … 461 464 if (n.getCoor().isOutSideWorld()) { 462 465 JOptionPane.showMessageDialog( 463 Main.parent,464 tr("Cannot add a node outside of the world."),465 tr("Warning"),466 JOptionPane.WARNING_MESSAGE467 );466 Main.parent, 467 tr("Cannot add a node outside of the world."), 468 tr("Warning"), 469 JOptionPane.WARNING_MESSAGE 470 ); 468 471 return; 469 472 } … … 473 476 // Insert the node into all the nearby way segments 474 477 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments( 475 Main.map.mapView.getPoint(n), OsmPrimitive.isSelectablePredicate);478 Main.map.mapView.getPoint(n), OsmPrimitive.isSelectablePredicate); 476 479 if (snapHelper.isActive()) { 477 480 tryToMoveNodeOnIntersection(wss,n); … … 804 807 805 808 determineCurrentBaseNodeAndPreviousNode(selection); 806 if (previousNode == null) snapHelper.noSnapNow(); 809 if (previousNode == null) { 810 snapHelper.noSnapNow(); 811 } 807 812 808 813 if (currentBaseNode == null || currentBaseNode == currentMouseNode) … … 811 816 812 817 double curHdg = Math.toDegrees(currentBaseNode.getEastNorth() 813 .heading(currentMouseEastNorth));818 .heading(currentMouseEastNorth)); 814 819 double baseHdg=-1; 815 820 if (previousNode != null) { 816 821 baseHdg = Math.toDegrees(previousNode.getEastNorth() 817 .heading(currentBaseNode.getEastNorth()));822 .heading(currentBaseNode.getEastNorth())); 818 823 } 819 824 … … 869 874 if (selectedNode == selectedWay.getNode(0)){ 870 875 currentBaseNode = selectedNode; 871 if (selectedWay.getNodesCount()>1) previousNode = selectedWay.getNode(1); 876 if (selectedWay.getNodesCount()>1) { 877 previousNode = selectedWay.getNode(1); 878 } 872 879 } 873 880 if (selectedNode == selectedWay.lastNode()) { 874 881 currentBaseNode = selectedNode; 875 if (selectedWay.getNodesCount()>1) 882 if (selectedWay.getNodesCount()>1) { 876 883 previousNode = selectedWay.getNode(selectedWay.getNodesCount()-2); 884 } 877 885 } 878 886 } … … 1018 1026 if (snapHelper.dir2!=null && currentBaseNode!=null) { 1019 1027 EastNorth xPoint = Geometry.getSegmentSegmentIntersection(p1, p2, snapHelper.dir2, currentBaseNode.getEastNorth()); 1020 if (xPoint!=null) n.setEastNorth(xPoint); 1028 if (xPoint!=null) { 1029 n.setEastNorth(xPoint); 1030 } 1021 1031 } 1022 1032 } … … 1027 1037 * done in redrawIfRequired. This means, calling addHighlighting() without redrawIfRequired() 1028 1038 * will leave the data in an inconsistent state. 1029 * 1039 * 1030 1040 * The status bar derives its information from oldHighlights, so in order to update the status 1031 1041 * bar both addHighlighting() and repaintIfRequired() are needed, since former fills newHighlights … … 1079 1089 // sanity checks 1080 1090 if (Main.map.mapView == null || mousePos == null 1081 // don't draw line if we don't know where from or where to1082 || currentBaseNode == null || currentMouseEastNorth == null1083 // don't draw line if mouse is outside window1084 || !Main.map.mapView.getBounds().contains(mousePos))1091 // don't draw line if we don't know where from or where to 1092 || currentBaseNode == null || currentMouseEastNorth == null 1093 // don't draw line if mouse is outside window 1094 || !Main.map.mapView.getBounds().contains(mousePos)) 1085 1095 return; 1086 1096 … … 1088 1098 snapHelper.drawIfNeeded(g2,mv); 1089 1099 if (!drawHelperLine || wayIsFinished || shift) 1090 return;1100 return; 1091 1101 1092 1102 if (!snapHelper.isActive()) { // else use color and stoke from snapHelper.draw … … 1205 1215 if (currentBaseNode != null && !ds.getSelected().isEmpty()) { 1206 1216 Way continueFrom = getWayForNode(currentBaseNode); 1207 if (alt && continueFrom != null) {1217 if (alt && continueFrom != null) 1208 1218 return Collections.<OsmPrimitive>singleton(continueFrom); 1209 }1210 1219 } 1211 1220 return ds.getSelected(); … … 1250 1259 } 1251 1260 // select last added node - maybe we will continue drawing from it 1252 if (n!=null) getCurrentDataSet().addSelected(n); 1261 if (n!=null) { 1262 getCurrentDataSet().addSelected(n); 1263 } 1253 1264 } 1254 1265 } … … 1299 1310 1300 1311 Collection<String> angles = Main.pref.getCollection("draw.anglesnap.angles", 1301 Arrays.asList("0","30","45","60","90","120","135","150","180"));1312 Arrays.asList("0","30","45","60","90","120","135","150","180")); 1302 1313 1303 1314 snapAngles = new double[2*angles.size()]; … … 1325 1336 1326 1337 highlightColor = Main.pref.getColor(marktr("draw angle snap highlight"), 1327 new Color(Color.ORANGE.getRed(),Color.ORANGE.getGreen(),Color.ORANGE.getBlue(),128));1338 new Color(Color.ORANGE.getRed(),Color.ORANGE.getGreen(),Color.ORANGE.getBlue(),128)); 1328 1339 highlightStroke = new BasicStroke(10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); 1329 1340 1330 1341 float dash1[] = { 4.0f }; 1331 1342 helperStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, 1332 BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);1343 BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f); 1333 1344 } 1334 1345 … … 1411 1422 if (snapOn && (activeBaseHeading>=0)) { 1412 1423 angle = curHeading - activeBaseHeading; 1413 if (angle < 0) angle+=360; 1414 if (angle > 360) angle=0; 1424 if (angle < 0) { 1425 angle+=360; 1426 } 1427 if (angle > 360) { 1428 angle=0; 1429 } 1415 1430 1416 1431 double nearestAngle; … … 1455 1470 if (baseHeading >=0 ) { // there is previous line segment with some heading 1456 1471 angle = hdg - baseHeading; 1457 if (angle < 0) angle+=360; 1458 if (angle > 360) angle=0; 1472 if (angle < 0) { 1473 angle+=360; 1474 } 1475 if (angle > 360) { 1476 angle=0; 1477 } 1459 1478 } 1460 1479 showStatusInfo(angle, hdg, distance, isSnapOn()); … … 1504 1523 Way w = selectedWays.iterator().next(); 1505 1524 Collection <EastNorth> pointsToProject = new ArrayList<EastNorth>(); 1506 if (w.getNodesCount()<1000) for (Node n: w.getNodes()) { 1507 pointsToProject.add(n.getEastNorth()); 1525 if (w.getNodesCount()<1000) { 1526 for (Node n: w.getNodes()) { 1527 pointsToProject.add(n.getEastNorth()); 1528 } 1508 1529 } 1509 1530 if (customBaseHeading >=0 ) { … … 1544 1565 double hdg = segmentPoint1.heading(segmentPoint2); 1545 1566 hdg=Math.toDegrees(hdg); 1546 if (hdg<0) hdg+=360; 1547 if (hdg>360) hdg-=360; 1567 if (hdg<0) { 1568 hdg+=360; 1569 } 1570 if (hdg>360) { 1571 hdg-=360; 1572 } 1548 1573 //fixed=true; 1549 1574 //absoluteFix=true; … … 1554 1579 if (snapOn) { 1555 1580 // turn off snapping if we are in fixed mode or no actile snapping line exist 1556 if (fixed || !active) { snapOn=false; unsetFixedMode(); } 1557 else setFixedMode(); 1581 if (fixed || !active) { snapOn=false; unsetFixedMode(); } else { 1582 setFixedMode(); 1583 } 1558 1584 } else { 1559 1585 snapOn=true; … … 1609 1635 } 1610 1636 } 1611 if (Math.abs(bestAngle-360) < 1e-3) 1637 if (Math.abs(bestAngle-360) < 1e-3) { 1612 1638 bestAngle=0; 1639 } 1613 1640 return bestAngle; 1614 1641 } … … 1623 1650 1624 1651 private void unFixOrTurnOff() { 1625 if (absoluteFix) 1652 if (absoluteFix) { 1626 1653 unsetFixedMode(); 1627 else1654 } else { 1628 1655 toggleSnapping(); 1656 } 1629 1657 } 1630 1658 … … 1706 1734 public SnapChangeAction() { 1707 1735 super(tr("Angle snapping"), "anglesnap", 1708 tr("Switch angle snapping mode while drawing"), null, false);1736 tr("Switch angle snapping mode while drawing"), null, false); 1709 1737 putValue("help", ht("/Action/Draw/AngleSnap")); 1710 1738 } … … 1712 1740 @Override 1713 1741 public void actionPerformed(ActionEvent e) { 1714 if (snapHelper!=null) snapHelper.toggleSnapping(); 1742 if (snapHelper!=null) { 1743 snapHelper.toggleSnapping(); 1744 } 1715 1745 } 1716 1746 } -
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r5170 r5512 68 68 69 69 private final DataSetListenerAdapter datasetAdapter = new DataSetListenerAdapter(this); 70 private Set<DataSet> changedDatasets = new HashSet<DataSet>();70 private final Set<DataSet> changedDatasets = new HashSet<DataSet>(); 71 71 private final List<AutosaveLayerInfo> layersInfo = new ArrayList<AutosaveLayerInfo>(); 72 72 private Timer timer; … … 163 163 info.layerName = info.layer.getName(); 164 164 } 165 if (changedDatasets. contains(info.layer.data)) {165 if (changedDatasets.remove(info.layer.data)) { 166 166 File file = getNewLayerFile(info); 167 167 if (file != null) {
Note:
See TracChangeset
for help on using the changeset viewer.