You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/11/26 21:15:55 UTC
svn commit: r479418 [20/43] - in
/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common:
javax/swing/ javax/swing/border/ javax/swing/colorchooser/
javax/swing/event/ javax/swing/filechooser/ javax/swing/plaf/
javax/swing/plaf/basic/ j...
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/ComponentViewTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/ComponentViewTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/ComponentViewTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/ComponentViewTest.java Sun Nov 26 12:15:43 2006
@@ -27,7 +27,6 @@
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
-
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
@@ -36,7 +35,6 @@
import javax.swing.SwingTestCase;
public class ComponentViewTest extends SwingTestCase {
-
StyledDocument document;
JTextPane textPane;
@@ -47,69 +45,53 @@
ComponentView view;
+ @Override
protected void setUp() throws Exception {
super.setUp();
-
insertedComponent = new JButton();
-
textPane = new JTextPane();
document = textPane.getStyledDocument();
document.insertString(0, "Hello\n word!!!", new SimpleAttributeSet());
-
textPane.setCaretPosition(3);
textPane.insertComponent(insertedComponent);
- componentElement = document.getDefaultRootElement().getElement(0)
- .getElement(1);
-
+ componentElement = document.getDefaultRootElement().getElement(0).getElement(1);
view = new ComponentView(componentElement);
-
}
public void testComponentView() {
-
- assertNotNull(StyleConstants.getComponent(componentElement.
- getAttributes()));
-
+ assertNotNull(StyleConstants.getComponent(componentElement.getAttributes()));
componentElement = document.getDefaultRootElement();
assertNull(view.getParent());
assertNull(view.getComponent());
}
public void testCreateComponent() {
-
final Marker createComponentCalled = new Marker();
view = new ComponentView(componentElement) {
+ @Override
public void setParent(View parent) {
createComponentCalled.setOccurred();
super.setParent(parent);
}
};
-
assertEquals(insertedComponent, view.createComponent());
-
JPanel panel = new JPanel();
MutableAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setComponent(attrs, panel);
document.setCharacterAttributes(3, 1, attrs, true);
-
assertSame(panel, view.createComponent());
-
createComponentCalled.reset();
view.setParent(textPane.getUI().getRootView(textPane));
assertTrue(createComponentCalled.isOccurred());
assertSame(panel, view.createComponent());
-
JTextArea textArea = new JTextArea();
-
createComponentCalled.reset();
view.setParent(textArea.getUI().getRootView(textArea));
assertSame(panel, view.createComponent());
assertTrue(createComponentCalled.isOccurred());
-
createComponentCalled.reset();
view.setParent(null);
assertTrue(createComponentCalled.isOccurred());
-
createComponentCalled.reset();
view.setParent(textArea.getUI().getRootView(textArea));
assertTrue(createComponentCalled.isOccurred());
@@ -118,47 +100,41 @@
public void testGetPreferredSpan() {
Component c;
-
assertTrue(0 == view.getPreferredSpan(View.X_AXIS));
assertTrue(0 == view.getPreferredSpan(View.Y_AXIS));
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getPreferredSpan(2);
}
});
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getPreferredSpan(-1);
}
});
-
insertedComponent.setPreferredSize(new Dimension(100, 200));
-
view.setParent(textPane.getUI().getRootView(textPane));
c = view.getComponent();
-
if (isHarmony()) {
- assertTrue(c.getPreferredSize().width + 2 ==
- view.getPreferredSpan(View.X_AXIS));
+ assertTrue(c.getPreferredSize().width + 2 == view.getPreferredSpan(View.X_AXIS));
} else {
- assertTrue(c.getPreferredSize().width ==
- view.getPreferredSpan(View.X_AXIS));
+ assertTrue(c.getPreferredSize().width == view.getPreferredSpan(View.X_AXIS));
}
- assertTrue(c.getPreferredSize().height ==
- view.getPreferredSpan(View.Y_AXIS));
+ assertTrue(c.getPreferredSize().height == view.getPreferredSpan(View.Y_AXIS));
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getPreferredSpan(2);
}
});
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
- view.getPreferredSpan(-1);
+ view.getPreferredSpan(-1);
}
});
-
c.setPreferredSize(new Dimension(20, 30));
if (isHarmony()) {
assertTrue(22 == view.getPreferredSpan(View.X_AXIS));
@@ -167,21 +143,19 @@
assertTrue(100 == view.getPreferredSpan(View.X_AXIS));
assertTrue(200 == view.getPreferredSpan(View.Y_AXIS));
}
-
view.setParent(null);
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getPreferredSpan(2);
}
});
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
- view.getPreferredSpan(-1);
+ view.getPreferredSpan(-1);
}
});
-
-
c = view.getComponent();
if (isHarmony()) {
assertTrue(0 == view.getPreferredSpan(View.X_AXIS));
@@ -190,7 +164,6 @@
assertTrue(100 == view.getPreferredSpan(View.X_AXIS));
assertTrue(200 == view.getPreferredSpan(View.Y_AXIS));
}
-
view.getComponent().setPreferredSize(new Dimension(20, 30));
if (isHarmony()) {
assertTrue(0 == view.getPreferredSpan(View.X_AXIS));
@@ -203,47 +176,41 @@
public void testGetMinimumSpan() {
Component c;
-
assertTrue(0 == view.getMinimumSpan(View.X_AXIS));
assertTrue(0 == view.getMinimumSpan(View.Y_AXIS));
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
- view.getMinimumSpan(2);
+ view.getMinimumSpan(2);
}
});
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
- view.getMinimumSpan(-1);
+ view.getMinimumSpan(-1);
}
});
-
insertedComponent.setMinimumSize(new Dimension(100, 200));
-
view.setParent(textPane.getUI().getRootView(textPane));
c = view.getComponent();
-
if (isHarmony()) {
- assertTrue(c.getMinimumSize().width + 2
- == view.getMinimumSpan(View.X_AXIS));
+ assertTrue(c.getMinimumSize().width + 2 == view.getMinimumSpan(View.X_AXIS));
} else {
- assertTrue(c.getMinimumSize().width
- == view.getMinimumSpan(View.X_AXIS));
+ assertTrue(c.getMinimumSize().width == view.getMinimumSpan(View.X_AXIS));
}
- assertTrue(c.getMinimumSize().height == view
- .getMinimumSpan(View.Y_AXIS));
+ assertTrue(c.getMinimumSize().height == view.getMinimumSpan(View.Y_AXIS));
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getMinimumSpan(2);
}
});
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getMinimumSpan(-1);
}
});
-
c.setMinimumSize(new Dimension(20, 30));
if (isHarmony()) {
assertTrue(22 == view.getMinimumSpan(View.X_AXIS));
@@ -252,20 +219,19 @@
assertTrue(100 == view.getMinimumSpan(View.X_AXIS));
assertTrue(200 == view.getMinimumSpan(View.Y_AXIS));
}
-
view.setParent(null);
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getMinimumSpan(2);
}
});
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
- view.getMinimumSpan(-1);
+ view.getMinimumSpan(-1);
}
});
-
c = view.getComponent();
if (isHarmony()) {
assertTrue(0 == view.getMinimumSpan(View.X_AXIS));
@@ -274,7 +240,6 @@
assertTrue(100 == view.getMinimumSpan(View.X_AXIS));
assertTrue(200 == view.getMinimumSpan(View.Y_AXIS));
}
-
view.getComponent().setMinimumSize(new Dimension(20, 30));
if (isHarmony()) {
assertTrue(0 == view.getMinimumSpan(View.X_AXIS));
@@ -287,47 +252,41 @@
public void testGetMaximumSpan() {
Component c;
-
assertTrue(0 == view.getMaximumSpan(View.X_AXIS));
assertTrue(0 == view.getMaximumSpan(View.Y_AXIS));
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getMaximumSpan(2);
}
});
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
- view.getMaximumSpan(-1);
+ view.getMaximumSpan(-1);
}
});
-
insertedComponent.setMaximumSize(new Dimension(100, 200));
-
view.setParent(textPane.getUI().getRootView(textPane));
c = view.getComponent();
-
if (isHarmony()) {
- assertTrue(c.getMaximumSize().width + 2
- == view.getMaximumSpan(View.X_AXIS));
+ assertTrue(c.getMaximumSize().width + 2 == view.getMaximumSpan(View.X_AXIS));
} else {
- assertTrue(c.getMaximumSize().width
- == view.getMaximumSpan(View.X_AXIS));
+ assertTrue(c.getMaximumSize().width == view.getMaximumSpan(View.X_AXIS));
}
- assertTrue(c.getMaximumSize().height == view
- .getMaximumSpan(View.Y_AXIS));
+ assertTrue(c.getMaximumSize().height == view.getMaximumSpan(View.Y_AXIS));
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getMaximumSpan(2);
}
});
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getMaximumSpan(-1);
}
});
-
c.setMaximumSize(new Dimension(20, 30));
if (isHarmony()) {
assertTrue(22 == view.getMaximumSpan(View.X_AXIS));
@@ -336,20 +295,19 @@
assertTrue(100 == view.getMaximumSpan(View.X_AXIS));
assertTrue(200 == view.getMaximumSpan(View.Y_AXIS));
}
-
view.setParent(null);
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.getMaximumSpan(2);
}
});
-
testExceptionalCase(new IllegalArgumentCase() {
+ @Override
public void exceptionalAction() throws Exception {
- view.getMaximumSpan(-1);
+ view.getMaximumSpan(-1);
}
});
-
c = view.getComponent();
if (isHarmony()) {
assertTrue(0 == view.getMaximumSpan(View.X_AXIS));
@@ -358,7 +316,6 @@
assertTrue(100 == view.getMaximumSpan(View.X_AXIS));
assertTrue(200 == view.getMaximumSpan(View.Y_AXIS));
}
-
view.getComponent().setMaximumSize(new Dimension(20, 30));
if (isHarmony()) {
assertTrue(0 == view.getMaximumSpan(View.X_AXIS));
@@ -371,28 +328,20 @@
public void testGetAlignment() {
JComponent jc;
-
assertTrue(View.ALIGN_CENTER == view.getAlignment(View.X_AXIS));
assertTrue(View.ALIGN_CENTER == view.getAlignment(View.Y_AXIS));
-
assertTrue(View.ALIGN_CENTER == view.getAlignment(2));
assertTrue(View.ALIGN_CENTER == view.getAlignment(-1));
-
insertedComponent.setAlignmentX(0.3f);
insertedComponent.setAlignmentY(0.6f);
-
view.setParent(textPane.getUI().getRootView(textPane));
jc = (JComponent) view.getComponent();
-
assertEquals(jc.getAlignmentX(), view.getAlignment(View.X_AXIS), 0.001);
assertEquals(jc.getAlignmentY(), view.getAlignment(View.Y_AXIS), 0.001);
-
assertTrue(View.ALIGN_CENTER == view.getAlignment(2));
assertTrue(View.ALIGN_CENTER == view.getAlignment(-1));
-
jc.setAlignmentX(0.8f);
jc.setAlignmentY(0.9f);
-
if (isHarmony()) {
assertEquals(0.8f, view.getAlignment(View.X_AXIS), 0.001);
assertEquals(0.9f, view.getAlignment(View.Y_AXIS), 0.001);
@@ -400,10 +349,8 @@
assertEquals(0.3f, view.getAlignment(View.X_AXIS), 0.001);
assertEquals(0.6f, view.getAlignment(View.Y_AXIS), 0.001);
}
-
jc.setAlignmentX(0.9f);
jc.setAlignmentY(1.0f);
-
if (isHarmony()) {
assertEquals(0.9f, view.getAlignment(View.X_AXIS), 0.001);
assertEquals(1.0f, view.getAlignment(View.Y_AXIS), 0.001);
@@ -411,9 +358,7 @@
assertEquals(0.3f, view.getAlignment(View.X_AXIS), 0.001);
assertEquals(0.6f, view.getAlignment(View.Y_AXIS), 0.001);
}
-
view.setParent(null);
-
if (isHarmony()) {
assertEquals(0.9f, view.getAlignment(View.X_AXIS), 0.001);
assertEquals(1.0f, view.getAlignment(View.Y_AXIS), 0.001);
@@ -421,7 +366,6 @@
assertEquals(0.3f, view.getAlignment(View.X_AXIS), 0.001);
assertEquals(0.6f, view.getAlignment(View.Y_AXIS), 0.001);
}
-
((JComponent) view.getComponent()).setAlignmentX(0.1f);
((JComponent) view.getComponent()).setAlignmentY(0.2f);
if (isHarmony()) {
@@ -434,30 +378,23 @@
}
public void testGetComponent() {
-
assertNull(view.getComponent());
assertNotNull(view.createComponent());
assertNull(view.getComponent());
-
view.setParent(null);
assertNull(view.getComponent());
assertNotNull(view.createComponent());
assertNull(view.getComponent());
-
view.setParent(textPane.getUI().getRootView(textPane));
Component c = view.createComponent();
assertSame(c, view.getComponent());
-
JPanel panel = new JPanel();
MutableAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setComponent(attrs, panel);
document.setCharacterAttributes(3, 1, attrs, true);
assertSame(c, view.getComponent());
-
-
view.setParent(null);
assertSame(c, view.getComponent());
-
JTextArea textArea = new JTextArea();
view.setParent(textArea.getUI().getRootView(textArea));
assertSame(c, view.getComponent());
@@ -465,91 +402,84 @@
public void testModelToView() throws BadLocationException {
testExceptionalCase(new BadLocationCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.modelToView(1, new Rectangle(), Position.Bias.Backward);
}
});
-
testExceptionalCase(new BadLocationCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.modelToView(5, new Rectangle(), Position.Bias.Forward);
}
});
-
testExceptionalCase(new BadLocationCase() {
+ @Override
public void exceptionalAction() throws Exception {
view.modelToView(500, new Rectangle(), Position.Bias.Forward);
}
});
-
Shape box;
-
- box = view.modelToView(3, new Rectangle(2, 5, 20, 30),
- Position.Bias.Backward);
+ box = view.modelToView(3, new Rectangle(2, 5, 20, 30), Position.Bias.Backward);
assertNotNull(box);
checkBounds(2, 5, 30, box);
-
- box = view.modelToView(3,
- new Rectangle(2, 3,
- insertedComponent.getWidth(),
- insertedComponent.getHeight()),
- Position.Bias.Backward);
+ box = view.modelToView(3, new Rectangle(2, 3, insertedComponent.getWidth(),
+ insertedComponent.getHeight()), Position.Bias.Backward);
assertNotNull(box);
checkBounds(2, 3, insertedComponent.getHeight(), box);
-
- box = view.modelToView(4, new Rectangle(1, 1, 16, 7),
- Position.Bias.Forward);
+ box = view.modelToView(4, new Rectangle(1, 1, 16, 7), Position.Bias.Forward);
assertNotNull(box);
checkBounds(17, 1, 7, box);
-
- box = view.modelToView(4, new Rectangle(0, 0, 1, 1),
- Position.Bias.Forward);
+ box = view.modelToView(4, new Rectangle(0, 0, 1, 1), Position.Bias.Forward);
assertNotNull(box);
checkBounds(1, 0, 1, box);
-
Ellipse2D ellipse = new Ellipse2D.Float(25, 3, 30, 40);
box = view.modelToView(4, ellipse, Position.Bias.Forward);
checkBounds(55, 3, 40, box);
-
box = view.modelToView(4, ellipse, Position.Bias.Backward);
assertNotNull(box);
-
checkBounds(55, 3, 40, box);
-
Rectangle2D rect = new Rectangle2D() {
-
- public void setRect(double x, double y,
- double width, double height) {
+ @Override
+ public void setRect(double x, double y, double width, double height) {
}
+ @Override
public int outcode(double x, double y) {
return 0;
}
+ @Override
public Rectangle2D createIntersection(Rectangle2D r) {
return null;
}
+ @Override
public Rectangle2D createUnion(Rectangle2D r) {
return null;
}
+ @Override
public double getX() {
return 1;
}
+ @Override
public double getY() {
return 2;
}
+ @Override
public double getWidth() {
return 50;
}
+ @Override
public double getHeight() {
return 60;
}
+ @Override
public boolean isEmpty() {
return false;
}
@@ -559,12 +489,9 @@
checkBounds(51, 2, 60, box);
}
-
public void testViewToModel() {
Shape shape;
-
shape = new Rectangle(4, 3, 20, 30);
-
checkViewToModel(shape, 1, 1);
checkViewToModel(shape, 1, 5);
checkViewToModel(shape, 1, 15);
@@ -574,32 +501,35 @@
checkViewToModel(shape, 16, 5);
checkViewToModel(shape, 30, 5);
checkViewToModel(shape, 46, 5);
-
final Ellipse2D floatEllipse = new Ellipse2D.Float(25, 3, 3, 4);
checkViewToModelWithEllipse(floatEllipse);
-
Ellipse2D intEllipse = new Ellipse2D() {
-
+ @Override
public double getX() {
return 25;
}
+ @Override
public double getY() {
return 3;
}
+ @Override
public double getWidth() {
return 3;
}
+ @Override
public double getHeight() {
return 4;
}
+ @Override
public boolean isEmpty() {
return false;
}
+ @Override
public void setFrame(double x, double y, double w, double h) {
return;
}
@@ -607,56 +537,54 @@
public Rectangle2D getBounds2D() {
return null;
}
-
};
checkViewToModelWithEllipse(intEllipse);
}
public void testPaint() {
-
final Marker paintCalled = new Marker();
JPanel panel = new JPanel() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
public void paint(Graphics graphics) {
throw new UnsupportedOperationException();
}
+ @Override
public void paintImmediately(Rectangle rect) {
throw new UnsupportedOperationException();
}
+ @Override
public void paintImmediately(int x, int y, int width, int height) {
throw new UnsupportedOperationException();
}
+ @Override
public void paintComponents(Graphics g) {
throw new UnsupportedOperationException();
}
+ @Override
public void paintAll(Graphics g) {
throw new UnsupportedOperationException();
}
};
-
MutableAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setComponent(attrs, panel);
document.setCharacterAttributes(3, 1, attrs, true);
-
view = new ComponentView(componentElement);
-
assertNull(view.getParent());
assertNull(view.getComponent());
paintCalled.reset();
view.paint(createTestGraphics(), new Rectangle(10, 10));
assertFalse(paintCalled.isOccurred());
-
view.setParent(textPane.getUI().getRootView(textPane));
-
paintCalled.reset();
view.paint(createTestGraphics(), new Rectangle(100, 100));
assertFalse(paintCalled.isOccurred());
-
assertSame(panel, view.getComponent());
-
view.setParent(null);
paintCalled.reset();
view.paint(createTestGraphics(), new Rectangle(10, 10));
@@ -664,33 +592,28 @@
}
public void testSetParent() {
-
final Marker getViewCountCalled = new Marker();
view = new ComponentView(componentElement) {
+ @Override
public int getViewCount() {
getViewCountCalled.setOccurred();
return super.getViewCount();
}
};
-
view.setParent(null);
assertNull(view.getComponent());
assertNull(view.getParent());
assertNull(view.getContainer());
-
view.setParent(textPane.getUI().getRootView(textPane));
-
if (isHarmony()) {
assertSame(textPane, view.getComponent().getParent());
} else {
assertSame(textPane, view.getComponent().getParent().getParent());
}
-
JTextArea textArea = new JTextArea();
view.setParent(textArea.getUI().getRootView(textArea));
assertNotNull(view.getParent());
assertNotNull(view.getContainer());
-
if (isHarmony()) {
assertSame(textPane, view.getComponent().getParent());
} else {
@@ -698,14 +621,12 @@
assertFalse(textPane.equals(view.getComponent().getParent()));
assertSame(textPane, view.getComponent().getParent().getParent());
}
-
getViewCountCalled.reset();
view.setParent(null);
assertTrue(getViewCountCalled.isOccurred());
assertNotNull(view.getComponent());
assertNull(view.getContainer());
assertNull(view.getParent());
-
if (isHarmony()) {
assertNull(view.getComponent().getParent());
} else {
@@ -713,12 +634,10 @@
assertNull(view.getComponent().getParent().getParent());
}
Component c = view.getComponent();
-
JPanel panel = new JPanel();
MutableAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setComponent(attrs, panel);
document.setCharacterAttributes(3, 1, attrs, true);
-
view.setParent(textPane.getUI().getRootView(textPane));
assertSame(c, view.getComponent());
if (isHarmony()) {
@@ -730,8 +649,7 @@
}
}
- private void checkBounds(final int x, final int y, final int height,
- final Shape box) {
+ private void checkBounds(final int x, final int y, final int height, final Shape box) {
Rectangle bounds = box.getBounds();
assertEquals(x, bounds.x);
assertEquals(y, bounds.y);
@@ -740,28 +658,28 @@
}
private void checkViewToModelWithEllipse(final Ellipse2D ellipse) {
-
if (isHarmony()) {
checkViewToModel(ellipse, 25, 15);
checkViewToModel(ellipse, 26, 5);
} else {
testExceptionalCase(new ClassCastCase() {
+ @Override
public void exceptionalAction() throws Exception {
checkViewToModel(ellipse, 25, 15);
}
});
testExceptionalCase(new ClassCastCase() {
+ @Override
public void exceptionalAction() throws Exception {
checkViewToModel(ellipse, 26, 5);
}
});
}
}
- private void checkViewToModel(final Shape shape, final int x, final int y) {
+ private void checkViewToModel(final Shape shape, final int x, final int y) {
Position.Bias[] bias = new Position.Bias[1];
int position = view.viewToModel(x, y, shape, bias);
-
if (x > shape.getBounds().width / 2 + shape.getBounds().x - 1) {
assertEquals(Position.Bias.Backward, bias[0]);
assertEquals(position, componentElement.getEndOffset());
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeViewRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeViewRTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeViewRTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeViewRTest.java Sun Nov 26 12:15:43 2006
@@ -22,22 +22,24 @@
import javax.swing.BasicSwingTestCase;
import javax.swing.text.CompositeViewTest.CompositeViewImpl;
-
import junit.framework.TestCase;
public class CompositeViewRTest extends TestCase {
- private PlainDocument doc; // Document used in tests
- private Element root; // Default root element of the document
- private CompositeView view; // View object used in tests
- private ViewFactory factory; // View factory used to create new views
+ private PlainDocument doc; // Document used in tests
+
+ private Element root; // Default root element of the document
+
+ private CompositeView view; // View object used in tests
+
+ private ViewFactory factory; // View factory used to create new views
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new PlainDocument();
doc.insertString(0, "line1\nline2\n\u05DC\u05DD\nline3\n", null);
// positions: 012345 678901 2 3 4 567890
// 0 1 2
-
view = new CompositeViewImpl(root = doc.getDefaultRootElement());
view.loadChildren(factory = new ViewFactory() {
public View create(final Element line) {
@@ -54,7 +56,6 @@
final int count = view.getViewCount();
view.replace(0, 0, null);
assertEquals(count, view.getViewCount());
-
assertTrue(count > 0);
view.replace(0, view.getViewCount(), null); // = removeAll()
assertEquals(0, view.getViewCount());
@@ -63,23 +64,18 @@
public void testReplace03() throws Exception {
View child = view.getView(0);
assertSame(view, child.getParent());
-
// This removes and places the same view at the same place
- view.replace(0, 1, new View[] {child});
-
+ view.replace(0, 1, new View[] { child });
assertSame(view, child.getParent());
}
public void testReplace04() throws Exception {
View child = view.getView(0);
assertSame(view, child.getParent());
-
View parent = new PlainView(root);
child.setParent(parent);
assertSame(parent, child.getParent());
-
view.remove(0);
-
assertSame(parent, child.getParent());
}
@@ -87,10 +83,10 @@
* <code>loadChildren</code> doesn't call <code>replace</code>.
*/
public void testLoadChildren02() {
- final boolean[] called = new boolean[] {false};
+ final boolean[] called = new boolean[] { false };
view = new CompositeViewImpl(root) {
- public void replace(final int index, final int length,
- final View[] views) {
+ @Override
+ public void replace(final int index, final int length, final View[] views) {
called[0] = true;
assertEquals(0, index);
if (BasicSwingTestCase.isHarmony()) {
@@ -102,11 +98,10 @@
super.replace(index, length, views);
}
};
-
view.loadChildren(factory);
- assertTrue(called[0]); called[0] = false;
+ assertTrue(called[0]);
+ called[0] = false;
assertEquals(root.getElementCount(), view.getViewCount());
-
assertTrue(view.getViewCount() > 0);
view.loadChildren(factory);
assertTrue(called[0]);
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=479418&r1=479417&r2=479418
==============================================================================
--- 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 Sun Nov 26 12:15:43 2006
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
/**
* @author Alexey A. Ivanov
* @version $Revision$
@@ -24,48 +23,53 @@
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Shape;
-
import javax.swing.BasicSwingTestCase;
import javax.swing.SwingConstants;
import javax.swing.text.Position.Bias;
public class CompositeViewTest extends BasicSwingTestCase {
+ private Document doc; // Document used in tests
+
+ private Element root; // Default root element of the document
+
+ private CompositeView view; // View object used in tests
+
+ private ViewFactory factory; // View factory used to create new views
- private Document doc; // Document used in tests
- private Element root; // Default root element of the document
- private CompositeView view; // View object used in tests
- private ViewFactory factory; // View factory used to create new views
- private Shape shape; // View allocation (area to render into)
- private Bias[] bias; // Place for bias return
+ private Shape shape; // View allocation (area to render into)
+
+ private Bias[] bias; // Place for bias return
private boolean childrenLoaded;
+
private int modelPosition;
/**
* Controls implementation of isAfter(), isBefore() in CompositeViewImpl.
*/
static boolean useBoth = true;
+
static boolean useX;
/**
* Just implements all abstract methods of CompositeView.
*/
protected static class CompositeViewImpl extends CompositeView {
-
public CompositeViewImpl(final Element element) {
super(element);
}
+ @Override
protected void childAllocation(final int index, final Rectangle rc) {
}
- protected View getViewAtPoint(final int x, final int y,
- final Rectangle shape) {
+ @Override
+ protected View getViewAtPoint(final int x, final int y, final Rectangle shape) {
return null;
}
- protected boolean isAfter(final int x, final int y,
- final Rectangle rc) {
+ @Override
+ protected boolean isAfter(final int x, final int y, final Rectangle rc) {
boolean result;
if (useBoth) {
result = x > rc.x + rc.width || y > rc.y + rc.height;
@@ -77,8 +81,8 @@
return result;
}
- protected boolean isBefore(final int x, final int y,
- final Rectangle rc) {
+ @Override
+ protected boolean isBefore(final int x, final int y, final Rectangle rc) {
boolean result;
if (useBoth) {
result = x < rc.x || y < rc.y;
@@ -90,9 +94,11 @@
return result;
}
+ @Override
public void paint(final Graphics g, final Shape shape) {
}
+ @Override
public float getPreferredSpan(final int axis) {
return 0;
}
@@ -101,13 +107,13 @@
/*
* @see TestCase#setUp()
*/
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new PlainDocument();
doc.insertString(0, "line1\nline2\n\u05DC\u05DD\nline3\n", null);
// positions: 012345 678901 2 3 4 567890
// 0 1 2
-
view = new CompositeViewImpl(root = doc.getDefaultRootElement());
view.loadChildren(factory = new ViewFactory() {
public View create(final Element line) {
@@ -120,45 +126,39 @@
public void testGetChildAllocation() {
final class Params {
- boolean called;
- int index;
+ boolean called;
+
+ int index;
+
Rectangle rc;
public void check(final int i, final Rectangle r) {
assertTrue(called);
assertEquals(i, index);
-
if (r != null) {
assertEquals(rc, r);
}
-
called = false;
}
}
-
final Params params = new Params();
-
view = new CompositeViewImpl(root) {
- protected void childAllocation(final int index,
- final Rectangle rc) {
+ @Override
+ protected void childAllocation(final int index, final Rectangle rc) {
params.called = true;
- params.index = index;
- params.rc = rc;
+ params.index = index;
+ params.rc = rc;
}
};
// Make insets
view.setParagraphInsets(getAttributeSet());
-
assertNull(view.getChildAllocation(0, null));
params.check(0, null);
-
Shape alloc = view.getChildAllocation(1, shape);
// The shape parameter is passed through getInsideAllocation
params.check(1, new Rectangle(7, 0, 100 - 7 - 4, 200 - 5));
assertSame(params.rc, alloc);
-
- assertSame(alloc,
- view.getChildAllocation(1, new Rectangle(0, 0, 300, 200)));
+ assertSame(alloc, view.getChildAllocation(1, new Rectangle(0, 0, 300, 200)));
}
/**
@@ -167,37 +167,26 @@
public void testReplace01() throws BadLocationException {
int count = root.getElementCount();
assertEquals(count, view.getViewCount());
-
- int end = root.getElement(0).getEndOffset();
+ int end = root.getElement(0).getEndOffset();
doc.insertString(0, "\nnew1\nnew2", null); // inserted 10 chars
-
- View[] views = new View[] {
- new PlainView(root.getElement(0)),
- new PlainView(root.getElement(1))
- };
-
+ View[] views = new View[] { new PlainView(root.getElement(0)),
+ new PlainView(root.getElement(1)) };
View[] removed = new View[count - 1 - 1];
for (int i = 0, index = 1; i < removed.length; i++, index++) {
removed[i] = view.getView(index);
assertSame(view, removed[i].getParent());
}
-
view.replace(1, count - 1, views);
-
assertEquals(3, view.getViewCount()); // removed all except [0], added 2
-
// Check first item is not deleted
assertEquals(0, view.getView(0).getStartOffset());
assertEquals(end + 10, view.getView(0).getEndOffset());
-
// Check other items
assertSame(views[0], view.getView(1));
assertSame(views[1], view.getView(2));
-
// Check parents of views added
assertSame(view, views[0].getParent());
assertSame(view, views[1].getParent());
-
// Check removed views have no parent
for (int i = 0; i < removed.length; i++) {
assertNull(removed[i].getParent());
@@ -208,19 +197,17 @@
assertSame(root.getElement(0), view.getView(0).getElement());
assertTrue(view.getView(0) instanceof PlainView);
assertSame(root.getElement(1), view.getView(1).getElement());
-
// Invalid indexes
try {
view.getView(-1);
-
fail("ArrayIndexOutOfBoundsException must be thrown");
- } catch (ArrayIndexOutOfBoundsException e) { }
-
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
try {
view.getView(view.getViewCount());
-
fail("ArrayIndexOutOfBoundsException must be thrown");
- } catch (ArrayIndexOutOfBoundsException e) { }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
}
public void testGetViewCount() {
@@ -229,6 +216,7 @@
public void testSetParent() {
view = new CompositeViewImpl(root) {
+ @Override
protected void loadChildren(final ViewFactory factory) {
childrenLoaded = true;
assertSame(getViewFactory(), factory);
@@ -236,16 +224,15 @@
}
};
View parent = new PlainView(root.getElement(0)) {
+ @Override
public ViewFactory getViewFactory() {
return factory;
}
};
-
assertFalse(childrenLoaded);
view.setParent(parent);
assertTrue(childrenLoaded);
assertSame(parent, view.getParent());
-
// Call setParent one more time
childrenLoaded = false;
view.setParent(new PlainView(root));
@@ -255,6 +242,7 @@
public void testSetParentNull() throws Exception {
view = new CompositeViewImpl(root) {
+ @Override
protected void loadChildren(final ViewFactory factory) {
childrenLoaded = true;
assertSame(getViewFactory(), factory);
@@ -269,6 +257,7 @@
public void testSetParentNoViewFactory() throws Exception {
view = new CompositeViewImpl(root) {
+ @Override
protected void loadChildren(final ViewFactory factory) {
childrenLoaded = true;
assertNull(factory);
@@ -297,10 +286,8 @@
assertEquals(30 + 0, rc.y);
assertEquals(50 - 7 - 4, rc.width);
assertEquals(40 - 0 - 5, rc.height);
-
// Returns the same instance whenever called
assertSame(rc, view.getInsideAllocation(new Rectangle(rc)));
-
assertNull(view.getInsideAllocation(null));
}
@@ -315,94 +302,86 @@
super(element);
}
- int offset;
- Position.Bias bias;
- Shape shape;
- int dir;
- boolean isEastWest;
- boolean isNorthSouth;
+ int offset;
- protected int getNextEastWestVisualPositionFrom(final int pos,
- final Position.Bias b, final Shape a, final int direction,
- final Position.Bias[] biasRet) {
+ Position.Bias bias;
- isEastWest = true;
- isNorthSouth = false;
+ Shape shape;
- offset = pos;
- bias = b;
- shape = a;
- dir = direction;
+ int dir;
+
+ boolean isEastWest;
+ boolean isNorthSouth;
+
+ @Override
+ protected int getNextEastWestVisualPositionFrom(final int pos,
+ final Position.Bias b, final Shape a, final int direction,
+ final Position.Bias[] biasRet) {
+ isEastWest = true;
+ isNorthSouth = false;
+ offset = pos;
+ bias = b;
+ shape = a;
+ dir = direction;
return 0;
}
+ @Override
protected int getNextNorthSouthVisualPositionFrom(final int pos,
- final Position.Bias b, final Shape a, final int direction,
- final Position.Bias[] biasRet) {
-
- isEastWest = false;
+ final Position.Bias b, final Shape a, final int direction,
+ final Position.Bias[] biasRet) {
+ isEastWest = false;
isNorthSouth = true;
-
offset = pos;
- bias = b;
- shape = a;
- dir = direction;
-
+ bias = b;
+ shape = a;
+ dir = direction;
return 0;
}
-
}
-
CompositeViewNextPos view = new CompositeViewNextPos(root);
-
- view.getNextVisualPositionFrom(0, Bias.Backward, shape,
- SwingConstants.EAST, bias);
- assertTrue(view.isEastWest); view.isEastWest = false;
+ view.getNextVisualPositionFrom(0, Bias.Backward, shape, SwingConstants.EAST, bias);
+ assertTrue(view.isEastWest);
+ view.isEastWest = false;
assertFalse(view.isNorthSouth);
assertEquals(0, view.offset);
assertSame(Bias.Backward, view.bias);
assertSame(shape, view.shape);
assertEquals(SwingConstants.EAST, view.dir);
-
- view.getNextVisualPositionFrom(5, Bias.Forward, shape,
- SwingConstants.WEST, bias);
- assertTrue(view.isEastWest); view.isEastWest = false;
+ view.getNextVisualPositionFrom(5, Bias.Forward, shape, SwingConstants.WEST, bias);
+ assertTrue(view.isEastWest);
+ view.isEastWest = false;
assertFalse(view.isNorthSouth);
assertEquals(5, view.offset);
assertSame(Bias.Forward, view.bias);
assertSame(shape, view.shape);
assertEquals(SwingConstants.WEST, view.dir);
-
// Vertical directions
-
- view.getNextVisualPositionFrom(1, Bias.Backward, shape,
- SwingConstants.SOUTH, bias);
+ view.getNextVisualPositionFrom(1, Bias.Backward, shape, SwingConstants.SOUTH, bias);
assertFalse(view.isEastWest);
- assertTrue(view.isNorthSouth); view.isNorthSouth = false;
+ assertTrue(view.isNorthSouth);
+ view.isNorthSouth = false;
assertEquals(1, view.offset);
assertSame(Bias.Backward, view.bias);
assertSame(shape, view.shape);
assertEquals(SwingConstants.SOUTH, view.dir);
-
- view.getNextVisualPositionFrom(0, Bias.Forward, shape,
- SwingConstants.NORTH, bias);
+ view.getNextVisualPositionFrom(0, Bias.Forward, shape, SwingConstants.NORTH, bias);
assertFalse(view.isEastWest);
- assertTrue(view.isNorthSouth); view.isNorthSouth = false;
+ assertTrue(view.isNorthSouth);
+ view.isNorthSouth = false;
assertEquals(0, view.offset);
assertSame(Bias.Forward, view.bias);
assertSame(shape, view.shape);
assertEquals(SwingConstants.NORTH, view.dir);
-
try {
- view.getNextVisualPositionFrom(0, Bias.Backward, shape,
- SwingConstants.NORTH_EAST, bias);
-
+ view.getNextVisualPositionFrom(0, Bias.Backward, shape, SwingConstants.NORTH_EAST,
+ bias);
fail("IllegalArgumentException must be thrown");
- } catch (IllegalArgumentException e) { }
+ } catch (IllegalArgumentException e) {
+ }
}
-
public void testFlipEastAndWestAtEnds() {
assertFalse(view.flipEastAndWestAtEnds(0, Position.Bias.Backward));
}
@@ -435,6 +414,7 @@
public void testGetViewIndexintBias() {
final Marker marker = new Marker(true);
view = new CompositeViewImpl(root) {
+ @Override
protected int getViewIndexAtPosition(final int pos) {
marker.setOccurred();
modelPosition = pos;
@@ -442,28 +422,18 @@
}
};
view.loadChildren(factory);
-
-
// Before document beginning
-
assertEquals(-1, view.getViewIndex(-1, Bias.Forward));
assertFalse(marker.isOccurred());
assertEquals(-1, view.getViewIndex(-1, Bias.Backward));
assertFalse(marker.isOccurred());
-
-
// The first position (0)
-
view.getViewIndex(0, Bias.Forward);
assertTrue(marker.isOccurred());
assertEquals(0, modelPosition);
-
assertEquals(-1, view.getViewIndex(0, Bias.Backward));
assertFalse(marker.isOccurred());
-
-
// In the middle
-
view.getViewIndex(4, Bias.Forward);
assertTrue(marker.isOccurred());
assertEquals(4, modelPosition);
@@ -476,10 +446,7 @@
view.getViewIndex(7, Bias.Backward);
assertTrue(marker.isOccurred());
assertEquals(6, modelPosition);
-
-
// At an edge
-
view.getViewIndex(5, Bias.Forward);
assertTrue(marker.isOccurred());
assertEquals(5, modelPosition);
@@ -492,22 +459,16 @@
view.getViewIndex(6, Bias.Backward);
assertTrue(marker.isOccurred());
assertEquals(5, modelPosition);
-
-
// In the end
-
final int lastOffset = doc.getLength();
-
view.getViewIndex(doc.getLength(), Bias.Forward);
assertTrue(marker.isOccurred());
assertEquals(doc.getLength(), modelPosition);
view.getViewIndex(doc.getLength(), Bias.Backward);
assertTrue(marker.isOccurred());
assertEquals(lastOffset - 1, modelPosition);
-
assertEquals(-1, view.getViewIndex(doc.getLength() + 3, Bias.Forward));
assertFalse(marker.isOccurred());
-
assertEquals(-1, view.getViewIndex(doc.getLength() + 3, Bias.Backward));
assertFalse(marker.isOccurred());
}
@@ -520,27 +481,24 @@
*/
public void testGetViewIndexintBiasNotRoot() throws BadLocationException {
doc = new DefaultStyledDocument();
-
final MutableAttributeSet bold = new SimpleAttributeSet();
StyleConstants.setBold(bold, true);
final MutableAttributeSet italic = new SimpleAttributeSet();
StyleConstants.setItalic(italic, true);
-
- doc.insertString(doc.getLength(), "line1\n", null); // 0 (6)
- doc.insertString(doc.getLength(), "plain", null); // 6 (5) [ 6, 11]
- doc.insertString(doc.getLength(), "bold", bold); // 11 (4) [11, 15]
- doc.insertString(doc.getLength(), "italic", italic); // 15 (6) [15, 21]
+ doc.insertString(doc.getLength(), "line1\n", null); // 0 (6)
+ doc.insertString(doc.getLength(), "plain", null); // 6 (5) [ 6, 11]
+ doc.insertString(doc.getLength(), "bold", bold); // 11 (4) [11, 15]
+ doc.insertString(doc.getLength(), "italic", italic); // 15 (6) [15, 21]
doc.insertString(doc.getLength(), "\nline3: ", null); // 21 (8) [21, 22]
- doc.insertString(doc.getLength(), "bold2", bold); // 29 (5)
-
+ doc.insertString(doc.getLength(), "bold2", bold); // 29 (5)
root = doc.getDefaultRootElement();
final Element paragraph = root.getElement(1);
assertEquals(4, paragraph.getElementCount());
assertEquals(6, paragraph.getStartOffset());
assertEquals(22, paragraph.getEndOffset());
-
final Marker marker = new Marker(true);
view = new CompositeViewImpl(paragraph) {
+ @Override
protected int getViewIndexAtPosition(final int pos) {
marker.setOccurred();
modelPosition = pos;
@@ -549,94 +507,71 @@
};
// Init the view by adding children
view.loadChildren(factory);
-
-
// Before document beginning
-
assertEquals(-1, view.getViewIndex(-1, Bias.Forward));
assertFalse(marker.isOccurred());
assertEquals(-1, view.getViewIndex(-1, Bias.Backward));
assertFalse(marker.isOccurred());
-
-
// Before the start offset (6)
-
assertEquals(-1, view.getViewIndex(0, Bias.Forward));
assertFalse(marker.isOccurred());
assertEquals(-1, view.getViewIndex(0, Bias.Backward));
assertFalse(marker.isOccurred());
-
assertEquals(-1, view.getViewIndex(3, Bias.Forward));
assertFalse(marker.isOccurred());
assertEquals(-1, view.getViewIndex(3, Bias.Backward));
assertFalse(marker.isOccurred());
-
-
// At the start offset (6)
-
assertEquals(-1, view.getViewIndex(5, Bias.Forward));
assertFalse(marker.isOccurred());
assertEquals(-1, view.getViewIndex(5, Bias.Backward));
assertFalse(marker.isOccurred());
-
assertEquals(-10101, view.getViewIndex(6, Bias.Forward));
assertTrue(marker.isOccurred());
assertEquals(6, modelPosition);
assertEquals(-1, view.getViewIndex(6, Bias.Backward));
assertFalse(marker.isOccurred());
-
assertEquals(-10101, view.getViewIndex(7, Bias.Forward));
assertTrue(marker.isOccurred());
assertEquals(7, modelPosition);
assertEquals(-10101, view.getViewIndex(7, Bias.Backward));
assertTrue(marker.isOccurred());
assertEquals(6, modelPosition);
-
-
// At an edge
-
view.getViewIndex(10, Bias.Forward);
assertTrue(marker.isOccurred());
assertEquals(10, modelPosition);
view.getViewIndex(10, Bias.Backward);
assertTrue(marker.isOccurred());
assertEquals(9, modelPosition);
-
view.getViewIndex(11, Bias.Forward);
assertTrue(marker.isOccurred());
assertEquals(11, modelPosition);
view.getViewIndex(11, Bias.Backward);
assertTrue(marker.isOccurred());
assertEquals(10, modelPosition);
-
view.getViewIndex(12, Bias.Forward);
assertTrue(marker.isOccurred());
assertEquals(12, modelPosition);
view.getViewIndex(12, Bias.Backward);
assertTrue(marker.isOccurred());
assertEquals(11, modelPosition);
-
-
// In the end
-
view.getViewIndex(21, Bias.Forward);
assertTrue(marker.isOccurred());
assertEquals(21, modelPosition);
view.getViewIndex(21, Bias.Backward);
assertTrue(marker.isOccurred());
assertEquals(20, modelPosition);
-
assertEquals(-1, view.getViewIndex(22, Bias.Forward));
assertFalse(marker.isOccurred());
assertEquals(-10101, view.getViewIndex(22, Bias.Backward));
assertTrue(marker.isOccurred());
assertEquals(21, modelPosition);
-
assertEquals(-1, view.getViewIndex(23, Bias.Forward));
assertFalse(marker.isOccurred());
assertEquals(-1, view.getViewIndex(23, Bias.Backward));
assertFalse(marker.isOccurred());
-
assertEquals(-1, view.getViewIndex(24, Bias.Forward));
assertFalse(marker.isOccurred());
assertEquals(-1, view.getViewIndex(24, Bias.Backward));
@@ -650,112 +585,85 @@
assertEquals(1, view.getViewIndexAtPosition(6));
assertEquals(1, view.getViewIndexAtPosition(11));
assertEquals(2, view.getViewIndexAtPosition(12));
- assertEquals(view.getViewCount() - 1,
- view.getViewIndexAtPosition(doc.getLength()));
- assertEquals(view.getViewCount() - 1,
- view.getViewIndexAtPosition(doc.getLength() + 2));
+ assertEquals(view.getViewCount() - 1, view.getViewIndexAtPosition(doc.getLength()));
+ assertEquals(view.getViewCount() - 1, view.getViewIndexAtPosition(doc.getLength() + 2));
}
- public void testGetViewIndexAtPositionNotRoot()
- throws BadLocationException {
-
+ public void testGetViewIndexAtPositionNotRoot() throws BadLocationException {
doc = new DefaultStyledDocument();
-
final MutableAttributeSet bold = new SimpleAttributeSet();
StyleConstants.setBold(bold, true);
final MutableAttributeSet italic = new SimpleAttributeSet();
StyleConstants.setItalic(italic, true);
-
- doc.insertString(doc.getLength(), "line1\n", null); // 0 (6)
- doc.insertString(doc.getLength(), "plain", null); // 6 (5)
- doc.insertString(doc.getLength(), "bold", bold); // 11 (4)
- doc.insertString(doc.getLength(), "italic", italic); // 15 (6)
+ doc.insertString(doc.getLength(), "line1\n", null); // 0 (6)
+ doc.insertString(doc.getLength(), "plain", null); // 6 (5)
+ doc.insertString(doc.getLength(), "bold", bold); // 11 (4)
+ doc.insertString(doc.getLength(), "italic", italic); // 15 (6)
doc.insertString(doc.getLength(), "\nline3: ", null); // 21 (8) / 22
- doc.insertString(doc.getLength(), "bold2", bold); // 29 (5)
-
+ doc.insertString(doc.getLength(), "bold2", bold); // 29 (5)
root = doc.getDefaultRootElement();
final Element paragraph = root.getElement(1);
assertEquals(4, paragraph.getElementCount());
assertEquals(6, paragraph.getStartOffset());
assertEquals(22, paragraph.getEndOffset());
-
view = new CompositeViewImpl(paragraph);
view.loadChildren(factory);
-
assertEquals(0, view.getViewIndexAtPosition(-1));
assertEquals(0, view.getViewIndexAtPosition(0));
-
assertEquals(0, view.getViewIndexAtPosition(5));
assertEquals(0, view.getViewIndexAtPosition(6));
assertEquals(0, view.getViewIndexAtPosition(7));
-
assertEquals(0, view.getViewIndexAtPosition(10));
assertEquals(1, view.getViewIndexAtPosition(11));
assertEquals(1, view.getViewIndexAtPosition(12));
-
assertEquals(1, view.getViewIndexAtPosition(14));
assertEquals(2, view.getViewIndexAtPosition(15));
assertEquals(2, view.getViewIndexAtPosition(16));
-
assertEquals(3, view.getViewIndexAtPosition(21));
assertEquals(3, view.getViewIndexAtPosition(22));
assertEquals(3, view.getViewIndexAtPosition(23));
-
assertEquals(3, view.getViewIndexAtPosition(doc.getLength()));
}
public void testGetViewAtPosition() {
Rectangle alloc;
-
alloc = view.getInsideAllocation(shape);
assertSame(view.getView(0), view.getViewAtPosition(-1, alloc));
assertEquals(alloc, view.getChildAllocation(-1, shape));
-
alloc = view.getInsideAllocation(shape);
assertSame(view.getView(0), view.getViewAtPosition(0, alloc));
assertEquals(alloc, view.getChildAllocation(0, shape));
-
alloc = view.getInsideAllocation(shape);
assertSame(view.getView(0), view.getViewAtPosition(5, alloc));
assertEquals(alloc, view.getChildAllocation(5, shape));
-
alloc = view.getInsideAllocation(shape);
assertSame(view.getView(1), view.getViewAtPosition(6, alloc));
assertEquals(alloc, view.getChildAllocation(6, shape));
-
alloc = view.getInsideAllocation(shape);
assertSame(view.getView(1), view.getViewAtPosition(11, alloc));
assertEquals(alloc, view.getChildAllocation(11, shape));
-
alloc = view.getInsideAllocation(shape);
assertSame(view.getView(2), view.getViewAtPosition(12, alloc));
assertEquals(alloc, view.getChildAllocation(12, shape));
-
alloc = view.getInsideAllocation(shape);
- assertSame(view.getView(view.getViewCount() - 1),
- view.getViewAtPosition(doc.getLength(), alloc));
+ assertSame(view.getView(view.getViewCount() - 1), view.getViewAtPosition(doc
+ .getLength(), alloc));
assertEquals(alloc, view.getChildAllocation(doc.getLength(), shape));
}
-
/**
* Keys for attribute set creation.
*/
- private static Object[] keys = {
- StyleConstants.SpaceAbove,
- StyleConstants.LeftIndent,
- StyleConstants.SpaceBelow,
- StyleConstants.RightIndent
- };
+ private static Object[] keys = { StyleConstants.SpaceAbove, StyleConstants.LeftIndent,
+ StyleConstants.SpaceBelow, StyleConstants.RightIndent };
/**
* Values for attribute set creation.
*/
- private static Object[] values = {
- new Float(0.1f), // top inset
- new Float(7.0f), // left
- new Float(5.3f), // bottom
- new Float(4.7f) // right
+ private static Object[] values = { new Float(0.1f), // top inset
+ new Float(7.0f), // left
+ new Float(5.3f), // bottom
+ new Float(4.7f) // right
};
/**
@@ -768,11 +676,9 @@
*/
static AttributeSet getAttributeSet(final int start, final int end) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
-
for (int i = start; i < end; i++) {
attrs.addAttribute(keys[i], values[i]);
}
-
return attrs;
}
@@ -821,13 +727,12 @@
* @param bottom expected bottom inset
* @param right expected right inset
*/
- private void assertInsets(final short top, final short left,
- final short bottom,
+ private void assertInsets(final short top, final short left, final short bottom,
final short right) {
- assertEquals("Top", top, view.getTopInset());
- assertEquals("Left", left, view.getLeftInset());
+ assertEquals("Top", top, view.getTopInset());
+ assertEquals("Left", left, view.getLeftInset());
assertEquals("Bottom", bottom, view.getBottomInset());
- assertEquals("Right", right, view.getRightInset());
+ assertEquals("Right", right, view.getRightInset());
}
/**
@@ -839,14 +744,13 @@
* @param bottom expected bottom inset
* @param right expected right inset
*/
- private void assertInsets(final int top, final int left, final int bottom,
- final int right) {
- assertInsets((short)top, (short)left, (short)bottom, (short)right);
+ private void assertInsets(final int top, final int left, final int bottom, final int right) {
+ assertInsets((short) top, (short) left, (short) bottom, (short) right);
}
public void testSetInsets() {
assertInsets(0, 0, 0, 0);
- view.setInsets((short)5, (short)10, (short)7, (short)13);
+ view.setInsets((short) 5, (short) 10, (short) 7, (short) 13);
assertInsets(5, 10, 7, 13);
}
@@ -854,5 +758,4 @@
view.setParagraphInsets(getAttributeSet());
assertInsets(0, 7, 5, 4);
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeView_ModelViewTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeView_ModelViewTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeView_ModelViewTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeView_ModelViewTest.java Sun Nov 26 12:15:43 2006
@@ -24,12 +24,10 @@
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Shape;
-
import javax.swing.BasicSwingTestCase;
import javax.swing.text.AbstractDocument.BranchElement;
import javax.swing.text.CompositeViewTest.CompositeViewImpl;
import javax.swing.text.Position.Bias;
-
import junit.framework.TestCase;
/**
@@ -37,30 +35,38 @@
*
*/
public class CompositeView_ModelViewTest extends TestCase {
+ static PlainDocument doc; // Document used in tests
+
+ static Element root; // Default root element of the document
+
+ static CompositeView view; // View object used in tests
- static PlainDocument doc; // Document used in tests
- static Element root; // Default root element of the document
- static CompositeView view; // View object used in tests
- static ViewFactory factory; // View factory used to create new views
- static Shape shape; // View allocation (area to render into)
- static Bias[] bias; // Place for bias return
+ static ViewFactory factory; // View factory used to create new views
+
+ static Shape shape; // View allocation (area to render into)
+
+ static Bias[] bias; // Place for bias return
/**
* View which passed as parameter to modelToView or viewToModel method.
*/
- private static View viewAsked;
+ private static View viewAsked;
+
/**
* Shape which passed as parameter to modelToView or viewToModel method.
*/
- private static Shape shapeAsked;
+ private static Shape shapeAsked;
+
/**
* Width of one position in the view.
*/
- static final int POS_WIDTH = 4;
+ static final int POS_WIDTH = 4;
+
/**
* Height of one child view, or line.
*/
static final int LINE_HEIGHT = 16;
+
/**
* Stores the same value as <code>shape</code> but with different
* type. Actually <code>bounds</code> and <code>shape</code>
@@ -76,15 +82,16 @@
super(element);
}
+ @Override
protected void childAllocation(final int index, final Rectangle rc) {
// The each view allocation is LINE_HEIGHT in height and
// represents a line-like rectangle
- rc.y = ((Rectangle)shape).y + LINE_HEIGHT * index;
+ rc.y = ((Rectangle) shape).y + LINE_HEIGHT * index;
rc.height = LINE_HEIGHT;
}
- protected View getViewAtPoint(final int x, final int y,
- final Rectangle rc) {
+ @Override
+ protected View getViewAtPoint(final int x, final int y, final Rectangle rc) {
int index = getViewIndex(x, y, rc);
if (index != -1) {
childAllocation(index, rc);
@@ -102,16 +109,18 @@
super(element);
}
- public int viewToModel(float x, final float y,
- final Shape shape, final Bias[] biasReturn) {
+ @Override
+ public int viewToModel(float x, final float y, final Shape shape,
+ final Bias[] biasReturn) {
assertTrue(shape.contains(x, y));
viewAsked = this;
shapeAsked = shape;
Rectangle rect = shape.getBounds();
x -= rect.x;
- return getStartOffset() + (int)x / POS_WIDTH;
+ return getStartOffset() + (int) x / POS_WIDTH;
}
+ @Override
public Shape modelToView(int pos, final Shape shape, final Bias bias)
throws BadLocationException {
Rectangle bounds = shape.getBounds();
@@ -121,9 +130,11 @@
return new Rectangle(bounds.x + pos * POS_WIDTH, bounds.y, 1, 16);
}
+ @Override
public void paint(final Graphics g, final Shape shape) {
}
+ @Override
public float getPreferredSpan(final int axis) {
return 0;
}
@@ -138,122 +149,96 @@
}
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new PlainDocument();
doc.insertString(0, "line1\nline2\n\u05DC\u05DD\nline3\n", null);
// positions: 012345 678901 2 3 4 567890
// 0 1 2
-
root = doc.getDefaultRootElement();
view = new WithChildrenView(root);
-
view.loadChildren(factory = new ChildFactory());
- shape = new Rectangle(100, 200, 190, 560);
- bounds = (Rectangle)shape;
+ shape = new Rectangle(100, 200, 190, 560);
+ bounds = (Rectangle) shape;
bias = new Position.Bias[1];
}
- private Rectangle getChildRect(final int index)
- throws BadLocationException {
-
+ private Rectangle getChildRect(final int index) throws BadLocationException {
View child = view.getView(index);
-
- return (Rectangle)child.modelToView(child.getStartOffset(),
- Bias.Forward,
- child.getEndOffset(), Bias.Forward,
- view.getChildAllocation(index, shape));
+ return (Rectangle) child.modelToView(child.getStartOffset(), Bias.Forward, child
+ .getEndOffset(), Bias.Forward, view.getChildAllocation(index, shape));
}
/*
* Class under test for Shape modelToView(int, Bias, int, Bias, Shape)
*/
- public void testModelToViewintBiasintBiasShape()
- throws BadLocationException {
-
+ public void testModelToViewintBiasintBiasShape() throws BadLocationException {
Shape res;
Rectangle rc1;
Rectangle rc2;
-
// Same positions
res = view.modelToView(0, Bias.Forward, 0, Bias.Forward, shape);
assertEquals(view.modelToView(0, shape, Bias.Forward), res);
-
// Both Forward
- rc1 = (Rectangle)view.modelToView(0, shape, Bias.Forward);
- rc2 = (Rectangle)view.modelToView(1, shape, Bias.Forward);
+ rc1 = (Rectangle) view.modelToView(0, shape, Bias.Forward);
+ rc2 = (Rectangle) view.modelToView(1, shape, Bias.Forward);
res = view.modelToView(0, Bias.Forward, 1, Bias.Forward, shape);
assertEquals(rc1.union(rc2), res);
-
- rc1 = (Rectangle)view.modelToView(0, shape, Bias.Forward);
- rc2 = (Rectangle)view.modelToView(2, shape, Bias.Forward);
+ rc1 = (Rectangle) view.modelToView(0, shape, Bias.Forward);
+ rc2 = (Rectangle) view.modelToView(2, shape, Bias.Forward);
res = view.modelToView(0, Bias.Forward, 2, Bias.Forward, shape);
assertEquals(rc1.union(rc2), res);
-
// Different biases
- rc1 = (Rectangle)view.modelToView(0, shape, Bias.Forward);
- rc2 = (Rectangle)view.modelToView(2, shape, Bias.Forward);
+ rc1 = (Rectangle) view.modelToView(0, shape, Bias.Forward);
+ rc2 = (Rectangle) view.modelToView(2, shape, Bias.Forward);
res = view.modelToView(0, Bias.Forward, 2, Bias.Backward, shape);
assertEquals(rc1.union(rc2), res);
-
// On different lines
- rc1 = (Rectangle)view.getView(0).modelToView(6, shape,
- Bias.Forward);
- rc2 = (Rectangle)view.modelToView(6, shape, Bias.Forward);
+ rc1 = (Rectangle) view.getView(0).modelToView(6, shape, Bias.Forward);
+ rc2 = (Rectangle) view.modelToView(6, shape, Bias.Forward);
res = view.modelToView(0, Bias.Forward, 6, Bias.Forward, shape);
assertEquals(rc1.union(rc2), res);
-
rc1 = getChildRect(0);
- rc2 = (Rectangle)view.modelToView(7, shape, Bias.Forward);
+ rc2 = (Rectangle) view.modelToView(7, shape, Bias.Forward);
res = view.modelToView(0, Bias.Forward, 7, Bias.Forward, shape);
assertEquals(rc1.union(rc2), res);
-
// Assert both previous cases return the same value
- assertEquals(view.modelToView(0, Bias.Forward,
- 6, Bias.Forward, shape),
- view.modelToView(0, Bias.Forward,
- 7, Bias.Forward, shape));
-
+ assertEquals(view.modelToView(0, Bias.Forward, 6, Bias.Forward, shape), view
+ .modelToView(0, Bias.Forward, 7, Bias.Forward, shape));
// When range doesn't include first line start
rc1 = getChildRect(0);
- rc2 = (Rectangle)view.modelToView(9, shape, Bias.Forward);
+ rc2 = (Rectangle) view.modelToView(9, shape, Bias.Forward);
res = view.modelToView(2, Bias.Forward, 7, Bias.Forward, shape);
assertEquals(rc1.union(rc2), res);
-
-
// Both on line 2
- rc1 = (Rectangle)view.modelToView(7, shape, Bias.Forward);
- rc2 = (Rectangle)view.modelToView(9, shape, Bias.Forward);
+ rc1 = (Rectangle) view.modelToView(7, shape, Bias.Forward);
+ rc2 = (Rectangle) view.modelToView(9, shape, Bias.Forward);
res = view.modelToView(7, Bias.Forward, 9, Bias.Forward, shape);
assertEquals(rc1.union(rc2), res);
-
-
// From line 1 to line 3
// TODO investigate more carefully modelToView(int, B, int, B, Shape)
-// Can't use this code 'cause view.getChildAllocation(1, shape) and
-// view.getChildAllocation(2, shape) return the same instance of
-// rectangles, tho' the instances MUST be different acc. to the spec
-//
-// rc1 = (Rectangle)view.getChildAllocation(1, shape);
-// rc1 = rc1.union((Rectangle)view.getChildAllocation(2, shape));
-// rc1 = rc1.union((Rectangle)view.getChildAllocation(3, shape));
-//
-// The work around is to get child allocations from the inside but
-// not the public interface
-
+ // Can't use this code 'cause view.getChildAllocation(1, shape) and
+ // view.getChildAllocation(2, shape) return the same instance of
+ // rectangles, tho' the instances MUST be different acc. to the spec
+ //
+ // rc1 = (Rectangle)view.getChildAllocation(1, shape);
+ // rc1 = rc1.union((Rectangle)view.getChildAllocation(2, shape));
+ // rc1 = rc1.union((Rectangle)view.getChildAllocation(3, shape));
+ //
+ // The work around is to get child allocations from the inside but
+ // not the public interface
rc1 = shape.getBounds();
view.childAllocation(0, rc1);
rc2 = shape.getBounds();
view.childAllocation(2, rc2);
res = view.modelToView(1, Bias.Forward, 13, Bias.Forward, shape);
assertEquals(rc1.union(rc2), res);
-
// From line 2 to line 3
rc1 = getChildRect(1);
- rc2 = (Rectangle)view.modelToView(13, shape, Bias.Forward);
+ rc2 = (Rectangle) view.modelToView(13, shape, Bias.Forward);
res = view.modelToView(9, Bias.Forward, 13, Bias.Forward, shape);
assertEquals(rc1.union(rc2), res);
-
// From line 2 to line 4
rc1 = shape.getBounds();
view.childAllocation(1, rc1);
@@ -268,37 +253,24 @@
* Class under test for Shape modelToView(int, Shape, Bias)
*/
public void testModelToViewintShapeBias() throws BadLocationException {
- assertEquals(new Rectangle(bounds.x, bounds.y, 1, LINE_HEIGHT),
- view.modelToView(0, shape, Bias.Forward));
+ assertEquals(new Rectangle(bounds.x, bounds.y, 1, LINE_HEIGHT), view.modelToView(0,
+ shape, Bias.Forward));
assertSame(view.getView(0), viewAsked);
-
-
- assertEquals(new Rectangle(bounds.x + 3 * POS_WIDTH, bounds.y,
- 1, LINE_HEIGHT),
- view.modelToView(3, shape, Bias.Forward));
+ assertEquals(new Rectangle(bounds.x + 3 * POS_WIDTH, bounds.y, 1, LINE_HEIGHT), view
+ .modelToView(3, shape, Bias.Forward));
assertSame(view.getView(0), viewAsked);
- assertEquals(LINE_HEIGHT, ((Rectangle)shapeAsked).height);
- assertEquals(bounds.y, ((Rectangle)shapeAsked).y);
-
-
- assertEquals(new Rectangle(bounds.x + 1 * POS_WIDTH,
- bounds.y + LINE_HEIGHT,
- 1,
- LINE_HEIGHT),
- view.modelToView(7, shape, Bias.Forward));
+ assertEquals(LINE_HEIGHT, ((Rectangle) shapeAsked).height);
+ assertEquals(bounds.y, ((Rectangle) shapeAsked).y);
+ assertEquals(new Rectangle(bounds.x + 1 * POS_WIDTH, bounds.y + LINE_HEIGHT, 1,
+ LINE_HEIGHT), view.modelToView(7, shape, Bias.Forward));
assertSame(view.getView(1), viewAsked);
- assertEquals(LINE_HEIGHT, ((Rectangle)shapeAsked).height);
- assertEquals(bounds.y + LINE_HEIGHT, ((Rectangle)shapeAsked).y);
-
-
- assertEquals(new Rectangle(bounds.x + 2 * POS_WIDTH,
- bounds.y + 3 * LINE_HEIGHT,
- 1,
- LINE_HEIGHT),
- view.modelToView(17, shape, Bias.Forward));
+ assertEquals(LINE_HEIGHT, ((Rectangle) shapeAsked).height);
+ assertEquals(bounds.y + LINE_HEIGHT, ((Rectangle) shapeAsked).y);
+ assertEquals(new Rectangle(bounds.x + 2 * POS_WIDTH, bounds.y + 3 * LINE_HEIGHT, 1,
+ LINE_HEIGHT), view.modelToView(17, shape, Bias.Forward));
assertSame(view.getView(3), viewAsked);
- assertEquals(LINE_HEIGHT, ((Rectangle)shapeAsked).height);
- assertEquals(bounds.y + 3 * LINE_HEIGHT, ((Rectangle)shapeAsked).y);
+ assertEquals(LINE_HEIGHT, ((Rectangle) shapeAsked).height);
+ assertEquals(bounds.y + 3 * LINE_HEIGHT, ((Rectangle) shapeAsked).y);
}
/**
@@ -308,16 +280,13 @@
*/
public void testViewToModel01() {
CompositeViewTest.useBoth = false;
- CompositeViewTest.useX = false;
-
+ CompositeViewTest.useX = false;
int x, y;
-
// Before the allocation
x = bounds.x;
y = bounds.y - 1;
assertTrue(view.isBefore(x, y, bounds));
assertEquals(0, view.viewToModel(x, y, shape, bias));
-
// After the allocation
y = bounds.y + bounds.height + 1;
assertTrue(view.isAfter(x, y, bounds));
@@ -330,18 +299,16 @@
*/
public void testViewToModel02() {
CompositeViewTest.useBoth = false;
- CompositeViewTest.useX = false;
-
+ CompositeViewTest.useX = false;
int x, y;
-
// In the first box
x = bounds.x + 5;
y = bounds.y + 4;
assertEquals(5 / POS_WIDTH, view.viewToModel(x, y, shape, bias));
assertSame(view.getView(0), viewAsked);
assertEquals(view.getChildAllocation(0, shape), shapeAsked);
- viewAsked = null; shapeAsked = null;
-
+ viewAsked = null;
+ shapeAsked = null;
// X coordinate is not in the shape
x = bounds.x - 1;
y = bounds.y + 4 + LINE_HEIGHT;
@@ -355,26 +322,23 @@
// No view was asked
assertNull(viewAsked);
assertNull(shapeAsked);
-
// One may easily the assertions above are also true for this case
x = bounds.x + bounds.width;
y = bounds.y + 4 + LINE_HEIGHT;
assertEquals(-1, view.viewToModel(x, y, shape, bias));
assertNull(viewAsked);
assertNull(shapeAsked);
-
// In the second box
x = bounds.x;
y = bounds.y + 4 + LINE_HEIGHT;
assertEquals(1, view.getViewIndex(x, y, shape));
- assertSame(view.getView(1),
- view.getViewAtPoint(x, y, shape.getBounds()));
- assertEquals(view.getView(1).getStartOffset(),
- view.viewToModel(x, y, shape, bias));
+ assertSame(view.getView(1), view.getViewAtPoint(x, y, shape.getBounds()));
+ assertEquals(view.getView(1).getStartOffset(), view.viewToModel(x, y, shape, bias));
assertSame(view.getView(1), viewAsked);
- assertEquals(LINE_HEIGHT, ((Rectangle)shapeAsked).height);
- assertEquals(bounds.y + LINE_HEIGHT, ((Rectangle)shapeAsked).y);
- viewAsked = null; shapeAsked = null;
+ assertEquals(LINE_HEIGHT, ((Rectangle) shapeAsked).height);
+ assertEquals(bounds.y + LINE_HEIGHT, ((Rectangle) shapeAsked).y);
+ viewAsked = null;
+ shapeAsked = null;
}
/**
@@ -385,18 +349,16 @@
*/
public void testViewToModel03() {
CompositeViewTest.useBoth = false;
- CompositeViewTest.useX = true;
-
+ CompositeViewTest.useX = true;
int x, y;
-
// In the first box
x = bounds.x + 5;
y = bounds.y + 4;
assertEquals(5 / POS_WIDTH, view.viewToModel(x, y, shape, bias));
assertSame(view.getView(0), viewAsked);
assertEquals(view.getChildAllocation(0, shape), shapeAsked);
- viewAsked = null; shapeAsked = null;
-
+ viewAsked = null;
+ shapeAsked = null;
// X coordinate is not in the shape
x = bounds.x - 1;
y = bounds.y + 4 + LINE_HEIGHT;
@@ -406,26 +368,23 @@
// No view was asked
assertNull(viewAsked);
assertNull(shapeAsked);
-
x = bounds.x + bounds.width + 1;
y = bounds.y + 4 + LINE_HEIGHT;
assertTrue(view.isAfter(x, y, bounds));
assertEquals(doc.getLength(), view.viewToModel(x, y, shape, bias));
assertNull(viewAsked);
assertNull(shapeAsked);
-
// In the second box
x = bounds.x;
y = bounds.y + 4 + LINE_HEIGHT;
assertEquals(1, view.getViewIndex(x, y, shape));
- assertSame(view.getView(1),
- view.getViewAtPoint(x, y, shape.getBounds()));
- assertEquals(view.getView(1).getStartOffset(),
- view.viewToModel(x, y, shape, bias));
+ assertSame(view.getView(1), view.getViewAtPoint(x, y, shape.getBounds()));
+ assertEquals(view.getView(1).getStartOffset(), view.viewToModel(x, y, shape, bias));
assertSame(view.getView(1), viewAsked);
- assertEquals(LINE_HEIGHT, ((Rectangle)shapeAsked).height);
- assertEquals(bounds.y + LINE_HEIGHT, ((Rectangle)shapeAsked).y);
- viewAsked = null; shapeAsked = null;
+ assertEquals(LINE_HEIGHT, ((Rectangle) shapeAsked).height);
+ assertEquals(bounds.y + LINE_HEIGHT, ((Rectangle) shapeAsked).y);
+ viewAsked = null;
+ shapeAsked = null;
}
/**
@@ -439,7 +398,7 @@
public void testViewToModel04() {
// Modify the root
final int oldCount = root.getElementCount();
- BranchElement docRoot = (BranchElement)root;
+ BranchElement docRoot = (BranchElement) root;
final Element[] empty = new Element[0];
docRoot.replace(0, 1, empty);
docRoot.replace(docRoot.getElementCount() - 1, 1, empty);
@@ -448,12 +407,9 @@
// Re-load children
view.removeAll();
view.loadChildren(factory);
-
CompositeViewTest.useBoth = false;
- CompositeViewTest.useX = false;
-
+ CompositeViewTest.useX = false;
int x, y;
-
// Before the allocation
x = bounds.x;
y = bounds.y - 1;
@@ -461,39 +417,32 @@
int offset = view.viewToModel(x, y, shape, bias);
assertEquals(view.getStartOffset(), offset);
assertEquals(root.getElement(0).getStartOffset(), offset);
-
// After the allocation
y = bounds.y + bounds.height + 1;
assertTrue(view.isAfter(x, y, bounds));
bias[0] = null;
offset = view.viewToModel(x, y, shape, bias);
assertEquals(view.getEndOffset() - 1, offset);
- assertEquals(root.getElement(root.getElementCount()
- - 1).getEndOffset() - 1,
- offset);
+ assertEquals(root.getElement(root.getElementCount() - 1).getEndOffset() - 1, offset);
if (BasicSwingTestCase.isHarmony()) {
assertSame(Bias.Backward, bias[0]);
}
}
public void testViewToModel05() {
- final boolean[] methodCalled = new boolean[] {false};
+ final boolean[] methodCalled = new boolean[] { false };
view = new WithChildrenView(root) {
+ @Override
protected View getViewAtPoint(int x, int y, Rectangle rc) {
methodCalled[0] = true;
return super.getViewAtPoint(x, y, rc);
}
};
view.loadChildren(factory);
-
assertFalse(methodCalled[0]);
- view.viewToModel(bounds.x + bounds.width / 2,
- bounds.y + bounds.height, shape, bias);
+ view.viewToModel(bounds.x + bounds.width / 2, bounds.y + bounds.height, shape, bias);
assertTrue(methodCalled[0]);
-
- assertSame(view.getView(view.getViewIndex(bounds.x, bounds.y, shape)),
- view.getViewAtPoint(bounds.x, bounds.y,
- view.getInsideAllocation(shape)));
+ assertSame(view.getView(view.getViewIndex(bounds.x, bounds.y, shape)), view
+ .getViewAtPoint(bounds.x, bounds.y, view.getInsideAllocation(shape)));
}
-
}