1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.aequo.file.action;
14
15 import java.awt.event.ActionEvent;
16 import java.awt.event.KeyEvent;
17
18 import javax.swing.Action;
19 import javax.swing.KeyStroke;
20 import javax.swing.ListSelectionModel;
21
22 import org.abstracthorizon.aequo.file.FileCompareEntry;
23 import org.abstracthorizon.aequo.file.FilesModel;
24
25
26
27
28
29
30 public class ShowComparisonAction extends FileBaseAction {
31
32 public ShowComparisonAction() {
33 setName("Show Comparison");
34 setMessage("Show Comparison");
35 setDescription("Show Comparison");
36 putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
37 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
38 }
39
40 public boolean isEnabled() {
41 ListSelectionModel selModel = getFilesModel().getSelectionModel();
42 int min = selModel.getMinSelectionIndex();
43 int max = selModel.getMaxSelectionIndex();
44 if ((min >= 0) && (min == max)) {
45 FileCompareEntry entry = filesModel.get(min);
46 if (entry.getData(0).isFile() || entry.getData(1).isFile()) {
47 return true;
48 }
49 }
50 return false;
51 }
52
53
54
55
56
57
58 public void perform(ActionEvent e) {
59 FilesModel filesModel = getFilesModel();
60 int index = filesModel.getSelectionModel().getMinSelectionIndex();
61 if ((index >= 0) && (index == filesModel.getSelectionModel().getMaxSelectionIndex())) {
62 FileCompareEntry entry = filesModel.get(index);
63 org.abstracthorizon.aequo.text.action.ShowComparisonAction compare = new org.abstracthorizon.aequo.text.action.ShowComparisonAction(entry);
64 compare.setGlobalContext(getGlobalContext());
65 compare.actionPerformed(e);
66 }
67 }
68 }