You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/08/27 15:16:20 UTC

svn commit: r990141 - in /pivot/trunk/wtk/src/org/apache/pivot/wtk: TextArea2.java Theme.java skin/TextAreaSkin2.java

Author: gbrown
Date: Fri Aug 27 13:16:19 2010
New Revision: 990141

URL: http://svn.apache.org/viewvc?rev=990141&view=rev
Log:
Continue to build out TextArea2; add stub TextArea2 skin class.


Added:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java
Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java?rev=990141&r1=990140&r2=990141&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextArea2.java Fri Aug 27 13:16:19 2010
@@ -16,6 +16,9 @@
  */
 package org.apache.pivot.wtk;
 
+import java.awt.Toolkit;
+import java.io.IOException;
+
 import org.apache.pivot.json.JSON;
 import org.apache.pivot.util.ListenerList;
 
@@ -179,6 +182,8 @@ public class TextArea2 extends Component
         }
     }
 
+    private CharSequence characters = null; // TODO
+
     private int selectionStart = 0;
     private int selectionLength = 0;
 
@@ -220,8 +225,7 @@ public class TextArea2 extends Component
      * A string containing a copy of the text area's text content.
      */
     public String getText() {
-        // TODO
-        return null;
+        return characters.toString();
     }
 
     /**
@@ -230,7 +234,82 @@ public class TextArea2 extends Component
      * @param text
      */
     public void setText(String text) {
-        // TODO
+        if (text == null) {
+            throw new IllegalArgumentException();
+        }
+
+        if (text.length() > maximumLength) {
+            throw new IllegalArgumentException("Text length is greater than maximum length.");
+        }
+
+        // TODO Create new text buffers
+
+        // Update selection
+        int previousSelectionStart = selectionStart;
+        int previousSelectionLength = selectionLength;
+        selectionStart = text.length();
+        selectionLength = 0;
+
+        // Fire change events
+        textAreaContentListeners.textChanged(this);
+
+        if (selectionStart != previousSelectionStart
+            || selectionLength != previousSelectionLength) {
+            textAreaSelectionListeners.selectionChanged(this, selectionStart, selectionLength);
+        }
+    }
+
+    public void insertText(String text, int index) {
+        if (text == null) {
+            throw new IllegalArgumentException();
+        }
+
+        if (characters.length() + text.length() > maximumLength) {
+            throw new IllegalArgumentException("Insertion of text would exceed maximum length.");
+        }
+
+        // Insert the text
+        if (text.length() > 0) {
+            // TODO Insert the text
+            // characters.insert(index, text);
+
+            // Update selection
+            int previousSelectionStart = selectionStart;
+            int previousSelectionLength = selectionLength;
+            selectionStart = index + text.length();
+            selectionLength = 0;
+
+            // Fire change events
+            textAreaContentListeners.textInserted(this, previousSelectionStart, text.length());
+            textAreaContentListeners.textChanged(this);
+
+            if (selectionStart != previousSelectionStart
+                || selectionLength != previousSelectionLength) {
+                textAreaSelectionListeners.selectionChanged(this, selectionStart, selectionLength);
+            }
+        }
+    }
+
+    public void removeText(int index, int count) {
+        if (count > 0) {
+            // TODO Remove the text
+            // characters.delete(index, index + count);
+
+            // Update the selection
+            int previousSelectionStart = selectionStart;
+            int previousSelectionLength = selectionLength;
+            selectionStart = index;
+            selectionLength = 0;
+
+            // Fire change events
+            textAreaContentListeners.textRemoved(this, selectionStart, count);
+            textAreaContentListeners.textChanged(this);
+
+            if (selectionStart != previousSelectionStart
+                || selectionLength != previousSelectionLength) {
+                textAreaSelectionListeners.selectionChanged(this, selectionStart, selectionLength);
+            }
+        }
     }
 
     /**
@@ -238,21 +317,48 @@ public class TextArea2 extends Component
      * the text input.
      */
     public void cut() {
-        // TODO
+        copy();
+        removeText(selectionStart, selectionLength);
     }
 
     /**
      * Places any selected text on the clipboard.
      */
     public void copy() {
-        // TODO
+        // Copy selection to clipboard
+        String selectedText = getSelectedText();
+
+        if (selectedText.length() > 0) {
+            LocalManifest clipboardContent = new LocalManifest();
+            clipboardContent.putText(selectedText);
+            Clipboard.setContent(clipboardContent);
+        }
     }
 
     /**
      * Inserts text from the clipboard into the text input.
      */
     public void paste() {
-        // TODO
+        Manifest clipboardContent = Clipboard.getContent();
+
+        if (clipboardContent != null
+            && clipboardContent.containsText()) {
+            // Paste the string representation of the content
+            String text = null;
+            try {
+                text = clipboardContent.getText();
+            } catch(IOException exception) {
+                // No-op
+            }
+
+            if (text != null) {
+                if ((characters.length() + text.length()) > maximumLength) {
+                    Toolkit.getDefaultToolkit().beep();
+                } else {
+                    insertText(text, selectionStart);
+                }
+            }
+        }
     }
 
     public void undo() {
@@ -306,7 +412,26 @@ public class TextArea2 extends Component
      * The length of the selection.
      */
     public void setSelection(int selectionStart, int selectionLength) {
-        // TODO
+        if (selectionLength < 0) {
+            throw new IllegalArgumentException("selectionLength is negative.");
+        }
+
+        if (selectionStart < 0
+            || selectionStart + selectionLength > characters.length()) {
+            throw new IndexOutOfBoundsException();
+        }
+
+        int previousSelectionStart = this.selectionStart;
+        int previousSelectionLength = this.selectionLength;
+
+        if (previousSelectionStart != selectionStart
+            || previousSelectionLength != selectionLength) {
+            this.selectionStart = selectionStart;
+            this.selectionLength = selectionLength;
+
+            textAreaSelectionListeners.selectionChanged(this, previousSelectionStart,
+                previousSelectionLength);
+        }
     }
 
     /**
@@ -328,7 +453,7 @@ public class TextArea2 extends Component
      * Selects all text.
      */
     public void selectAll() {
-        setSelection(0, getCharacters().length());
+        setSelection(0, characters.length());
     }
 
     /**
@@ -345,7 +470,7 @@ public class TextArea2 extends Component
      * A string containing a copy of the selected text.
      */
     public String getSelectedText() {
-        return getCharacters().subSequence(selectionStart, selectionStart + selectionLength).toString();
+        return characters.subSequence(selectionStart, selectionStart + selectionLength).toString();
     }
 
     /**
@@ -372,15 +497,21 @@ public class TextArea2 extends Component
         int previousMaximumLength = this.maximumLength;
 
         if (previousMaximumLength != maximumLength) {
-            // Truncate the text, if necessary
-            int characterCount = getCharacters().length();
-            if (characterCount > maximumLength) {
-                // TODO Delete characters beyond max. length (need to fire event; do via
-                // call to delete, or fire here?)
-            }
+            int previousTextLength = characters.length();
 
             this.maximumLength = maximumLength;
+
+            // TODO Truncate the text, if necessary
+            if (previousTextLength > maximumLength) {
+                // characters.delete(maximumLength, previousTextLength);
+            }
+
+            // Fire change events
             textAreaListeners.maximumLengthChanged(this, previousMaximumLength);
+
+            if (characters.length() != previousTextLength) {
+                textAreaContentListeners.textChanged(this);
+            }
         }
     }
 

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java?rev=990141&r1=990140&r2=990141&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Theme.java Fri Aug 27 13:16:19 2010
@@ -38,6 +38,7 @@ import org.apache.pivot.wtk.skin.StackPa
 import org.apache.pivot.wtk.skin.TablePaneFillerSkin;
 import org.apache.pivot.wtk.skin.TablePaneSkin;
 import org.apache.pivot.wtk.skin.TextAreaSkin;
+import org.apache.pivot.wtk.skin.TextAreaSkin2;
 import org.apache.pivot.wtk.skin.WindowSkin;
 
 /**
@@ -95,6 +96,7 @@ public abstract class Theme {
         componentSkinMap.put(TablePane.class, TablePaneSkin.class);
         componentSkinMap.put(TablePane.Filler.class, TablePaneFillerSkin.class);
         componentSkinMap.put(TextArea.class, TextAreaSkin.class);
+        componentSkinMap.put(TextArea2.class, TextAreaSkin2.class);
         componentSkinMap.put(Window.class, WindowSkin.class);
     }
 

Added: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java?rev=990141&view=auto
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java (added)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin2.java Fri Aug 27 13:16:19 2010
@@ -0,0 +1,125 @@
+/*
+ * 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.pivot.wtk.skin;
+
+import java.awt.Graphics2D;
+
+import org.apache.pivot.wtk.Bounds;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.Dimensions;
+import org.apache.pivot.wtk.FocusTraversalDirection;
+import org.apache.pivot.wtk.TextArea2;
+import org.apache.pivot.wtk.TextAreaListener2;
+import org.apache.pivot.wtk.TextAreaContentListener2;
+import org.apache.pivot.wtk.TextAreaSelectionListener2;
+
+/**
+ * Text area skin.
+ */
+public class TextAreaSkin2 extends ComponentSkin implements TextArea2.Skin,
+    TextAreaListener2, TextAreaContentListener2, TextAreaSelectionListener2 {
+    @Override
+    public void install(Component component) {
+        super.install(component);
+
+        // TODO
+    }
+
+    @Override
+    public int getPreferredWidth(int height) {
+        // TODO
+        return 0;
+    }
+
+    @Override
+    public int getPreferredHeight(int width) {
+        // TODO
+        return 0;
+    }
+
+    @Override
+    public Dimensions getPreferredSize() {
+        // TODO
+        return null;
+    }
+
+    @Override
+    public void layout() {
+        // TODO
+    }
+
+    @Override
+    public void paint(Graphics2D graphics) {
+        // TODO
+    }
+
+    public int getInsertionPoint(int x, int y) {
+        // TODO
+        return -1;
+    }
+
+    public int getNextInsertionPoint(int x, int from, FocusTraversalDirection direction) {
+        // TODO
+        return -1;
+    }
+
+    public int getRowIndex(int offset) {
+        // TODO
+        return -1;
+    }
+
+    public int getRowCount() {
+        // TODO
+        return 0;
+    }
+
+    public Bounds getCharacterBounds(int offset) {
+        // TODO
+        return null;
+    }
+
+    @Override
+    public void maximumLengthChanged(TextArea2 textArea, int previousMaximumLength) {
+        // TODO
+    }
+
+    @Override
+    public void editableChanged(TextArea2 textArea) {
+        // TODO
+    }
+
+    @Override
+    public void textInserted(TextArea2 textArea, int index, int count) {
+        // TODO
+    }
+
+    @Override
+    public void textRemoved(TextArea2 textArea, int index, int count) {
+        // TODO
+    }
+
+    @Override
+    public void textChanged(TextArea2 textArea) {
+        // TODO
+    }
+
+    @Override
+    public void selectionChanged(TextArea2 textArea, int previousSelectionStart,
+        int previousSelectionLength) {
+        // TODO
+    }
+}