Author: joern
Date: Fri Oct 21 09:46:06 2011
New Revision: 1187266

URL: http://svn.apache.org/viewvc?rev=1187266&view=rev
Log:
UIMA-2271 Replaced "line length hint" word wrapping with proper word wrapping.

Added:
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java
   (with props)
Modified:
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java

Modified: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java?rev=1187266&r1=1187265&r2=1187266&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationDocument.java
 Fri Oct 21 09:46:06 2011
@@ -40,37 +40,11 @@ class AnnotationDocument extends Documen
 
   private ICasDocument mDocument;
 
-  private int lineLengthHint;
-
-  public AnnotationDocument() {
-    IPreferenceStore prefStore = 
CasEditorPlugin.getDefault().getPreferenceStore();
-    lineLengthHint = 
prefStore.getInt(AnnotationEditorPreferencePage.EDITOR_LINE_LENGTH_HINT);
-    
-    if (lineLengthHint == 0)
-      lineLengthHint = 80;
-  }
-  
-  private String transformText(String text) {
-       if (lineLengthHint != 0 && text != null) {
-           return wrapWords(text, lineLengthHint);
-       } else {
-         if (text != null)
-           return text;
-         else
-           return "";
-       }
-  }
-  
   /**
    * Call is forwarded to the set document.
    *
    * @return the text
    */
-  private String getText() {
-
-    String text = getCAS().getDocumentText();
-    return transformText(text);
-  }  
   /**
    * Notifies listener about a document change.
    */
@@ -80,17 +54,13 @@ class AnnotationDocument extends Documen
     fireDocumentChanged(ev);
   }
   
-//  public void setLineLengthHint(int lineLengthHint) {
-//    this.lineLengthHint = lineLengthHint;
-//  }
-
   /**
    * @param element
    */
   public void setDocument(ICasDocument element) {
     mDocument = element;
 
-    set(getText());
+    set(getCAS().getDocumentText());
   }
 
   public ICasDocument getDocument() {
@@ -262,7 +232,7 @@ class AnnotationDocument extends Documen
          // but without sending out notifications.
          // The stop and resume notification methods do not yield
          // the desired effect
-         String text = 
transformText(getCAS().getView(viewName).getDocumentText());
+         String text = getCAS().getView(viewName).getDocumentText();
          getStore().set(text);
          getTracker().set(text);
          

Modified: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?rev=1187266&r1=1187265&r2=1187266&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
 Fri Oct 21 09:46:06 2011
@@ -630,6 +630,12 @@ public final class AnnotationEditor exte
 
     sourceViewer.addPainter(mPainter);
     
+    // UIMA-2271: Set word wrap based on the preferences
+    IPreferenceStore preferences = 
CasEditorPlugin.getDefault().getPreferenceStore();
+    
+    sourceViewer.getTextWidget().setWordWrap(preferences.getBoolean(
+            
AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_ENABLE_WORD_WRAP));
+    
     return sourceViewer;
   }
 
@@ -740,24 +746,32 @@ public final class AnnotationEditor exte
       
     // Retrieve font size from preference store, default is 15
     IPreferenceStore prefStore = 
CasEditorPlugin.getDefault().getPreferenceStore();
-    int textSize = 
prefStore.getInt(AnnotationEditorPreferencePage.EDITOR_TEXT_SIZE);
+    int textSize = prefStore.getInt(
+            AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_TEXT_SIZE);
+    
+    // TODO: We should use a preference initialize instead ...
     
     if (textSize > 0) {
       setTextSize(textSize);
     }
     
-    preferenceStoreChangeListener = (new IPropertyChangeListener() {
+    preferenceStoreChangeListener = new IPropertyChangeListener() {
       
       public void propertyChange(PropertyChangeEvent event) {
-        if 
(AnnotationEditorPreferencePage.EDITOR_TEXT_SIZE.equals(event.getProperty())) {
+        if (AnnotationEditorPreferenceConstants.
+                ANNOTATION_EDITOR_TEXT_SIZE.equals(event.getProperty())) {
           Integer textSize = (Integer) event.getNewValue();
           
           if (textSize != null && textSize > 0) {
             setTextSize(textSize);
           }
         }
+        else if (AnnotationEditorPreferenceConstants.
+                
ANNOTATION_EDITOR_ENABLE_WORD_WRAP.equals(event.getProperty())) {
+          getSourceViewer().getTextWidget().setWordWrap((Boolean) 
event.getNewValue());
+        }
       }
-    });
+    };
     
     prefStore.addPropertyChangeListener(preferenceStoreChangeListener);
     

Added: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java?rev=1187266&view=auto
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java
 (added)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java
 Fri Oct 21 09:46:06 2011
@@ -0,0 +1,31 @@
+/*
+ * 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 org.apache.uima.caseditor.editor;
+
+import org.apache.uima.caseditor.CasEditorPlugin;
+
+public class AnnotationEditorPreferenceConstants {
+
+  public static final String ANNOTATION_EDITOR_TEXT_SIZE =
+          CasEditorPlugin.ID + ".editor-text-size";
+  
+  public static final String ANNOTATION_EDITOR_ENABLE_WORD_WRAP = 
+          CasEditorPlugin.ID + ".enable-word-wrap";
+}

Propchange: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceConstants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java?rev=1187266&r1=1187265&r2=1187266&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferenceInitializer.java
 Fri Oct 21 09:46:06 2011
@@ -28,7 +28,9 @@ public class AnnotationEditorPreferenceI
 
        public void initializeDefaultPreferences() {
                IPreferenceStore store = 
CasEditorPlugin.getDefault().getPreferenceStore();
-               
store.setDefault(AnnotationEditorPreferencePage.EDITOR_LINE_LENGTH_HINT, 80);
-               
store.setDefault(AnnotationEditorPreferencePage.EDITOR_TEXT_SIZE, 13);
+               store.setDefault(
+                       
AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_ENABLE_WORD_WRAP, true);
+               store.setDefault(
+                       
AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_TEXT_SIZE, 13);
        }
 }

Modified: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java?rev=1187266&r1=1187265&r2=1187266&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditorPreferencePage.java
 Fri Oct 21 09:46:06 2011
@@ -20,6 +20,7 @@
 package org.apache.uima.caseditor.editor;
 
 import org.apache.uima.caseditor.CasEditorPlugin;
+import org.eclipse.jface.preference.BooleanFieldEditor;
 import org.eclipse.jface.preference.FieldEditorPreferencePage;
 import org.eclipse.jface.preference.IntegerFieldEditor;
 import org.eclipse.ui.IWorkbench;
@@ -31,11 +32,6 @@ import org.eclipse.ui.IWorkbenchPreferen
 public class AnnotationEditorPreferencePage extends FieldEditorPreferencePage
         implements IWorkbenchPreferencePage {
 
-  static final String EDITOR_LINE_LENGTH_HINT = "EDITOR_LINE_LENGTH_HINT";
-
-  public static final String EDITOR_TEXT_SIZE = "EDITOR_TEXT_SIZE";
-  
-  private IntegerFieldEditor mEditorLineLengthHint;
   private IntegerFieldEditor mEditorTextSize;
   
   public AnnotationEditorPreferencePage() {
@@ -46,15 +42,15 @@ public class AnnotationEditorPreferenceP
 
   @Override
   protected void createFieldEditors() {
-    // editor line length hint
-    mEditorLineLengthHint = new IntegerFieldEditor(
-            EDITOR_LINE_LENGTH_HINT,
-            "Line Length Hint", getFieldEditorParent());
+    // editor word wrap
+    BooleanFieldEditor mEditorLineLengthHint = new BooleanFieldEditor(
+            
AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_ENABLE_WORD_WRAP,
+            "Enable Word Wrap", getFieldEditorParent());
     addField(mEditorLineLengthHint);
     
     // editor text size
     mEditorTextSize = new IntegerFieldEditor(
-            EDITOR_TEXT_SIZE,
+            AnnotationEditorPreferenceConstants.ANNOTATION_EDITOR_TEXT_SIZE,
             "Editor Text Size", getFieldEditorParent());
     addField(mEditorTextSize);
   }
@@ -66,15 +62,6 @@ public class AnnotationEditorPreferenceP
   protected void checkState() {
     super.checkState();
     
-    if (mEditorLineLengthHint.getIntValue() > 0) {
-      setErrorMessage(null);
-      setValid(true);
-    }
-    else {
-      setErrorMessage("Line length hint must be a larger than zero!");
-      setValid(false);
-    }
-    
     if (mEditorTextSize.getIntValue() > 5) {
       setErrorMessage(null);
       setValid(true);


Reply via email to