You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by no...@apache.org on 2011/08/11 13:21:39 UTC

svn commit: r1156576 - in /pivot/trunk: demos/src/org/apache/pivot/demos/text/ wtk/src/org/apache/pivot/wtk/skin/ wtk/src/org/apache/pivot/wtk/text/

Author: noelgrandin
Date: Thu Aug 11 11:21:39 2011
New Revision: 1156576

URL: http://svn.apache.org/viewvc?rev=1156576&view=rev
Log:
rename wtk.text.Span to TextSpan to reduce confusion with the other Span class in Pivot

Added:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextSpan.java
Modified:
    pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinSpanView.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Span.java

Modified: pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java?rev=1156576&r1=1156575&r2=1156576&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/text/TextPaneDemo.java Thu Aug 11 11:21:39 2011
@@ -59,6 +59,7 @@ import org.apache.pivot.wtk.text.Node;
 import org.apache.pivot.wtk.text.Paragraph;
 import org.apache.pivot.wtk.text.PlainTextSerializer;
 import org.apache.pivot.wtk.text.TextNode;
+import org.apache.pivot.wtk.text.TextSpan;
 
 /**
  * Demonstrates the use of the rich-text functionality in TextPane.
@@ -211,7 +212,7 @@ public class TextPaneDemo implements App
             public void buttonPressed(Button button) {
                 applyStyleToSelection(new StyleApplicator() {
                     @Override
-                    public void apply(org.apache.pivot.wtk.text.Span span) {
+                    public void apply(TextSpan span) {
                         if (span.getFont() != null) {
                             Font font = span.getFont();
                             if (font.getStyle() == Font.PLAIN) {
@@ -236,7 +237,7 @@ public class TextPaneDemo implements App
             public void buttonPressed(Button button) {
                 applyStyleToSelection(new StyleApplicator() {
                     @Override
-                    public void apply(org.apache.pivot.wtk.text.Span span) {
+                    public void apply(TextSpan span) {
                         if (span.getFont() != null) {
                             Font font = span.getFont();
                             if (font.getStyle() == Font.PLAIN) {
@@ -261,7 +262,7 @@ public class TextPaneDemo implements App
             public void buttonPressed(Button button) {
                 applyStyleToSelection(new StyleApplicator() {
                     @Override
-                    public void apply(org.apache.pivot.wtk.text.Span span) {
+                    public void apply(TextSpan span) {
                         span.setUnderline(!span.isUnderline());
                     }
                 });
@@ -273,7 +274,7 @@ public class TextPaneDemo implements App
             public void buttonPressed(Button button) {
                 applyStyleToSelection(new StyleApplicator() {
                     @Override
-                    public void apply(org.apache.pivot.wtk.text.Span span) {
+                    public void apply(TextSpan span) {
                         span.setStrikethrough(!span.isStrikethrough());
                     }
                 });
@@ -287,7 +288,7 @@ public class TextPaneDemo implements App
                     Color previousSelectedColor) {
                     applyStyleToSelection(new StyleApplicator() {
                         @Override
-                        public void apply(org.apache.pivot.wtk.text.Span span) {
+                        public void apply(TextSpan span) {
                             span.setForegroundColor(foregroundColorChooserButton.getSelectedColor());
                         }
                     });
@@ -301,7 +302,7 @@ public class TextPaneDemo implements App
                     Color previousSelectedColor) {
                     applyStyleToSelection(new StyleApplicator() {
                         @Override
-                        public void apply(org.apache.pivot.wtk.text.Span span) {
+                        public void apply(TextSpan span) {
                             span.setBackgroundColor(backgroundColorChooserButton.getSelectedColor());
                         }
                     });
@@ -317,7 +318,7 @@ public class TextPaneDemo implements App
 
                 applyStyleToSelection(new StyleApplicator() {
                     @Override
-                    public void apply(org.apache.pivot.wtk.text.Span span) {
+                    public void apply(TextSpan span) {
                         span.setFont(derivedFont);
                     }
                 });
@@ -359,7 +360,7 @@ public class TextPaneDemo implements App
     }
 
     private interface StyleApplicator {
-        void apply(org.apache.pivot.wtk.text.Span span);
+        void apply(TextSpan span);
     }
 
     private void applyAlignmentStyle(HorizontalAlignment horizontalAlignment) {
@@ -431,8 +432,8 @@ public class TextPaneDemo implements App
         final int selectionLength = textPane.getSelectionLength();
 
         for (Node node : nodeList) {
-            if (node instanceof org.apache.pivot.wtk.text.Span) {
-                org.apache.pivot.wtk.text.Span span = (org.apache.pivot.wtk.text.Span)node;
+            if (node instanceof TextSpan) {
+                TextSpan span = (TextSpan)node;
                 int documentOffset = node.getDocumentOffset();
                 int characterCount = node.getCharacterCount();
                 org.apache.pivot.wtk.Span textSpan = new org.apache.pivot.wtk.Span(documentOffset,
@@ -466,7 +467,7 @@ public class TextPaneDemo implements App
             // if the text-node is contained wholly inside the selection, remove
             // the text-node, replace it with a Span, and apply the style
             Element parent = textNode.getParent();
-            org.apache.pivot.wtk.text.Span newSpanNode = new org.apache.pivot.wtk.text.Span();
+            TextSpan newSpanNode = new TextSpan();
             newSpanNode.add(new TextNode(textNode.getText()));
             styleApplicator.apply(newSpanNode);
             int index = parent.remove(textNode);
@@ -478,7 +479,7 @@ public class TextPaneDemo implements App
             String part1 = textNode.getSubstring(0, intersectionLength);
             String part2 = textNode.getSubstring(intersectionLength, characterCount);
 
-            org.apache.pivot.wtk.text.Span newSpanNode = new org.apache.pivot.wtk.text.Span();
+            TextSpan newSpanNode = new TextSpan();
             newSpanNode.add(new TextNode(part1));
             styleApplicator.apply(newSpanNode);
 
@@ -494,7 +495,7 @@ public class TextPaneDemo implements App
             String part1 = textNode.getSubstring(0, intersectionStart);
             String part2 = textNode.getSubstring(intersectionStart, characterCount);
 
-            org.apache.pivot.wtk.text.Span newSpanNode = new org.apache.pivot.wtk.text.Span();
+            TextSpan newSpanNode = new TextSpan();
             newSpanNode.add(new TextNode(part2));
             styleApplicator.apply(newSpanNode);
 
@@ -512,7 +513,7 @@ public class TextPaneDemo implements App
             String part2 = textNode.getSubstring(part2Start, part2End);
             String part3 = textNode.getSubstring(part2End, characterCount);
 
-            org.apache.pivot.wtk.text.Span newSpanNode = new org.apache.pivot.wtk.text.Span();
+            TextSpan newSpanNode = new TextSpan();
             newSpanNode.add(new TextNode(part2));
             styleApplicator.apply(newSpanNode);
 
@@ -525,7 +526,7 @@ public class TextPaneDemo implements App
     }
 
     private void applyStyleToSpanNode(org.apache.pivot.wtk.Span selectionSpan,
-        StyleApplicator styleApplicator, org.apache.pivot.wtk.text.Span spanNode,
+        StyleApplicator styleApplicator, TextSpan spanNode,
         int characterCount, org.apache.pivot.wtk.Span textSpan) {
         if (selectionSpan.contains(textSpan)) {
             // if the span-node is contained wholly inside the
@@ -535,7 +536,7 @@ public class TextPaneDemo implements App
             // if the selection covers the first part of the span-node, split
             // off the first part of the span-node, and apply the style to it
             int intersectionLength = selectionSpan.end - textSpan.start;
-            org.apache.pivot.wtk.text.Span node1 = spanNode.getRange(0, intersectionLength);
+            TextSpan node1 = spanNode.getRange(0, intersectionLength);
             styleApplicator.apply(node1);
             Node node2 = spanNode.getRange(intersectionLength, characterCount - intersectionLength);
             Element parent = spanNode.getParent();
@@ -546,8 +547,8 @@ public class TextPaneDemo implements App
             // if the selection covers the last part of the span-node, split off
             // the last part of the span-node, and apply the style to it
             int intersectionStart = selectionSpan.start - textSpan.start;
-            org.apache.pivot.wtk.text.Span part1 = spanNode.getRange(0, intersectionStart);
-            org.apache.pivot.wtk.text.Span part2 = spanNode.getRange(intersectionStart,
+            TextSpan part1 = spanNode.getRange(0, intersectionStart);
+            TextSpan part2 = spanNode.getRange(intersectionStart,
                 characterCount - intersectionStart);
 
             styleApplicator.apply(part2);
@@ -562,10 +563,10 @@ public class TextPaneDemo implements App
             // span-node into 3 parts, and apply the style to the second part
             int part2Start = selectionSpan.start - textSpan.start;
             int part2End = selectionSpan.end - textSpan.start;
-            org.apache.pivot.wtk.text.Span part1 = spanNode.getRange(0, part2Start);
-            org.apache.pivot.wtk.text.Span part2 = spanNode.getRange(part2Start, part2End
+            TextSpan part1 = spanNode.getRange(0, part2Start);
+            TextSpan part2 = spanNode.getRange(part2Start, part2End
                 - part2Start);
-            org.apache.pivot.wtk.text.Span part3 = spanNode.getRange(part2End, characterCount
+            TextSpan part3 = spanNode.getRange(part2End, characterCount
                 - part2End);
 
             styleApplicator.apply(part2);
@@ -580,7 +581,7 @@ public class TextPaneDemo implements App
 
     private void collectNodes(org.apache.pivot.wtk.text.Node node, List<Node> nodeList) {
         // don't worry about the text-nodes that are children of Span nodes.
-        if (node instanceof org.apache.pivot.wtk.text.Span) {
+        if (node instanceof TextSpan) {
             return;
         }
         if (node instanceof org.apache.pivot.wtk.text.Element) {

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java?rev=1156576&r1=1156575&r2=1156576&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java Thu Aug 11 11:21:39 2011
@@ -48,6 +48,7 @@ import org.apache.pivot.wtk.text.Node;
 import org.apache.pivot.wtk.text.NumberedList;
 import org.apache.pivot.wtk.text.Paragraph;
 import org.apache.pivot.wtk.text.TextNode;
+import org.apache.pivot.wtk.text.TextSpan;
 
 /**
  * Text pane skin.
@@ -1089,8 +1090,8 @@ public class TextPaneSkin extends Contai
             nodeView = new TextPaneSkinImageNodeView((ImageNode)node);
         } else if (node instanceof ComponentNode) {
             nodeView = new TextPaneSkinComponentNodeView((ComponentNode)node);
-        } else if (node instanceof org.apache.pivot.wtk.text.Span) {
-            nodeView = new TextPaneSkinSpanView(this, (org.apache.pivot.wtk.text.Span)node);
+        } else if (node instanceof TextSpan) {
+            nodeView = new TextPaneSkinSpanView(this, (TextSpan)node);
         } else if (node instanceof NumberedList) {
             nodeView = new TextPaneSkinNumberedListView(this, (NumberedList)node);
         } else if (node instanceof BulletedList) {

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinSpanView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinSpanView.java?rev=1156576&r1=1156575&r2=1156576&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinSpanView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinSpanView.java Thu Aug 11 11:21:39 2011
@@ -21,13 +21,14 @@ import org.apache.pivot.wtk.Dimensions;
 import org.apache.pivot.wtk.TextPane;
 import org.apache.pivot.wtk.text.Element;
 import org.apache.pivot.wtk.text.Node;
+import org.apache.pivot.wtk.text.TextSpan;
 
 /**
  * Span node view.
  */
 class TextPaneSkinSpanView extends TextPaneSkinElementView {
 
-    public TextPaneSkinSpanView(TextPaneSkin textPaneSkin, org.apache.pivot.wtk.text.Span span) {
+    public TextPaneSkinSpanView(TextPaneSkin textPaneSkin, TextSpan span) {
         super(textPaneSkin, span);
     }
 
@@ -35,7 +36,7 @@ class TextPaneSkinSpanView extends TextP
     protected void attach() {
         super.attach();
 
-        org.apache.pivot.wtk.text.Span span = (org.apache.pivot.wtk.text.Span)getNode();
+        TextSpan span = (TextSpan)getNode();
 
         // for now, assume that span contains at most one child, and
         // that child is a TextNode
@@ -134,7 +135,7 @@ class TextPaneSkinSpanView extends TextP
     public void nodeInserted(Element element, int index) {
         super.nodeInserted(element, index);
 
-        org.apache.pivot.wtk.text.Span span = (org.apache.pivot.wtk.text.Span)getNode();
+        TextSpan span = (TextSpan)getNode();
         insert(textPaneSkin.createNodeView(span.get(index)), index);
     }
 

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Span.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Span.java?rev=1156576&r1=1156575&r2=1156576&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Span.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/text/Span.java Thu Aug 11 11:21:39 2011
@@ -19,8 +19,10 @@ package org.apache.pivot.wtk.text;
 
 /**
  * Element representing an inline range of styled characters.
+ * @deprecated class has been renamed to TextSpan
  */
-public class Span extends Element {
+@Deprecated
+public class Span extends TextSpan {
     public Span() {
         super();
     }
@@ -29,20 +31,6 @@ public class Span extends Element {
         super(span, recursive);
     }
 
-    public int add(String text) {
-        return add(new TextNode(text));
-    }
-
-    @Override
-    public void insert(Node node, int index) {
-        if (node instanceof Block) {
-            throw new IllegalArgumentException("Child node must not be an instance of "
-                + Block.class.getName() + ", " + node.getClass());
-        }
-
-        super.insert(node, index);
-    }
-
     @Override
     public Span duplicate(boolean recursive) {
         return new Span(this, recursive);

Added: pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextSpan.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextSpan.java?rev=1156576&view=auto
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextSpan.java (added)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/text/TextSpan.java Thu Aug 11 11:21:39 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.text;
+
+
+/**
+ * Element representing an inline range of styled characters.
+ */
+public class TextSpan extends Element {
+    public TextSpan() {
+        super();
+    }
+
+    public TextSpan(TextSpan span, boolean recursive) {
+        super(span, recursive);
+    }
+
+    public int add(String text) {
+        return add(new TextNode(text));
+    }
+
+    @Override
+    public void insert(Node node, int index) {
+        if (node instanceof Block) {
+            throw new IllegalArgumentException("Child node must not be an instance of "
+                + Block.class.getName() + ", " + node.getClass());
+        }
+
+        super.insert(node, index);
+    }
+
+    @Override
+    public TextSpan duplicate(boolean recursive) {
+        return new TextSpan(this, recursive);
+    }
+
+    @Override
+    public TextSpan getRange(int offset, int characterCount) {
+        return (TextSpan) super.getRange(offset, characterCount);
+    }
+}