source: trunk/src/org/expeditee/actions/Spelling.java@ 778

Last change on this file since 778 was 778, checked in by jts21, 10 years ago

Move some settings into subpackages to tidy up the main settings page a bit, and make settings parser look for settings in subpages of the current settings page if it finds a setting it doesn't know what to do with

File size: 2.2 KB
Line 
1package org.expeditee.actions;
2
3import java.io.BufferedReader;
4import java.io.FileNotFoundException;
5import java.io.FileReader;
6import java.io.IOException;
7import java.util.Collection;
8import java.util.LinkedList;
9
10import org.expeditee.agents.wordprocessing.JSpellChecker;
11import org.expeditee.gui.FrameIO;
12import org.expeditee.gui.MessageBay;
13import org.expeditee.settings.folders.FolderSettings;
14
15public 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}
Note: See TracBrowser for help on using the repository browser.