| 
 | ||||||||
| 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
javalib.worldcanvas.AppletCanvas
public class AppletCanvas
A class to represent a canvas for the applet to draw on
| Nested Class Summary | |
|---|---|
| static class | AppletCanvas.PainterPanel that paints the internal buffered image that maintains the persistent graphics state of the buffered panel. | 
| static class | AppletCanvas.RefreshClass Refreshencapsulates methods for graphics refresh. | 
| Nested classes/interfaces inherited from class javax.swing.JPanel | 
|---|
| JPanel.AccessibleJPanel | 
| Nested classes/interfaces inherited from class javax.swing.JComponent | 
|---|
| JComponent.AccessibleJComponent | 
| Nested classes/interfaces inherited from class java.awt.Container | 
|---|
| Container.AccessibleAWTContainer | 
| Nested classes/interfaces inherited from class java.awt.Component | 
|---|
| Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy | 
| Field Summary | |
|---|---|
| protected  BufferedImage | bufferThe buffered image that maintains the persistent graphics state. | 
| protected  int | HEIGHT | 
|  AppletCanvas.Painter | painterThe internal painter panel. | 
| static AppletCanvas | theCanvas | 
| protected  int | WIDTHThe width and height for this buffered panel. | 
| Fields inherited from class javax.swing.JComponent | 
|---|
| accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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.image.ImageObserver | 
|---|
| ABORT, ALLBITS, ERROR, FRAMEBITS, PROPERTIES, SOMEBITS | 
| Constructor Summary | |
|---|---|
| AppletCanvas(int width,
             int height)Create an instance of a CanvasPanel of the given dimensions. | |
| Method Summary | |
|---|---|
|  void | clear()Fills this buffered panel with its background color or Paint. | 
|  void | clearPanel()Fills this buffered panel with its background color or Paint. | 
|  void | drawImage(ImageMaker imread,
          int x,
          int y)Draw the image provided by the on theat the given
 NW corner | 
|  void | drawImage(String fileName,
          Posn nw)Draw the image in the specified file at the location of the given NW corner | 
|  void | drawImage(WorldImage image)Draw the image on the at its
 pinhole location. | 
|  BufferedImage | getBuffer()Returns the internal buffered image for this panel. | 
|  Graphics2D | getBufferGraphics()Returns a Graphics2Dobject that permits
 painting to the internal buffered image for this panel. | 
|  int | getBufferHeight()Returns the height of the buffered image. | 
|  int | getBufferWidth()Returns the width of the buffered image. | 
|  JPanel | getInnerPanel()Returns the internal panel for this buffered panel, that is, the panel that paints the buffered image and handles the mouse and key adapters. | 
|  boolean | isFocusable()We must implement this method to make sure the canvas panel gets focus when moused over - and responds to the key events appropriately. | 
|  boolean | isRequestFocusEnabled()Overrides to delegate to the inner panel that is the panel returned by getInnerPanel(). | 
| protected  boolean | isWhite(Color c) | 
|  void | paintOver(Graphics2D g2)Override this paintOvermethod to add additional
 painting actions after the default buffer repaint is done during
 arepaint()call. | 
|  void | requestFocus()Overrides to delegate to the inner panel that is the panel returned by getInnerPanel(). | 
|  boolean | requestFocusInWindow()Overrides to delegate to the inner panel that is the panel returned by getInnerPanel(). | 
|  void | setBufferSize(int width,
              int height)Sets the size of the buffered image to the given height and width. | 
|  void | setFocusable(boolean focusable)Overrides to delegate to the inner panel that is the panel returned by getInnerPanel(). | 
|  String | toIndentedString(String indent)Produce an indented Stringrepresentation of this Canvas | 
|  String | toString()Produce a Stringrepresentation of this Canvas | 
| Methods inherited from class javax.swing.JPanel | 
|---|
| getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
|---|
protected BufferedImage buffer
protected int HEIGHT
public AppletCanvas.Painter painter
public static AppletCanvas theCanvas
protected int WIDTH
| Constructor Detail | 
|---|
public AppletCanvas(int width,
                    int height)
width - the width of the panelheight - the height of the panel| Method Detail | 
|---|
public final void clear()
Fills this buffered panel 
 with its background color or Paint.
public final void clearPanel()
Fills this buffered panel 
 with its background color or Paint.
public void drawImage(ImageMaker imread,
                      int x,
                      int y)
ImageMakerCanvas
imread - the image maker for the image filex - the x coordinate for the image placementy - the y coordinate for the image placement
public void drawImage(String fileName,
                      Posn nw)
fileName - the name of the image filenw - the NW corner for the image placementpublic void drawImage(WorldImage image)
Canvas
image - the image to be drawnpublic final BufferedImage getBuffer()
Returns the internal buffered image for this panel.
public final Graphics2D getBufferGraphics()
Returns a Graphics2D object that permits
 painting to the internal buffered image for this panel.
The user should always use this object to paint to the buffer and thus indirectly modify this buffered panel.
To make painting changes to the buffer visible, the
 repaint() method must explicitly be called.
 This allows a number of painting operations to be done
 prior to screen repaint.
public final int getBufferHeight()
public final int getBufferWidth()
public final JPanel getInnerPanel()
Returns the internal panel for this buffered panel, that is, the panel that paints the buffered image and handles the mouse and key adapters.
This panel may be used when access to the panel on which the graphics is drawn is needed.
Do not set a border on this internal panel.  Set a
 border on the outer BufferedPanel object.
public boolean isFocusable()
isFocusable in class Componentpublic final boolean isRequestFocusEnabled()
Overrides to delegate to the inner panel that is
 the panel returned by getInnerPanel().
isRequestFocusEnabled in class JComponentprotected boolean isWhite(Color c)
public void paintOver(Graphics2D g2)
Override this paintOver method to add additional
 painting actions after the default buffer repaint is done during
 a repaint() call.
The intention of this facility is to enable algorithmic
 painting to be done via the paintOver method on
 top of the default painting of the buffer image on the panel.
 This makes the buffer appear to be the background and what is
 painted via the paintOver method to be painted in
 the foreground.
The default implementation of the paintOver
 method is to do nothing.  This enables overrides as desired.
As of 2.4.0, this method is called after both the painting of the buffer and the painting of the internal paintable sequence. Given the power inherent in painting both the buffer bitmap and the internal paintable sequence, it is rare that this method will need to be overridden.
g2 - the Graphics2D context for the buffer
           repaint operationpublic final void requestFocus()
Overrides to delegate to the inner panel that is
 the panel returned by getInnerPanel().
requestFocus in class JComponentpublic final boolean requestFocusInWindow()
Overrides to delegate to the inner panel that is
 the panel returned by getInnerPanel().
requestFocusInWindow in class JComponent
public void setBufferSize(int width,
                          int height)
Sets the size of the buffered image to the given height and width.
If the given width or height is less than 1 pixel, it is set to 1 pixel.
Any image area gained by an size increase in either direction will be painted with the current background color.
Any image area lost by a size decrease in either direction will be clipped on the right and/or bottom of the image.
For a short time both the image of the previous size and an image of the new size are maintained in memory.
width - the new width  for the imageheight - the new height for the imagepublic final void setFocusable(boolean focusable)
Overrides to delegate to the inner panel that is
 the panel returned by getInnerPanel().
setFocusable in class Componentpublic String toIndentedString(String indent)
String representation of this Canvas
indent - the desired indentation: ignored, because we only produce
 one line of text.public String toString()
String representation of this Canvas
toString in class Component| 
 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||