You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2014/04/25 07:27:08 UTC

[03/18] Squiggly spell checker donation from Adobe Systems Inc.

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/a52655ac/Squiggly/main/AdobeSpellingUITLF/src/com/adobe/linguistics/spelling/SquigglyCustomContainerController.as
----------------------------------------------------------------------
diff --git a/Squiggly/main/AdobeSpellingUITLF/src/com/adobe/linguistics/spelling/SquigglyCustomContainerController.as b/Squiggly/main/AdobeSpellingUITLF/src/com/adobe/linguistics/spelling/SquigglyCustomContainerController.as
new file mode 100644
index 0000000..9ea0f9a
--- /dev/null
+++ b/Squiggly/main/AdobeSpellingUITLF/src/com/adobe/linguistics/spelling/SquigglyCustomContainerController.as
@@ -0,0 +1,258 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You 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 com.adobe.linguistics.spelling
+{
+	import com.adobe.linguistics.spelling.SpellUIForTLF;
+	import com.adobe.linguistics.spelling.framework.SpellingService;
+	import com.adobe.linguistics.spelling.ui.IHighlighter;
+	import com.adobe.linguistics.spelling.ui.IWordProcessor;
+	import com.adobe.linguistics.spelling.ui.TLFHighlighter;
+	import com.adobe.linguistics.spelling.ui.TLFWordProcessor;
+	import com.adobe.linguistics.utils.TextTokenizer;
+	import com.adobe.linguistics.utils.Token;
+	
+	import flash.display.Sprite;
+	import flash.events.ContextMenuEvent;
+	import flash.events.Event;
+	import flash.events.EventDispatcher;
+	import flash.geom.Point;
+	import flash.geom.Rectangle;
+	import flash.ui.ContextMenu;
+	import flash.ui.ContextMenuItem;
+	
+	import flashx.textLayout.compose.StandardFlowComposer;
+	import flashx.textLayout.compose.TextFlowLine;
+	import flashx.textLayout.container.ContainerController;
+	import flashx.textLayout.conversion.TextConverter;
+	import flashx.textLayout.edit.SelectionManager;
+	import flashx.textLayout.elements.FlowLeafElement;
+	import flashx.textLayout.elements.ParagraphElement;
+	import flashx.textLayout.elements.TextFlow;
+	import flashx.textLayout.events.CompositionCompleteEvent;
+	import flashx.textLayout.events.StatusChangeEvent;
+	import flashx.textLayout.tlf_internal;
+	
+	/** Custom container controller for populating context menu and hanlding menu item selection  */
+	internal class SquigglyCustomContainerController extends ContainerController
+	{
+		private var disableMenuItem:ContextMenuItem = new ContextMenuItem("Disable spell checking",true);
+		private var enableMenuItem:ContextMenuItem = new ContextMenuItem("Enable spell checking");		
+		
+		private var controlMenuItemList:Array = new Array();
+		private var suggestionMenuItemList:Array = new Array();
+		private var _spellingEnabled:Boolean;
+		private var _contextMenu:ContextMenu;
+		private var mTextHighlighter:IHighlighter;
+		private var mWordProcessor:IWordProcessor;
+		private var mSpellEngine:SpellingService;
+		private var mTextFlow:TextFlow;
+		private var _ignoreWordFunctionProcessor:Function;
+		private var _misspelledToken:Token;
+		private var _misspelled:String;
+		
+		public function SquigglyCustomContainerController(container:Sprite,textHighlighter:IHighlighter, wordProcessor:IWordProcessor, engine:SpellingService,
+														  func:Function, compositionWidth:Number=100,compositionHeight:Number=100)
+		{
+			super (container, compositionWidth, compositionHeight);
+			mTextHighlighter = textHighlighter;
+			mWordProcessor = wordProcessor;
+			mSpellEngine = engine;
+			_ignoreWordFunctionProcessor = func;
+			
+			spellingEnabled = true;
+		}
+		
+		/** Overridden to add custom items to the context menu */
+		override protected function createContextMenu():ContextMenu
+		{
+			// Get the default context menu used by TLF for editable flows
+			_contextMenu = super.container.contextMenu;
+			if (_contextMenu == null)
+				_contextMenu = super.createContextMenu();
+				
+			
+			enableMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleEnableSpellCheck);
+			disableMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleDisableSpellCheck);
+			controlMenuItemList.push(enableMenuItem);
+			controlMenuItemList.push(disableMenuItem);
+			
+			_contextMenu.customItems.push(disableMenuItem);
+			_contextMenu.customItems.push(enableMenuItem);
+			
+			// Listen for menu selection
+			_contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, updateCustomMenuItems);
+			
+			return _contextMenu;
+		}
+		
+		/** Update the state of the custom menu items before the context menu is displayed */
+		private function updateCustomMenuItems(event:ContextMenuEvent):void 
+		{
+			/* Clear the context menu */
+			//spellingEnabled= mTextHighlighter.spellingEnabled;
+			//SpellUI.doSpelling1();
+			var removedNum:int = 0;
+			var count:uint = _contextMenu.customItems.length;
+			for (var j:uint=count; j>0; j--) {
+				if ( isWordItem(_contextMenu.customItems[j-1]) ) {
+					_contextMenu.customItems.splice(j-1,1);
+					removedNum++
+				}
+			}
+			if ( removedNum != suggestionMenuItemList.length ) {
+				trace("internal error");
+			}
+			
+			
+			suggestionMenuItemList = new Array();
+			
+			// localized entries
+			var entries:Object = SpellUIForTLF.getSpellingMenuEntries();
+			disableMenuItem.caption = entries.disable;
+			enableMenuItem.caption = entries.enable;				
+			
+			if (spellingEnabled == true) {
+				(mWordProcessor as TLFWordProcessor).textFlowContainerController = this;
+				
+				//trace("stageX " +  super.container.stage.mouseX);
+				//trace("stageY " +  super.container.stage.mouseY);
+				//trace("mouseX " +  super.container.mouseX);
+				//trace("mouseY " +  super.container.mouseY);
+				_misspelledToken = mWordProcessor.getWordAtPoint(this.container.mouseX, this.container.mouseY);
+				if (_misspelledToken==null) return;
+				var currentLeaf:FlowLeafElement = this.textFlow.findLeaf(_misspelledToken.first);
+				var currentParagraph:ParagraphElement = currentLeaf ? currentLeaf.getParagraph() : null;
+				_misspelled = 	currentParagraph.getText().substring(_misspelledToken.first - currentParagraph.getAbsoluteStart(), 
+																		_misspelledToken.last - currentParagraph.getAbsoluteStart());
+				if ((_misspelled==null) || (_misspelled == "")) return;
+				
+				if (mSpellEngine.checkWord(_misspelled)==true) return;				
+				
+				var suseAddToItem:ContextMenuItem = new ContextMenuItem(entries.add);
+				suseAddToItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleAddToItemSelect);
+				suggestionMenuItemList.push(suseAddToItem);
+				_contextMenu.customItems.splice(0,0,suseAddToItem);	
+				//var result:Array = mWordProcessor.getSuggestionsAtPoint();
+				var resultVector:Vector.<String> = mSpellEngine.getSuggestions(_misspelled);
+				var result:Array = new Array();
+				if (resultVector) {
+					for each (var w:String in resultVector)
+					result.push(w);
+				}
+				if (result!=null) {
+					for (var i:int=result.length-1;i>=0;i-- ) {
+						var suseMenuItem:ContextMenuItem = new ContextMenuItem(result[i]);
+						suseMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleSuseItemSelect);
+						suggestionMenuItemList.push(suseMenuItem);
+						//_contextMenu.customItems.push(suseMenuItem);
+						_contextMenu.customItems.splice(0,0,suseMenuItem);
+					}
+				}
+			}
+		}
+		
+		private function handleAddToItemSelect(event:ContextMenuEvent):void
+		{
+			if ( _ignoreWordFunctionProcessor == null ) return;
+			
+			/*
+			var menuEntry:String = (event.currentTarget as ContextMenuItem).caption;
+			var start:uint = 5;
+			var end:uint = menuEntry.length - 15;
+			var word:String = menuEntry.substring(start, end);
+			*/
+			_ignoreWordFunctionProcessor(_misspelled);
+			SpellUIForTLF.UITable[SpellUIForTLF.parentComp[super.textFlow]].doSpellingJob();
+		}
+		
+		private function handleSuseItemSelect(event:ContextMenuEvent):void
+		{
+			mWordProcessor.replaceText(_misspelledToken, (event.currentTarget as ContextMenuItem).caption );
+			SpellUIForTLF.UITable[SpellUIForTLF.parentComp[super.textFlow]].doSpellingJob();
+		}
+			
+		private function set spellingEnabled(value:Boolean) :void {
+			_spellingEnabled = value;
+			disableMenuItem.visible=spellingEnabled;
+			enableMenuItem.visible=!spellingEnabled;
+		}
+		private function get spellingEnabled():Boolean {
+			return this._spellingEnabled;
+		}
+		
+		private function isWordItem(item:ContextMenuItem):Boolean {
+			
+			for ( var i:int=0; i<suggestionMenuItemList.length; ++i ) {
+				if ( suggestionMenuItemList[i] == item ) return true;
+			}
+			return false;
+		}
+		
+		private function isControlItem(item:ContextMenuItem):Boolean {
+			for (var i:int=0; i<controlMenuItemList.length; ++i) {
+				if ( controlMenuItemList[i] == item) return true;
+			}
+			return false;
+		}
+		
+		private function handleEnableSpellCheck(event:ContextMenuEvent):void
+		{
+			spellingEnabled= true;
+			//mTextHighlighter.spellingEnabled= spellingEnabled;
+			//SpellUI.doSpellingJob();
+			//dispatchEvent(new Event(Event.RENDER));
+			
+			SpellUIForTLF.UITable[SpellUIForTLF.parentComp[this.textFlow]].spellingEnabled = spellingEnabled;
+			SpellUIForTLF.UITable[SpellUIForTLF.parentComp[this.textFlow]].doSpellingJob();
+			//spellCheckRange(getValidFirstWordIndex(), getValidLastWordIndex());
+		}
+		private function handleDisableSpellCheck(event:ContextMenuEvent):void
+		{
+			spellingEnabled= false;
+			SpellUIForTLF.UITable[SpellUIForTLF.parentComp[this.textFlow]].spellingEnabled = spellingEnabled;
+			mTextHighlighter.clearSquiggles();
+		}
+		
+		public function cleanUpContextMenu():void
+		{
+			mTextHighlighter=null;
+			mWordProcessor=null;
+			spellingEnabled = false;
+			_ignoreWordFunctionProcessor=null;
+			
+			_contextMenu.removeEventListener(ContextMenuEvent.MENU_SELECT, updateCustomMenuItems);
+			
+			var removedNum:int = 0;
+			var count:uint = _contextMenu.customItems.length;
+			for (var j:uint=count; j>0; j--) {
+				if ( isWordItem(_contextMenu.customItems[j-1]) || isControlItem(_contextMenu.customItems[j-1]) ) {
+					_contextMenu.customItems.splice(j-1,1);
+					removedNum++
+				}
+			}
+			if ( removedNum != suggestionMenuItemList.length + controlMenuItemList.length ) {
+				trace("internal error");
+			}
+			
+			suggestionMenuItemList = null;
+			controlMenuItemList = null;
+		}
+		
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/a52655ac/Squiggly/main/Automation/asdocgen.bat
----------------------------------------------------------------------
diff --git a/Squiggly/main/Automation/asdocgen.bat b/Squiggly/main/Automation/asdocgen.bat
new file mode 100644
index 0000000..c9f3925
--- /dev/null
+++ b/Squiggly/main/Automation/asdocgen.bat
@@ -0,0 +1,18 @@
+@echo off
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements.  See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License.  You may obtain a copy of the License at
+rem
+rem     http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+
+REM This generates the ASDoc for Engine and SInC. Modify the path as you need.
+"C:\flexsdk4.1\bin\asdoc" -source-path ..\AdobeSpellingUI\src ..\AdobeSpellingUITLF\src ..\AdobeSpellingEngine\src ..\AdobeLinguisticUtils\src ..\AdobeSpellingFramework\src -doc-classes com.adobe.linguistics.spelling.SpellUI com.adobe.linguistics.spelling.SpellUIForTLF com.adobe.linguistics.spelling.HunspellDictionary com.adobe.linguistics.spelling.SpellChecker com.adobe.linguistics.spelling.UserDictionary com.adobe.linguistics.utils.TextTokenizer com.adobe.linguistics.utils.Token com.adobe.linguistics.spelling.framework.ResourceTable com.adobe.linguistics.spelling.framework.SpellingConfiguration com.adobe.linguistics.spelling.framework.SpellingService com.adobe.linguistics.spelling.ui.IHighlighter com.adobe.linguistics.spelling.ui.HaloHighlighter com.adobe.linguistics.spelling.ui.SparkHighlighter com.adobe.linguistics.spelling.ui.TLFHighlighter -library-path ..\AdobeSpellingEngine\bin  ..\AdobeLinguisticUtils\bin ..\AdobeSpellingUI\bin ..\AdobeSpellingUITLF\bin "C:\flexsdk4.1\frame
 works\libs" -exclude-dependencies=true -examples-path "..\ASDocExamples" -output Release\SquigglyDoc -main-title "Squiggly API Documentation 0.5" -package com.adobe.linguistics.spelling "This package providing spell checking functionality to your action script applications. This includes the core spell checking engine and the optional SpellUI class for easy integration with your existing Flex projects." -package com.adobe.linguistics.spelling.ui "This package provides text highlighting related functionalities" -package com.adobe.linguistics.spelling.framework "This package provides spelling service and spelling configuration related functionalities" -package com.adobe.linguistics.utils "This package provides text parsing and tokenizing related classes"

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/a52655ac/Squiggly/main/Automation/copydictsandlibs.bat
----------------------------------------------------------------------
diff --git a/Squiggly/main/Automation/copydictsandlibs.bat b/Squiggly/main/Automation/copydictsandlibs.bat
new file mode 100644
index 0000000..7b55846
--- /dev/null
+++ b/Squiggly/main/Automation/copydictsandlibs.bat
@@ -0,0 +1,35 @@
+@echo off
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements.  See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License.  You may obtain a copy of the License at
+rem
+rem     http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+
+REM This copies dictionaries and libs to Release folder, do this after you build them in Flex builder 3/4
+mkdir Release
+mkdir Release\SquigglySDK
+mkdir Release\SquigglySDK\libs
+mkdir Release\SquigglySDK\src
+mkdir Release\SquigglySDK\src\dictionaries
+mkdir Release\SquigglySDK\src\dictionaries\en_US
+copy ..\AdobeSpellingEngine\bin\AdobeSpellingEngine.swc .\Release\SquigglySDK\libs
+copy ..\AdobeSpellingUI\bin\AdobeSpellingUI.swc .\Release\SquigglySDK\libs
+copy ..\AdobeSpellingUIEx\bin\AdobeSpellingUIEx.swc .\Release\SquigglySDK\libs
+copy ..\AdobeSpellingUITLF\bin\AdobeSpellingUITLF.swc .\Release\SquigglySDK\libs
+copy ..\AdobeSpellingFramework\bin\AdobeSpellingFramework.swc .\Release\SquigglySDK\libs
+copy ..\AdobeLinguisticUtils\bin\AdobeLinguisticUtils.swc .\Release\SquigglySDK\libs
+copy ..\..\releases\0.3\Dictionary\en_US.* .\Release\SquigglySDK\src\dictionaries\en_US
+copy ..\..\releases\0.3\Dictionary\*.txt .\Release\SquigglySDK\src\dictionaries\en_US
+copy ..\*.pdf .\Release\SquigglySDK\src\dictionaries\en_US
+copy ..\*.txt .\Release\SquigglySDK
+copy ..\..\releases\0.3\Dictionary\*.xml .\Release\SquigglySDK\src
+

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/a52655ac/Squiggly/main/Automation/examplegen.py
----------------------------------------------------------------------
diff --git a/Squiggly/main/Automation/examplegen.py b/Squiggly/main/Automation/examplegen.py
new file mode 100644
index 0000000..0f9878a
--- /dev/null
+++ b/Squiggly/main/Automation/examplegen.py
@@ -0,0 +1,75 @@
+import shutil, os, stat, re, errno
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+
+# Source and destination paths
+asdocExamplePath = "../ASDocExamples/com/adobe/linguistics/spelling/Examples"
+packageExamplePath = "./Release/SquigglySDK/Examples"
+
+# Go over all mxml files and modify them
+def modifyAll():
+    for root, dirs, files in os.walk(packageExamplePath):
+        for filename in files:
+            if '.mxml' in filename:
+                modifyMxml(os.path.join(root, filename))
+                
+# Modify one mxml file by removing all asdoc comments
+def modifyMxml(filename):
+    print filename + "....."
+    code = file(filename, 'r').read()
+    code = removeComment(code)
+    if (not os.stat(filename)[0] & stat.S_IWRITE):
+        os.chmod(filename, stat.S_IWRITE)
+    file(filename, 'w').write(code)
+
+# Remove asdoc comment, we don't remove // comment
+def removeComment(text):
+    def replacer(match):
+        s = match.group(0)
+        if s.startswith('/'):
+            return ""
+        else:
+            return s
+    pattern = re.compile(
+        r'/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
+        re.DOTALL | re.MULTILINE
+    )
+    return re.sub(pattern, replacer, text)
+
+# Remove a readonly file, required by windows
+def removeReadonly(func, path, exc):
+  excvalue = exc[1]
+  if func in (os.rmdir, os.remove) and excvalue.errno == errno.EACCES:
+      os.chmod(path, stat.S_IWRITE)
+      func(path)
+  else:
+      raise
+
+# Main function
+def main():
+    print "Removing the asdoc comments from mxml source code"
+    if os.path.isdir(packageExamplePath):
+        shutil.rmtree(packageExamplePath, onerror=removeReadonly)
+    shutil.copytree(asdocExamplePath, packageExamplePath)
+    modifyAll()
+    print "Done! Check " + packageExamplePath + " for example code."
+
+if __name__ == '__main__':
+    main()
+        
+    
+

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/a52655ac/Squiggly/main/Automation/prepareReleasePackage.bat
----------------------------------------------------------------------
diff --git a/Squiggly/main/Automation/prepareReleasePackage.bat b/Squiggly/main/Automation/prepareReleasePackage.bat
new file mode 100644
index 0000000..0cc9174
--- /dev/null
+++ b/Squiggly/main/Automation/prepareReleasePackage.bat
@@ -0,0 +1,20 @@
+@echo off
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements.  See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License.  You may obtain a copy of the License at
+rem
+rem     http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+
+REM This prepare the Release folder, do this after you build them in Flex builder 3/4
+call copydictsandlibs.bat
+python examplegen.py
+call asdocgen.bat

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/a52655ac/Squiggly/main/Data/genTextWordlist.sh
----------------------------------------------------------------------
diff --git a/Squiggly/main/Data/genTextWordlist.sh b/Squiggly/main/Data/genTextWordlist.sh
new file mode 100644
index 0000000..d4e31e5
--- /dev/null
+++ b/Squiggly/main/Data/genTextWordlist.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+
+
+
+
+# Author (U)  Zhigang Qi (zhigang.qi@gmail.com) XieFang (xfang@adobe.com)
+# Created  02/26/2010
+
+
+# Put your selected word lists in squigglyWordlist folder, then run this #
+
+
+cat squigglyWordlist/* | sort > usatemp.txt
+uniq usatemp.txt usa.txt
+rm -f usatemp.txt