Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / command / CommandTableModel.java @ 37573

History | View | Annotate | Download (1.27 KB)

1
package org.gvsig.app.gui.command;
2

    
3
import javax.swing.table.AbstractTableModel;
4

    
5
import org.gvsig.tools.undo.RedoException;
6
import org.gvsig.tools.undo.UndoException;
7
import org.gvsig.tools.undo.UndoRedoStack;
8
import org.gvsig.tools.undo.command.Command;
9

    
10

    
11
public class CommandTableModel extends AbstractTableModel{
12
private UndoRedoStack cr;
13
public CommandTableModel(UndoRedoStack cr) {
14
        this.cr=cr;
15
        }
16
        public int getPos() {
17
                return cr.getUndoInfos().size()-1;
18
        }
19
        public int getColumnCount() {
20
                return 1;
21
        }
22
        public int getRowCount() {
23
                return cr.getRedoInfos().size()+cr.getUndoInfos().size();
24
        }
25
        public Object getValueAt(int i, int j) {
26
                Command[] undos=(Command[])cr.getUndoInfos().toArray(new Command[0]);
27
                Command[] redos=(Command[])cr.getRedoInfos().toArray(new Command[0]);
28
                if (i<undos.length){
29
                        //System.out.println("undo i=" + i + " index=" + (undos.length-1-i));
30
                        return undos[undos.length-1-i];
31
                }else{
32
                        //System.out.println("redo i=" + i + " index=" + (i-undos.length));
33
                        return redos[i-undos.length];
34
                }
35
        }
36
        public void setPos(int newpos) {
37
                try {
38
                        if (newpos>getPos()){
39
                                cr.redo(newpos-getPos());
40

    
41
                        }else{
42
                                cr.undo(getPos()-newpos);
43
                        }
44
                } catch (RedoException e) {
45
                        e.printStackTrace();
46
                } catch (UndoException e) {
47
                        e.printStackTrace();
48
                }
49
        }
50
}