public class Playground
extends javax.swing.JPanel
implements java.awt.print.Printable
Playground
is the Turtle
's home, i.e. the Turtle
lives
and moves in the Playground
.
ThePlayground
is responsible for interpreting angle and position of the
Turtle
and for choosing the correct turtle image and putting it on the right
spot of the Playground. This means: e.g. whenever you wish to switch the x- and y-axis, you
should do it in this class, and not in the Turtle
class.Modifier and Type | Field and Description |
---|---|
int |
originX
originX is the x-position of the cartesian coodinate system within the playground.
|
int |
originY
originY is the y-position of the cartesian coodinate system within the playground.
|
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
Playground()
Create a Playground with default background color.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Turtle turtle)
Add a new
Turtle to the Playground. |
void |
clear()
Clear playground.
|
void |
clear(java.awt.Color color)
Clear the playground with given color.
|
void |
clearTurtle(Turtle turtle)
Remove the given turtle from the turtle buffer.
|
void |
clearTurtles()
Remove all turtles from the turtle buffer.
|
int |
countTurtles()
Tell current number of
Turtle s in this Playground. |
void |
enableRepaint(boolean b) |
void |
fill(Turtle t,
java.awt.Color bgColor)
Fill a region.
|
int |
getOriginX() |
int |
getOriginY() |
java.awt.Color |
getPixelColor(Turtle t)
Return the color of the pixel at the current turtle position.
|
java.awt.Graphics2D |
getPrinterG2D()
Return the graphics context of the printer.
|
java.awt.image.BufferedImage |
getTraceBuffer()
Return the image of the trace buffer.
|
java.awt.Graphics2D |
getTraceG2D()
Return the graphics context of the trace buffer.
|
Turtle |
getTurtle(int index)
Return the
Turtle at index index . |
java.awt.image.BufferedImage |
getTurtleBuffer()
Return the image of the turtle buffer.
|
java.awt.Graphics2D |
getTurtleG2D()
Return the graphics context of the turtle buffer.
|
void |
label(java.lang.String text,
Turtle t)
Draw the
text at the current position of the Turtle t . |
void |
paintComponent()
Paint the Playground.
|
void |
paintComponent(java.awt.Graphics g)
Draw the trace and turtle buffers.
|
void |
paintPlayground() |
void |
paintTurtle(Turtle turtle)
Paint the given
Turtle |
void |
paintTurtles()
Paint all turtles (calling paintComponent())
|
void |
paintTurtles(Turtle turtle)
Move the given
Turtle above all the others, then
paints all turtles. |
int |
print(java.awt.Graphics g,
java.awt.print.PageFormat pf,
int pageIndex)
For internal use only.
|
void |
remove(Turtle turtle)
Remove a
Turtle from the Playground. |
void |
setAntiAliasing(boolean on)
Set antialiasing on or off for the turtle trace buffer
This may result in an better trace quality.
|
void |
setBackground(java.awt.Color color)
set the background color of the playground
|
void |
setBounds(int x,
int y,
int width,
int height) |
void |
setOrigin(int x,
int y)
Sets the origin of the cartesian coordinate system within the playground
|
Turtle |
toBottom(Turtle turtle)
Put a Turtle below all others.
|
java.awt.geom.Point2D.Double |
toScreenCoords(double x,
double y)
Calculate the screen coordinates of the given point coordinates.
|
java.awt.geom.Point2D.Double |
toScreenCoords(java.awt.geom.Point2D.Double p)
Calculate the screen coordinates of the given point.
|
Turtle |
toTop(Turtle turtle)
Puts a Turtle above all others.
|
java.awt.geom.Point2D.Double |
toTurtleCoords(double x,
double y)
Calculate the turtle coordinates of the given screen coordinates.
|
java.awt.geom.Point2D.Double |
toTurtleCoords(java.awt.geom.Point2D.Double p)
Calculate the turtle coordinates of the given screen point.
|
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public int originX
public int originY
public Playground()
Turtle
s),public void add(Turtle turtle)
Turtle
to the Playground.public void setBounds(int x, int y, int width, int height)
setBounds
in class java.awt.Component
public void remove(Turtle turtle)
Turtle
from the Playground.public int countTurtles()
Turtle
s in this Playground.public Turtle getTurtle(int index)
Turtle
at index index
.public void paintTurtles(Turtle turtle)
Turtle
above all the others, then
paints all turtles.toTop(ch.aplu.turtle.Turtle)
public void paintTurtles()
public void paintTurtle(Turtle turtle)
Turtle
.
( no repaint() )public void fill(Turtle t, java.awt.Color bgColor)
Turtle
s actual position and
is bounded by any other color than the give background color.public void clear(java.awt.Color color)
public void clear()
public void paintComponent()
public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
public void paintPlayground()
public void clearTurtles()
public void clearTurtle(Turtle turtle)
public java.awt.geom.Point2D.Double toScreenCoords(java.awt.geom.Point2D.Double p)
public java.awt.geom.Point2D.Double toScreenCoords(double x, double y)
public java.awt.geom.Point2D.Double toTurtleCoords(double x, double y)
public java.awt.geom.Point2D.Double toTurtleCoords(java.awt.geom.Point2D.Double p)
public java.awt.Graphics2D getTurtleG2D()
public java.awt.image.BufferedImage getTurtleBuffer()
public java.awt.Graphics2D getTraceG2D()
public java.awt.Graphics2D getPrinterG2D()
public java.awt.image.BufferedImage getTraceBuffer()
public void label(java.lang.String text, Turtle t)
text
at the current position of the Turtle t
.
Drawing a text at some coordinates (x,y)
we mean that the bottom left corner of
the text will be at these coordinates.
Font and colour are specified by the Turtle's Pen.public void setAntiAliasing(boolean on)
public int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pageIndex)
print
in interface java.awt.print.Printable
public java.awt.Color getPixelColor(Turtle t)
public void enableRepaint(boolean b)
public void setBackground(java.awt.Color color)
setBackground
in class javax.swing.JComponent
public void setOrigin(int x, int y)
public int getOriginX()
public int getOriginY()