You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ShapeFigureElement.java 819B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (c) 2002 Palo Alto Research Center, Incorporated.
  2. // All Rights Reserved.
  3. package figures;
  4. import java.awt.*;
  5. import java.awt.geom.*;
  6. public abstract class ShapeFigureElement implements FigureElement {
  7. public abstract void move(int dx, int dy);
  8. public abstract Shape getShape();
  9. public Rectangle getBounds() {
  10. return getShape().getBounds();
  11. }
  12. public boolean contains(Point2D p) {
  13. return getShape().contains(p);
  14. }
  15. public Color getLineColor() {
  16. return Color.black;
  17. }
  18. public Color getFillColor() {
  19. return Color.red;
  20. }
  21. public final void paint(Graphics2D g2) {
  22. Shape shape = getShape();
  23. g2.setPaint(getFillColor());
  24. g2.fill(shape);
  25. g2.setPaint(getLineColor());
  26. g2.draw(shape);
  27. }
  28. }