Changeset 4803 in josm
- Timestamp:
- 2012-01-16T20:05:23+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r4785 r4803 22 22 import java.awt.event.KeyEvent; 23 23 import java.awt.event.MouseEvent; 24 import java.awt.event.MouseListener; 24 25 import java.awt.geom.GeneralPath; 25 26 import java.util.ArrayList; … … 39 40 import javax.swing.JOptionPane; 40 41 41 import javax.swing. SwingUtilities;42 import javax.swing.JPopupMenu; 42 43 import javax.swing.Timer; 43 44 import org.openstreetmap.josm.Main; … … 63 64 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 64 65 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 66 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 65 67 import org.openstreetmap.josm.tools.ImageProvider; 66 68 import org.openstreetmap.josm.tools.Pair; … … 157 159 158 160 }); 159 161 Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener); 160 162 backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace", tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.GROUP_EDIT); 161 163 Main.registerActionShortcut(new BackSpaceAction(), backspaceShortcut); … … 183 185 snapHelper.unsetFixedMode(); 184 186 snapCheckboxMenuItem.getAction().setEnabled(false); 187 Main.map.statusLine.getAnglePanel().removeMouseListener(snapHelper.anglePopupListener); 185 188 186 189 removeHighlighting(); … … 717 720 mouseOnExistingWays = new HashSet<Way>(); 718 721 719 Main.map.statusLine.setAngle(-1); 720 Main.map.statusLine.setHeading(-1); 721 Main.map.statusLine.setDist(-1); 722 showStausInfo(-1, -1, -1); 722 723 723 724 if (!ctrl && mousePos != null) { … … 750 751 return; // Don't create zero length way segments. 751 752 752 // find out the distance, in metres, between the base point and the mouse cursor753 LatLon mouseLatLon = mv.getProjection().eastNorth2latlon(currentMouseEastNorth);754 distance = currentBaseNode.getCoor().greatCircleDistance(mouseLatLon);755 753 756 754 double hdg = Math.toDegrees(currentBaseNode.getEastNorth() … … 761 759 angle += angle < 0 ? 360 : 0; 762 760 } 763 761 764 762 snapHelper.checkAngleSnapping(currentMouseEastNorth,angle); 765 763 if (!snapHelper.isActive()) { 764 // find out the distance, in metres, between the base point and the mouse cursor 765 LatLon mouseLatLon = mv.getProjection().eastNorth2latlon(currentMouseEastNorth); 766 distance = currentBaseNode.getCoor().greatCircleDistance(mouseLatLon); 767 showStausInfo(angle, hdg, distance); 768 } // elsewhere status ar was filled by snapHelper 769 770 // Now done in redrawIfRequired() 771 //updateStatusLine(); 772 } 773 774 private void showStausInfo(double angle, double hdg, double distance) { 766 775 Main.map.statusLine.setAngle(angle); 767 776 Main.map.statusLine.setHeading(hdg); 768 777 Main.map.statusLine.setDist(distance); 769 // Now done in redrawIfRequired() 770 //updateStatusLine(); 771 } 772 773 778 } 779 774 780 /** 775 781 * Helper function that sets fields currentBaseNode and previousNode … … 1192 1198 1193 1199 Collection<String> angles = Main.pref.getCollection("draw.anglesnap.angles", 1194 Arrays.asList("0","30","45","60","90","120","135","150" ,"210","225","240","270","300","315","330"));1200 Arrays.asList("0","30","45","60","90","120","135","150")); 1195 1201 1196 snapAngles = new double[ angles.size()];1202 snapAngles = new double[2*angles.size()]; 1197 1203 int i=0; 1198 1204 for (String s: angles) { 1199 1205 try { 1200 snapAngles[i] = Double.parseDouble(s); 1206 snapAngles[i] = Double.parseDouble(s); i++; 1207 snapAngles[i] = 360-Double.parseDouble(s); i++; 1201 1208 } catch (NumberFormatException e) { 1202 1209 System.err.println("Warning: incorrect number in draw.anglesnap.angles preferences: "+s); 1203 snapAngles[i]=0; 1210 snapAngles[i]=0;i++; 1211 snapAngles[i]=0;i++; 1204 1212 } 1205 i++;1206 1213 } 1207 1214 snapAngleTolerance = Main.pref.getDouble("draw.anglesnap.tolerance", 5.0); … … 1217 1224 BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f); 1218 1225 1226 } 1227 1228 public void saveAngles(String ... angles) { 1229 Main.pref.putCollection("draw.anglesnap.angles", Arrays.asList(angles)); 1219 1230 } 1220 1231 … … 1315 1326 double scale = 20*Main.map.mapView.getDist100Pixel(); 1316 1327 dir2 = new EastNorth( e0+scale*pe, n0+scale*pn); 1317 getSnapPoint(currentEN); 1328 EastNorth snapPoint = getSnapPoint(currentEN); 1329 1330 // find out the distance, in metres, between the base point and projected point 1331 LatLon mouseLatLon = Main.map.mapView.getProjection().eastNorth2latlon(snapPoint); 1332 double distance = currentBaseNode.getCoor().greatCircleDistance(mouseLatLon); 1333 double hdg = Math.toDegrees(p0.heading(snapPoint)); 1334 if (previousNode != null) { 1335 angle = hdg - Math.toDegrees(previousNode.getEastNorth().heading(p0)); 1336 angle += angle < 0 ? 360 : 0; 1337 if (Math.abs(angle-360)<1e-4) angle=0; 1338 } 1339 1340 showStausInfo(angle, hdg, distance); 1318 1341 } else { 1319 1342 noSnapNow(); … … 1360 1383 } 1361 1384 1385 private void enableSnapping() { 1386 snapOn = true; 1387 checkBox.setState(snapOn); 1388 unsetFixedMode(); 1389 } 1390 1362 1391 private void toggleSnapping() { 1363 1392 snapOn = !snapOn; … … 1369 1398 if (active) { fixed=true; } 1370 1399 } 1371 1400 1372 1401 1373 1402 public void unsetFixedMode() { … … 1406 1435 if (absoluteFix) unsetFixedMode(); else toggleSnapping(); 1407 1436 } 1437 1438 MouseListener anglePopupListener = new PopupMenuLauncher( new JPopupMenu() { 1439 { 1440 add(new JCheckBoxMenuItem(new AbstractAction(tr("Show helper geometry")){ 1441 public void actionPerformed(ActionEvent e) { 1442 boolean sel=((JCheckBoxMenuItem) e.getSource()).getState(); 1443 Main.pref.put("draw.anglesnap.drawConstructionGeometry", sel); 1444 Main.pref.put("draw.anglesnap.drawProjectedPoint", sel); 1445 Main.pref.put("draw.anglesnap.showAngle", sel); 1446 init(); enableSnapping(); 1447 } 1448 })); 1449 add(new AbstractAction(tr("0,90,...")) { 1450 public void actionPerformed(ActionEvent e) { 1451 saveAngles("0","90"); 1452 init(); enableSnapping(); 1453 } 1454 }); 1455 add(new AbstractAction(tr("0,45,90,...")) { 1456 public void actionPerformed(ActionEvent e) { 1457 saveAngles("0","45","90","135"); 1458 init(); enableSnapping(); 1459 } 1460 }); 1461 add(new AbstractAction(tr("0,30,45,60,90,...")) { 1462 public void actionPerformed(ActionEvent e) { 1463 saveAngles("0","30","45","60","90","120","135","150"); 1464 init(); enableSnapping(); 1465 } 1466 }); 1467 } 1468 }) { 1469 @Override 1470 public void mouseClicked(MouseEvent e) { 1471 super.mouseClicked(e); 1472 if (e.getButton()==MouseEvent.BUTTON1) { 1473 toggleSnapping(); 1474 updateStatusLine(); 1475 } 1476 } 1477 }; 1408 1478 } 1409 1479 -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r4763 r4803 17 17 import java.awt.Toolkit; 18 18 import java.awt.event.AWTEventListener; 19 import java.awt.event.ActionEvent; 19 20 import java.awt.event.InputEvent; 20 21 import java.awt.event.KeyAdapter; … … 31 32 import javax.swing.BorderFactory; 32 33 import javax.swing.JLabel; 34 import javax.swing.JMenu; 33 35 import javax.swing.JPanel; 36 import javax.swing.JPopupMenu; 34 37 import javax.swing.JProgressBar; 35 38 import javax.swing.JScrollPane; … … 48 51 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 49 52 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog; 53 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 50 54 import org.openstreetmap.josm.tools.GBC; 51 55 import org.openstreetmap.josm.tools.ImageProvider; … … 681 685 lonText.addMouseListener(Main.main.menu.jumpToAct); 682 686 latText.addMouseListener(Main.main.menu.jumpToAct); 683 687 684 688 // Listen for mouse movements and set the position text field 685 689 mv.addMouseMotionListener(new MouseMotionListener(){ … … 734 738 thread.start(); 735 739 } 740 741 public JPanel getAnglePanel() { 742 return angleText; 743 } 736 744 737 745 public String helpTopic() {
Note:
See TracChangeset
for help on using the changeset viewer.