Changeset 25854 in osm for applications
- Timestamp:
- 2011-04-16T18:56:13+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/dumbutils
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/dumbutils/src/dumbutils/DumbUtilsPlugin.java
r25852 r25854 17 17 Main.main.menu.toolsMenu.addSeparator(); 18 18 replaceGeometry = MainMenu.add(Main.main.menu.toolsMenu, new ReplaceGeometryAction()); 19 //tagBuffer = MainMenu.add(Main.main.menu.toolsMenu, new TagBufferAction());19 tagBuffer = MainMenu.add(Main.main.menu.toolsMenu, new TagBufferAction()); 20 20 } 21 21 … … 24 24 boolean enabled = newFrame != null; 25 25 replaceGeometry.setEnabled(enabled); 26 //tagBuffer.setEnabled(enabled);26 tagBuffer.setEnabled(enabled); 27 27 } 28 28 } -
applications/editors/josm/plugins/dumbutils/src/dumbutils/ReplaceGeometryAction.java
r25852 r25854 53 53 Command changeCommand = new ChangeCommand(way, result); 54 54 Command deleteCommand = new DeleteCommand(geometry); 55 Main.main.undoRedo.add(new SequenceCommand(tr("Replace geometry of way {0}", way.getDisplayName(DefaultNameFormatter.getInstance())))); 55 Main.main.undoRedo.add(new SequenceCommand( 56 tr("Replace geometry of way {0}", way.getDisplayName(DefaultNameFormatter.getInstance())), 57 changeCommand, deleteCommand)); 56 58 } 57 59 } -
applications/editors/josm/plugins/dumbutils/src/dumbutils/TagBufferAction.java
r25852 r25854 1 1 package dumbutils; 2 2 3 import org.openstreetmap.josm.Main; 4 import org.openstreetmap.josm.command.*; 3 5 import java.util.*; 4 6 import java.awt.event.KeyEvent; … … 17 19 private static final String TITLE = "Paste remembered tags"; 18 20 private Map<String, String> tags = new HashMap<String, String>(); 21 private Map<String, String> currentTags = new HashMap<String, String>(); 22 private Set<OsmPrimitive> selectionBuf = new HashSet<OsmPrimitive>(); 19 23 20 24 public TagBufferAction() { … … 24 28 25 29 public void actionPerformed( ActionEvent e ) { 26 for( OsmPrimitive p : getCurrentDataSet().getSelected() ) { 27 for( String key : tags.keySet() ) 28 p.put(key, tags.get(key)); 29 // todo: undoRedo 30 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 31 if( selection.isEmpty() ) 32 return; 33 34 List<Command> commands = new ArrayList<Command>(); 35 for( String key : tags.keySet() ) { 36 String value = tags.get(key); 37 boolean foundNew = false; 38 for( OsmPrimitive p : selection ) { 39 if( !p.hasKey(key) || !p.get(key).equals(value) ) { 40 foundNew = true; 41 break; 42 } 43 } 44 if( foundNew ) 45 commands.add(new ChangePropertyCommand(selection, key, value)); 46 } 47 48 if( !commands.isEmpty() ) 49 Main.main.undoRedo.add(new SequenceCommand(tr(TITLE), commands)); 50 } 51 52 @Override 53 protected void updateEnabledState() { 54 if( getCurrentDataSet() == null ) { 55 setEnabled(false); 56 if( selectionBuf != null ) 57 selectionBuf.clear(); 58 } else 59 updateEnabledState(getCurrentDataSet().getSelected()); 60 } 61 62 @Override 63 protected void updateEnabledState( Collection<? extends OsmPrimitive> selection ) { 64 // selection changed => check if selection is completely different from before 65 boolean foundOld = false; 66 if( selection != null ) { 67 for( OsmPrimitive p : selectionBuf ) { 68 if( selection.contains(p) ) { 69 foundOld = true; 70 break; 71 } 72 } 73 selectionBuf.clear(); 74 selectionBuf.addAll(selection); 75 } else { 76 foundOld = selectionBuf.isEmpty(); 77 selectionBuf.clear(); 78 } 79 if( !foundOld ) { 80 // selection has completely changed, remember tags 81 tags.clear(); 82 tags.putAll(currentTags); 83 } 84 rememberSelectionTags(); 85 86 setEnabled(selection != null && !selection.isEmpty() && !tags.isEmpty()); 87 } 88 89 private void rememberSelectionTags() { 90 if( getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty() ) { 91 currentTags.clear(); 92 Set<String> bad = new HashSet<String>(); 93 for( OsmPrimitive p : getCurrentDataSet().getSelected() ) { 94 if( currentTags.isEmpty() ) { 95 for( String key : p.keySet() ) 96 currentTags.put(key, p.get(key)); 97 } else { 98 for( String key : p.keySet() ) 99 if( !currentTags.containsKey(key) || !currentTags.get(key).equals(p.get(key)) ) 100 bad.add(key); 101 for( String key : currentTags.keySet() ) 102 if( !p.hasKey(key) ) 103 bad.add(key); 104 } 105 } 106 for( String key : bad ) 107 currentTags.remove(key); 30 108 } 31 109 } 32 110 } 33
Note:
See TracChangeset
for help on using the changeset viewer.