You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2007/01/14 23:04:03 UTC
svn commit: r496164 - in /harmony/enhanced/classlib/trunk/modules/swing/src:
main/java/common/javax/swing/text/BoxView.java
test/api/java/common/javax/swing/text/BoxView_WithChildrenTest.java
Author: hindessm
Date: Sun Jan 14 14:04:02 2007
New Revision: 496164
URL: http://svn.apache.org/viewvc?view=rev&rev=496164
Log:
Applying patches from "[#HARMONY-2776] [classlib][swing]
j.s.text.BoxView.childAllocation does not throw NPE whereas RI does".
Modified:
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/BoxView.java
harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/BoxView_WithChildrenTest.java
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/BoxView.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/BoxView.java?view=diff&rev=496164&r1=496163&r2=496164
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/BoxView.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/BoxView.java Sun Jan 14 14:04:02 2007
@@ -14,10 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/**
- * @author Alexey A. Ivanov
- * @version $Revision$
- */
package javax.swing.text;
import java.awt.Component;
@@ -33,7 +29,6 @@
import org.apache.harmony.x.swing.SizeRequirementsHelper;
import org.apache.harmony.x.swing.Utilities;
-
public class BoxView extends CompositeView {
private static final int[] EMPTY_INT_ARRAY = new int[0];
private static final SizeRequirements[] EMPTY_REQUIREMENTS_ARRAY =
@@ -67,6 +62,7 @@
majorAxis = axis;
}
+ @Override
public float getAlignment(final int axis) {
isAxisValid(axis);
@@ -77,25 +73,29 @@
return majorAxis;
}
+ @Override
public Shape getChildAllocation(final int index, final Shape shape) {
- if (isLayoutValid()) {
- return super.getChildAllocation(index, shape);
+ if (shape == null || !isLayoutValid()) {
+ return null;
}
- return null;
+ return super.getChildAllocation(index, shape);
}
+ @Override
public float getMinimumSpan(final int axis) {
isAxisValid(axis);
return getTotalRequirements(axis).minimum + getSideInset(axis);
}
+ @Override
public float getPreferredSpan(final int axis) {
isAxisValid(axis);
return getTotalRequirements(axis).preferred + getSideInset(axis);
}
+ @Override
public float getMaximumSpan(final int axis) {
isAxisValid(axis);
@@ -103,6 +103,7 @@
getSideInset(axis));
}
+ @Override
public int getResizeWeight(final int axis) {
isAxisValid(axis);
@@ -118,6 +119,7 @@
}
}
+ @Override
public void paint(final Graphics g, final Shape shape) {
final Rectangle insideAlloc = getInsideAllocation(shape);
final Rectangle allocation = new Rectangle();
@@ -132,6 +134,7 @@
}
}
+ @Override
public void preferenceChanged(final View child,
final boolean width,
final boolean height) {
@@ -140,6 +143,7 @@
super.preferenceChanged(child, width, height);
}
+ @Override
public void replace(final int index, final int length, final View[] elems) {
super.replace(index, length, elems);
@@ -162,6 +166,7 @@
invalidateLayout(true, true);
}
+ @Override
public void setSize(final float width, final float height) {
layout((int)(width - getSideInset(X_AXIS)),
(int)(height - getSideInset(Y_AXIS)));
@@ -175,6 +180,7 @@
return boxHeight;
}
+ @Override
public Shape modelToView(final int pos, final Shape shape,
final Bias bias) throws BadLocationException {
final Rectangle bounds = shape.getBounds();
@@ -182,6 +188,7 @@
return super.modelToView(pos, shape, bias);
}
+ @Override
public int viewToModel(final float x, final float y,
final Shape shape, final Bias[] bias) {
final Rectangle bounds = shape.getBounds();
@@ -232,11 +239,8 @@
return result;
}
+ @Override
protected void childAllocation(final int index, final Rectangle alloc) {
- if (alloc == null) {
- return;
- }
-
if (isLayoutValid()) {
alloc.x += getOffset(X_AXIS, index);
alloc.y += getOffset(Y_AXIS, index);
@@ -248,6 +252,7 @@
}
}
+ @Override
protected boolean flipEastAndWestAtEnds(final int position,
final Bias bias) {
if (isMajor(X_AXIS)) {
@@ -261,6 +266,7 @@
&& ((CompositeView)child).flipEastAndWestAtEnds(position, bias);
}
+ @Override
protected void forwardUpdate(final ElementChange change,
final DocumentEvent event,
final Shape shape,
@@ -298,6 +304,7 @@
: minorSpans[childIndex];
}
+ @Override
protected View getViewAtPoint(final int x, final int y,
final Rectangle alloc) {
final int location = isMajor(Y_AXIS) ? y - alloc.y : x - alloc.x;
@@ -321,11 +328,13 @@
return null;
}
+ @Override
protected boolean isBefore(final int x, final int y,
final Rectangle innerAlloc) {
return isMajor(X_AXIS) ? x < innerAlloc.x : y < innerAlloc.y;
}
+ @Override
protected boolean isAfter(final int x, final int y,
final Rectangle innerAlloc) {
return isMajor(X_AXIS) ? x > (innerAlloc.x + innerAlloc.width)
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/BoxView_WithChildrenTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/BoxView_WithChildrenTest.java?view=diff&rev=496164&r1=496163&r2=496164
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/BoxView_WithChildrenTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/BoxView_WithChildrenTest.java Sun Jan 14 14:04:02 2007
@@ -14,15 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/**
- * @author Alexey A. Ivanov
- * @version $Revision$
- */
package javax.swing.text;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Rectangle;
+import java.awt.Shape;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import javax.swing.BasicSwingTestCase;
@@ -186,6 +183,36 @@
assertEquals(new Rectangle(getChildX(1), getChildY(1), getWidth(1), getHeight(1)),
alloc);
}
+
+ // Regression test for HARMONY-2776
+ public void testChildAllocationNull() throws Exception {
+ final Marker marker = new Marker();
+ view = new BoxView(root, Y_AXIS) {
+ @Override
+ protected void childAllocation(int index, Rectangle alloc) {
+ marker.setOccurred();
+ super.childAllocation(index, alloc);
+ }
+
+ @Override
+ protected Rectangle getInsideAllocation(Shape shape) {
+ return null;
+ }
+ };
+ view.loadChildren(factory);
+ view.layout(shape.width, shape.height);
+ assertTrue(view.isLayoutValid(X_AXIS) && view.isLayoutValid(Y_AXIS));
+ assertNull(view.getChildAllocation(0, null));
+ assertFalse(marker.isOccurred());
+ try {
+ view.getChildAllocation(0, shape);
+ fail("NullPointerException is expected");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ assertTrue(marker.isOccurred());
+ }
+
public void testFlipEastAndWestAtEnds() {
assertEquals(Y_AXIS, view.getAxis());