svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / command / CommandTableModel.java @ 37606
History | View | Annotate | Download (1.76 KB)
1 |
package org.gvsig.app.gui.command; |
---|---|
2 |
|
3 |
import javax.swing.table.AbstractTableModel; |
4 |
|
5 |
import org.slf4j.Logger; |
6 |
import org.slf4j.LoggerFactory; |
7 |
|
8 |
import org.gvsig.tools.undo.RedoException; |
9 |
import org.gvsig.tools.undo.UndoException; |
10 |
import org.gvsig.tools.undo.UndoRedoStack; |
11 |
import org.gvsig.tools.undo.command.Command; |
12 |
|
13 |
|
14 |
@SuppressWarnings("serial") |
15 |
public class CommandTableModel extends AbstractTableModel{ |
16 |
private static final Logger LOG = |
17 |
LoggerFactory.getLogger(CommandTableModel.class); |
18 |
private UndoRedoStack cr;
|
19 |
|
20 |
public CommandTableModel(UndoRedoStack cr) {
|
21 |
this.cr = cr;
|
22 |
} |
23 |
|
24 |
public int getPos() { |
25 |
if ((cr == null) || cr.getUndoInfos() == null){ |
26 |
return 0; |
27 |
} |
28 |
return cr.getUndoInfos().size() - 1; |
29 |
} |
30 |
|
31 |
public int getColumnCount() { |
32 |
return 1; |
33 |
} |
34 |
|
35 |
public int getRowCount() { |
36 |
if ((cr == null) || cr.getUndoInfos() == null || cr.getRedoInfos() == null){ |
37 |
return 0; |
38 |
} |
39 |
return cr.getRedoInfos().size() + cr.getUndoInfos().size();
|
40 |
} |
41 |
|
42 |
@SuppressWarnings("unchecked") |
43 |
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]); |
46 |
if (i<undos.length){
|
47 |
//System.out.println("undo i=" + i + " index=" + (undos.length-1-i));
|
48 |
return undos[undos.length-1-i]; |
49 |
}else{
|
50 |
//System.out.println("redo i=" + i + " index=" + (i-undos.length));
|
51 |
return redos[i-undos.length];
|
52 |
} |
53 |
} |
54 |
|
55 |
public void setPos(int newpos) { |
56 |
try {
|
57 |
if (newpos > getPos()) {
|
58 |
cr.redo(newpos - getPos()); |
59 |
}else if (newpos < getPos()) { |
60 |
cr.undo(getPos() - newpos); |
61 |
} |
62 |
} catch (RedoException e) {
|
63 |
LOG.error("Error executing the command", e);
|
64 |
} catch (UndoException e) {
|
65 |
LOG.error("Error executing the command", e);
|
66 |
} |
67 |
} |
68 |
} |