Changeset 31 in josm for src/org/openstreetmap/josm/gui


Ignore:
Timestamp:
2005-12-06T23:23:20+01:00 (19 years ago)
Author:
imi
Message:
  • fixed broken stuff from last checkin
  • complete undo and redo
  • futher simplification in DeleteAction
Location:
src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r30 r31  
    243243                map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    244244
    245                
     245
    246246                tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    247247       
     
    261261                pack();
    262262                Dimension s = Main.main.getSize();
    263                 setLocation(s.width/2-getWidth()/2, s.height/2-getHeight()/2);
     263                setLocation(Main.main.getX()+s.width/2-getWidth()/2, Main.main.getY()+s.height/2-getHeight()/2);
    264264        }
    265265
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r30 r31  
    22
    33import java.awt.Graphics;
    4 import java.io.FileWriter;
    5 import java.io.StringWriter;
    64import java.util.LinkedList;
     5import java.util.Stack;
    76
    87import javax.swing.Icon;
     
    1615import org.openstreetmap.josm.data.osm.Track;
    1716import org.openstreetmap.josm.data.osm.visitor.BoundingVisitor;
    18 import org.openstreetmap.josm.data.osm.visitor.CsvVisitor;
    1917import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor;
    2018import org.openstreetmap.josm.data.projection.Projection;
     
    4139         */
    4240        private LinkedList<Command> commands = new LinkedList<Command>();
    43         private LinkedList<String> debugDsBefore = new LinkedList<String>();
     41        /**
     42         * The stack for redoing commands
     43         */
     44        private Stack<Command> redoCommands = new Stack<Command>();
    4445
    4546        /**
     
    7172                SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv, null);
    7273
     74                for (LineSegment ls : data.lineSegments)
     75                        visitor.visit(ls);
    7376                for (Track t : data.tracks)
    7477                        visitor.visit(t);
    75                 for (LineSegment ls : data.lineSegments)
    76                         visitor.visit(ls);
    7778                for (Node n : data.nodes)
    7879                        visitor.visit(n);
     
    117118
    118119        /**
     120         * @return the last command added or <code>null</code> if no command in queue.
     121         */
     122        public Command lastCommand() {
     123                return commands.isEmpty() ? null : commands.getLast();
     124        }
     125       
     126        /**
    119127         * Execute the command and add it to the intern command queue. Also mark all
    120128         * primitives in the command as modified.
    121129         */
    122130        public void add(Command c) {
    123                 StringWriter sw = new StringWriter();
    124                 CsvVisitor v = new CsvVisitor(sw);
    125                 for (Node n : Main.main.ds.nodes) {
    126                         v.visit(n);
    127                         sw.append('\n');
    128                 }
    129                 for (LineSegment ls : Main.main.ds.lineSegments) {
    130                         v.visit(ls);
    131                         sw.append('\n');
    132                 }
    133                 for (Track t : Main.main.ds.tracks) {
    134                         v.visit(t);
    135                         sw.append('\n');
    136                 }
    137                 debugDsBefore.add(sw.getBuffer().toString());
    138                
    139131                c.executeCommand();
    140132                commands.add(c);
     133                redoCommands.clear();
     134                // TODO: Replace with listener scheme
     135                Main.main.undoAction.setEnabled(true);
     136                Main.main.redoAction.setEnabled(false);
    141137        }
    142138
     
    149145                Command c = commands.removeLast();
    150146                c.undoCommand();
    151                
    152                 //DEBUG
    153                 StringWriter sw = new StringWriter();
    154                 CsvVisitor v = new CsvVisitor(sw);
    155                 for (Node n : Main.main.ds.nodes) {
    156                         v.visit(n);
    157                         sw.append('\n');
    158                 }
    159                 for (LineSegment ls : Main.main.ds.lineSegments) {
    160                         v.visit(ls);
    161                         sw.append('\n');
    162                 }
    163                 for (Track t : Main.main.ds.tracks) {
    164                         v.visit(t);
    165                         sw.append('\n');
    166                 }
    167                 String s = Main.main.getMapFrame().mapView.editLayer().debugDsBefore.removeLast();
    168                 if (!s.equals(sw.getBuffer().toString())) {
    169                         try {
    170                                 FileWriter fw = new FileWriter("/home/imi/richtig");
    171                                 fw.append(sw.getBuffer().toString());
    172                                 fw.close();
    173                                 fw = new FileWriter("/home/imi/falsch");
    174                                 fw.append(s);
    175                                 fw.close();
    176                         } catch (Exception x) {
    177                                 x.printStackTrace();
    178                         }
    179                 }
     147                redoCommands.push(c);
     148                //TODO: Replace with listener scheme
     149                Main.main.undoAction.setEnabled(!commands.isEmpty());
     150                Main.main.redoAction.setEnabled(true);
     151        }
     152        /**
     153         * Redoes the last undoed command.
     154         */
     155        public void redo() {
     156                if (redoCommands.isEmpty())
     157                        return;
     158                Command c = redoCommands.pop();
     159                c.executeCommand();
     160                commands.add(c);
     161                //TODO: Replace with listener scheme
     162                Main.main.undoAction.setEnabled(true);
     163                Main.main.redoAction.setEnabled(!redoCommands.isEmpty());
    180164        }
    181165}
Note: See TracChangeset for help on using the changeset viewer.