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 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package figures;
  13. import java.awt.*;
  14. import java.awt.geom.*;
  15. public abstract class ShapeFigureElement implements FigureElement {
  16. public abstract void move(int dx, int dy);
  17. public abstract Shape getShape();
  18. public Rectangle getBounds() {
  19. return getShape().getBounds();
  20. }
  21. public boolean contains(Point2D p) {
  22. return getShape().contains(p);
  23. }
  24. public Color getLineColor() {
  25. return Color.black;
  26. }
  27. public Color getFillColor() {
  28. return Color.red;
  29. }
  30. public final void paint(Graphics2D g2) {
  31. Shape shape = getShape();
  32. g2.setPaint(getFillColor());
  33. g2.fill(shape);
  34. g2.setPaint(getLineColor());
  35. g2.draw(shape);
  36. }
  37. }