Changeset 3384 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
- Timestamp:
- 2010-07-25T15:56:14+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r3289 r3384 27 27 import java.util.Iterator; 28 28 import java.util.List; 29 import java.util.Set; 29 30 import java.util.logging.Logger; 30 31 … … 50 51 51 52 import org.openstreetmap.josm.Main; 53 import org.openstreetmap.josm.actions.CopyAction; 52 54 import org.openstreetmap.josm.command.AddCommand; 53 55 import org.openstreetmap.josm.command.ChangeCommand; … … 56 58 import org.openstreetmap.josm.data.osm.DataSet; 57 59 import org.openstreetmap.josm.data.osm.OsmPrimitive; 60 import org.openstreetmap.josm.data.osm.PrimitiveData; 58 61 import org.openstreetmap.josm.data.osm.Relation; 59 62 import org.openstreetmap.josm.data.osm.RelationMember; … … 91 94 92 95 /** the model for the selection table */ 96 private SelectionTable selectionTable; 93 97 private SelectionTableModel selectionTableModel; 94 98 … … 383 387 pnl3.setLayout(new BorderLayout()); 384 388 pnl3.add(splitPane, BorderLayout.CENTER); 389 390 new PasteMembersAction(); 391 new CopyMembersAction(); 392 385 393 return pnl3; 386 394 } … … 394 402 JPanel pnl = new JPanel(); 395 403 pnl.setLayout(new BorderLayout()); 396 SelectionTable tbl= new SelectionTable(selectionTableModel, new SelectionTableColumnModel(memberTableModel));397 tbl.setMemberTableModel(memberTableModel);398 JScrollPane pane = new JScrollPane( tbl);404 selectionTable = new SelectionTable(selectionTableModel, new SelectionTableColumnModel(memberTableModel)); 405 selectionTable.setMemberTableModel(memberTableModel); 406 JScrollPane pane = new JScrollPane(selectionTable); 399 407 pnl.add(pane, BorderLayout.CENTER); 400 408 return pnl; … … 591 599 } 592 600 601 private void registerCopyPasteAction(AbstractAction action, Object actionName, KeyStroke shortcut) { 602 getRootPane().getActionMap().put(actionName, action); 603 getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortcut, actionName); 604 // Assign also to JTables because they have their own Copy&Paste implementation (which is disabled in this case but eats key shortcuts anyway) 605 memberTable.getInputMap(JComponent.WHEN_FOCUSED).put(shortcut, actionName); 606 memberTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(shortcut, actionName); 607 memberTable.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortcut, actionName); 608 selectionTable.getInputMap(JComponent.WHEN_FOCUSED).put(shortcut, actionName); 609 selectionTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(shortcut, actionName); 610 selectionTable.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortcut, actionName); 611 } 612 593 613 static class AddAbortException extends Exception { 594 614 } … … 1442 1462 } 1443 1463 1464 class PasteMembersAction extends AddFromSelectionAction { 1465 1466 public PasteMembersAction() { 1467 registerCopyPasteAction(this, "PASTE_MEMBERS", Shortcut.getPasteKeyStroke()); 1468 } 1469 1470 @Override 1471 public void actionPerformed(ActionEvent e) { 1472 try { 1473 List<PrimitiveData> primitives = Main.pasteBuffer.getDirectlyAdded(); 1474 DataSet ds = getLayer().data; 1475 List<OsmPrimitive> toAdd = new ArrayList<OsmPrimitive>(); 1476 boolean hasNewInOtherLayer = false; 1477 1478 for (PrimitiveData primitive: primitives) { 1479 OsmPrimitive primitiveInDs = ds.getPrimitiveById(primitive); 1480 if (primitiveInDs != null) { 1481 toAdd.add(primitiveInDs); 1482 } else if (!primitive.isNew()) { 1483 toAdd.add(ds.getPrimitiveById(primitive, true)); 1484 } else { 1485 hasNewInOtherLayer = true; 1486 break; 1487 } 1488 } 1489 1490 if (hasNewInOtherLayer) { 1491 JOptionPane.showMessageDialog(Main.parent, tr("Members from paste buffer cannot be added because they are not included in current layer")); 1492 return; 1493 } 1494 1495 toAdd = filterConfirmedPrimitives(toAdd); 1496 memberTableModel.addMembersAfterIdx(toAdd, memberTableModel 1497 .getSelectionModel().getMaxSelectionIndex()); 1498 1499 tfRole.requestFocusInWindow(); 1500 1501 } catch (AddAbortException ex) { 1502 // Do nothing 1503 } 1504 } 1505 } 1506 1507 class CopyMembersAction extends AbstractAction { 1508 1509 public CopyMembersAction() { 1510 registerCopyPasteAction(this, "COPY_MEMBERS", Shortcut.getCopyKeyStroke()); 1511 } 1512 1513 @Override 1514 public void actionPerformed(ActionEvent e) { 1515 Set<OsmPrimitive> primitives = new HashSet<OsmPrimitive>(); 1516 for (RelationMember rm: memberTableModel.getSelectedMembers()) { 1517 primitives.add(rm.getMember()); 1518 } 1519 if (!primitives.isEmpty()) { 1520 CopyAction.copy(getLayer(), primitives); 1521 } 1522 } 1523 1524 } 1525 1444 1526 class MemberTableDblClickAdapter extends MouseAdapter { 1445 1527 @Override
Note:
See TracChangeset
for help on using the changeset viewer.