Changeset 2626 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2009-12-13T11:48:12+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java
r2548 r2626 19 19 import java.text.ParsePosition; 20 20 import java.util.Locale; 21 import java.util.logging.Logger;22 21 23 22 import javax.swing.AbstractAction; … … 52 51 */ 53 52 public final class AddNodeAction extends JosmAction { 54 static private final Logger logger = Logger.getLogger(AddNodeAction.class.getName());53 //static private final Logger logger = Logger.getLogger(AddNodeAction.class.getName()); 55 54 56 55 public AddNodeAction() { … … 311 310 } 312 311 313 class TextFieldFocusHandler implements FocusListener {312 static class TextFieldFocusHandler implements FocusListener { 314 313 public void focusGained(FocusEvent e) { 315 314 Component c = e.getComponent(); -
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r2610 r2626 56 56 // HelperClass 57 57 // Saves a node and two positions where to insert the node into the ways 58 private class NodeToSegs implements Comparable<NodeToSegs> {58 private static class NodeToSegs implements Comparable<NodeToSegs> { 59 59 public int pos; 60 60 public Node n; … … 71 71 return this.pos - o.pos; 72 72 } 73 74 @Override 75 public int hashCode() { 76 return pos; 77 } 78 79 @Override 80 public boolean equals(Object o) { 81 if (o instanceof NodeToSegs) 82 return compareTo((NodeToSegs) o) == 0; 83 else 84 return false; 85 } 73 86 } 74 87 75 88 // HelperClass 76 89 // Saves a relation and a role an OsmPrimitve was part of until it was stripped from all relations 77 private class RelationRole {90 private static class RelationRole { 78 91 public final Relation rel; 79 92 public final String role; -
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r2596 r2626 37 37 public final class OrthogonalizeAction extends JosmAction { 38 38 String USAGE = "<h3>"+ 39 40 41 42 39 "When one or more ways are selected, the shape is adjusted, such that all angles are 90 or 180 degrees.<h3>"+ 40 "You can add two nodes to the selection. Then the direction is fixed by these two reference nodes.<h3>"+ 41 "(Afterwards, you can undo the movement for certain nodes:<br>"+ 42 "Select them and press the shortcut for Orthogonalize / Undo. The default is Shift-Q.)"; 43 43 44 44 public OrthogonalizeAction() { … … 72 72 * This action can be triggered by shortcut only. 73 73 */ 74 public class Undo extends JosmAction {74 public static class Undo extends JosmAction { 75 75 public Undo() { 76 76 super(tr("Orthogonalize Shape / Undo"), 77 "ortho",78 tr("Undo orthogonalization for certain nodes"),79 Shortcut.registerShortcut("tools:orthogonalizeUndo", tr("Tool: {0}", tr("Orthogonalize Shape / Undo")),80 KeyEvent.VK_Q,81 Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);77 "ortho", 78 tr("Undo orthogonalization for certain nodes"), 79 Shortcut.registerShortcut("tools:orthogonalizeUndo", tr("Tool: {0}", tr("Orthogonalize Shape / Undo")), 80 KeyEvent.VK_Q, 81 Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true); 82 82 } 83 83 public void actionPerformed(ActionEvent e) { … … 103 103 catch (InvalidUserInputException ex) { 104 104 JOptionPane.showMessageDialog( 105 Main.parent,106 tr("Orthogonalize Shape / Undo\n"+105 Main.parent, 106 tr("Orthogonalize Shape / Undo\n"+ 107 107 "Please select nodes that were moved by the previous Orthogonalize Shape action!"), 108 tr("Undo Orthogonalize Shape"),109 JOptionPane.INFORMATION_MESSAGE);108 tr("Undo Orthogonalize Shape"), 109 JOptionPane.INFORMATION_MESSAGE); 110 110 } 111 111 } … … 143 143 else if (p instanceof Way) { 144 144 wayDataList.add(new WayData((Way) p)); 145 } 146 else { // maybe a relation got selected... 145 } else 147 146 throw new InvalidUserInputException("Selection must consist only of ways and nodes."); 148 } 149 } 150 if (wayDataList.isEmpty()) { 147 } 148 if (wayDataList.isEmpty()) 151 149 throw new InvalidUserInputException("usage"); 152 }153 150 else { 154 151 if (nodeList.size() == 2 || nodeList.isEmpty()) { … … 186 183 } else 187 184 throw new IllegalStateException(); 188 185 189 186 Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), commands)); 190 187 Main.map.repaint(); 191 188 192 189 } else 193 190 throw new InvalidUserInputException("usage"); … … 196 193 if (ex.getMessage().equals("usage")) { 197 194 JOptionPane.showMessageDialog( 198 Main.parent,199 "<html><h2>"+tr("Usage")+tr(USAGE),200 tr("Orthogonalize Shape"),201 JOptionPane.INFORMATION_MESSAGE);195 Main.parent, 196 "<html><h2>"+tr("Usage")+tr(USAGE), 197 tr("Orthogonalize Shape"), 198 JOptionPane.INFORMATION_MESSAGE); 202 199 } 203 200 else { 204 201 JOptionPane.showMessageDialog( 205 Main.parent,206 "<html><h3>"+tr(ex.getMessage())+"<br><hr><h3>"+tr("Usage")+tr(USAGE),207 tr("Selected Elements cannot be orthogonalized"),208 JOptionPane.INFORMATION_MESSAGE);202 Main.parent, 203 "<html><h3>"+tr(ex.getMessage())+"<br><hr><h3>"+tr("Usage")+tr(USAGE), 204 tr("Selected Elements cannot be orthogonalized"), 205 JOptionPane.INFORMATION_MESSAGE); 209 206 } 210 207 } … … 232 229 **/ 233 230 private static Collection<Command> orthogonalize(ArrayList<WayData> wayDataList, ArrayList<Node> headingNodes) 234 231 throws InvalidUserInputException 235 232 { 236 233 // find average heading … … 263 260 } catch (RejectedAngleException ex) { 264 261 throw new InvalidUserInputException( 265 "<html>Please make sure all selected ways head in a similar direction<br>"+266 262 "<html>Please make sure all selected ways head in a similar direction<br>"+ 263 "or orthogonalize them one by one."); 267 264 } 268 265 … … 302 299 int s_size = s.size(); 303 300 for (int dummy = 0; dummy < s_size; ++ dummy) { 304 if (s.isEmpty()) break; 301 if (s.isEmpty()) { 302 break; 303 } 305 304 final Node dummy_n = s.iterator().next(); // pick arbitrary element of s 306 305 … … 357 356 // rotate back and log the change 358 357 final Collection<Command> commands = new LinkedList<Command>(); 359 // OrthogonalizeAction.rememberMovements.clear();358 // OrthogonalizeAction.rememberMovements.clear(); 360 359 for (Node n: allNodes) { 361 360 EastNorth tmp = new EastNorth(nX.get(n), nY.get(n)); … … 366 365 final double EPSILON = 1E-6; 367 366 if (Math.abs(dx) > Math.abs(EPSILON * tmp.east()) || 368 Math.abs(dy) > Math.abs(EPSILON * tmp.east())) {367 Math.abs(dy) > Math.abs(EPSILON * tmp.east())) 369 368 throw new AssertionError(); 370 }371 369 } 372 370 else { … … 386 384 final public int nNode; // Number of Nodes of the Way 387 385 public Direction[] segDirections; // Direction of the segments 388 386 // segment i goes from node i to node (i+1) 389 387 public EastNorth segSum; // (Vector-)sum of all horizontal segments plus the sum of all vertical 390 388 // segments turned by 90 degrees 391 389 public double heading; // heading of segSum == approximate heading of the way 392 390 public WayData(Way pWay) { … … 422 420 // sum up segments 423 421 EastNorth h = new EastNorth(0.,0.); 424 double lh = EN.abs(h);422 //double lh = EN.abs(h); 425 423 EastNorth v = new EastNorth(0.,0.); 426 double lv = EN.abs(v);424 //double lv = EN.abs(v); 427 425 for (int i = 0; i < nSeg; ++i) { 428 426 EastNorth segment = EN.diff(en[i+1], en[i]); 429 if (segDirections[i] == Direction.RIGHT) h = EN.sum(h,segment); 430 else if (segDirections[i] == Direction.UP) v = EN.sum(v,segment); 431 else if (segDirections[i] == Direction.LEFT) h = EN.diff(h,segment); 432 else if (segDirections[i] == Direction.DOWN) v = EN.diff(v,segment); 433 else throw new IllegalStateException(); 427 if (segDirections[i] == Direction.RIGHT) { 428 h = EN.sum(h,segment); 429 } else if (segDirections[i] == Direction.UP) { 430 v = EN.sum(v,segment); 431 } else if (segDirections[i] == Direction.LEFT) { 432 h = EN.diff(h,segment); 433 } else if (segDirections[i] == Direction.DOWN) { 434 v = EN.diff(v,segment); 435 } else throw new IllegalStateException(); 434 436 /** 435 437 * When summing up the length of the sum vector should increase. … … 437 439 * So only uncomment this for testing 438 440 **/ 439 // if (segDirections[i].ordinal() % 2 == 0) {440 // if (EN.abs(h) < lh) throw new AssertionError();441 // lh = EN.abs(h);442 // } else {443 // if (EN.abs(v) < lv) throw new AssertionError();444 // lv = EN.abs(v);445 // }441 // if (segDirections[i].ordinal() % 2 == 0) { 442 // if (EN.abs(h) < lh) throw new AssertionError(); 443 // lh = EN.abs(h); 444 // } else { 445 // if (EN.abs(v) < lv) throw new AssertionError(); 446 // lv = EN.abs(v); 447 // } 446 448 } 447 449 // rotate the vertical vector by 90 degrees (clockwise) and add it to the horizontal vector 448 450 segSum = EN.sum(h, new EastNorth(v.north(), - v.east())); 449 // if (EN.abs(segSum) < lh) throw new AssertionError();451 // if (EN.abs(segSum) < lh) throw new AssertionError(); 450 452 this.heading = EN.polar(new EastNorth(0.,0.), segSum); 451 453 } … … 456 458 public Direction changeBy(int directionChange) { 457 459 int tmp = (this.ordinal() + directionChange) % 4; 458 if (tmp < 0) tmp += 4; // the % operator can return negative value 460 if (tmp < 0) { 461 tmp += 4; // the % operator can return negative value 462 } 459 463 return Direction.values()[tmp]; 460 464 } … … 465 469 */ 466 470 private static double standard_angle_0_to_2PI(double a) { 467 while (a >= 2 * Math.PI) a -= 2 * Math.PI; 468 while (a < 0) a += 2 * Math.PI; 471 while (a >= 2 * Math.PI) { 472 a -= 2 * Math.PI; 473 } 474 while (a < 0) { 475 a += 2 * Math.PI; 476 } 469 477 return a; 470 478 } … … 474 482 */ 475 483 private static double standard_angle_mPI_to_PI(double a) { 476 while (a > Math.PI) a -= 2 * Math.PI; 477 while (a <= - Math.PI) a += 2 * Math.PI; 484 while (a > Math.PI) { 485 a -= 2 * Math.PI; 486 } 487 while (a <= - Math.PI) { 488 a += 2 * Math.PI; 489 } 478 490 return a; 479 491 } … … 499 511 return new EastNorth(en1.east() - en2.east(), en1.north() - en2.north()); 500 512 } 501 public static double abs(EastNorth en) {502 return Math.sqrt(en.east() * en.east() + en.north() * en.north());503 }504 public static String toString(EastNorth en) {505 return "["+u(en.east())+","+u(en.north())+"]";506 }507 public static long u(double d) {508 return Math.round(d * 1000000.);509 }510 513 public static double polar(EastNorth en1, EastNorth en2) { 511 514 return Math.atan2(en2.north() - en1.north(), en2.east() - en1.east()); … … 523 526 double d_m90 = Math.abs(a + Math.PI / 2); 524 527 int dirChange; 525 if (d0 < deltaMax) dirChange = 0; 526 else if (d90 < deltaMax) dirChange = 1; 527 else if (d_m90 < deltaMax) dirChange = -1; 528 else { 528 if (d0 < deltaMax) { 529 dirChange = 0; 530 } else if (d90 < deltaMax) { 531 dirChange = 1; 532 } else if (d_m90 < deltaMax) { 533 dirChange = -1; 534 } else { 529 535 a = standard_angle_0_to_2PI(a); 530 536 double d180 = Math.abs(a - Math.PI); 531 if (d180 < deltaMax) dirChange = 2; 532 else { 537 if (d180 < deltaMax) { 538 dirChange = 2; 539 } else 533 540 throw new RejectedAngleException(); 534 }535 541 } 536 542 return dirChange; -
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r2598 r2626 38 38 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 39 39 reader.append(getCurrentDataSet(),id, type); 40 DataSet ds = null;41 40 try { 42 ds = reader.parseOsm(NullProgressMonitor.INSTANCE); 41 DataSet ds = reader.parseOsm(NullProgressMonitor.INSTANCE); 42 Main.map.mapView.getEditLayer().mergeFrom(ds); 43 43 } catch(Exception e) { 44 44 ExceptionDialogUtil.explainException(e); 45 45 } 46 Main.map.mapView.getEditLayer().mergeFrom(ds);47 46 } 48 47
Note:
See TracChangeset
for help on using the changeset viewer.