Revision 37814 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/gui/command/CommandTableModel.java

View differences:

CommandTableModel.java
15 15
public class CommandTableModel extends AbstractTableModel{
16 16
    private static final Logger LOG = 
17 17
        LoggerFactory.getLogger(CommandTableModel.class);
18
    private UndoRedoStack cr;
19 18
    
20
    public CommandTableModel(UndoRedoStack cr) {
21
        this.cr = cr;
19
    private UndoRedoStack undoRedoStack;
20
        
21
    public CommandTableModel(UndoRedoStack undoRedoStack) {
22
        this.undoRedoStack = undoRedoStack;
22 23
	}
23 24

  
24 25
	public int getPos() {
25
		if ((cr == null) || cr.getUndoInfos() == null){
26
		if ((undoRedoStack == null) || undoRedoStack.getUndoInfos() == null){
26 27
		    return 0;
27 28
		}
28
	    return cr.getUndoInfos().size() - 1;
29
	    return undoRedoStack.getUndoInfos().size() - 1;
29 30
	}
30 31
	
31 32
	public int getColumnCount() {
......
33 34
	}
34 35
	
35 36
	public int getRowCount() {
36
		if ((cr == null) || cr.getUndoInfos() == null || cr.getRedoInfos() == null){
37
		if ((undoRedoStack == null) || undoRedoStack.getUndoInfos() == null || undoRedoStack.getRedoInfos() == null){
37 38
		    return 0;
38 39
		}
39
		return cr.getRedoInfos().size() + cr.getUndoInfos().size();
40
		return undoRedoStack.getRedoInfos().size() + undoRedoStack.getUndoInfos().size();
40 41
	}
41 42
	
42 43
	@SuppressWarnings("unchecked")
43 44
    public Object getValueAt(int i, int j) {
44
		Command[] undos=(Command[])cr.getUndoInfos().toArray(new Command[0]);
45
		Command[] redos=(Command[])cr.getRedoInfos().toArray(new Command[0]);
45
		Command[] undos=(Command[])undoRedoStack.getUndoInfos().toArray(new Command[0]);
46
		Command[] redos=(Command[])undoRedoStack.getRedoInfos().toArray(new Command[0]);
46 47
		if (i<undos.length){
47 48
			//System.out.println("undo i=" + i + " index=" + (undos.length-1-i));
48 49
			return undos[undos.length-1-i];
......
54 55
	
55 56
	public void setPos(int newpos) {
56 57
		try {
58
		    int currentPos = getPos();
57 59
			if (newpos > getPos()) {
58
				cr.redo(newpos - getPos());
60
				undoRedoStack.redo(newpos - getPos());
59 61
			}else if (newpos < getPos()) {
60
				cr.undo(getPos() - newpos);
62
				undoRedoStack.undo(getPos() - newpos);
61 63
			}
62 64
		} catch (RedoException e) {
63 65
			LOG.error("Error executing the command", e);

Also available in: Unified diff