|
||||||||
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.CanvasPanel
public class CanvasPanel
A buffered panel to hold the drawings.
Nested Class Summary | |
---|---|
protected static class |
CanvasPanel.Painter
Panel that paints the internal buffered image that maintains the persistent graphics state of the buffered panel. |
static class |
CanvasPanel.Refresh
Class Refresh encapsulates 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 |
buffer
The buffered image that maintains the persistent graphics state. |
protected int |
HEIGHT
|
protected CanvasPanel.Painter |
painter
The internal painter panel. |
protected int |
WIDTH
The 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 | |
---|---|
CanvasPanel(int width,
int height)
Constructs a BufferedPanel containing a buffered image with the given width and height, and the given background color or Paint
for the image. |
Method Summary | |
---|---|
void |
clearPanel()
Fills this buffered panel with its background color or Paint . |
void |
drawImage(ImageMaker imread,
int x,
int y)
Draw the image from the .png file that has been read by the given . |
void |
drawImage(String fileName,
int x,
int y)
Draw the image from the given .png file at the specified location |
void |
drawImage(WorldImage image)
Draw the given image into this panel |
void |
drawImagePixels(ImageMaker imread,
int x,
int y)
Draw the image from the .png file that has been read by the given . |
BufferedImage |
getBuffer()
Returns the internal buffered image for this panel. |
Graphics2D |
getBufferGraphics()
Returns a Graphics2D object 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. |
void |
getFonts()
|
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()
Overrides to delegate to the inner panel that is the panel returned by getInnerPanel() . |
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 paintOver method to add additional
painting actions after the default buffer repaint is done during
a repaint() 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() . |
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 transient BufferedImage buffer
protected int HEIGHT
protected transient CanvasPanel.Painter painter
protected int WIDTH
Constructor Detail |
---|
public CanvasPanel(int width, int height)
Constructs a BufferedPanel containing a buffered image
with the given width and height,
and the given background color or Paint
for the image.
If the given width or height is less than 1 pixel, that value is set to 1 pixel.
Though the component itself may grow arbitrarily large,
the buffered image painted to the buffer will
remain the size specified in this constructor
unless the size is reset using the
setBufferSize
method.
width
- the width of the buffered imageheight
- the height of the buffered imageMethod Detail |
---|
public final void clearPanel()
Fills this buffered panel
with its background color or Paint
.
public void drawImage(ImageMaker imread, int x, int y)
ImageMaker
.
imread
- the given image makerx
- the x coordinate for the NW cornery
- the y coordinate for the NW cornerpublic void drawImage(String fileName, int x, int y)
fileName
- the image filenamex
- the x coordinate for the NW cornery
- the y coordinate for the NW cornerpublic void drawImage(WorldImage image)
image
- the image to drawpublic void drawImagePixels(ImageMaker imread, int x, int y)
ImageMaker
.
imread
- the given image makerx
- the x coordinate for the NW cornery
- the y coordinate for the NW cornerpublic 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 void getFonts()
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 final boolean isFocusable()
Overrides to delegate to the inner panel that is
the panel returned by getInnerPanel()
.
isFocusable
in class Component
public final boolean isRequestFocusEnabled()
Overrides to delegate to the inner panel that is
the panel returned by getInnerPanel()
.
isRequestFocusEnabled
in class JComponent
protected 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 JComponent
public 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 Component
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |