- Timestamp:
- 2010-07-25T15:56:14+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CopyAction.java
r2892 r3384 3 3 package org.openstreetmap.josm.actions; 4 4 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;7 7 8 8 import java.awt.Toolkit; … … 14 14 import java.awt.event.KeyEvent; 15 15 import java.util.Collection; 16 import java.util.LinkedList;17 16 18 17 import javax.swing.JOptionPane; … … 20 19 import org.openstreetmap.josm.Main; 21 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 22 22 import org.openstreetmap.josm.tools.Shortcut; 23 23 24 24 public final class CopyAction extends JosmAction { 25 26 private LinkedList<JosmAction> listeners;27 25 28 26 public CopyAction() { … … 31 29 Shortcut.registerShortcut("system:copy", tr("Edit: {0}", tr("Copy")), KeyEvent.VK_C, Shortcut.GROUP_MENU), true); 32 30 putValue("help", ht("/Action/Copy")); 33 listeners = new LinkedList<JosmAction>();34 }35 36 @Override public void addListener(JosmAction a) {37 listeners.add(a);38 31 } 39 32 … … 42 35 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 43 36 37 copy(getEditLayer(), selection); 38 } 39 40 public static void copy(OsmDataLayer source, Collection<OsmPrimitive> primitives) { 44 41 /* copy ids to the clipboard */ 45 42 StringBuilder idsBuilder = new StringBuilder(); 46 for (OsmPrimitive p : selection) {43 for (OsmPrimitive p : primitives) { 47 44 idsBuilder.append(p.getId()+","); 48 45 } … … 56 53 } 57 54 catch (RuntimeException x) {} 58 59 Main.pasteBuffer.makeCopy(selection);60 Main.pasteSource = getEditLayer();61 Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */62 55 63 for(JosmAction a : listeners) { 64 a.pasteBufferChanged(Main.pasteBuffer); 65 } 56 Main.pasteBuffer.makeCopy(primitives); 57 Main.pasteSource = source; 66 58 } 67 59 -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r3327 r3384 12 12 import org.openstreetmap.josm.data.osm.DataSet; 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy;15 14 import org.openstreetmap.josm.gui.MapView; 16 15 import org.openstreetmap.josm.gui.layer.Layer; … … 103 102 * needs to be overridden to be useful 104 103 */ 105 public void pasteBufferChanged(PrimitiveDeepCopy newPasteBuffer) {106 return;107 }108 109 /**110 * needs to be overridden to be useful111 */112 104 public void addListener(JosmAction a) { 113 105 return; -
trunk/src/org/openstreetmap/josm/actions/PasteAction.java
r2932 r3384 23 23 import org.openstreetmap.josm.data.osm.RelationMemberData; 24 24 import org.openstreetmap.josm.data.osm.WayData; 25 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy.PasteBufferChangedListener; 25 26 import org.openstreetmap.josm.gui.ExtendedDialog; 26 27 import org.openstreetmap.josm.gui.layer.Layer; 27 28 import org.openstreetmap.josm.tools.Shortcut; 28 29 29 public final class PasteAction extends JosmAction {30 public final class PasteAction extends JosmAction implements PasteBufferChangedListener { 30 31 31 32 public PasteAction() { … … 33 34 Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.GROUP_MENU), true); 34 35 putValue("help", ht("/Action/Paste")); 36 Main.pasteBuffer.addPasteBufferChangedListener(this); 35 37 } 36 38 … … 167 169 setEnabled(!Main.pasteBuffer.isEmpty()); 168 170 } 171 172 @Override 173 public void pasteBufferChanged(PrimitiveDeepCopy pasteBuffer) { 174 updateEnabledState(); 175 } 169 176 } -
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r2512 r3384 3 3 package org.openstreetmap.josm.actions; 4 4 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;7 7 import static org.openstreetmap.josm.tools.I18n.trn; 8 8 … … 24 24 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy; 25 25 import org.openstreetmap.josm.data.osm.TagCollection; 26 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy.PasteBufferChangedListener; 26 27 import org.openstreetmap.josm.gui.conflict.tags.PasteTagsConflictResolverDialog; 27 28 import org.openstreetmap.josm.tools.Shortcut; 28 29 29 public final class PasteTagsAction extends JosmAction {30 public final class PasteTagsAction extends JosmAction implements PasteBufferChangedListener { 30 31 31 32 public PasteTagsAction(JosmAction copyAction) { … … 33 34 tr("Apply tags of contents of paste buffer to all selected items."), 34 35 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true); 35 copyAction.addListener(this);36 Main.pasteBuffer.addPasteBufferChangedListener(this); 36 37 putValue("help", ht("/Action/PasteTags")); 37 38 } -
trunk/src/org/openstreetmap/josm/data/osm/PrimitiveDeepCopy.java
r3083 r3384 7 7 import java.util.List; 8 8 import java.util.Set; 9 import java.util.concurrent.CopyOnWriteArrayList; 9 10 10 11 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; … … 17 18 public class PrimitiveDeepCopy { 18 19 20 public interface PasteBufferChangedListener { 21 void pasteBufferChanged(PrimitiveDeepCopy pasteBuffer); 22 } 23 19 24 private final List<PrimitiveData> directlyAdded = new ArrayList<PrimitiveData>(); 20 25 private final List<PrimitiveData> referenced = new ArrayList<PrimitiveData>(); 26 private final CopyOnWriteArrayList<PasteBufferChangedListener> listeners = new CopyOnWriteArrayList<PasteBufferChangedListener>(); 21 27 22 28 public PrimitiveDeepCopy() { … … 74 80 } 75 81 }.visitAll(); 82 83 firePasteBufferChanged(); 76 84 } 77 85 … … 95 103 } 96 104 105 private void firePasteBufferChanged() { 106 for (PasteBufferChangedListener listener: listeners) { 107 listener.pasteBufferChanged(this); 108 } 109 } 110 111 public void addPasteBufferChangedListener(PasteBufferChangedListener listener) { 112 listeners.addIfAbsent(listener); 113 } 114 115 public void removePasteBufferChangedListener(PasteBufferChangedListener listener) { 116 listeners.remove(listener); 117 } 118 97 119 } -
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.