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

Last change on this file since 614 was 570, checked in by jts21, 11 years ago

Add settings package which uses reflection to allow changing settings without hard coding the code to change every setting.

  • Currently only works for String/Int/Boolean/Double values
  • Supports default values by looking for fields with the prefix 'default', and will reset unset values to their default if a default exists.
  • For more complex settings (e.g. proxy settings), there is a "onParsed()" callback which can be used to run additional code, and (in the case of the password widget) parse abnormal items.
  • Some of the settings code in FrameUtils.ParseProfile has already been commented out since it's handled by default with the new Settings package. The rest could be moved over to UserSettings.onParsed(). Given the number of settings that remain to be moved, it may be a good idea to add the possibility for setting-specific onParsed() callbacks (could be done quite easily, similarly to how default values are handled).
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.UserSettings;
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 : UserSettings.FrameDirs) {
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.