1 package net.sf.bibkeeper.groups;
2
3 import javax.swing.undo;
4 import java.util.Vector;
5
6 class UndoableModifyGroup extends AbstractUndoableEdit {
7
8 private Vector groups;
9 private int index;
10 private String name, regexp, field, oldName, oldRegexp, oldField;
11 private GroupSelector gs;
12
13 public UndoableModifyGroup
14 (GroupSelector gs, Vector groups, int index,
15 String field, String name, String regexp,
16 String oldField, String oldName, String oldRegexp) {
17
18 this.gs = gs;
19 this.groups = groups;
20 this.index = index;
21 this.name = name;
22 this.regexp = regexp;
23 this.field = field;
24 this.oldName = oldName;
25 this.oldRegexp = oldRegexp;
26 this.oldField = oldField;
27 }
28
29 public String getUndoPresentationName() {
30 return "Undo: modify group";
31 }
32
33 public String getRedoPresentationName() {
34 return "Redo: modify group";
35 }
36
37 public void undo() {
38 remove();
39 insert(oldRegexp, oldName, oldField);
40 }
41
42 public void redo() {
43 remove();
44 insert(regexp, name, field);
45 }
46
47 private void remove() {
48 for (int i=0; i<GroupSelector.DIM; i++)
49 groups.removeElementAt(index);
50 }
51
52 private void insert(String one, String two, String three) {
53 index = GroupSelector.findPos(groups, two);
54 groups.add(index, one);
55 groups.add(index, two);
56 groups.add(index, three);
57 gs.revalidateList();
58 }
59
60 }