1 | package org.expeditee.actions;
|
---|
2 |
|
---|
3 | import java.io.BufferedReader;
|
---|
4 | import java.io.FileNotFoundException;
|
---|
5 | import java.io.FileReader;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.LinkedList;
|
---|
9 |
|
---|
10 | import org.expeditee.agents.wordprocessing.JSpellChecker;
|
---|
11 | import org.expeditee.gui.FrameIO;
|
---|
12 | import org.expeditee.gui.MessageBay;
|
---|
13 | import org.expeditee.settings.folders.FolderSettings;
|
---|
14 |
|
---|
15 | public class Spelling {
|
---|
16 | public static Collection<String> spellCheckFrame(String frameName,
|
---|
17 | String path) {
|
---|
18 | String fullPath = null;
|
---|
19 | JSpellChecker spellChecker = null;
|
---|
20 | try {
|
---|
21 | spellChecker = JSpellChecker.getInstance();
|
---|
22 | } catch (FileNotFoundException e1) {
|
---|
23 | e1.printStackTrace();
|
---|
24 | return null;
|
---|
25 | } catch (IOException e1) {
|
---|
26 | e1.printStackTrace();
|
---|
27 | return null;
|
---|
28 | }
|
---|
29 | if (path == null) {
|
---|
30 | for (String possiblePath : FolderSettings.FrameDirs.get()) {
|
---|
31 | fullPath = FrameIO
|
---|
32 | .getFrameFullPathName(possiblePath, frameName);
|
---|
33 | if (fullPath != null)
|
---|
34 | break;
|
---|
35 | }
|
---|
36 | } else {
|
---|
37 | fullPath = FrameIO.getFrameFullPathName(path, frameName);
|
---|
38 | }
|
---|
39 | // If the frame was not located return null
|
---|
40 | if (fullPath == null)
|
---|
41 | return null;
|
---|
42 | Collection<String> results = new LinkedList<String>();
|
---|
43 | // Open the file and search the text items
|
---|
44 | try {
|
---|
45 | BufferedReader reader = new BufferedReader(new FileReader(fullPath));
|
---|
46 | String next;
|
---|
47 | while (reader.ready() && ((next = reader.readLine()) != null)) {
|
---|
48 | if (next.startsWith("T")) {
|
---|
49 | String toSearch = next.substring(2);
|
---|
50 | spellChecker.setText(toSearch);
|
---|
51 | String misspelled = spellChecker.getMisspelledWord();
|
---|
52 | if (misspelled != null && misspelled.length() > 0) {
|
---|
53 | results.add(toSearch);
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
57 | } catch (FileNotFoundException e) {
|
---|
58 | e.printStackTrace();
|
---|
59 | return null;
|
---|
60 | } catch (IOException e) {
|
---|
61 | e.printStackTrace();
|
---|
62 | }
|
---|
63 | return results;
|
---|
64 | }
|
---|
65 |
|
---|
66 | public static String checkSpelling(String word) {
|
---|
67 | try {
|
---|
68 | return JSpellChecker.getInstance().getSuggestions(word);
|
---|
69 | } catch (FileNotFoundException e) {
|
---|
70 | MessageBay.errorMessage("Could not find dictionary: "
|
---|
71 | + e.getMessage());
|
---|
72 | } catch (IOException e) {
|
---|
73 | e.printStackTrace();
|
---|
74 | }
|
---|
75 | return null;
|
---|
76 | }
|
---|
77 |
|
---|
78 | public static String spellCheck(String word) {
|
---|
79 | return checkSpelling(word);
|
---|
80 | }
|
---|
81 | }
|
---|