~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package org.herac.tuxguitar.gui.undo.undoables;

import java.util.ArrayList;
import java.util.List;

import org.herac.tuxguitar.gui.undo.CannotRedoException;
import org.herac.tuxguitar.gui.undo.CannotUndoException;
import org.herac.tuxguitar.gui.undo.UndoableEdit;

public class UndoableJoined implements UndoableEdit{
	private int doAction;
	private UndoableCaretHelper undoCaret;
	private UndoableCaretHelper redoCaret;
	private List undoables;
	
	public UndoableJoined(){
		this.doAction = UNDO_ACTION;
		this.undoCaret = new UndoableCaretHelper();
		this.undoables = new ArrayList();
	}
	
	public void addUndoableEdit(UndoableEdit undoable){
		this.undoables.add(undoable);
	}
	
	public void redo() throws CannotRedoException {
		int count = this.undoables.size();
		for(int i = 0;i < count;i++){
			UndoableEdit undoable = (UndoableEdit)this.undoables.get(i);
			undoable.redo();
		}
		this.redoCaret.update();
		this.doAction = UNDO_ACTION;
	}
	
	public void undo() throws CannotUndoException {
		int count = this.undoables.size();
		for(int i = (count - 1);i >= 0;i--){
			UndoableEdit undoable = (UndoableEdit)this.undoables.get(i);
			undoable.undo();
		}
		this.undoCaret.update();
		this.doAction = REDO_ACTION;
	}
	
	public boolean canRedo() {
		return (this.doAction == REDO_ACTION);
	}
	
	public boolean canUndo() {
		return (this.doAction == UNDO_ACTION);
	}
	
	public UndoableJoined endUndo(){
		this.redoCaret = new UndoableCaretHelper();
		return this;
	}
}