public class Pane extends Object implements PaneObject
Modifier and Type | Field and Description |
---|---|
protected String |
referenceIdentification
Reference identification of the instance.
|
Constructor and Description |
---|
Pane()
Constructs a pane with predefined size.
|
Pane(int width,
int height)
Constructs a pane at position [0, 0] with center in its top-left corner.
|
Pane(int x,
int y,
int width,
int height)
Constructs a pane at a given position.
|
Modifier and Type | Method and Description |
---|---|
void |
add(PaneObject o)
Adds the new pane object (Pane, Turtle, etc.) on the pane.
|
void |
bringToBack(PaneObject o)
Moves a pane object to back of all other pane objects.
|
void |
bringToBackOf(PaneObject o,
PaneObject location)
Moves a pane object to back of another pane object.
|
void |
bringToFront(PaneObject o)
Moves a pane object to front of all other pane objects.
|
void |
bringToFrontOf(PaneObject o,
PaneObject location)
Moves a pane object to front of another pane object.
|
boolean |
canClick(int x,
int y,
boolean inParentCoordinates)
Returns whether a point at given location is clickable, i.e., a hand
mouse cursor should be shown over this point.
|
void |
clear()
Cleans the graphical content of the pane.
|
boolean |
containsPoint(int x,
int y)
Returns whether the pane contains a point at given coordinates.
|
void |
draw(Shape shape,
Stroke stroke,
Color color,
Paint paint)
Draws the shape to the pane.
|
void |
fill(Shape shape,
Stroke stroke,
Color color,
Paint paint)
Fills the shape to the pane.
|
Color |
getBackgroundColor()
Gets the pane's background color.
|
Color |
getBorderColor()
Gets the current border color.
|
int |
getBorderWidth()
Gets the current border with (in pixels).
|
Point2D |
getCenter()
Gets the coordinates of the pane's center.
|
int |
getHeight()
Gets the current height of this pane.
|
long |
getKeyRepeatPeriod()
Returns the period in which key pressed events are generated for key
codes that are hold.
|
long |
getKeyRepeatPeriod(int keyCode)
Returns the period in which key pressed events are generated for given
key code when it is hold.
|
int |
getObjectCount()
Gets the number of children objects currently living in this pane.
|
Pane |
getPane()
Gets the current parent pane of this pane.
|
Pane |
getPane(int index)
Gets the pane associated with the specified index.
|
int |
getPaneCount()
Gets the number of children panes currently living in this pane.
|
PaneObject |
getPaneObject(int index)
Gets the pane object associated with the specified index.
|
PaneObject[] |
getPaneObjects()
Gets an array of all children object currently living in this pane.
|
Pane[] |
getPanes()
Gets an array of children panes currently living in this pane.
|
Point2D |
getPosition()
Returns the position of this pane.
|
double |
getRotation()
Gets the rotation angle of this pane in degrees.
|
long |
getTickPeriod()
Gets the time period (in milliseconds) in which the onTick method is
executed.
|
double |
getTransparency()
Gets the current transparency of the pane.
|
Turtle |
getTurtle(int index)
Gets the turtle associated with the specified index.
|
int |
getTurtleCount()
Gets the number of turtles currently living in this pane.
|
Turtle[] |
getTurtles()
Gets an array of turtles currently living in this pane.
|
int |
getWidth()
Gets the current width of this pane.
|
double |
getX()
Gets the x-coordinate of this pane relative to the parent pane.
|
double |
getXCenter()
Gets the x-coordinate of the center of this pane.
|
double |
getY()
Gets the y-coordinate of this pane relative to the parent pane.
|
double |
getYCenter()
Gets the y-coordinate of the center of this pane.
|
void |
invalidate()
Marks that the content of the pane is no longer valid.
|
boolean |
isAntialiased()
Gets whether the drawing actions are antialiased.
|
boolean |
isMouseTransparent()
Returns whether the pane is transparent for mouse events.
|
boolean |
isTransparentBackground()
Returns whether drawing the pane's background is disabled.
|
boolean |
isTurtleCentering()
Returns whether turtles are centered when added to this pane.
|
protected boolean |
onCanClick(int x,
int y)
Called when querying whether a point at given location can be clicked.
|
protected void |
onKeyPressed(KeyEvent e)
Called on key pressed event.
|
protected void |
onKeyReleased(KeyEvent e)
Called on key released event.
|
protected void |
onKeyTyped(KeyEvent e)
Called on key typed event.
|
protected void |
onMouseClicked(int x,
int y,
MouseEvent detail)
Called on mouse clicked event.
|
protected void |
onMouseDragged(int x,
int y,
MouseEvent detail)
Called on mouse dragged event.
|
protected void |
onMouseMoved(int x,
int y,
MouseEvent detail)
Called on mouse moved event.
|
protected void |
onMousePressed(int x,
int y,
MouseEvent detail)
Called on mouse pressed event.
|
protected void |
onMouseReleased(int x,
int y,
MouseEvent detail)
Called on mouse released event.
|
protected void |
onTick()
Called periodically by the pane.
|
void |
paintToPaneGraphics(Graphics2D g)
Paints the pane to a graphics at position relative to parent's coordinate
system.
|
void |
remove(PaneObject o)
Removes a pane object from the pane.
|
void |
resize(int newWidth,
int newHeight)
Resizes the pane.
|
boolean |
savePicture(String filename)
Stores picture of the pane to an image file.
|
void |
setAntialiased(boolean antialiased)
Sets whether the drawing actions are antialiased.
|
void |
setBackgroundColor(Color backgroundColor)
Sets the pane's background color.
|
void |
setBorderColor(Color borderColor)
Sets the new border color.
|
void |
setBorderWidth(int borderWidth)
Sets new border with.
|
void |
setCenter(double xCenter,
double yCenter)
Changes the location of center of this pane.
|
void |
setCenter(Point2D center)
Sets the center of this pane.
|
void |
setHeight(int height)
Sets new height of this pane.
|
void |
setKeyRepeatPeriod(int keyCode,
long keyRepeatPeriod)
Sets the period in which key pressed events are generated for given key
code when it is hold.
|
void |
setKeyRepeatPeriod(long keyRepeatPeriod)
Sets the period in which key pressed events are generated for key codes
that are hold.
|
void |
setMouseTransparent(boolean mouseTransparent)
Sets transparency of the pane for mouse events.
|
void |
setPane(Pane newParentPane)
Sets the parent pane of this pane.
|
void |
setPosition(double x,
double y)
Changes the position of the pane.
|
void |
setPosition(Point2D position)
Changes the location of the pane.
|
void |
setRotation(double rotation)
Sets the rotation angle of this pane.
|
void |
setTickPeriod(long tickPeriod)
Sets the time period (in milliseconds) in which the onTick method is
executed.
|
void |
setTransparency(double transparency)
Sets the pane's transparency.
|
void |
setTransparentBackground(boolean transparentBackground)
Sets whether the pane's background is drawn, i.e., whether pane's
background is transparent.
|
void |
setTurtleCentering(boolean turtleCentering)
Sets whether turtles are centered when added to this pane.
|
void |
setWidth(int width)
Sets new width of this pane.
|
void |
setX(double x)
Sets the new x-coordinate of this pane.
|
void |
setXCenter(double xCenter)
Sets the x-coordinate of the center of this pane.
|
void |
setY(double y)
Sets the new y-coordinate of this pane.
|
void |
setYCenter(double yCenter)
Sets the y-coordinate of the center of this pane.
|
String |
toString() |
protected final String referenceIdentification
public Pane()
public Pane(int width, int height)
width
- the width of the paneheight
- the height of the panepublic Pane(int x, int y, int width, int height)
x
- the x-coordinate of the top-left corner of the paney
- the y-coordinate of the top-left corner of the panewidth
- the width of the paneheight
- the height of the panepublic int getWidth()
public void setWidth(int width)
width
- the desired width of the pane.public int getHeight()
public void setHeight(int height)
height
- the desired height of the pane.public double getX()
public void setX(double x)
x
- the desired x-coordinate of the pane.public double getY()
public void setY(double y)
y
- the desired y-coordinate of the pane.public double getXCenter()
public void setXCenter(double xCenter)
xCenter
- the desired x-coordinate of the pane's center.public double getYCenter()
public void setYCenter(double yCenter)
yCenter
- the desired y-coordinate of the pane's center.public void setCenter(Point2D center)
center
- the desired coordinates of the pane's center.public Point2D getCenter()
public double getRotation()
public void setRotation(double rotation)
rotation
- the desired rotation angle in degrees.public void resize(int newWidth, int newHeight)
newWidth
- desired width of the pane.newHeight
- desired height of the pane.public void setPosition(double x, double y)
x
- the desired x-coordinate.y
- the desired y-coordinate.public void setPosition(Point2D position)
position
- the desired position of this pane.public Point2D getPosition()
public void setCenter(double xCenter, double yCenter)
xCenter
- the desired x-coordinate of the center.yCenter
- the desired y-coordinate of the center.public boolean containsPoint(int x, int y)
x
- the x-coordinate of the point.y
- the y-coordinate of the point.public int getBorderWidth()
public void setBorderWidth(int borderWidth)
borderWidth
- the desired border with in pixels.public Color getBorderColor()
public void setBorderColor(Color borderColor)
borderColor
- the desired color of the border. If it is set to null, no
border is drawn.public double getTransparency()
public void setTransparency(double transparency)
transparency
- the desired pane's transparency. If it is a number smaller
than 0, the value 0 is set. If it is a number greater than 1,
the value 1 is set.public Color getBackgroundColor()
public void setBackgroundColor(Color backgroundColor)
backgroundColor
- the desired pane's background color. If set to null, the
pane's background is transparent.public boolean isTransparentBackground()
public void setTransparentBackground(boolean transparentBackground)
transparentBackground
- true for transparent (not drawn) backgroundpublic boolean isAntialiased()
public void setAntialiased(boolean antialiased)
antialiased
- true for drawing with antialiasing, false for drawing without
anitialiasing.public void paintToPaneGraphics(Graphics2D g)
paintToPaneGraphics
in interface PaneObject
g
- the graphics where the content is drawn.public void invalidate()
public void clear()
public Pane getPane()
getPane
in interface PaneObject
public void setPane(Pane newParentPane)
setPane
in interface PaneObject
newParentPane
- the new parent panepublic void add(PaneObject o)
o
- the object adding to the pane. If null, nothing is done.public boolean isTurtleCentering()
public void setTurtleCentering(boolean turtleCentering)
turtleCentering
- true, to enabled centering, false to disable.public void remove(PaneObject o)
o
- the removing pane objectpublic void bringToFront(PaneObject o)
o
- the pane object that will be movedpublic void bringToBack(PaneObject o)
o
- the pane object that will be movedpublic void bringToFrontOf(PaneObject o, PaneObject location)
o
- the pane object that will be movedlocation
- the pane object to front of which the object o will be movedpublic void bringToBackOf(PaneObject o, PaneObject location)
o
- the pane object that will be movedlocation
- the pane object to back of which the object o will be movedpublic Turtle[] getTurtles()
public int getTurtleCount()
public Turtle getTurtle(int index)
index
- the position of the turtle.public Pane[] getPanes()
public int getPaneCount()
public Pane getPane(int index)
index
- the position of the pane.public PaneObject[] getPaneObjects()
public int getObjectCount()
public PaneObject getPaneObject(int index)
index
- the position of the pane object.public boolean isMouseTransparent()
public void setMouseTransparent(boolean mouseTransparent)
mouseTransparent
- true for mouse transparent pane, false otherwise.public void setKeyRepeatPeriod(long keyRepeatPeriod)
keyRepeatPeriod
- the period in milliseconds. 0 for default strategy (defined by
OS or JRE).public long getKeyRepeatPeriod()
public void setKeyRepeatPeriod(int keyCode, long keyRepeatPeriod)
keyCode
- the key code.keyRepeatPeriod
- the period in milliseconds. 0 for default strategy (defined by
OS or JRE).public long getKeyRepeatPeriod(int keyCode)
keyCode
- the key codeprotected void onMouseClicked(int x, int y, MouseEvent detail)
x
- the X-coordinate of the mouse click with respect to pane
coordinate system.y
- the Y-coordinate of the mouse click with respect to pane
coordinate system.detail
- the additional information about the event.protected void onMouseMoved(int x, int y, MouseEvent detail)
x
- the X-coordinate of the mouse with respect to pane coordinate
systemy
- the Y-coordinate of the mouse with respect to pane coordinate
systemdetail
- the additional information about the eventprotected void onMouseDragged(int x, int y, MouseEvent detail)
x
- the X-coordinate of the mouse with respect to pane coordinate
system.y
- the Y-coordinate of the mouse with respect to pane coordinate
system.detail
- the additional information about the event.protected void onMousePressed(int x, int y, MouseEvent detail)
x
- the X-coordinate of the mouse with respect to pane coordinate
system.y
- the Y-coordinate of the mouse with respect to pane coordinate
system.detail
- the additional information about the event.protected void onMouseReleased(int x, int y, MouseEvent detail)
x
- the X-coordinate of the mouse with respect to pane coordinate
system.y
- the Y-coordinate of the mouse with respect to pane coordinate
system.detail
- the additional information about the event.protected void onKeyPressed(KeyEvent e)
e
- the additional information about the event.protected void onKeyReleased(KeyEvent e)
e
- the additional information about the event.protected void onKeyTyped(KeyEvent e)
e
- the additional information about the event.public boolean canClick(int x, int y, boolean inParentCoordinates)
x
- the X-coordinate of the location with respect to specified
coordinate system.y
- the Y-coordinate of the location with respect to specified
coordinate system.inParentCoordinates
- a boolean that determines coordinate system of given
coordinates. True, if the coordinates are in coordinate system
of the parent pane, false, if the coordinates are in
coordinate system of this pane.protected boolean onCanClick(int x, int y)
x
- the X-coordinate of the location with respect to pane
coordinate system.y
- the Y-coordinate of the location with respect to pane
coordinate system.public void draw(Shape shape, Stroke stroke, Color color, Paint paint)
shape
- the shape to be drawnstroke
- the stroke used to draw the shapecolor
- the color used to draw the shapepaint
- the color used to paint the shapepublic void fill(Shape shape, Stroke stroke, Color color, Paint paint)
shape
- the shape to be drawnstroke
- the stroke used to draw the shapecolor
- the color used to draw the shapepaint
- the color used to paint the shapepublic long getTickPeriod()
public void setTickPeriod(long tickPeriod)
tickPeriod
- the tick period in milliseconds.protected void onTick()
public boolean savePicture(String filename)
filename
- the name of the output image file.Copyright © 2017. All rights reserved.