package lab5;
/**
*
* @author Michael Kozelsky
*
* Created on: Jul 28, 2006
*/
public class CompoundGraphic extends AbstractGraphic implements IContainer {
private java.util.ArrayList _graphicsList;
public CompoundGraphic() {
_graphicsList = new java.util.ArrayList();
this.setDimension(new java.awt.Dimension(1, 1));
}
public void add(IGraphic g) {
_graphicsList.add(g);
g.setContainer(this);
if (this.getContainer() != null) {
this.getContainer().repaint(this.getBounds());
}
}
public void remove(IGraphic g) {
_graphicsList.remove(g);
if (this.getContainer() != null)
this.getContainer().repaint(this.getBounds());
}
public void actualPaint(java.awt.Graphics2D gs, java.awt.Point location,
java.awt.Dimension dimension) {
Graphics offsetGraphics = gs.create(location.x,location.y, dimension.width, dimension.height);
for (IGraphic g : _graphicsList) {
// paint each graphic with an offset
g.paint((Graphics2D)offsetGraphics);
}
}
public void repaint() {
if (this.getContainer() != null)
this.getContainer().repaint();
}
}