harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r480828 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/CompositeView.java test/api/java/common/javax/swing/text/CompositeViewTest.java
Date Thu, 30 Nov 2006 04:15:57 GMT
Author: ndbeyer
Date: Wed Nov 29 20:15:56 2006
New Revision: 480828

URL: http://svn.apache.org/viewvc?view=rev&rev=480828
Log:
Apply patch for HARMONY-2189: [classlib][swing] j.s.text.CompositeView.getInsideAllocation
doesn't call inset getters

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/CompositeView.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeViewTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/CompositeView.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/CompositeView.java?view=diff&rev=480828&r1=480827&r2=480828
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/CompositeView.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/CompositeView.java
Wed Nov 29 20:15:56 2006
@@ -20,20 +20,21 @@
  */
 package javax.swing.text;
 
-import java.awt.Insets;
 import java.awt.Rectangle;
 import java.awt.Shape;
 
 import javax.swing.text.Position.Bias;
 
 import org.apache.harmony.awt.text.TextUtils;
-import org.apache.harmony.x.swing.Utilities;
 
 
 public abstract class CompositeView extends View {
     private View[] children;
-    private final Insets insets = new Insets(0, 0, 0, 0);
     private final Rectangle rect = new Rectangle();
+    private short topInset;
+    private short leftInset;
+    private short bottomInset;
+    private short rightInset;
 
     public CompositeView(final Element element) {
         super(element);
@@ -45,6 +46,7 @@
     protected abstract boolean isBefore(int x, int y, Rectangle rc);
     protected abstract View getViewAtPoint(int x, int y, Rectangle alloc);
 
+    @Override
     public Shape getChildAllocation(final int index, final Shape shape) {
         Rectangle rc = getInsideAllocation(shape);
         childAllocation(index, rc);
@@ -52,10 +54,12 @@
         return rc;
     }
 
+    @Override
     public View getView(final int index) {
         return children[index];
     }
 
+    @Override
     public int getViewIndex(final int pos, final Bias bias) {
         int offset = bias == Bias.Backward ? pos - 1 : pos;
         if (offset < getStartOffset() || offset >= getEndOffset()) {
@@ -65,10 +69,12 @@
         return getViewIndexAtPosition(offset);
     }
 
+    @Override
     public int getViewCount() {
         return children.length;
     }
 
+    @Override
     public void replace(final int index, final int length, final View[] views) {
         int toAdd = views != null ? views.length : 0;
 
@@ -100,6 +106,7 @@
         }
     }
 
+    @Override
     public void setParent(final View parentView) {
         super.setParent(parentView);
 
@@ -108,6 +115,7 @@
         }
     }
 
+    @Override
     public Shape modelToView(final int pos, final Shape shape, final Bias bias)
             throws BadLocationException {
         int index = getViewIndexAtPosition(bias == Bias.Backward ? pos - 1
@@ -121,6 +129,7 @@
                                        + " not found", pos);
     }
 
+    @Override
     public Shape modelToView(final int p1, final Bias b1,
                              final int p2, final Bias b2, final Shape shape)
         throws BadLocationException {
@@ -170,6 +179,7 @@
         return rc1.union(rc2);
     }
 
+    @Override
     public int viewToModel(final float x,
                            final float y,
                            final Shape shape,
@@ -194,6 +204,7 @@
         }
     }
 
+    @Override
     public int getNextVisualPositionFrom(final int pos,
                                          final Bias bias,
                                          final Shape shape,
@@ -259,29 +270,29 @@
     }
 
     protected short getTopInset() {
-        return (short)insets.top;
+        return topInset;
     }
 
     protected short getLeftInset() {
-        return (short)insets.left;
+        return leftInset;
     }
 
     protected short getBottomInset() {
-        return (short)insets.bottom;
+        return bottomInset;
     }
 
     protected short getRightInset() {
-        return (short)insets.right;
+        return rightInset;
     }
 
     protected void setInsets(final short top,
                              final short left,
                              final short bottom,
                              final short right) {
-        insets.top    = top;
-        insets.left   = left;
-        insets.bottom = bottom;
-        insets.right  = right;
+        topInset    = top;
+        leftInset   = left;
+        bottomInset = bottom;
+        rightInset  = right;
     }
 
     protected void setParagraphInsets(final AttributeSet attrs) {
@@ -297,7 +308,11 @@
         }
 
         rect.setBounds(shape.getBounds());
-        return Utilities.subtractInsets(rect, insets);
+        rect.x += getLeftInset();
+        rect.y += getTopInset();
+        rect.width  -= (getLeftInset() + getRightInset());
+        rect.height -= (getTopInset() + getBottomInset());
+        return rect;
     }
 
     protected int getNextEastWestVisualPositionFrom(final int pos,

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeViewTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeViewTest.java?view=diff&rev=480828&r1=480827&r2=480828
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeViewTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeViewTest.java
Wed Nov 29 20:15:56 2006
@@ -291,6 +291,58 @@
         assertNull(view.getInsideAllocation(null));
     }
 
+    // Regression test for HARMONY-2189
+    public void testGetInsideAllocationOverridden() {
+        final Marker top = new Marker();
+        final Marker left = new Marker();
+        final Marker bottom = new Marker();
+        final Marker right = new Marker();
+
+        view = new CompositeViewImpl(root = doc.getDefaultRootElement()) {
+            @Override
+            protected short getTopInset() {
+                top.setOccurred();
+                return 12;
+            }
+
+            @Override
+            protected short getLeftInset() {
+                left.setOccurred();
+                return 11;
+            }
+
+            @Override
+            protected short getBottomInset() {
+                bottom.setOccurred();
+                return 3;
+            }
+
+            @Override
+            protected short getRightInset() {
+                right.setOccurred();
+                return 9;
+            }
+        };
+        view.loadChildren(factory);
+
+        view.setParagraphInsets(getAttributeSet());
+        assertFalse(top.isOccurred());
+        assertFalse(left.isOccurred());
+        assertFalse(bottom.isOccurred());
+        assertFalse(right.isOccurred());
+
+        Rectangle rc = view.getInsideAllocation(new Rectangle(20, 30, 50, 40));
+        assertTrue(top.isOccurred());
+        assertTrue(left.isOccurred());
+        assertTrue(bottom.isOccurred());
+        assertTrue(right.isOccurred());
+
+        assertEquals(20 + 11, rc.x);
+        assertEquals(30 + 12, rc.y);
+        assertEquals(50 - 11 - 9, rc.width);
+        assertEquals(40 - 12 - 3, rc.height);
+    }
+
     /*
      * See tests for individual methods namely EastWest and NorthSouth in
      * class CompositeView_NextNSVisPosTest



Mime
View raw message