public class DraggablePoint extends Drawable implements InputObject, Draggable
Modifier and Type | Field and Description |
---|---|
static int |
CROSS
A style constant that specifies the visual appearance of a DraggablePoint to be a cross.
|
static int |
DISK
A style constant that specifies the visual appearance of a DraggablePoint to be a disk.
|
static int |
SQUARE
A style constant that specifies the visual appearance of a DraggablePoint to be a square.
|
Constructor and Description |
---|
DraggablePoint()
Create a DraggablePoint with default values for style, radius, color.
|
DraggablePoint(int style)
Create a DraggablePoint with specified visual style.
|
Modifier and Type | Method and Description |
---|---|
void |
checkInput()
This method is required by the InputObject interface.
|
void |
clampX(double x)
Clamp the x-value of the point to the constant x, so that the point is constrained to a vertical line.
|
void |
clampX(Function f)
Clamp the x-value of the point to the function f, so that the point is constrained to move along the graph of x = f(y).
|
void |
clampX(Value v)
Clamp the x-value of the point to v.
|
void |
clampY(double y)
Clamp the y-value of the point to the constant y, so that the point is constrained to a horizontal line.
|
void |
clampY(Function f)
Clamp the y-value of the point to the function f, so that the point is constrained to move along the graph of y = f(x).
|
void |
clampY(Value v)
Clamp the y-value of the point to v.
|
void |
continueDrag(MouseEvent evt)
Continue a drag operation begun in startDrag().
|
void |
draw(Graphics g,
boolean coordsChanged)
This method, from the Drawable interface, draws the point.
|
void |
finishDrag(MouseEvent evt)
Finish a drag operation begun in startDrag().
|
Color |
getColor()
Get the color used for drawing the point.
|
Color |
getGhostColor()
Get the "ghostColor" of the point.
|
Controller |
getOnUserAction(Controller c)
Get the Controller that is notified when the user drags the point.
|
int |
getRadius()
Get the radius used for drawing the point.
|
int |
getStyle()
Get the visual style of the point, which must be one of the constants
DraggablePoint.DISK, DraggablePoint.SQUARE, or DraggablePoint.CROSS.
|
Variable |
getXVar()
Get the variable that represents the current x-value of the point.
|
Variable |
getYVar()
Get the variable that represents the current y-value of the point.
|
void |
notifyControllerOnChange(Controller c)
Method required by InputObject interface; in this class, it simply calls
setOnUserAction(c).
|
void |
setColor(Color c)
Set the color to be used for drawing the point.
|
void |
setGhostColor(Color c)
Set the ghoseColor to be used for drawing the point when it location is undefined or is outside the
proper limits.
|
void |
setLocation(double x,
double y)
Move the point to (x,y), then "clamp" the value of x or y, if a clamp Value has been set.
|
void |
setOnUserAction(Controller c)
Set the Controller that is to be notified when the user drags the point.
|
void |
setRadius(int r)
Set the radius that determines the size of the point when it is drawn.
|
void |
setStyle(int style)
Set the visual style of the point.
|
boolean |
startDrag(MouseEvent evt)
Check whether a mouse click (as specified in the MouseEvent parameter) is a
click on this DraggablePoint.
|
getVisible, needsRedraw, setOwnerData, setVisible
public static final int DISK
public static final int SQUARE
public static final int CROSS
public DraggablePoint()
public DraggablePoint(int style)
style
- One of the style constants DraggablePoint.DISK, DraggablePoint.SQUARE, or DraggablePoint.CROSS.public void clampX(Value v)
public void clampY(Value v)
public void clampX(double x)
public void clampY(double y)
public void clampX(Function f)
public void clampY(Function f)
public int getRadius()
public void setRadius(int r)
public void setStyle(int style)
public int getStyle()
public Variable getXVar()
public Variable getYVar()
public Color getColor()
public void setColor(Color c)
public Color getGhostColor()
public void setGhostColor(Color c)
public void setOnUserAction(Controller c)
public void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
public Controller getOnUserAction(Controller c)
public void setLocation(double x, double y)
public void checkInput()
checkInput
in interface InputObject
public void draw(Graphics g, boolean coordsChanged)
draw
in class Drawable
g
- The graphics context in which the Drawble is to be drawn. (The drawing
can change the color in g, but should not permanently change font, painting mode, etc.
Thus, every drawable is responsible for setting the color it wants to use.)coordsChanged
- Indicates whether the CoordinateRect has changed.public boolean startDrag(MouseEvent evt)
public void continueDrag(MouseEvent evt)
continueDrag
in interface Draggable
public void finishDrag(MouseEvent evt)
finishDrag
in interface Draggable