|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
TGCanvas
public class TGCanvas
This class is an implementation of a graphics canvas window for TG. All graphics (pixels painted) are maintained in an Image for redisplay in the event of resizing.
Other features of TGCanvas are:
- the coordinate space is the traditional mathematics; [0,0] is in the middle of the graphics window.
- KeyListener method invocations are handled and may be passed on.
- MouseListener.mouseReleased() and MouseMotionListener.mouseMoved() are captured and can be passed on.
- higher-level functionality (i.e., flood-fill provided).
- in-memory Image maintained with buffered operations to improve graphics display performance.
Nested Class Summary |
---|
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 | |
---|---|
static int |
AQUA
|
static int |
BLACK
The SETPENCOLOR command's input is a built-in color number or an RGB value. |
static int |
BLUE
|
static int |
BROWN
|
static int |
CHOCOLATE
|
static int |
CYAN
|
static int |
EAST
Turtle heading for the positive X axis. |
static int |
FOREST
|
static int |
GOLD
|
static int |
GRAY
|
static int |
GREEN
|
static int |
KHAKI
|
static int |
LAWNGREEN
|
static int |
LIGHTBLUE
|
static int |
LIGHTGRAY
|
static int |
LIME
|
static java.awt.Color[] |
LOGO_COLORS
All derivations of Logo have a basic, minimum set of colors that are specified by numbers. |
static int |
MAGENTA
|
static int |
MAX_LOGO_COLOR
The maximum value for a Logo color which require conversion to RGB colors used by Java. |
static int |
NAVY
|
static int |
NORTH
Turtle heading for the positive Y axis. |
static int |
OLIVE
|
static int |
ORANGE
|
static int |
PALEGREEN
|
static int |
PERU
|
static int |
PINK
|
static int |
PURPLE
|
static int |
RED
|
static int |
SALMON
|
static int |
SKYBLUE
|
static int |
SOUTH
Turtle heading for the negative Y axis. |
static int |
STEELBLUE
|
static int |
TAN
|
static int |
VIOLET
|
static int |
WEST
Turtle heading for the negative X axis. |
static int |
WHEAT
|
static int |
WHITE
|
static int |
YELLOW
|
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 | |
---|---|
TGCanvas()
Instantiate a turtle graphics canvas with initial width of 700 turtle steps and a height of 400 turtle steps. |
|
TGCanvas(int width,
int height)
Instantiate a turtle graphics canvas of a specified width and height. |
Method Summary | |
---|---|
void |
addGraphOp(TGGraphicsOp grafOp)
Append a graphics operation, a TGGraphicsOp object, to the queue of outstanding operations. |
void |
addKeyHandler(TGKeyHandler kh)
Add an object which implements TGKeyHandler to the list of those that want a callback when a key is pressed while the graphics canvas has focus. |
void |
addMouseHandler(TGMouseHandler mh)
Add an object which implements TGMouseHandler to the list of those that want a callback. |
void |
addSprite(Sprite sprite)
Add a new Sprite, start displaying its image on the graphics canvas. |
int |
canvasHeight()
Return the height of the graphics canvas. |
int |
canvasWidth()
Return the width of the graphics canvas. |
void |
clean()
Clean graphics off of the display. |
void |
focusGained(java.awt.event.FocusEvent e)
Invoked when this Component gets focus. |
void |
focusLost(java.awt.event.FocusEvent e)
Invoked when this Component loses focus. |
int |
getBackgroundColor()
Return the background Logo color number. |
java.awt.image.BufferedImage |
getPicture()
Return the contents of the graphics canvas overlaid with existing Sprite images as a composite BufferedImage. |
int[] |
getPixels(TGPoint topLeft,
int width,
int height)
Return an array of pixel RGB values. |
void |
keyPressed(java.awt.event.KeyEvent ke)
Invoked when a key has been pressed. |
void |
keyReleased(java.awt.event.KeyEvent ke)
Invoked when a key has been released. |
void |
keyTyped(java.awt.event.KeyEvent ke)
Invoked when a key has been typed. |
void |
loadPicture(java.awt.Image pictureImage)
Load the provided array of pixels into the background. |
static java.awt.Color |
logoColorToJavaColor(int logoColor)
Convert a Logo color to a Java Color object. |
static int |
logoColorToRGB(int logoColor)
Convert a Logo color to a Java RGB int with the alpha component maintained. |
void |
mouseClicked(java.awt.event.MouseEvent me)
Invoked when a mouse button has been clicked (pressed and released) on this Component. |
void |
mouseDragged(java.awt.event.MouseEvent me)
Invoked when a mouse button is held down on TGCanvas and the mouse is moved. |
void |
mouseEntered(java.awt.event.MouseEvent me)
Invoked when the mouse enters a Component. |
void |
mouseExited(java.awt.event.MouseEvent me)
Invoked when the mouse exits a Component. |
void |
mouseMoved(java.awt.event.MouseEvent me)
Invoked when the mouse is moved around on the TGCanvas without any buttons in a depressed state. |
void |
mousePressed(java.awt.event.MouseEvent me)
Invoked when a mouse button has been pressed while on a Component. |
void |
mouseReleased(java.awt.event.MouseEvent me)
Invoked when a mouse button has been released on TGCanvas. |
int |
mousex()
Return the TurtleSpace x-coordinate of the mouse when it was last clicked. |
int |
mousey()
Return the TurtleSpace y-coordinate of the mouse when it was last clicked. |
void |
paint(java.awt.Graphics g)
Paints this Component. |
void |
removeKeyHandler(TGKeyHandler kh)
Remove an object from TGCanvas' list of those wanting their keyPressed() method invoked when TGCanvas receives this Event. |
void |
removeMouseHandler(TGMouseHandler mh)
Remove an object from TGCanvas' list of those wanting their mouseClicked() and mouseMoved() methods invoked when we receive these Events. |
void |
removeSprite(Sprite sprite)
Remove the specified Sprite from the list of sprites whose images are displayed on the graphics canvas. |
static int |
rgbToLogoColor(int rgbValue)
Return a Logo pen color number given an ARGB or RGB value. |
void |
setbg(int logoColor)
Set the background color of the graphics canvas. |
void |
setBounds(int x,
int y,
int width,
int height)
Moves and resizes this Component. |
void |
setSize(int width,
int height)
Resizes this Component to have the specified width and height. |
void |
update(java.awt.Graphics gfx)
Update the displayed image of this Component. |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, 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, getAccessibleContext, 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, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, 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 static final int NORTH
public static final int EAST
public static final int SOUTH
public static final int WEST
public static final int BLACK
public static final int BLUE
public static final int GREEN
public static final int CYAN
public static final int RED
public static final int MAGENTA
public static final int YELLOW
public static final int WHITE
public static final int BROWN
public static final int TAN
public static final int FOREST
public static final int AQUA
public static final int SALMON
public static final int VIOLET
public static final int ORANGE
public static final int GRAY
public static final int NAVY
public static final int SKYBLUE
public static final int LIME
public static final int STEELBLUE
public static final int CHOCOLATE
public static final int PURPLE
public static final int GOLD
public static final int LIGHTGRAY
public static final int PERU
public static final int WHEAT
public static final int PALEGREEN
public static final int LIGHTBLUE
public static final int KHAKI
public static final int PINK
public static final int LAWNGREEN
public static final int OLIVE
public static final int MAX_LOGO_COLOR
public static final java.awt.Color[] LOGO_COLORS
Constructor Detail |
---|
public TGCanvas()
public TGCanvas(int width, int height)
Method Detail |
---|
public void focusGained(java.awt.event.FocusEvent e)
focusGained
in interface java.awt.event.FocusListener
public void focusLost(java.awt.event.FocusEvent e)
focusLost
in interface java.awt.event.FocusListener
public void keyPressed(java.awt.event.KeyEvent ke)
keyPressed
in interface java.awt.event.KeyListener
public void keyReleased(java.awt.event.KeyEvent ke)
keyReleased
in interface java.awt.event.KeyListener
public void keyTyped(java.awt.event.KeyEvent ke)
keyTyped
in interface java.awt.event.KeyListener
public void mouseClicked(java.awt.event.MouseEvent me)
mouseClicked
in interface java.awt.event.MouseListener
public void mouseEntered(java.awt.event.MouseEvent me)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent me)
mouseExited
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent me)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent me)
mouseReleased
in interface java.awt.event.MouseListener
public void mouseDragged(java.awt.event.MouseEvent me)
mouseDragged
in interface java.awt.event.MouseMotionListener
public void mouseMoved(java.awt.event.MouseEvent me)
mouseMoved
in interface java.awt.event.MouseMotionListener
public void paint(java.awt.Graphics g)
Something has occured that requires updating the graphics canvas. As an example, TGGraphicsOps have been queued to be performed, or a Sprite whose image is being displayed has moved or rotated, or the AWT has decided we need to redraw at least some subset of our pixels, e.g., partially covered stuff (by some other application on the desktop) has moved/gone away, etc...
paint
in class java.awt.Component
public void setBounds(int x, int y, int width, int height)
setBounds
in class java.awt.Component
public void setSize(int width, int height)
setSize
in class java.awt.Component
public void update(java.awt.Graphics gfx)
Overridden in TGCanvas to eliminate Component.update()'s invocation of Graphics.clear().
update
in class java.awt.Component
public void addGraphOp(TGGraphicsOp grafOp)
public void addKeyHandler(TGKeyHandler kh)
public void addMouseHandler(TGMouseHandler mh)
public void addSprite(Sprite sprite)
public int canvasHeight()
public int canvasWidth()
public void clean()
public int getBackgroundColor()
public java.awt.image.BufferedImage getPicture()
public int[] getPixels(TGPoint topLeft, int width, int height)
Since all drawing operations are queued to be performed by the paint() method, we must wait for all outstanding operations to complete before we grab pixels.
public void loadPicture(java.awt.Image pictureImage)
*NOTE* a side-effect of changing the background color is that all current graphics is cleared.
public static java.awt.Color logoColorToJavaColor(int logoColor)
public static int logoColorToRGB(int logoColor)
public int mousex()
mousey()
public int mousey()
mousex()
public void removeKeyHandler(TGKeyHandler kh)
public void removeMouseHandler(TGMouseHandler mh)
public void removeSprite(Sprite sprite)
public static int rgbToLogoColor(int rgbValue)
public void setbg(int logoColor)
*NOTE* a side-effect of changing the background color is that all current graphics is cleared.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |