|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Canvas
net.kolls.railworld.RailCanvas
public abstract class RailCanvas
The RailCanvas is one of the workhorses of the Rail World game. A RailCanvas represents the main drawing window where the image is drawn and overlaid with rail segments and trains. The rail canvas is also where the user clicks to select trains and operate segment devices, such as switches.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.awt.Canvas |
|---|
java.awt.Canvas.AccessibleAWTCanvas |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
RailSegment[] |
la
The rail segments. |
protected java.awt.image.BufferedImage |
minisource
The miniviewer image |
protected MiniViewer |
miniv
The mini-viewer for this canvas |
protected int |
mx
The mouse location during a drag (x) |
protected int |
my
The mouse location during a drag (y) |
java.awt.image.BufferedImage |
orig_src
The original, unmodified source image |
protected int |
vx
The left edge of the current viewing location on the image |
protected int |
vy
The upper edge of the current viewing location on the image |
static double |
zoom
The zoom value may be changed at any time, but appropriate redraws may be needed. |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
RailCanvas(java.awt.image.BufferedImage s,
RailSegment[] lines,
MiniViewer mini)
Construct a new rail canvas |
|
| Method Summary | |
|---|---|
static java.awt.geom.Line2D |
angle(java.awt.geom.Line2D bl,
java.awt.geom.Point2D myPoint,
double angle,
Distance len)
Find a position relative to an existing line. |
java.awt.Dimension |
areaSize()
Finds the area of the entire playing map at current zoom level. |
abstract void |
doMiniPaint(java.awt.Graphics2D ofg)
Given the graphics context of the mini image, paint it. |
protected abstract void |
doPaint(java.awt.Graphics2D ofg,
int hvx,
int hvy,
boolean detailed)
Paint the main image. |
void |
draw(java.awt.Graphics2D g,
java.awt.geom.Point2D center,
int width,
int height,
double useZoom,
boolean detailed)
Draws a portion of the display |
void |
drawCanvas()
Draw the rail canvas and its miniviewer, if appropriate. |
static void |
drawOutlineFont(java.awt.Graphics2D ofg,
int x,
int y,
java.lang.String text,
int size,
java.awt.Color c,
double angle,
boolean centered)
Draws a shadowed text on a graphics device. |
java.awt.geom.Point2D |
getCenterPoint()
Returns the center of the currently displayed area. |
java.awt.geom.Point2D |
getVXY()
|
void |
leftDrag(java.awt.event.MouseEvent e)
Called if the left mouse button is held and dragged. |
void |
leftMove(java.awt.event.MouseEvent e)
Called if the mouse is moved without the right mouse button down |
void |
leftPress(java.awt.event.MouseEvent e)
Called if the left mouse button is pressed |
void |
leftRelease(java.awt.event.MouseEvent e)
Called if the left mouse button is released |
static double |
lineAngle(java.awt.geom.Line2D bl)
Calculate the angle of a line, in radians. |
void |
mouseClicked(java.awt.event.MouseEvent e)
|
void |
mouseDragged(java.awt.event.MouseEvent e)
If the right mouse button is dragged, moves the displayed location. |
void |
mouseEntered(java.awt.event.MouseEvent e)
|
void |
mouseExited(java.awt.event.MouseEvent e)
|
void |
mouseMoved(java.awt.event.MouseEvent e)
|
void |
mousePressed(java.awt.event.MouseEvent e)
|
void |
mouseReleased(java.awt.event.MouseEvent e)
|
void |
recomp()
Recompute all segment details |
void |
stop()
Deallocate images for garbage collection. |
void |
submitCenterCoords(int x,
int y)
Move the display to attempt to accomodate the given image coordinates as a center point. |
void |
submitCoords(int x,
int y)
Move the display to attempt to accomodate the given upper-left coordinates on the static image. |
double |
trackLength()
Calculates the total length of all rail segments in feet. |
protected java.awt.geom.Point2D |
transform(java.awt.event.MouseEvent e)
Transforms a point on the canvas to a point on the image. |
protected java.awt.geom.Point2D |
transform(java.awt.geom.Point2D p)
Transforms a point on the canvas to a point on the image. |
| Methods inherited from class java.awt.Canvas |
|---|
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, paint, update |
| Methods inherited from class java.awt.Component |
|---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public java.awt.image.BufferedImage orig_src
protected java.awt.image.BufferedImage minisource
public RailSegment[] la
protected int vx
protected int vy
protected int mx
protected int my
protected MiniViewer miniv
public static double zoom
| Constructor Detail |
|---|
public RailCanvas(java.awt.image.BufferedImage s,
RailSegment[] lines,
MiniViewer mini)
s - The source image (@link{#orig_src}) to use.lines - The rail segments (@link{#la}) to use.mini - The mini viewer (@link{#miniv}) to use.| Method Detail |
|---|
public java.awt.geom.Point2D getVXY()
public double trackLength()
public void stop()
public void recomp()
public java.awt.geom.Point2D getCenterPoint()
Point2D representing the center point of display on the image.
public void submitCenterCoords(int x,
int y)
x - X position on static imagey - Y position on static image
public void submitCoords(int x,
int y)
x - The x coordinate on the imagey - The y coordinate on the imagepublic static double lineAngle(java.awt.geom.Line2D bl)
bl - A Line2D to find the angle of.
double value, representing angle in radians.
public static java.awt.geom.Line2D angle(java.awt.geom.Line2D bl,
java.awt.geom.Point2D myPoint,
double angle,
Distance len)
bl - A Line2D to start from.myPoint - A Point2D as a fixed starting point.angle - An angle, in radians, relative to the line given.len - A Distance at the given relative angle to move.
Line2D from the given starting point to the end along the relative angle.
public static void drawOutlineFont(java.awt.Graphics2D ofg,
int x,
int y,
java.lang.String text,
int size,
java.awt.Color c,
double angle,
boolean centered)
ofg - A Graphics2D to draw on.x - Position to draw the text.y - text - The actual text to draw.size - The size, in pixels, of the text.c - The Color of the text.angle - The angle, in radians, to draw the text.centered - The position given represents the center of the text?
public void draw(java.awt.Graphics2D g,
java.awt.geom.Point2D center,
int width,
int height,
double useZoom,
boolean detailed)
center - A Point2D representing the center position of the image.g - The Graphics2D to draw into. Drawing is always performed at (0,0) in the target graphics.width - The width of the draw.height - The height of the draw.useZoom - The zoom factor to use for this draw. Normally zoomdetailed - Should high expense items like scripts be drawn as well?public void drawCanvas()
public java.awt.Dimension areaSize()
public abstract void doMiniPaint(java.awt.Graphics2D ofg)
ofg - A Graphics2D context for the mini image.
protected abstract void doPaint(java.awt.Graphics2D ofg,
int hvx,
int hvy,
boolean detailed)
ofg - A Graphics2D context for the main image.hvy - The vx coordinate to usehvx - The vy coordinate to usedetailed - Should expensive items also be drawn?protected final java.awt.geom.Point2D transform(java.awt.event.MouseEvent e)
e - The mouse event which includes the point.
protected final java.awt.geom.Point2D transform(java.awt.geom.Point2D p)
p - The point on the canvas to transform
public void leftDrag(java.awt.event.MouseEvent e)
e - The mouse event generatedpublic void leftMove(java.awt.event.MouseEvent e)
e - The mouse event generatedpublic void leftRelease(java.awt.event.MouseEvent e)
e - The mouse event generatedpublic void leftPress(java.awt.event.MouseEvent e)
e - The mouse event generatedpublic void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked in interface java.awt.event.MouseListenerpublic void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered in interface java.awt.event.MouseListenerpublic void mouseExited(java.awt.event.MouseEvent e)
mouseExited in interface java.awt.event.MouseListenerpublic final void mousePressed(java.awt.event.MouseEvent e)
mousePressed in interface java.awt.event.MouseListenerpublic final void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased in interface java.awt.event.MouseListenerpublic final void mouseDragged(java.awt.event.MouseEvent e)
leftDrag(MouseEvent).
mouseDragged in interface java.awt.event.MouseMotionListenerpublic final void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved in interface java.awt.event.MouseMotionListener
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||