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 NextDifferenceAction extends TextBaseAction {
33
34
35 protected TextComparePanel panel;
36
37
38
39
40 public NextDifferenceAction() {
41 setName("Next difference");
42 setMessage("Next difference");
43 setDescription("Next difference");
44 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 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 int size = model.getSize();
67 while ((i < size) && (model.get(i).getStatus(0) != CompareEntry.EQUAL)) {
68 i++;
69 }
70 if (i == size) {
71 return;
72 }
73
74 while ((i < size) && (model.get(i).getStatus(0) == CompareEntry.EQUAL)) {
75 i++;
76 }
77 if (i == size) {
78 return;
79 }
80
81 JList list = ((JList)panel.getLeftList());
82
83 list.getSelectionModel().setSelectionInterval(i, i);
84 if (i > size - 10) {
85 i = size;
86 } else {
87 i = i + 10;
88 }
89 list.ensureIndexIsVisible(i);
90 }
91 }
92
93
94 }