Source Code Cross Referenced for JTextComponentSpellChecker.java in  » XML-UI » xui32 » com » xoetrope » carousel » langed » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML UI » xui32 » com.xoetrope.carousel.langed 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.carousel.langed;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:        import java.util.Locale;
006:        import java.util.ResourceBundle;
007:
008:        import java.awt.Component;
009:        import java.awt.Dialog;
010:        import java.awt.Frame;
011:        import java.awt.Window;
012:        import javax.swing.SwingUtilities;
013:        import javax.swing.text.JTextComponent;
014:
015:        import com.swabunga.spell.engine.SpellDictionary;
016:        import com.swabunga.spell.event.DocumentWordTokenizer;
017:        import com.swabunga.spell.event.SpellCheckEvent;
018:        import com.swabunga.spell.event.SpellCheckListener;
019:        import com.swabunga.spell.event.SpellChecker;
020:
021:        /** This class spellchecks a JTextComponent throwing up a Dialog everytime
022:         *  it encounters a misspelled word.
023:         *
024:         * @author Robert Gustavsson (robert@lindesign.se)
025:         */
026:        public class JTextComponentSpellChecker implements  SpellCheckListener {
027:
028:            private static final String COMPLETED = "COMPLETED";
029:            private String dialogTitle = null;
030:
031:            private SpellChecker spellCheck = null;
032:            private JSpellDialog dlg = null;
033:            private JTextComponent textComp = null;
034:
035:            // Constructor
036:            public JTextComponentSpellChecker(SpellDictionary dict) {
037:                this (dict, null);
038:            }
039:
040:            // Convinient Constructors, for those lazy guys.
041:            public JTextComponentSpellChecker(String dictFile)
042:                    throws IOException {
043:                this (dictFile, null);
044:            }
045:
046:            public JTextComponentSpellChecker(String dictFile, String title)
047:                    throws IOException {
048:                this (new SpellDictionary(new File(dictFile)), title);
049:            }
050:
051:            public JTextComponentSpellChecker(String dictFile,
052:                    String phoneticFile, String title) throws IOException {
053:                this (new SpellDictionary(new File(dictFile), new File(
054:                        phoneticFile)), title);
055:            }
056:
057:            public JTextComponentSpellChecker(SpellDictionary dict, String title) {
058:                spellCheck = new SpellChecker(dict);
059:                spellCheck.addSpellCheckListener(this );
060:                dialogTitle = title;
061:            }
062:
063:            // MEMBER METHODS
064:            private void setupDialog(JTextComponent textComp) {
065:
066:                Component comp = SwingUtilities.getRoot(textComp);
067:
068:                // Probably the most common situation efter the first time.
069:                if (dlg != null && dlg.getOwner() == comp)
070:                    return;
071:
072:                if (comp != null && comp instanceof  Window) {
073:                    if (comp instanceof  Frame)
074:                        dlg = new JSpellDialog((Frame) comp, dialogTitle, true);
075:                    if (comp instanceof  Dialog)
076:                        dlg = new JSpellDialog((Dialog) comp, dialogTitle, true);
077:                    // Put the dialog in the middle of it's parent.
078:                    if (dlg != null) {
079:                        Window win = (Window) comp;
080:                        int x = (int) (win.getLocation().getX()
081:                                + win.getWidth() / 2 - dlg.getWidth() / 2);
082:                        int y = (int) (win.getLocation().getY()
083:                                + win.getHeight() / 2 - dlg.getHeight() / 2);
084:                        dlg.setLocation(x, y);
085:                    }
086:                } else {
087:                    dlg = new JSpellDialog((Frame) null, dialogTitle, true);
088:                }
089:            }
090:
091:            public synchronized int spellCheck(JTextComponent textComp) {
092:                setupDialog(textComp);
093:                this .textComp = textComp;
094:
095:                DocumentWordTokenizer tokenizer = new DocumentWordTokenizer(
096:                        textComp.getDocument());
097:                int exitStatus = spellCheck.checkSpelling(tokenizer);
098:
099:                textComp.requestFocus();
100:                textComp.setCaretPosition(0);
101:                this .textComp = null;
102:                return exitStatus;
103:            }
104:
105:            public void spellingError(SpellCheckEvent event) {
106:
107:                java.util.List suggestions = event.getSuggestions();
108:                int start = event.getWordContextPosition();
109:                int end = start + event.getInvalidWord().length();
110:
111:                // Mark the invalid word in TextComponent
112:                textComp.requestFocus();
113:                textComp.setCaretPosition(0);
114:                textComp.setCaretPosition(start);
115:                textComp.moveCaretPosition(end);
116:
117:                dlg.show(event);
118:            }
119:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.