MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / DrawableShape

Class DrawableShape

src/org/opensourcephysics/display/DrawableShape.java:21–218  ·  view source on GitHub ↗

A class that draws shapes using the Java 2D API.

Source from the content-addressed store, hash-verified

19 * A class that draws shapes using the Java 2D API.
20 */
21public class DrawableShape implements Drawable {
22 // no harm in letting a client access the color
23 public Color color = new Color(255, 128, 128, 128); // transparent light red fill color
24 public Color edgeColor = Color.RED;
25 Shape shape;
26 double x, y; // the shape's coordinates
27 double theta;
28 public String shapeClass;
29
30 /**
31 * Constructs a DrawableShape with the given coordinates.
32 *
33 * @param shape
34 * @param x coordinate
35 * @param y coordinate
36 */
37 public DrawableShape(Shape shape, double x, double y) {
38 this.x = x;
39 this.y = y;
40 shapeClass = shape.getClass().getName();
41 trDS.setToTranslation(x, y);
42 this.shape = trDS.createTransformedShape(shape);
43 }
44
45 /**
46 * Creates a drawable circle.
47 * @param x
48 * @param y
49 * @param d the diameter
50 * @return the DrawableShape
51 */
52 public static DrawableShape createCircle(double x, double y, double d) {
53 return new DrawableShape(new Ellipse2D.Double(-d/2, -d/2, d, d), x, y);
54 }
55
56 /**
57 * Creates a drawable rectangle.
58 * @param x
59 * @param y
60 * @param w
61 * @param h
62 * @return the drawable rectangle
63 */
64 public static DrawableShape createRectangle(double x, double y, double w, double h) {
65 return new DrawableShape(new Rectangle2D.Double(-w/2, -h/2, w, h), x, y);
66 }
67
68 /**
69 * Sets the shape's drawing colors.
70 *
71 * The error bar color is set equal to the edge color.
72 *
73 * @param fillColor
74 * @param edgeColor
75 */
76 public void setMarkerColor(Color fillColor, Color edgeColor) {
77 this.color = fillColor;
78 this.edgeColor = edgeColor;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected