ch.aplu.turtle
Class Playground

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--ch.aplu.turtle.Playground
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable

public class Playground
extends javax.swing.JPanel
implements java.awt.print.Printable

A 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. Remarks:

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Playground(TurtleContainer rootpane)
          Create a new Playground inside the given TurtleContainer and with standard size (400 x 400 pixels).
Playground(TurtleContainer rootpane, java.awt.Dimension size)
          Create a new Playground inside the given TurtleContainer and size.
 
Method Summary
 void add(Turtle turtle)
          Add a new Turtle to the Playground.
 void clear()
          Clear the playground.
 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 Turtles in this Playground.
 void fill(Turtle t)
          Fill a region.
 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()
          Returnt 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 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.
 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.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Playground

public Playground(TurtleContainer rootpane)
Create a new Playground inside the given TurtleContainer and with standard size (400 x 400 pixels).


Playground

public Playground(TurtleContainer rootpane,
                  java.awt.Dimension size)
Create a new Playground inside the given TurtleContainer and size.

Method Detail

add

public void add(Turtle turtle)
Add a new Turtle to the Playground.


clear

public void clear()
Clear the playground.


clearTurtle

public void clearTurtle(Turtle turtle)
Remove the given turtle from the turtle buffer. Override this method if you have added a new behaviour (like wrap or clip) to the turtle.


clearTurtles

public void clearTurtles()
Remove all turtles from the turtle buffer.


countTurtles

public int countTurtles()
Tell current number of Turtles in this Playground.


fill

public void fill(Turtle t)
Fill a region. The region is defined by the Turtles actual position and is bounded by any other color than the background color.
Remark: If the Turtle is already standing on a colored pixel, nothing happens.


getPrinterG2D

public java.awt.Graphics2D getPrinterG2D()
Return the graphics context of the printer.


getTraceBuffer

public java.awt.image.BufferedImage getTraceBuffer()
Return the image of the trace buffer.


getTraceG2D

public java.awt.Graphics2D getTraceG2D()
Return the graphics context of the trace buffer.


getTurtle

public Turtle getTurtle(int index)
Return the Turtle at index index.


getTurtleBuffer

public java.awt.image.BufferedImage getTurtleBuffer()
Return the image of the turtle buffer.


getTurtleG2D

public java.awt.Graphics2D getTurtleG2D()
Returnt the graphics context of the turtle buffer.


label

public void label(java.lang.String text,
                  Turtle t)
Draw the 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.


paintComponent

public void paintComponent()
Paint the Playground. just a method for convenience.


paintComponent

public void paintComponent(java.awt.Graphics g)
Draw the trace and turtle buffers.

Overrides:
paintComponent in class javax.swing.JComponent

paintTurtle

public void paintTurtle(Turtle turtle)
Paint the given Turtle. ( no repaint() )


paintTurtles

public void paintTurtles()
Paint all turtles (calling paintComponent())


paintTurtles

public void paintTurtles(Turtle turtle)
Move the given Turtle above all the others, then paints all turtles.

See Also:
toTop(ch.aplu.turtle.Turtle)

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pf,
                 int pageIndex)
For internal use only. Implementation of Printable. (Callback method called by printing system.)

Specified by:
print in interface java.awt.print.Printable

remove

public void remove(Turtle turtle)
Remove a Turtle from the Playground.


setAntiAliasing

public void setAntiAliasing(boolean on)
Set antialiasing on or off for the turtle trace buffer This may result in an better trace quality.


toBottom

public Turtle toBottom(Turtle turtle)
Put a Turtle below all others.


toScreenCoords

public java.awt.geom.Point2D.Double toScreenCoords(double x,
                                                   double y)
Calculate the screen coordinates of the given point coordinates.


toScreenCoords

public java.awt.geom.Point2D.Double toScreenCoords(java.awt.geom.Point2D.Double p)
Calculate the screen coordinates of the given point.


toTop

public Turtle toTop(Turtle turtle)
Puts a Turtle above all others.


toTurtleCoords

public java.awt.geom.Point2D.Double toTurtleCoords(double x,
                                                   double y)
Calculate the turtle coordinates of the given screen coordinates.


toTurtleCoords

public java.awt.geom.Point2D.Double toTurtleCoords(java.awt.geom.Point2D.Double p)
Calculate the turtle coordinates of the given screen point.