1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.aequo.action;
14
15 import java.awt.event.ActionEvent;
16 import java.awt.event.KeyEvent;
17 import java.io.File;
18
19 import javax.swing.Action;
20
21 import org.abstracthorizon.aequo.GlobalContext;
22 import org.abstracthorizon.aequo.util.Preferences;
23 import org.abstracthorizon.aequo.util.StringUtils;
24 import org.abstracthorizon.aequo.util.filters.Filter;
25 import org.abstracthorizon.aequo.util.prefs.RecentFileEntry;
26
27
28
29
30
31
32 public class PreviousSessionAction extends BaseAction {
33
34
35 protected int sessionNo;
36
37
38
39
40 public PreviousSessionAction() {
41 setName("Previous Session");
42 setMessage("Previous Session");
43 setDescription("Previous Session");
44 }
45
46
47
48
49
50
51 public void setSessionNo(int sessionNo) {
52 this.sessionNo = sessionNo;
53 Preferences prefs = context.getPreferences();
54
55 RecentFileEntry entry = RecentFileEntry.read(prefs, sessionNo);
56
57 String sessionName = StringUtils.calculateShortestTitle(entry.left, entry.right);
58
59 setName(sessionNo + " " + sessionName);
60 setMessage("Comparing " + sessionName);
61 setDescription("Comparing " + sessionName);
62
63 if (sessionNo < 9) {
64 int[] keys = new int[]{KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_3, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_6, KeyEvent.VK_7, KeyEvent.VK_8, KeyEvent.VK_9};
65 putValue(Action.MNEMONIC_KEY, keys[sessionNo]);
66 }
67 autoloadIcon();
68 }
69
70
71
72
73
74 public void perform(ActionEvent e) {
75 GlobalContext context = getGlobalContext();
76
77 Preferences prefs = context.getPreferences();
78 RecentFileEntry entry = RecentFileEntry.read(prefs, sessionNo);
79
80 if ((entry.left != null) && (entry.right != null)) {
81 CompareFilesAction compareFilesAction = new CompareFilesAction(new File(entry.left), new File(entry.right), new Filter(entry.filters), context);
82 compareFilesAction.actionPerformed(e);
83 }
84 }
85 }