1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.aequo.text.action;
14
15 import java.awt.event.ActionEvent;
16 import java.awt.event.KeyEvent;
17
18 import javax.swing.Action;
19 import javax.swing.JList;
20 import javax.swing.KeyStroke;
21 import javax.swing.ListSelectionModel;
22
23 import org.abstracthorizon.aequo.CompareEntry;
24 import org.abstracthorizon.aequo.text.TextComparePanel;
25 import org.abstracthorizon.aequo.text.TextModel;
26
27
28
29
30
31
32 public class PreviousDifferenceAction extends TextBaseAction {
33
34
35 protected TextComparePanel panel;
36
37
38
39
40 public PreviousDifferenceAction() {
41 setName("Previous difference");
42 setMessage("Previous difference");
43 setDescription("Previous difference");
44 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_UP, ActionEvent.CTRL_MASK));
45 }
46
47
48
49
50
51 public void setTextComparePanel(TextComparePanel panel) {
52 this.panel = panel;
53 }
54
55
56
57
58
59
60 public void perform(ActionEvent e) {
61
62 TextModel model = getTextModel();
63 ListSelectionModel selModel = model.getSelectionModel();
64 int i = selModel.getLeadSelectionIndex();
65 if (i > 0) {
66 while ((i >= 0) && (model.get(i).getStatus(0) != CompareEntry.EQUAL)) {
67 i--;
68 }
69 if (i < 0) {
70 return;
71 }
72
73 while ((i >= 0) && (model.get(i).getStatus(0) == CompareEntry.EQUAL)) {
74 i--;
75 }
76 if (i < 0) {
77 return;
78 }
79
80 while ((i >= 0) && (model.get(i).getStatus(0) != CompareEntry.EQUAL)) {
81 i--;
82 }
83 i++;
84
85 JList list = ((JList)panel.getLeftList());
86
87 list.getSelectionModel().setSelectionInterval(i, i);
88 if (i < 10) {
89 i = 0;
90 } else {
91 i = i - 10;
92 }
93 list.ensureIndexIsVisible(i);
94 }
95 }
96
97
98 }