You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2006/10/30 07:58:11 UTC
svn commit: r469081 - in
/webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck: ./
src/ src/spellcheck/ src/spellcheck/text_editor/
Author: sanka
Date: Sun Oct 29 22:58:10 2006
New Revision: 469081
URL: http://svn.apache.org/viewvc?view=rev&rev=469081
Log:
Added the new code for this sample
Added:
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/build.xml
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/AsyncPanel.java
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/FormModel.java
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/Observer.java
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SimplifiedSpellCheckCallbackHandlerImpl.java
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SuggestionForm.java
webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SyncPanel.java
Added: webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/build.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/build.xml?view=auto&rev=469081
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/build.xml (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/build.xml Sun Oct 29 22:58:10 2006
@@ -0,0 +1,61 @@
+<project basedir="." default="run.text_editor">
+
+ <property environment="env" />
+
+ <property name="wsdl.file" value="http://tools.wso2.net:12001/axis2/services/SimplifiedSpellCheck?wsdl" />
+
+ <property name="dest.dir" value="target" />
+
+ <property name="dest.dir.classes" value="${dest.dir}/classes" />
+
+ <property name="dest.dir.lib" value="${dest.dir}/lib" />
+
+ <path id="runtime.class.path">
+ <fileset dir="${env.AXIS2_HOME}/lib">
+ <include name="*.jar" />
+ </fileset>
+ <fileset dir="${dest.dir.lib}" includes="*.jar" />
+ </path>
+
+ <path id="build.class.path">
+ <fileset dir="${env.AXIS2_HOME}/lib">
+ <include name="*.jar" />
+ </fileset>
+ </path>
+
+ <target name="clean">
+ <delete dir="${dest.dir}" />
+ <delete dir="src/spellcheck_stub" />
+ </target>
+
+ <target name="build.text_editor" depends="clean">
+
+ <mkdir dir="${dest.dir}" />
+ <mkdir dir="${dest.dir.classes}" />
+ <mkdir dir="${dest.dir.lib}" />
+
+ <java classname="org.apache.axis2.wsdl.WSDL2Java">
+ <arg value="-uri" />
+ <arg value="${wsdl.file}" />
+ <arg value="-p" />
+ <arg value="spellcheck_stub" />
+ <arg value="-o" />
+ <arg value="src" />
+ <arg value="-f"/>
+ <classpath refid="build.class.path" />
+ </java>
+
+ <javac srcdir="src" destdir="${dest.dir.classes}">
+ <classpath refid="build.class.path" />
+ </javac>
+
+ <jar basedir="${dest.dir.classes}" destfile="${dest.dir.lib}/text_editor.jar" />
+ </target>
+
+ <target name="run.text_editor" depends="build.text_editor">
+ <java classname="spellcheck.text_editor.SuggestionForm" fork="true">
+ <classpath refid="runtime.class.path" />
+ </java>
+ </target>
+
+</project>
\ No newline at end of file
Added: webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/AsyncPanel.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/AsyncPanel.java?view=auto&rev=469081
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/AsyncPanel.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/AsyncPanel.java Sun Oct 29 22:58:10 2006
@@ -0,0 +1,110 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package spellcheck.text_editor;
+
+import java.awt.Color;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+/**
+ * class sample.google.spellcheck.AsyncPanel
+ * This Impements its own GUI of the Asynchronous Client and it updates the string after getting the response to textarea
+ */
+public class AsyncPanel extends javax.swing.JPanel implements Observer,
+ KeyListener {
+ FormModel formModel;
+ JTextArea writingTextArea;
+ JTextArea displayTextArea;
+ JTextField errorMessageField;
+
+ public AsyncPanel() {
+ GridBagLayout gbLayout = new GridBagLayout();
+ GridBagConstraints constraint = new GridBagConstraints();
+ this.setLayout(gbLayout);
+
+ formModel = new FormModel(this);
+
+ writingTextArea = new JTextArea();
+ writingTextArea.setLineWrap(true);
+
+ displayTextArea = new JTextArea();
+ displayTextArea.setEditable(false);
+ displayTextArea.setLineWrap(true);
+
+ errorMessageField = new JTextField();
+ errorMessageField.setEditable(false);
+ errorMessageField.setBackground(Color.LIGHT_GRAY);
+ errorMessageField.setForeground(Color.RED);
+
+ JScrollPane scrollPaneGet = new JScrollPane(writingTextArea);
+ JScrollPane scrollPaneSet = new JScrollPane(displayTextArea);
+
+ writingTextArea.setText("Enter a String");
+ writingTextArea.addKeyListener(this);
+
+ constraint.fill = GridBagConstraints.BOTH;
+ constraint.gridx = 0;
+ constraint.weightx = 1;
+ constraint.weighty = 8;
+ gbLayout.setConstraints(scrollPaneGet, constraint);
+ this.add(scrollPaneGet);
+ gbLayout.setConstraints(scrollPaneSet, constraint);
+ this.add(scrollPaneSet);
+ constraint.weighty = 1;
+ gbLayout.setConstraints(errorMessageField, constraint);
+ this.add(errorMessageField);
+
+
+ }
+
+ public void update(String message) {
+ displayTextArea.setText(displayTextArea.getText() + " " + message);
+ }
+
+ //updates the error message to the error message display area
+ public void updateError(String message) {
+ errorMessageField.setText(message);
+ }
+
+
+ public void keyPressed(KeyEvent e) {
+ int key = e.getKeyChar();
+ if ((key == KeyEvent.VK_SPACE) || (key == KeyEvent.VK_ENTER)) {
+ String[] words = writingTextArea.getText().split("\\s");
+ if (words.length > 0)
+ formModel.doAsyncSpellingSuggestion(words[words.length - 1]);
+ }
+ }
+
+ public void keyReleased(KeyEvent e) {
+ }
+
+ public void keyTyped(KeyEvent e) {
+ }
+
+ public void clear() {
+ displayTextArea.setText("");
+ writingTextArea.setText("");
+ errorMessageField.setText("");
+ }
+}
Added: webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/FormModel.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/FormModel.java?view=auto&rev=469081
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/FormModel.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/FormModel.java Sun Oct 29 22:58:10 2006
@@ -0,0 +1,76 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package spellcheck.text_editor;
+
+
+import spellcheck_stub.SimplifiedSpellCheckStub;
+import spellcheck_stub.SimplifiedSpellCheckStub.DoSpellingSuggestions;
+import spellcheck_stub.SimplifiedSpellCheckStub.DoSpellingSuggestionsResponse;
+
+/**
+ * class sample.google.spellcheck.FormModel
+ * This is the Impementation of the Asynchronous Client
+ */
+public class FormModel {
+ Observer observer;
+
+ public FormModel(Observer observer) {
+ this.observer = observer;
+ }
+
+ public void doAsyncSpellingSuggestion(String word) {
+
+ try {
+
+ SimplifiedSpellCheckStub stub = new SimplifiedSpellCheckStub();
+
+ DoSpellingSuggestions doSpellingSuggestions = new DoSpellingSuggestions();
+ doSpellingSuggestions.setPhrase(word);
+
+ SimplifiedSpellCheckCallbackHandlerImpl callbackHandlerImpl = new SimplifiedSpellCheckCallbackHandlerImpl(observer, word);
+
+ stub.startdoSpellingSuggestions(doSpellingSuggestions, callbackHandlerImpl);
+
+ } catch (Exception ex) {
+ observer.updateError(ex.getMessage());
+ }
+ }
+
+ public void doSyncSpellingSuggestion(String word) {
+
+ try {
+ SimplifiedSpellCheckStub stub = new SimplifiedSpellCheckStub();
+
+ DoSpellingSuggestions suggestions = new DoSpellingSuggestions();
+ suggestions.setPhrase(word);
+
+ DoSpellingSuggestionsResponse response = stub.doSpellingSuggestions(suggestions);
+ String suggestion = response.get_return();
+
+ if (suggestion == null) {
+ observer.update("No suggestions found for " + word);
+
+ } else {
+ observer.update(suggestion);
+ }
+
+ } catch (Exception ex) {
+ observer.updateError(ex.getMessage());
+ }
+ }
+
+}
Added: webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/Observer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/Observer.java?view=auto&rev=469081
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/Observer.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/Observer.java Sun Oct 29 22:58:10 2006
@@ -0,0 +1,31 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package spellcheck.text_editor;
+
+
+/**
+ * interface sample.google.spellcheck.Observer
+ */
+public interface Observer {
+ // updates the message to the main test display area
+ public void update(String message);
+
+ //updates the error message to the error message display area
+ public void updateError(String message);
+
+ public void clear();
+}
Added: webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SimplifiedSpellCheckCallbackHandlerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SimplifiedSpellCheckCallbackHandlerImpl.java?view=auto&rev=469081
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SimplifiedSpellCheckCallbackHandlerImpl.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SimplifiedSpellCheckCallbackHandlerImpl.java Sun Oct 29 22:58:10 2006
@@ -0,0 +1,53 @@
+package spellcheck.text_editor;
+
+import spellcheck_stub.SimplifiedSpellCheckCallbackHandler;
+import spellcheck_stub.SimplifiedSpellCheckStub.DoSpellingSuggestionsResponse;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class SimplifiedSpellCheckCallbackHandlerImpl extends SimplifiedSpellCheckCallbackHandler {
+
+ private Observer observer = null;
+ private String phrase = null;
+
+ public SimplifiedSpellCheckCallbackHandlerImpl(Observer observer, String phrase) {
+ this.observer = observer;
+ this.phrase = phrase;
+ }
+
+ public void receiveResultdoSpellingSuggestions(DoSpellingSuggestionsResponse param1) {
+ String suggestion = param1.get_return();
+
+ if (suggestion == null) {
+ observer.update(phrase);
+ observer.updateError(
+ "No suggestions found for " + phrase);
+ } else {
+ observer.update(suggestion);
+ }
+ }
+
+ public void receiveErrordoSpellingSuggestions(Exception e) {
+ e.printStackTrace();
+ observer.updateError(e.getMessage());
+ }
+
+
+
+
+}
+
Added: webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SuggestionForm.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SuggestionForm.java?view=auto&rev=469081
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SuggestionForm.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SuggestionForm.java Sun Oct 29 22:58:10 2006
@@ -0,0 +1,205 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package spellcheck.text_editor;
+
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.awt.HeadlessException;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.io.File;
+import java.io.IOException;
+
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JScrollPane;
+import javax.swing.KeyStroke;
+import javax.swing.WindowConstants;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
+
+/**
+ * class sample.google.spellcheck.SuggestionForm
+ * This is the implementation of the GUI
+ */
+public class SuggestionForm extends javax.swing.JFrame implements HyperlinkListener {
+ private AsyncPanel asyncPanel;
+ private SyncPanel syncPanel;
+ private JEditorPane helpDisplayPane;
+
+ private JMenuItem syncMenuItem;
+ private JMenuItem asyncMenuItem;
+ private static final String HELP_FILE_NAME = "/docs/GoogleSpellCheck.html";
+
+
+ public SuggestionForm() throws HeadlessException {
+ asyncPanel = new AsyncPanel();
+ syncPanel = new SyncPanel();
+
+ JMenuBar menuBar;
+ //Create the menu bar.
+ menuBar = new JMenuBar();
+
+ JMenu modeMenu = new JMenu("Mode");
+ modeMenu.setMnemonic(KeyEvent.VK_M);
+ syncMenuItem = new JMenuItem("Sync Mode", KeyEvent.VK_S);
+ syncMenuItem.setAccelerator(
+ KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
+ syncMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ setSyncPanel();
+ }
+ });
+ asyncMenuItem = new JMenuItem("ASync Mode", KeyEvent.VK_A);
+ asyncMenuItem.setAccelerator(
+ KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
+ asyncMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ setAsyncPanel();
+ }
+ });
+ modeMenu.add(syncMenuItem);
+ modeMenu.add(asyncMenuItem);
+
+ JMenu clearMenu = new JMenu("Clear");
+ clearMenu.setMnemonic(KeyEvent.VK_C);
+ JMenuItem clearMenuItem = new JMenuItem("Clear text boxes");
+ clearMenuItem.setAccelerator(
+ KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
+ clearMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ asyncPanel.clear();
+ syncPanel.clear();
+ }
+ });
+ clearMenu.add(clearMenuItem);
+
+ JMenu helpMenu = new JMenu("Help");
+ JMenuItem mnuItemHelp = new JMenuItem("Show Help");
+ helpMenu.add(mnuItemHelp);
+
+ mnuItemHelp.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ showHelp();
+ }
+ });
+
+ menuBar.add(modeMenu);
+ menuBar.add(clearMenu);
+ menuBar.add(helpMenu);
+
+ this.setJMenuBar(menuBar);
+
+ this.getContentPane().setLayout(new GridLayout(1, 1));
+ setAsyncPanel();
+
+
+ }
+
+ public static void main(String[] args) {
+ SuggestionForm form = new SuggestionForm();
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ form.setLocation(screenSize.width / 4,
+ screenSize.height / 4);
+ form.setSize(screenSize.width / 2, screenSize.height / 2);
+ form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ //form.setResizable(false);
+ //form.pack();
+ form.setVisible(true);
+ }
+
+ private void setAsyncPanel() {
+ this.getContentPane().removeAll();
+ this.getContentPane().add(asyncPanel);
+ this.syncMenuItem.setEnabled(true);
+ this.asyncMenuItem.setEnabled(false);
+ this.getContentPane().repaint();
+ this.setTitle("Google Spell checker - Async Mode");
+ this.setVisible(true);
+
+ }
+
+ private void setSyncPanel() {
+ this.getContentPane().removeAll();
+ this.getContentPane().add(syncPanel);
+ this.syncMenuItem.setEnabled(false);
+ this.asyncMenuItem.setEnabled(true);
+ this.getContentPane().repaint();
+ this.setTitle("Google Spell checker - Sync Mode");
+ this.setVisible(true);
+ }
+
+ /**
+ * method showHelp
+ */
+ private void showHelp() {
+
+ JFrame frame = new JFrame();
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ frame.setLocation(screenSize.width / 5,
+ screenSize.height / 5);
+ frame.setSize(screenSize.width / 2, screenSize.height / 2);
+
+ BorderLayout layout = new BorderLayout();
+
+ JScrollPane jsp;
+
+
+ helpDisplayPane = new JEditorPane();
+ helpDisplayPane.addHyperlinkListener(this);
+ helpDisplayPane.setEditable(false);
+ helpDisplayPane.setContentType("text/html");
+
+ jsp = new JScrollPane(helpDisplayPane);
+
+ Container contentPane = frame.getContentPane();
+ contentPane.setLayout(layout);
+ contentPane.add(jsp, BorderLayout.CENTER);
+ String helpDoc = System.getProperty("user.dir") + HELP_FILE_NAME;
+
+ try {
+ helpDisplayPane.setPage(new File(helpDoc).toURL());
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(this, "Help file not detected", "Help file error",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ frame.setVisible(true);
+ }
+
+
+ public void hyperlinkUpdate(HyperlinkEvent e) {
+ if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+ try {
+ String url = e.getURL().toString();
+ helpDisplayPane.setPage(url);
+ } catch (Exception err) {
+ JOptionPane.showMessageDialog(this, "Help file not detected", err.getMessage(),
+ JOptionPane.ERROR_MESSAGE);
+ }
+
+ }
+ }
+}
Added: webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SyncPanel.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SyncPanel.java?view=auto&rev=469081
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SyncPanel.java (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/googlespellcheck/src/spellcheck/text_editor/SyncPanel.java Sun Oct 29 22:58:10 2006
@@ -0,0 +1,100 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package spellcheck.text_editor;
+
+import javax.swing.*;
+
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * class sample.google.spellcheck.SyncPanel
+ * This Impements its own GUI of the Synchronous Client and it send the SOAP request after the mouse event.
+ */
+public class SyncPanel extends javax.swing.JPanel implements Observer,
+ ActionListener {
+ FormModel formModel;
+ JTextArea writingTextArea;
+ JTextArea displayTextArea;
+ JTextField errorMessageField;
+ JButton sendButton;
+
+ public SyncPanel() {
+ GridBagLayout gbLayout = new GridBagLayout();
+ GridBagConstraints constraint = new GridBagConstraints();
+ this.setLayout(gbLayout);
+
+ formModel = new FormModel(this);
+ writingTextArea = new javax.swing.JTextArea();
+ writingTextArea.setLineWrap(true);
+
+ displayTextArea = new javax.swing.JTextArea();
+ displayTextArea.setLineWrap(true);
+ displayTextArea.setEditable(false);
+
+ errorMessageField = new JTextField();
+ errorMessageField.setEditable(false);
+ errorMessageField.setBackground(Color.LIGHT_GRAY);
+ errorMessageField.setForeground(Color.RED);
+
+ sendButton = new javax.swing.JButton("Send");
+ JScrollPane scrollPaneget = new JScrollPane(writingTextArea);
+ JScrollPane scrollPaneset = new JScrollPane(displayTextArea);
+ writingTextArea.setText("Enter a String");
+
+ constraint.fill = GridBagConstraints.BOTH;
+ constraint.gridx = 0;
+ constraint.weightx = 1;
+ constraint.weighty = 8;
+ gbLayout.setConstraints(scrollPaneget, constraint);
+ this.add(scrollPaneget);
+ gbLayout.setConstraints(scrollPaneset, constraint);
+ this.add(scrollPaneset);
+ constraint.weighty = 1;
+ gbLayout.setConstraints(sendButton, constraint);
+ this.add(sendButton);
+ gbLayout.setConstraints(errorMessageField, constraint);
+ this.add(errorMessageField);
+
+ sendButton.addActionListener(this);
+
+ }
+
+ public void update(String suggestion) {
+ displayTextArea.setText(suggestion);
+ }
+
+ //updates the error message to the error message display area
+ public void updateError(String message) {
+ errorMessageField.setText(message);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ String str = writingTextArea.getText().trim();
+ formModel.doSyncSpellingSuggestion(str);
+ }
+
+ public void clear() {
+ writingTextArea.setText("");
+ displayTextArea.setText("");
+ errorMessageField.setText("");
+ }
+
+}
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org