@Test public void testCloning() throws CloneNotSupportedException { GradientPaint gp = new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE); Rectangle2D bounds1 = new Rectangle2D.Double(10.0, 20.0, 30.0, 40.0); ColorBlock b1 = new ColorBlock(gp, 1.0, 2.0); b1.setBounds(bounds1); ColorBlock b2 = (ColorBlock) b1.clone(); assertNotSame(b1, b2); assertSame(b1.getClass(), b2.getClass()); assertEquals(b1, b2); bounds1.setRect(1.0, 2.0, 3.0, 4.0); assertFalse(b1.equals(b2)); b2.setBounds(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertEquals(b1, b2); }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ColorBlock)) { return false; } ColorBlock that = (ColorBlock) obj; if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } return super.equals(obj); }
ColorBlock extends AbstractBlock implements Block { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ColorBlock)) { return false; } ColorBlock that = (ColorBlock) obj; if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } return super.equals(obj); } }
ColorBlock extends AbstractBlock implements Block { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ColorBlock)) { return false; } ColorBlock that = (ColorBlock) obj; if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } return super.equals(obj); } ColorBlock(Paint paint, double width, double height); }
ColorBlock extends AbstractBlock implements Block { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ColorBlock)) { return false; } ColorBlock that = (ColorBlock) obj; if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } return super.equals(obj); } ColorBlock(Paint paint, double width, double height); Paint getPaint(); @Override Size2D arrange(Graphics2D g2, RectangleConstraint constraint); @Override void draw(Graphics2D g2, Rectangle2D area); @Override Object draw(Graphics2D g2, Rectangle2D area, Object params); @Override boolean equals(Object obj); }
ColorBlock extends AbstractBlock implements Block { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ColorBlock)) { return false; } ColorBlock that = (ColorBlock) obj; if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } return super.equals(obj); } ColorBlock(Paint paint, double width, double height); Paint getPaint(); @Override Size2D arrange(Graphics2D g2, RectangleConstraint constraint); @Override void draw(Graphics2D g2, Rectangle2D area); @Override Object draw(Graphics2D g2, Rectangle2D area, Object params); @Override boolean equals(Object obj);  }