-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinder.java
More file actions
85 lines (62 loc) · 2.21 KB
/
Finder.java
File metadata and controls
85 lines (62 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import javax.swing.*;
import javax.swing.text.BadLocationException;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Finder extends AbstractAction {
private static String content;
private static int fullIndex = 0;
public void actionPerformed(ActionEvent evt) {
findText(Interface.textField.getText());
}
public static void findText(String c){
if (c.equals("")) {
Interface.status.setText("Nothing to search");
} else {
if (!c.equals(content)) {
fullIndex = 0;
Interface.hilit.removeAllHighlights();
}
content = c;
int r = read();
if (r != -1) {
int end = r + content.length();
try {
Interface.hilit.addHighlight(r, end, Interface.painter);
} catch (BadLocationException e) {
}
Interface.textArea.setCaretPosition(end);
fullIndex = end;
} else {
fullIndex = 0;
}
}
}
public static int read() {
String str;
int len, allIndex = fullIndex, index;
try {
BufferedReader in = new BufferedReader(new FileReader(TextFile.file.getAbsoluteFile()));
in.skip(fullIndex);
while ((str = in.readLine()) != null) {
len = str.length();
str = str.replaceAll("\\/\\/Connected to [0-9.]*", "");
str = str.replaceAll("===============End of session==============", "");
str = str.replaceAll("\\[.*\\]:\\s", "");
index = str.indexOf(content, 0);
if (index != -1) {
allIndex = allIndex + index + 29;
Interface.status.setText("Press the button to find next");
return allIndex;
} else {
allIndex = allIndex + len + 2;
}
}
} catch(IOException e) {
throw new RuntimeException(e);
}
Interface.status.setText("End of file");
return -1;
}
}