@NotThreadSafe public final class Viewport extends java.lang.Object
The size of the image the viewport is into is not allowed to be changed. If the image size changes a new viewport must be constructed.
Modifier and Type | Class and Description |
---|---|
static class |
Viewport.Go
Directions about how to animate the viewport.
|
static interface |
Viewport.MovementRateSource
A source for the rate of animated viewport movement.
|
Constructor and Description |
---|
Viewport(int intoWidth,
int intoHeight) |
Modifier and Type | Method and Description |
---|---|
void |
animateHorizontalMovement(Viewport.Go toward)
Starts or stops animated horizontal movement of this viewport.
|
void |
animateVerticalMovement(Viewport.Go toward)
Starts or stops animated vertical movement of this viewport.
|
void |
dispose()
Disposes this viewport by ensuring that any running animations are stopped.
|
int |
getHeight()
Gets the height of this viewport.
|
long |
getMovementRate()
Gets the rate of animated viewport movement.
|
int |
getWidth()
Gets the width of this viewport.
|
int |
getX()
Gets the X coordinate of the upper-left of this viewport.
|
int |
getY()
Gets the Y coordinate of the upper-left of this viewport.
|
void |
setHeight(int value)
Sets the height of this viewport.
|
void |
setMovementRate(long nanosPerPixel)
Sets the rate of animated viewport movement.
|
void |
setMovementRateSource(Viewport.MovementRateSource source)
Sets a source for the rate of animated viewport movement.
|
void |
setPosition(int x,
int y)
Sets the coordinate of the upper-left of this viewport.
|
void |
setPositionDelta(int deltaX,
int deltaY)
Moves the viewport position relative to its current position.
|
void |
setSize(int width,
int height)
Sets the size of this viewport.
|
void |
setWidth(int value)
Sets the width of this viewport.
|
void |
setX(int value)
Sets the X coordinate of the upper-left of this viewport.
|
void |
setY(int value)
Sets the Y coordinate of the upper-left of this viewport.
|
public void animateHorizontalMovement(Viewport.Go toward)
toward
- the direction of the animation, either Viewport.Go.LEFT
or
Viewport.Go.RIGHT
. A value of Viewport.Go.STOP
stops animated
horizontal movement, if any is in progress.java.lang.IllegalArgumentException
- if toward is not one of Viewport.Go.LEFT
, Viewport.Go.RIGHT
, or
Viewport.Go.STOP
.java.lang.IllegalStateException
- if the viewport width is less than one.public void animateVerticalMovement(Viewport.Go toward)
toward
- the direction of the animation, either Viewport.Go.UP
or
Viewport.Go.DOWN
. A value of Viewport.Go.STOP
stops animated
horizontal movement, if any is in progress.java.lang.IllegalArgumentException
- if toward is not one of Viewport.Go.UP
, Viewport.Go.DOWN
, or
Viewport.Go.STOP
.java.lang.IllegalStateException
- if the viewport height is less than one.public void setPositionDelta(int deltaX, int deltaY)
deltaX
- the number of pixels to move the viewport horizontally. A negative
value moves the viewport to the left. A positive value moves the
viewport to the right. A value of zero leaves the horizontal
position of the viewport unchanged.deltaY
- the number of pixels to move the viewport vertically. A negative
value moves the viewport up. A positive value moves the viewport
down. A value of zero leaves the vertical position of the viewport
unchanged.java.lang.IllegalStateException
- if either the viewport width or height is less than one.public void setPosition(int x, int y)
x
- the X coordinate of the upper-left of this viewport in pixels.y
- the Y coordinate of the upper-left of this viewport in pixels.java.lang.IllegalStateException
- if either the viewport width or height is less than one.public int getX()
public void setX(int value)
value
- the X coordinate of the upper-left of this viewport in pixels.java.lang.IllegalStateException
- if the viewport width is less than one.public int getY()
public void setY(int value)
value
- the Y coordinate of the upper-left of this viewport in pixels.java.lang.IllegalStateException
- if the viewport height is less than one.public void setSize(int width, int height)
width
- the width of this viewport in pixels.height
- the height of this viewport in pixels.public int getWidth()
public void setWidth(int value)
value
- the width of this viewport in pixels.public int getHeight()
public void setHeight(int value)
value
- the height of this viewport in pixels.public void setMovementRate(long nanosPerPixel)
nanosPerPixel
- the rate of animated viewport movement in nanoseconds per pixel or
value less than one to reset the movement rate to its default
value.public void setMovementRateSource(Viewport.MovementRateSource source)
null
resets the movement rate to its default value.source
- a source for the rate of animated viewport movement or
null
to reset the movement rate to its default value.public long getMovementRate()
public void dispose()