|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
ch.aplu.turtle.Playground
public class Playground
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:
Playground
needs a Window (e.g. Frame
, Applet
)
to be displayed. One possible solution for this problem is already given with the TurtleFrame
class, which implements the TurtleContainer
interface. Applets are not yet supported.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
javax.swing.JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.BaselineResizeBehavior |
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()
Create a Playground inside the given TurtleContainer and with standard size (400 x 400 pixels) and default background color. |
|
Playground(java.awt.Color bkColor)
Create a Playground inside the given TurtleContainer and with standard size (400 x 400 pixels) and given background color. |
|
Playground(java.awt.Dimension size)
Create a new Playground inside the given TurtleContainer and size. |
|
Playground(java.awt.Dimension size,
java.awt.Color bkColor)
Create a new Playground inside the given TurtleContainer, size and background color. |
Method Summary | |
---|---|
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. |
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.Dimension |
getSize()
Return the size of the playground. |
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, 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, 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, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, 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, 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, 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, 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, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, 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 |
---|
public Playground()
public Playground(java.awt.Color bkColor)
public Playground(java.awt.Dimension size)
public Playground(java.awt.Dimension size, java.awt.Color bkColor)
Method Detail |
---|
public java.awt.Dimension getSize()
getSize
in class java.awt.Component
public void add(Turtle turtle)
Turtle
to the Playground.
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 clearTurtles()
public void clearTurtle(Turtle turtle)
public Turtle toTop(Turtle turtle)
public Turtle toBottom(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)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |