Source Code Cross Referenced for JSpellForm.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:        /*
002:         * put your module comment here
003:         * formatted with JxBeauty (c) johann.langhofer@nextra.at
004:         */
005:
006:        package com.xoetrope.carousel.langed;
007:
008:        import java.util.Locale;
009:        import java.util.ResourceBundle;
010:
011:        import java.awt.BorderLayout;
012:        import java.awt.Dimension;
013:        import java.awt.event.ActionEvent;
014:        import java.awt.event.ActionListener;
015:        import javax.swing.BoxLayout;
016:        import javax.swing.DefaultListModel;
017:        import javax.swing.JButton;
018:        import javax.swing.JLabel;
019:        import javax.swing.JList;
020:        import javax.swing.JPanel;
021:        import javax.swing.JScrollPane;
022:        import javax.swing.JTextArea;
023:        import javax.swing.ListSelectionModel;
024:        import javax.swing.event.EventListenerList;
025:        import javax.swing.event.ListSelectionEvent;
026:        import javax.swing.event.ListSelectionListener;
027:
028:        import com.swabunga.spell.engine.Word;
029:        import com.swabunga.spell.event.SpellCheckEvent;
030:
031:        /** Implementation of a spell check form.
032:         *  <p>This needs to layed out correctly but for the most part it works.</p>
033:         *
034:         * @author Jason Height (jheight@chariot.net.au)
035:         */
036:        public class JSpellForm extends JPanel implements  ActionListener,
037:                ListSelectionListener {
038:            /** The Ignore button click action command*/
039:            public static final String IGNORE_CMD = "IGNORE";
040:            /** The Ignore All button click action command*/
041:            public static final String IGNOREALL_CMD = "IGNOREALL";
042:            /** The Add button click action command*/
043:            public static final String ADD_CMD = "ADD";
044:            /** The Replace button click action command*/
045:            public static final String REPLACE_CMD = "REPLACE";
046:            /** The Replace All button click action command*/
047:            public static final String REPLACEALL_CMD = "REPLACEALL";
048:            /** The Cancel button click action command*/
049:            public static final String CANCEL_CMD = "CANCEL";
050:            /** The resource for the Suggestions label*/
051:            private static final String SUGGESTIONS_RES = "SUGGESTIONS";
052:            private static final String INVALIDWORD_RES = "INVALIDWORD";
053:
054:            /* Accessible GUI Components */
055:            protected JList suggestList;
056:            protected JTextArea checkText;
057:            /* The current spell check event */
058:            protected SpellCheckEvent spellEvent;
059:            /** The listener list (holds actionlisteners) */
060:            protected EventListenerList listenerList = new EventListenerList();
061:            protected ResourceBundle messages;
062:
063:            /** Panel constructor */
064:            public JSpellForm() {
065:                messages = ResourceBundle.getBundle(
066:                        "com.swabunga.spell.swing.messages", Locale
067:                                .getDefault());
068:                initialiseGUI();
069:            }
070:
071:            /** Helper method to create a JButton with a command, a text label and a listener*/
072:            private static final JButton createButton(String command,
073:                    String text, ActionListener listener) {
074:                JButton btn = new JButton(text);
075:                btn.setActionCommand(command);
076:                btn.addActionListener(listener);
077:                return btn;
078:            }
079:
080:            /** Creates the buttons on the left hand side of the panel*/
081:            protected JPanel makeEastPanel() {
082:                JPanel jPanel1 = new JPanel();
083:                BoxLayout layout = new BoxLayout(jPanel1, BoxLayout.Y_AXIS);
084:                jPanel1.setLayout(layout);
085:
086:                JButton ignoreBtn = createButton(IGNORE_CMD, messages
087:                        .getString(IGNORE_CMD), this );
088:                ignoreBtn.setMaximumSize(new Dimension(Short.MAX_VALUE,
089:                        Short.MAX_VALUE));
090:                jPanel1.add(ignoreBtn);
091:
092:                JButton ignoreAllBtn = createButton(IGNOREALL_CMD, messages
093:                        .getString(IGNOREALL_CMD), this );
094:                ignoreAllBtn.setMaximumSize(new Dimension(Short.MAX_VALUE,
095:                        Short.MAX_VALUE));
096:                jPanel1.add(ignoreAllBtn);
097:
098:                JButton addBtn = createButton(ADD_CMD, messages
099:                        .getString(ADD_CMD), this );
100:                addBtn.setMaximumSize(new Dimension(Short.MAX_VALUE,
101:                        Short.MAX_VALUE));
102:                jPanel1.add(addBtn);
103:
104:                JButton changeBtn = createButton(REPLACE_CMD, messages
105:                        .getString(REPLACE_CMD), this );
106:                changeBtn.setMaximumSize(new Dimension(Short.MAX_VALUE,
107:                        Short.MAX_VALUE));
108:                jPanel1.add(changeBtn);
109:
110:                JButton changeAllBtn = createButton(REPLACEALL_CMD, messages
111:                        .getString(REPLACEALL_CMD), this );
112:                changeAllBtn.setMaximumSize(new Dimension(Short.MAX_VALUE,
113:                        Short.MAX_VALUE));
114:                jPanel1.add(changeAllBtn);
115:
116:                JButton cancelBtn = createButton(CANCEL_CMD, messages
117:                        .getString(CANCEL_CMD), this );
118:                cancelBtn.setMaximumSize(new Dimension(Short.MAX_VALUE,
119:                        Short.MAX_VALUE));
120:                jPanel1.add(cancelBtn);
121:
122:                return jPanel1;
123:            }
124:
125:            protected JPanel makeCentrePanel() {
126:                JPanel jPanel2 = new JPanel();
127:                jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.Y_AXIS));
128:                JLabel lbl1 = new JLabel(messages.getString(INVALIDWORD_RES));
129:                jPanel2.add(lbl1);
130:                checkText = new JTextArea();
131:                jPanel2.add(new JScrollPane(checkText));
132:                JLabel lbl2 = new JLabel(messages.getString(SUGGESTIONS_RES));
133:                jPanel2.add(lbl2);
134:                suggestList = new JList();
135:                suggestList
136:                        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
137:                jPanel2.add(new JScrollPane(suggestList));
138:                suggestList.addListSelectionListener(this );
139:                return jPanel2;
140:            }
141:
142:            /** Called by the constructor to initialise the GUI*/
143:            protected void initialiseGUI() {
144:                setLayout(new BorderLayout());
145:                this .add(makeEastPanel(), BorderLayout.EAST);
146:                this .add(makeCentrePanel(), BorderLayout.CENTER);
147:            }
148:
149:            /** Register an action listener */
150:            public void addActionListener(ActionListener l) {
151:                listenerList.add(ActionListener.class, l);
152:            }
153:
154:            /** Deregister an action listener*/
155:            public void removeActionListener(ActionListener l) {
156:                listenerList.remove(ActionListener.class, l);
157:            }
158:
159:            protected void fireActionEvent(ActionEvent e) {
160:                // Guaranteed to return a non-null array
161:                Object[] listeners = listenerList.getListenerList();
162:                // Process the listeners last to first, notifying
163:                // those that are interested in this event
164:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
165:                    if (listeners[i] == ActionListener.class) {
166:                        ((ActionListener) listeners[i + 1]).actionPerformed(e);
167:                    }
168:                }
169:            }
170:
171:            /** Sets the current spell check event that is being shown to the user*/
172:            public void setSpellEvent(SpellCheckEvent event) {
173:                spellEvent = event;
174:                DefaultListModel m = new DefaultListModel();
175:                java.util.List suggestions = event.getSuggestions();
176:                for (int i = 0; i < suggestions.size(); i++) {
177:                    m.addElement(suggestions.get(i));
178:                }
179:                suggestList.setModel(m);
180:                if (m.size() > 0) {
181:                    suggestList.setSelectedIndex(0);
182:                    checkText.setText(((Word) m.get(0)).getWord());
183:                } else {
184:                    checkText.setText(event.getInvalidWord());
185:                }
186:            }
187:
188:            /** Fired when a value in the list is selected*/
189:            public void valueChanged(ListSelectionEvent e) {
190:                if (!e.getValueIsAdjusting()) {
191:                    Object selectedValue = suggestList.getSelectedValue();
192:                    if (selectedValue != null)
193:                        checkText.setText(selectedValue.toString());
194:                }
195:            }
196:
197:            /** Fired when a button is selected */
198:            public void actionPerformed(ActionEvent e) {
199:                if (IGNORE_CMD.equals(e.getActionCommand())) {
200:                    spellEvent.ignoreWord(false);
201:                } else if (IGNOREALL_CMD.equals(e.getActionCommand())) {
202:                    spellEvent.ignoreWord(true);
203:                } else if (REPLACE_CMD.equals(e.getActionCommand())) {
204:                    spellEvent.replaceWord(checkText.getText(), false);
205:                } else if (REPLACEALL_CMD.equals(e.getActionCommand())) {
206:                    spellEvent.replaceWord(checkText.getText(), true);
207:                } else if (ADD_CMD.equals(e.getActionCommand())) {
208:                    spellEvent.addToDictionary(checkText.getText());
209:                } else if (CANCEL_CMD.equals(e.getActionCommand())) {
210:                    spellEvent.cancel();
211:                }
212:                fireActionEvent(e);
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.