Changeset 301 in josm


Ignore:
Timestamp:
2007-08-08T14:56:38+02:00 (14 years ago)
Author:
imi
Message:
  • fixed undo/redo to be global
  • fixed adding of objects work with undo/redo (#212)
Files:
1 added
22 edited

Legend:

Unmodified
Added
Removed
  • .settings/org.eclipse.jdt.ui.prefs

    r86 r301  
    1 #Fri Apr 21 12:51:47 CEST 2006
     1#Wed Aug 08 13:31:47 GMT+01:00 2007
    22eclipse.preferences.version=1
    33formatter_profile=_josm
    44formatter_settings_version=10
     5org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">// License\: GPL. Copyright 2007 by Immanuel Scholz and others\n</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">// License\: GPL. Copyright 2007 by Immanuel Scholz and others\n${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
  • src/org/openstreetmap/josm/Main.java

    r298 r301  
    4040import org.openstreetmap.josm.data.Bounds;
    4141import org.openstreetmap.josm.data.Preferences;
     42import org.openstreetmap.josm.data.UndoRedoHandler;
    4243import org.openstreetmap.josm.data.osm.DataSet;
    4344import org.openstreetmap.josm.data.projection.Epsg4326;
     
    4748import org.openstreetmap.josm.gui.MapFrame;
    4849import org.openstreetmap.josm.gui.PleaseWaitDialog;
    49 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    5050import org.openstreetmap.josm.gui.download.BoundingBoxSelection;
    5151import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;
     
    111111
    112112
     113        public UndoRedoHandler undoRedo = new UndoRedoHandler();
     114
    113115        /**
    114116         * The main menu bar at top of screen.
    115117         */
    116118        public final MainMenu menu;
     119
     120
    117121
    118122
     
    125129                panel.setVisible(false);
    126130                panel.removeAll();
    127                 if (map != null) {
     131                if (map != null)
    128132                        map.fillPanel(panel);
    129                         map.mapView.addLayerChangeListener(new LayerChangeListener(){
    130                                 public void activeLayerChange(final Layer oldLayer, final Layer newLayer) {
    131                                         setLayerMenu(newLayer.getMenuEntries());
    132                                 }
    133                                 public void layerAdded(final Layer newLayer) {
    134                                         if (newLayer instanceof OsmDataLayer)
    135                                                 Main.main.editLayer().listenerCommands.add(redoUndoListener);
    136                                 }
    137                                 public void layerRemoved(final Layer oldLayer) {
    138                                         if (oldLayer instanceof OsmDataLayer)
    139                                                 Main.main.editLayer().listenerCommands.add(redoUndoListener);
    140                                         if (map.mapView.getAllLayers().isEmpty())
    141                                                 setLayerMenu(null);
    142                                 }
    143                         });
    144                         if (map.mapView.editLayer != null)
    145                                 map.mapView.editLayer.listenerCommands.add(redoUndoListener);
    146                 } else {
     133                else {
    147134                        old.destroy();
    148135                        panel.add(new GettingStarted(), BorderLayout.CENTER);
     
    187174                menu = new MainMenu();
    188175
     176                undoRedo.listenerCommands.add(redoUndoListener);
     177               
    189178                // creating toolbar
    190179                contentPane.add(toolbar.control, BorderLayout.NORTH);
     
    305294                }
    306295        };
    307 
    308296        /**
    309297         * Should be called before the main constructor to setup some parameter stuff
  • src/org/openstreetmap/josm/actions/AlignInCircleAction.java

    r298 r301  
    6868                }
    6969
    70                 Main.main.editLayer().add(new SequenceCommand(tr("Align Nodes in Circle"), cmds));
     70                Main.main.undoRedo.add(new SequenceCommand(tr("Align Nodes in Circle"), cmds));
    7171                Main.map.repaint();
    7272        }
  • src/org/openstreetmap/josm/actions/AlignInLineAction.java

    r298 r301  
    110110
    111111                // Do it!
    112                 Main.main.editLayer().add(new SequenceCommand(tr("Align Nodes in Line"), cmds));
     112                Main.main.undoRedo.add(new SequenceCommand(tr("Align Nodes in Line"), cmds));
    113113                Main.map.repaint();
    114114        }
  • src/org/openstreetmap/josm/actions/CombineWayAction.java

    r298 r301  
    9999                cmds.add(new DeleteCommand(selectedWays));
    100100                cmds.add(new ChangeCommand(oldWay, newWay));
    101                 Main.main.editLayer().add(new SequenceCommand(tr("Combine {0} ways", selectedWays.size()), cmds));
     101                Main.main.undoRedo.add(new SequenceCommand(tr("Combine {0} ways", selectedWays.size()), cmds));
    102102                Main.ds.setSelected(oldWay);
    103103        }
  • src/org/openstreetmap/josm/actions/RedoAction.java

    r298 r301  
    3030                        return;
    3131                Main.map.repaint();
    32                 Main.main.editLayer().redo();
     32                Main.main.undoRedo.redo();
    3333        }
    3434}
  • src/org/openstreetmap/josm/actions/ReorderAction.java

    r298 r301  
    5959
    6060                                if( c != null )
    61                                         Main.main.editLayer().add( c );
     61                                        Main.main.undoRedo.add(c);
    6262                        }
    6363                }
  • src/org/openstreetmap/josm/actions/ReverseSegmentAction.java

    r298 r301  
    5454                c.add(new ChangeCommand(s, snew));
    5555        }
    56         Main.main.editLayer().add(new SequenceCommand(tr("Reverse Segments"), c));
     56        Main.main.undoRedo.add(new SequenceCommand(tr("Reverse Segments"), c));
    5757        Main.map.repaint();
    5858    }
  • src/org/openstreetmap/josm/actions/SplitWayAction.java

    r298 r301  
    455455                NameVisitor v = new NameVisitor();
    456456                v.visit(selectedWay);
    457                 Main.main.editLayer().add(new SequenceCommand(tr("Split way {0} into {1} parts",v.name, segmentSets.size()), commandList));
     457                Main.main.undoRedo.add(new SequenceCommand(tr("Split way {0} into {1} parts",v.name, segmentSets.size()), commandList));
    458458                Main.ds.setSelected(newSelection);
    459459        }
  • src/org/openstreetmap/josm/actions/UndoAction.java

    r298 r301  
    3030                        return;
    3131                Main.map.repaint();
    32                 Main.main.editLayer().undo();
     32                Main.main.undoRedo.undo();
    3333        }
    3434}
  • src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java

    r298 r301  
    170170                }               
    171171       
    172                 Main.main.editLayer().add(c);
     172                Main.main.undoRedo.add(c);
    173173                Main.ds.setSelected(n);
    174174                Main.map.mapView.repaint();
  • src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java

    r298 r301  
    146146
    147147                        Segment ls = new Segment(start, end);
    148                         Main.main.editLayer().add(new AddCommand(ls));
     148                        Main.main.undoRedo.add(new AddCommand(ls));
    149149                        Collection<OsmPrimitive> sel = Main.ds.getSelected();
    150150                        sel.add(ls);
  • src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java

    r298 r301  
    107107                        copy.segments.remove(s);
    108108                        if (copy.segments.isEmpty()) {
    109                                 Main.main.editLayer().add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{way})));
     109                                Main.main.undoRedo.add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{way})));
    110110                                way = null;
    111111                        } else
    112                                 Main.main.editLayer().add(new ChangeCommand(way, copy));
     112                                Main.main.undoRedo.add(new ChangeCommand(way, copy));
    113113                } else {
    114114                        if (way == null) {
    115115                                way = new Way();
    116116                                way.segments.add(s);
    117                                 Main.main.editLayer().add(new AddCommand(way));
     117                                Main.main.undoRedo.add(new AddCommand(way));
    118118                        } else {
    119119                                Way copy = new Way(way);
     
    123123                                                break;
    124124                                copy.segments.add(i, s);
    125                                 Main.main.editLayer().add(new ChangeCommand(way, copy));
     125                                Main.main.undoRedo.add(new ChangeCommand(way, copy));
    126126                        }
    127127                }
     
    198198                                w.segments.clear();
    199199                        w.segments.addAll(sortedSegments);
    200                         Main.main.editLayer().add(new ChangeCommand(wayToAdd, w));
     200                        Main.main.undoRedo.add(new ChangeCommand(wayToAdd, w));
    201201                        return wayToAdd;
    202202                }
     
    207207                Way w = new Way();
    208208                w.segments.addAll(sortedSegments);
    209                 Main.main.editLayer().add(new AddCommand(w));
     209                Main.main.undoRedo.add(new AddCommand(w));
    210210                return w;
    211211        }
  • src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r298 r301  
    126126                v.data.addAll(selection);
    127127                if (!v.data.isEmpty())
    128                         Main.main.editLayer().add(new DeleteCommand(v.data));
     128                        Main.main.undoRedo.add(new DeleteCommand(v.data));
    129129        }
    130130
     
    164164                }
    165165                if (!del.isEmpty())
    166                         Main.main.editLayer().add(new DeleteCommand(del));
     166                        Main.main.undoRedo.add(new DeleteCommand(del));
    167167        }
    168168
     
    213213                cmds.add(new ChangeCommand(seg1, s));
    214214                cmds.add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{n, seg2})));
    215                 Main.main.editLayer().add(new SequenceCommand(tr("Delete Node"), cmds));
     215                Main.main.undoRedo.add(new SequenceCommand(tr("Delete Node"), cmds));
    216216                return null;
    217217    }
  • src/org/openstreetmap/josm/actions/mapmode/MoveAction.java

    r298 r301  
    106106                }
    107107
    108                 Command c = !Main.main.editLayer().commands.isEmpty() ? Main.main.editLayer().commands.getLast() : null;
     108                Command c = !Main.main.undoRedo.commands.isEmpty() ? Main.main.undoRedo.commands.getLast() : null;
    109109                if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects))
    110110                        ((MoveCommand)c).moveAgain(dx,dy);
    111111                else
    112                         Main.main.editLayer().add(new MoveCommand(selection, dx, dy));
     112                        Main.main.undoRedo.add(new MoveCommand(selection, dx, dy));
    113113
    114114                Main.map.mapView.repaint();
  • src/org/openstreetmap/josm/command/AddCommand.java

    r298 r301  
    1111
    1212import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.data.osm.DataSet;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1415import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
     
    2829         */
    2930        private final OsmPrimitive osm;
     31       
     32        private DataSet ds;
    3033
    3134        /**
     
    3437        public AddCommand(OsmPrimitive osm) {
    3538                this.osm = osm;
     39                this.ds = Main.ds;
    3640        }
    3741
    3842        @Override public void executeCommand() {
    39                 osm.visit(new AddVisitor(Main.ds));
     43                osm.visit(new AddVisitor(ds));
    4044        }
    4145
    4246        @Override public void undoCommand() {
    43                 osm.visit(new DeleteVisitor(Main.ds));
     47                osm.visit(new DeleteVisitor(ds));
    4448        }
    4549
  • src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r298 r301  
    1919import org.openstreetmap.josm.command.Command;
    2020import org.openstreetmap.josm.gui.MapFrame;
    21 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    22 import org.openstreetmap.josm.gui.layer.Layer;
    23 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2421import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    2522
     
    3128        public CommandStackDialog(final MapFrame mapFrame) {
    3229                super(tr("Command Stack"), "commandstack", tr("Open a list of all commands (undo buffer)."), KeyEvent.VK_O, 100);
    33                 mapFrame.mapView.addLayerChangeListener(new LayerChangeListener(){
    34                         public void activeLayerChange(Layer oldLayer, Layer newLayer) {}
    35                         public void layerAdded(Layer newLayer) {
    36                                 if (newLayer instanceof OsmDataLayer)
    37                                         Main.main.editLayer().listenerCommands.add(CommandStackDialog.this);
    38                         }
    39                         public void layerRemoved(Layer oldLayer) {
    40                                 if (oldLayer instanceof OsmDataLayer)
    41                                         Main.main.editLayer().listenerCommands.remove(CommandStackDialog.this);
    42                         }
    43                 });
    44                 if (mapFrame.mapView.editLayer != null)
    45                         mapFrame.mapView.editLayer.listenerCommands.add(this);
     30                Main.main.undoRedo.listenerCommands.add(this);
    4631                       
    4732                tree.setRootVisible(false);
     
    7560                if (Main.map == null || Main.map.mapView == null || Main.map.mapView.editLayer == null)
    7661                        return;
    77                 Collection<Command> commands = Main.main.editLayer().commands;
     62                Collection<Command> commands = Main.main.undoRedo.commands;
    7863                DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    7964                for (Command c : commands)
  • src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r298 r301  
    120120                if (answer != JOptionPane.OK_OPTION)
    121121                        return;
    122                 Main.main.editLayer().add(new ConflictResolveCommand(resolver.conflicts, sel));
     122                Main.main.undoRedo.add(new ConflictResolveCommand(resolver.conflicts, sel));
    123123                Main.map.mapView.repaint();
    124124        }
  • src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r298 r301  
    157157                }
    158158                if (key.equals(newkey) || value == null)
    159                         Main.main.editLayer().add(new ChangePropertyCommand(sel, newkey, value));
     159                        Main.main.undoRedo.add(new ChangePropertyCommand(sel, newkey, value));
    160160                else {
    161                         Main.main.editLayer().add(new SequenceCommand(trn("Change properties of {0} object", "Change properties of {0} objects", sel.size(), sel.size()),
     161                        Main.main.undoRedo.add(new SequenceCommand(trn("Change properties of {0} object", "Change properties of {0} objects", sel.size(), sel.size()),
    162162                                        new ChangePropertyCommand(sel, key, null),
    163163                                        new ChangePropertyCommand(sel, newkey, value)));
     
    239239                if (value.equals(""))
    240240                        return;
    241                 Main.main.editLayer().add(new ChangePropertyCommand(sel, key, value));
     241                Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value));
    242242                selectionChanged(sel); // update table
    243243                Main.parent.repaint(); // repaint all - drawing could have been changed
     
    251251                String key = data.getValueAt(row, 0).toString();
    252252                Collection<OsmPrimitive> sel = Main.ds.getSelected();
    253                 Main.main.editLayer().add(new ChangePropertyCommand(sel, key, null));
     253                Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, null));
    254254                selectionChanged(sel); // update table
    255255        }
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r298 r301  
    1717import java.util.LinkedList;
    1818import java.util.Set;
    19 import java.util.Stack;
    2019
    2120import javax.swing.Icon;
     
    3130import org.openstreetmap.josm.actions.SaveAction;
    3231import org.openstreetmap.josm.actions.SaveAsAction;
    33 import org.openstreetmap.josm.command.Command;
    3432import org.openstreetmap.josm.data.coor.EastNorth;
    3533import org.openstreetmap.josm.data.osm.DataSet;
     
    107105         */
    108106        private boolean fromDisk = false;
    109         /**
    110          * All commands that were made on the dataset. Don't write from outside!
    111          */
    112         public final LinkedList<Command> commands = new LinkedList<Command>();
    113         /**
    114          * The stack for redoing commands
    115          */
    116         private final Stack<Command> redoCommands = new Stack<Command>();
    117107
    118108        public final LinkedList<ModifiedChangedListener> listenerModified = new LinkedList<ModifiedChangedListener>();
    119         public final LinkedList<CommandQueueListener> listenerCommands = new LinkedList<CommandQueueListener>();
    120109
    121110        private SimplePaintVisitor mapPainter = new SimplePaintVisitor();
     
    209198
    210199        /**
    211          * Execute the command and add it to the intern command queue. Also mark all
    212          * primitives in the command as modified.
    213          */
    214         public void add(final Command c) {
    215                 c.executeCommand();
    216                 commands.add(c);
    217                 redoCommands.clear();
    218                 setModified(true);
    219                 fireCommandsChanged();
    220         }
    221 
    222         /**
    223          * Undoes the last added command.
    224          * TODO: This has to be moved to a central place in order to support multiple layers.
    225          */
    226         public void undo() {
    227                 if (commands.isEmpty())
    228                         return;
    229                 final Command c = commands.removeLast();
    230                 c.undoCommand();
    231                 redoCommands.push(c);
    232                 setModified(uploadedModified || !commands.isEmpty());
    233                 Main.ds.setSelected();
    234                 fireCommandsChanged();
    235         }
    236         /**
    237          * Redoes the last undoed command.
    238          * TODO: This has to be moved to a central place in order to support multiple layers.
    239          */
    240         public void redo() {
    241                 if (redoCommands.isEmpty())
    242                         return;
    243                 final Command c = redoCommands.pop();
    244                 c.executeCommand();
    245                 commands.add(c);
    246                 setModified(true);
    247                 fireCommandsChanged();
    248         }
    249 
    250         /**
    251200         * Clean out the data behind the layer. This means clearing the redo/undo lists,
    252201         * really deleting all deleted objects and reset the modified flags. This is done
     
    264213                        return;
    265214               
    266                 redoCommands.clear();
    267                 commands.clear();
     215                Main.main.undoRedo.clean();
    268216
    269217                // if uploaded, clean the modified flags as well
     
    285233                uploadedModified = fromDisk && processed != null && dataAdded;
    286234                setModified(uploadedModified);
    287                 fireCommandsChanged();
    288         }
    289 
    290         public void fireCommandsChanged() {
    291                 for (final CommandQueueListener l : listenerCommands)
    292                         l.commandChanged(commands.size(), redoCommands.size());
    293235        }
    294236
  • src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r298 r301  
    285285                        Command cmd = createCommand(Main.ds.getSelected());
    286286                        if (cmd != null)
    287                                 Main.main.editLayer().add(cmd);
     287                                Main.main.undoRedo.add(cmd);
    288288                }
    289289                Main.ds.setSelected(Main.ds.getSelected()); // force update
  • src/org/openstreetmap/josm/io/IncompleteDownloader.java

    r298 r301  
    7777                }
    7878                if (cmds.size() > 0)
    79                         Main.main.editLayer().add(new SequenceCommand(tr("Fix data errors"), cmds));
     79                        Main.main.undoRedo.add(new SequenceCommand(tr("Fix data errors"), cmds));
    8080        }
    8181
Note: See TracChangeset for help on using the changeset viewer.