1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.tutorial.section44;
11
12 import java.awt.Color;
13 import java.awt.Font;
14 import java.awt.Graphics2D;
15 import java.awt.image.ImageObserver;
16
17 import nl.tudelft.simulation.dsol.animation.LocatableInterface;
18 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
19 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
20
21 /***
22 * The Animation of a Ball.
23 * <p>
24 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
25 * University of Technology </a>, the Netherlands. <br>
26 * See for project information <a
27 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
28 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
29 * License (GPL) </a>, no warranty <br>
30 *
31 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
32 * Jacobs </a>
33 * @version 1.2 Apr 16, 2004
34 * @since 1.4
35 */
36 public class BallAnimation2D extends Renderable2D
37 {
38 /***
39 * the color of the ballAnimation
40 */
41 private Color color = Color.ORANGE;
42
43 /***
44 * constructs a new BallAnimation2D
45 *
46 * @param source the source
47 * @param simulator the simulator
48 */
49 public BallAnimation2D(final LocatableInterface source,
50 final SimulatorInterface simulator)
51 {
52 super(source, simulator);
53 }
54
55 /***
56 * @see nl.tudelft.simulation.dsol.animation.D2.
57 * Renderable2D#paint(java.awt.Graphics2D,
58 * java.awt.image.ImageObserver)
59 */
60 public void paint(final Graphics2D graphics, final ImageObserver observer)
61 {
62 graphics.setColor(this.color);
63 graphics.fillOval(-(int) Ball.RADIUS, -(int) Ball.RADIUS,
64 (int) (Ball.RADIUS * 2.0), (int) (Ball.RADIUS * 2.0));
65 graphics.setFont(graphics.getFont().deriveFont(Font.BOLD));
66 graphics.setColor(Color.GRAY);
67 graphics.drawString(this.source.toString(), (int) (Ball.RADIUS * -1.0),
68 (int) (Ball.RADIUS * 1.0));
69 }
70
71 /***
72 * @return Returns the color.
73 */
74 public Color getColor()
75 {
76 return this.color;
77 }
78
79 /***
80 * @param color The color to set.
81 */
82 public void setColor(final Color color)
83 {
84 this.color = color;
85 }
86 }