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/04/06 14:29:49 UTC

svn commit: r1089425 - /pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/

Author: noelgrandin
Date: Wed Apr  6 12:29:48 2011
New Revision: 1089425

URL: http://svn.apache.org/viewvc?rev=1089425&view=rev
Log:
PIVOT-726 Selection in a Paragraph with non-null background color displays incorrectly

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinBlockView.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinElementView.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNodeView.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinSpanView.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinVerticalElementView.java

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=1089425&r1=1089424&r2=1089425&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 Wed Apr  6 12:29:48 2011
@@ -1166,4 +1166,8 @@ public class TextPaneSkin extends Contai
             scheduledBlinkCaretCallback = null;
         }
     }
+
+    Area getSelection() {
+        return selection;
+    }
 }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinBlockView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinBlockView.java?rev=1089425&r1=1089424&r2=1089425&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinBlockView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinBlockView.java Wed Apr  6 12:29:48 2011
@@ -23,8 +23,8 @@ import org.apache.pivot.wtk.text.BlockLi
 abstract class TextPaneSkinBlockView extends TextPaneSkinElementView implements
     BlockListener {
 
-    public TextPaneSkinBlockView(Block block) {
-        super(block);
+    public TextPaneSkinBlockView(TextPaneSkin textPaneSkin, Block block) {
+        super(textPaneSkin, block);
     }
 
     @Override

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinElementView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinElementView.java?rev=1089425&r1=1089424&r2=1089425&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinElementView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinElementView.java Wed Apr  6 12:29:48 2011
@@ -20,6 +20,8 @@ import java.awt.Color;
 import java.awt.Font;
 import java.awt.Graphics2D;
 import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Area;
 import java.util.Iterator;
 
 import org.apache.pivot.collections.ArrayList;
@@ -36,9 +38,13 @@ import org.apache.pivot.wtk.text.Node;
 abstract class TextPaneSkinElementView extends TextPaneSkinNodeView
     implements Sequence<TextPaneSkinNodeView>, Iterable<TextPaneSkinNodeView>, ElementListener {
     private ArrayList<TextPaneSkinNodeView> nodeViews = new ArrayList<TextPaneSkinNodeView>();
+    protected final TextPaneSkin textPaneSkin;
+    private int skinX = 0;
+    private int skinY = 0;
 
-    public TextPaneSkinElementView(Element element) {
+    public TextPaneSkinElementView(TextPaneSkin textPaneSkin, Element element) {
         super(element);
+        this.textPaneSkin = textPaneSkin;
     }
 
     @Override
@@ -126,6 +132,12 @@ abstract class TextPaneSkinElementView e
     }
 
     @Override
+    protected void setSkinLocation(int skinX, int skinY) {
+        this.skinX = skinX;
+        this.skinY = skinY;
+    }
+
+    @Override
     public void paint(Graphics2D graphics) {
         // Determine the paint bounds
         Bounds paintBounds = new Bounds(0, 0, getWidth(), getHeight());
@@ -142,13 +154,23 @@ abstract class TextPaneSkinElementView e
                 // Create a copy of the current graphics context and
                 // translate to the node view's coordinate system
                 Graphics2D nodeViewGraphics = (Graphics2D)graphics.create();
-                nodeViewGraphics.translate(nodeViewBounds.x, nodeViewBounds.y);
 
                 Color styledBackgroundColor = getStyledBackgroundColor();
                 if (styledBackgroundColor != null) {
-                    nodeViewGraphics.setColor(styledBackgroundColor);
-                    nodeViewGraphics.fillRect(0, 0, nodeViewBounds.width, nodeViewBounds.height);
+                    // don't paint over the selection background
+                    Area selection = textPaneSkin.getSelection();
+                    if (selection != null) {
+                        Area fillArea = new Area(new Rectangle(nodeViewBounds.x, nodeViewBounds.y, nodeViewBounds.width, nodeViewBounds.height));
+                        selection = selection.createTransformedArea(AffineTransform.getTranslateInstance(-skinX, -skinY));
+                        fillArea.subtract(selection);
+                        nodeViewGraphics.setColor(styledBackgroundColor);
+                        nodeViewGraphics.fill(fillArea);
+                    } else {
+                        nodeViewGraphics.setColor(styledBackgroundColor);
+                        nodeViewGraphics.fillRect(nodeViewBounds.x, nodeViewBounds.y, nodeViewBounds.width, nodeViewBounds.height);
+                    }
                 }
+                nodeViewGraphics.translate(nodeViewBounds.x, nodeViewBounds.y);
 
                 // NOTE We don't clip here because views should generally
                 // not overlap and clipping would impose an unnecessary

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNodeView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNodeView.java?rev=1089425&r1=1089424&r2=1089425&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNodeView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinNodeView.java Wed Apr  6 12:29:48 2011
@@ -16,12 +16,13 @@
  */
 package org.apache.pivot.wtk.skin;
 
+import java.awt.Graphics2D;
+
 import org.apache.pivot.collections.Sequence;
 import org.apache.pivot.wtk.Bounds;
 import org.apache.pivot.wtk.Dimensions;
 import org.apache.pivot.wtk.Point;
 import org.apache.pivot.wtk.TextPane;
-import org.apache.pivot.wtk.Visual;
 import org.apache.pivot.wtk.text.Element;
 import org.apache.pivot.wtk.text.Node;
 import org.apache.pivot.wtk.text.NodeListener;
@@ -29,7 +30,7 @@ import org.apache.pivot.wtk.text.NodeLis
 /**
  * Abstract base class for node views.
  */
-abstract class TextPaneSkinNodeView implements Visual, NodeListener {
+abstract class TextPaneSkinNodeView implements NodeListener {
     private Node node = null;
     private TextPaneSkinElementView parent = null;
 
@@ -66,20 +67,15 @@ abstract class TextPaneSkinNodeView impl
         node.getNodeListeners().remove(this);
     }
 
-    @Override
     public int getWidth() {
         return width;
     }
 
-    @Override
     public int getHeight() {
         return height;
     }
 
-    @Override
-    public int getBaseline() {
-        return -1;
-    }
+    public abstract void paint(Graphics2D g);
 
     public Dimensions getSize() {
         return new Dimensions(width, height);
@@ -123,6 +119,7 @@ abstract class TextPaneSkinNodeView impl
     }
 
     /**
+     * Set location of the NodeView relative to the skin component.
      * This is needed by the ComponentViewNode to correctly position child Component's.
      *
      * @param skinX the X coordinate in the skin's frame of reference

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java?rev=1089425&r1=1089424&r2=1089425&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinParagraphView.java Wed Apr  6 12:29:48 2011
@@ -31,8 +31,6 @@ class TextPaneSkinParagraphView extends 
 
     private static final int PARAGRAPH_TERMINATOR_WIDTH = 4;
 
-    private final TextPaneSkin textPaneSkin;
-
     private static class Row {
         public int x = 0;
         public int y = 0;
@@ -45,8 +43,7 @@ class TextPaneSkinParagraphView extends 
     private Bounds terminatorBounds = new Bounds(0, 0, 0, 0);
 
     public TextPaneSkinParagraphView(TextPaneSkin textPaneSkin, Paragraph paragraph) {
-        super(paragraph);
-        this.textPaneSkin = textPaneSkin;
+        super(textPaneSkin, paragraph);
     }
 
     @Override
@@ -179,6 +176,7 @@ class TextPaneSkinParagraphView extends 
 
     @Override
     protected void setSkinLocation(int skinX, int skinY) {
+        super.setSkinLocation(skinX, skinY);
         for (int i = 0, n = rows.getLength(); i < n; i++) {
             Row row = rows.get(i);
             for (TextPaneSkinNodeView nodeView : row.nodeViews) {

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=1089425&r1=1089424&r2=1089425&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 Wed Apr  6 12:29:48 2011
@@ -27,11 +27,8 @@ import org.apache.pivot.wtk.text.TextNod
  */
 class TextPaneSkinSpanView extends TextPaneSkinElementView {
 
-    private final TextPaneSkin textPaneSkin;
-
     public TextPaneSkinSpanView(TextPaneSkin textPaneSkin, org.apache.pivot.wtk.text.Span span) {
-        super(span);
-        this.textPaneSkin = textPaneSkin;
+        super(textPaneSkin, span);
     }
 
     @Override
@@ -129,6 +126,7 @@ class TextPaneSkinSpanView extends TextP
 
     @Override
     protected void setSkinLocation(int skinX, int skinY) {
+        super.setSkinLocation(skinX, skinY);
         for (TextPaneSkinNodeView nodeView : this) {
             nodeView.setSkinLocation(skinX, skinY + nodeView.getY());
         }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinVerticalElementView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinVerticalElementView.java?rev=1089425&r1=1089424&r2=1089425&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinVerticalElementView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinVerticalElementView.java Wed Apr  6 12:29:48 2011
@@ -26,11 +26,9 @@ import org.apache.pivot.wtk.text.Node;
  * Some of the classes in the text hierarchy are very similar in layout ie. they lay their children out vertically. This class groups that functionality.
  */
 abstract class TextPaneSkinVerticalElementView extends TextPaneSkinElementView {
-    protected final TextPaneSkin textPaneSkin;
 
     public TextPaneSkinVerticalElementView(TextPaneSkin textPaneSkin, Element element) {
-        super(element);
-        this.textPaneSkin = textPaneSkin;
+        super(textPaneSkin, element);
     }
 
     @Override
@@ -77,6 +75,7 @@ abstract class TextPaneSkinVerticalEleme
 
     @Override
     protected void setSkinLocation(int skinX, int skinY) {
+        super.setSkinLocation(skinX, skinY);
         for (TextPaneSkinNodeView nodeView : this) {
             nodeView.setSkinLocation(skinX, skinY + nodeView.getY());
         }