Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
gnu.java.awt.peer.swing.SwingComponentPeer
getGraphics()
and createImage(int,int)
, as well as
getLocationOnScreen()
.
This class also provides the necesary hooks into the Swing painting and
event handling system. In order to achieve this, it traps paint, mouse and
key events in handleEvent(AWTEvent)
and calls some special methods
(peerPaint(Graphics)
, handleKeyEvent(KeyEvent)
,
handleMouseEvent(MouseEvent)
and
handleMouseMotionEvent(MouseEvent)
) that call the corresponding
Swing methods.
Field Summary | |
protected Component |
|
protected Rectangle |
|
protected Font |
|
protected SwingComponent |
|
Constructor Summary | |
|
Method Summary | |
boolean |
|
int |
|
void |
|
void |
|
Image |
|
Image |
|
VolatileImage |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Image |
|
Rectangle |
|
ColorModel |
|
Component |
|
FontMetrics |
|
Graphics |
|
GraphicsConfiguration |
|
Point |
|
Dimension |
|
Dimension |
|
Toolkit |
|
void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
boolean |
|
void |
|
protected void |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
void |
|
Dimension |
|
void | |
protected void | |
protected void |
|
Dimension |
|
boolean |
|
void | |
void |
|
void |
|
void |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
protected SwingComponentPeer()
Creates a SwingComponentPeer instance. Subclasses are expected to call this constructor and thereafter callinit(Component, JComponent)
in order to setup the AWT and Swing components properly.
public boolean canDetermineObscurity()
Returnstrue
if this component peer can determine if the component has been obscured,false
otherwise. This is not yet implemented.
- Specified by:
- canDetermineObscurity in interface ComponentPeer
- Returns:
true
if this component peer can determine if the component has been obscured,false
otherwise
public int checkImage(Image img, int width, int height, ImageObserver ob)
Returns the construction status of the specified image. This is called byComponent.checkImage(Image,int,int,ImageObserver)
.
- Specified by:
- checkImage in interface ComponentPeer
- Parameters:
img
- the imagewidth
- the width of the imageheight
- the height of the imageob
- the image observer to be notified of updates of the status
- Returns:
- a bitwise ORed set of ImageObserver flags
public void coalescePaintEvent(PaintEvent e)
Coalesces the specified paint event.
- Specified by:
- coalescePaintEvent in interface ComponentPeer
- Parameters:
e
- the paint event
public void createBuffers(int numBuffers, BufferCapabilities caps) throws AWTException
Create a number of image buffers that implement a buffering strategy according to the given capabilities. This is implemented to forward to the parent component peer. Eventually this ends up in the top level component peer, which is then responsible for doing the real work.
- Specified by:
- createBuffers in interface ComponentPeer
- Parameters:
numBuffers
- the number of bufferscaps
- the buffering capabilities
- Throws:
AWTException
- if the specified buffering strategy is not implemented
- Since:
- 1.2
public Image createImage(int width, int height)
Creates an empty image with the specifiedwidth
andheight
. This is implemented to let the parent component create the image. This eventually goes up to the top-level component peer, which is then expected to deliver the image.
- Specified by:
- createImage in interface ComponentPeer
- Parameters:
width
- the width of the image to be createdheight
- the height of the image to be created
- Returns:
- the created image
public Image createImage(ImageProducer prod)
Creates an image by starting the specified image producer. This is called byComponent.createImage(ImageProducer)
.
- Specified by:
- createImage in interface ComponentPeer
- Parameters:
prod
- the image producer to be used to create the image
- Returns:
- the created image
public VolatileImage createVolatileImage(int width, int height)
A convenience method that creates a volatile image. The volatile image is created on the screen device on which this component is displayed, in the device's current graphics configuration. This is implemented to let the parent component peer create an image. This eventually ends up in the toplevel component peer, which is then responsible for creating the real image.
- Specified by:
- createVolatileImage in interface ComponentPeer
- Parameters:
width
- width of the imageheight
- height of the image
- Since:
- 1.2
- See Also:
VolatileImage
public void destroyBuffers()
Destroy the resources created by createBuffers. This is implemented to forward to the parent component peer. Eventually this ends up in the top level component peer, which is then responsible for doing the real work.
- Specified by:
- destroyBuffers in interface ComponentPeer
- Since:
- 1.2
public void disable()
Disables the component. This is called byComponent.disable()
.
- Specified by:
- disable in interface ComponentPeer
public void dispose()
Disposes the component peer. This should release all resources held by the peer. This is called when the component is no longer in use.
- Specified by:
- dispose in interface ComponentPeer
public void enable()
Enables the component. This is called byComponent.enable()
.
- Specified by:
- enable in interface ComponentPeer
public void flip(BufferCapabilities.FlipContents contents)
Perform a page flip, leaving the contents of the back buffer in the specified state. This is implemented to forward to the parent. Eventually this ends up in the toplevel component, which is then responsible for doing the real work.
- Specified by:
- flip in interface ComponentPeer
- Parameters:
contents
- the state in which to leave the back buffer
- Since:
- 1.2
public Image getBackBuffer()
Return the back buffer of this component. This is implemented to forward to the parent. Eventually this ends up in the toplevel component, which is then responsible for providing a back buffer.
- Specified by:
- getBackBuffer in interface ComponentPeer
- Returns:
- the back buffer of this component.
- Since:
- 1.2
public Rectangle getBounds()
Get the bounds of this component peer. This is implemented to forward to the Swing component.
- Specified by:
- getBounds in interface ComponentPeer
- Returns:
- component peer bounds
- Since:
- 1.5
public ColorModel getColorModel()
Returns the color model of the component. This is currently not used.
- Specified by:
- getColorModel in interface ComponentPeer
- Returns:
- the color model of the component
public Component getComponent()
Returns the AWT component for this peer.
- Returns:
- the AWT component for this peer
public FontMetrics getFontMetrics(Font f)
Returns the font metrics for the specified font. This is called byComponent.getFontMetrics(Font)
. This is implemented to query the font metrics from the parent component. This will eventually call the top-level component peer, which is then expected to deliver a font metrics object.
- Specified by:
- getFontMetrics in interface ComponentPeer
- Parameters:
f
- the font for which to query the font metrics
- Returns:
- the font metrics for the specified font
public Graphics getGraphics()
Returns aGraphics
object suitable for drawing on this component. This is called byComponent.getGraphics()
. This is implemented to query the graphics from the parent component and adjust the clip and translation to match this component. This will eventually call the top-level component peer, which is then expected to deliver a graphics object.
- Specified by:
- getGraphics in interface ComponentPeer
- Returns:
- a graphics object suitable for drawing on this component
public GraphicsConfiguration getGraphicsConfiguration()
Get the graphics configuration of the component. The color model of the component can be derived from the configuration. This is implemented to return the GraphicsConfiguration of the parent component. This will eventually call the toplevel component peer, which is expected to provide a real implementation.
- Specified by:
- getGraphicsConfiguration in interface ComponentPeer
- Returns:
- the graphics configuration of the component
public Point getLocationOnScreen()
Returns the location of this component in screen coordinates. This is called byComponent.getLocationOnScreen()
. This is implemented to query the parent component peer for its screen location and adds the offset of this component to it. This will eventually call the top-level component's peer, which is then expected to provide it's screen location.
- Specified by:
- getLocationOnScreen in interface ComponentPeer
- Returns:
- the location of this component in screen coordinates
public Dimension getMinimumSize()
Returns the minimum size for the component. This is called byComponent.getMinimumSize()
. This is implemented to return the Swing component's minimum size.
- Specified by:
- getMinimumSize in interface ComponentPeer
- Returns:
- the minimum size for the component
public Dimension getPreferredSize()
Returns the preferred size for the component. This is called byComponent.getPreferredSize()
. This is implemented to return the Swing component's preferred size.
- Specified by:
- getPreferredSize in interface ComponentPeer
- Returns:
- the preferred size for the component
public Toolkit getToolkit()
Returns the toolkit that created this peer.
- Specified by:
- getToolkit in interface ComponentPeer
- Returns:
- the toolkit that created this peer
public void handleEvent(AWTEvent e)
Handles the given event. This is called fromComponent.dispatchEvent(AWTEvent)
to give the peer a chance to react to events for the component.
- Specified by:
- handleEvent in interface ComponentPeer
- Parameters:
e
- the event
protected void handleFocusEvent(FocusEvent e)
Handles focus events on the component. This is usually forwarded to the SwingComponent's processFocusEvent() method.
- Parameters:
e
- the key event
protected void handleKeyEvent(KeyEvent e)
Handles key events on the component. This is usually forwarded to the SwingComponent's processKeyEvent() method.
- Parameters:
e
- the key event
protected void handleMouseEvent(MouseEvent e)
Handles mouse events on the component. This is usually forwarded to the SwingComponent's processMouseEvent() method.
- Parameters:
e
- the mouse event
protected void handleMouseMotionEvent(MouseEvent e)
Handles mouse motion events on the component. This is usually forwarded to the SwingComponent's processMouseMotionEvent() method.
- Parameters:
e
- the mouse motion event
public boolean handlesWheelScrolling()
Returns true, if this component can handle wheel scrolling,false
otherwise. This is not yet implemented and returnsfalse
.
- Specified by:
- handlesWheelScrolling in interface ComponentPeer
- Returns:
- true, if this component can handle wheel scrolling,
false
otherwise
public void hide()
Makes the component invisible. This is called fromComponent.hide()
. This is implemented to call setVisible(false) on the Swing component.
- Specified by:
- hide in interface ComponentPeer
protected void init(Component awtComp, SwingComponent swingComp)
Initializes the AWT and Swing component for this peer. It is expected that subclasses call this from within their constructor.
- Parameters:
awtComp
- the AWT component for this peerswingComp
- the Swing component for this peer
public boolean isFocusTraversable()
Returnstrue
if the component can receive keyboard input focus. This is called fromComponent.isFocusTraversable()
. This is implemented to return isFocusable() from the Swing component.
- Specified by:
- isFocusTraversable in interface ComponentPeer
public boolean isFocusable()
Returnstrue
if the component can receive keyboard input focus. This is called fromComponent.isFocusable()
. This is implemented to return isFocusable() from the Swing component.
- Specified by:
- isFocusable in interface ComponentPeer
public boolean isObscured()
Returnstrue
if this component has been obscured,false
otherwise. This will only work ifcanDetermineObscurity()
also returnstrue
. This is not yet implemented.
- Specified by:
- isObscured in interface ComponentPeer
- Returns:
true
if this component has been obscured,false
otherwise.
public boolean isReparentSupported()
Check if this component supports being reparented.
- Specified by:
- isReparentSupported in interface ComponentPeer
- Returns:
- true if this component can be reparented, false otherwise.
- Since:
- 1.5
public void layout()
Layout this component peer.
- Specified by:
- layout in interface ComponentPeer
- Since:
- 1.5
public Dimension minimumSize()
Returns the minimum size for the component. This is called byComponent.minimumSize()
. This is implemented to return the Swing component's minimum size.
- Specified by:
- minimumSize in interface ComponentPeer
- Returns:
- the minimum size for the component
public void paint(Graphics graphics)
Paints the component. This is triggered byComponent.paintAll(Graphics)
.
- Specified by:
- paint in interface ComponentPeer
- Parameters:
graphics
- the graphics to paint with
protected void peerPaint(Graphics g, boolean update)
Triggers 'heavyweight' painting of the components. This usually calls paint() on the Swing component.
- Parameters:
g
- the graphics context to use for paintingupdate
- wether we need to call update or paint on the AWT component
protected void peerPaintComponent(Graphics g)
Paints the actual 'heavyweight' swing component, if there is one associated to this peer.
- Parameters:
g
- the graphics to paint the component with
public Dimension preferredSize()
Returns the preferred size for the component. This is called byComponent.getPreferredSize()
. This is implemented to return the Swing component's preferred size.
- Specified by:
- preferredSize in interface ComponentPeer
- Returns:
- the preferred size for the component
public boolean prepareImage(Image img, int width, int height, ImageObserver ob)
Prepares an image for rendering on this component. This is called byComponent.prepareImage(Image,int,int,ImageObserver)
.
- Specified by:
- prepareImage in interface ComponentPeer
- Parameters:
img
- the image to preparewidth
- the desired width of the rendered imageheight
- the desired height of the rendered imageob
- the image observer to be notified of updates in the preparation process
- Returns:
true
if the image has been fully prepared,false
otherwise (in which case the image observer receives updates)
public void repaint(long tm, int x, int y, int width, int height)
Repaints the specified rectangle of this component. This is called fromComponent.repaint(long,int,int,int,int)
. This is implemented to call repaint() on the Swing component.
- Specified by:
- repaint in interface ComponentPeer
- Parameters:
tm
- number of milliseconds to wait with repaintingx
- the X coordinate of the upper left corner of the damaged rectangley
- the Y coordinate of the upper left corner of the damaged rectanglewidth
- the width of the damaged rectangleheight
- the height of the damaged rectangle
public void reparent(ContainerPeer parent)
Reparent this component under another container.
- Specified by:
- reparent in interface ComponentPeer
- Parameters:
parent
-
- Since:
- 1.5
public void requestFocus()
Requests that this component receives the focus. This is called fromComponent.requestFocus()
. This calls requestFocus() on the Swing component.
- Specified by:
- requestFocus in interface ComponentPeer
public boolean requestFocus(Component source, boolean tmp, boolean allowWindowFocus, long tm)
Requests that this component receives the focus. This is called fromComponent.requestFocus()
. This calls requestFocus() on the Swing component.
- Specified by:
- requestFocus in interface ComponentPeer
- Parameters:
source
- the actual component that requests focus (may be a lightweight descendant of the heavyweight container)tmp
- true when the change is temporaryallowWindowFocus
-tm
- the timestamp of the focus change
- Returns:
- true when the focus change is guaranteed to be granted, false otherwise
public boolean requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
- Specified by:
- requestFocus in interface ComponentPeer
public void reshape(int x, int y, int width, int height)
Notifies the peer that the bounds of this component have changed. This is called byComponent.reshape(int,int,int,int)
. This is implemented to call setBounds() on the Swing component.
- Specified by:
- reshape in interface ComponentPeer
- Parameters:
x
- the X coordinate of the upper left corner of the componenty
- the Y coordinate of the upper left corner of the componentwidth
- the width of the componentheight
- the height of the component
public void setBackground(Color color)
Sets the background color of the component. This is called byComponent.setBackground(Color)
. This is implemented to call setBackground() on the Swing component.
- Specified by:
- setBackground in interface ComponentPeer
- Parameters:
color
- the background color to set
public void setBounds(int x, int y, int width, int height)
Notifies the peer that the bounds of this component have changed. This is called byComponent.setBounds(int,int,int,int)
. This is implemented to call setBounds() on the Swing component.
- Specified by:
- setBounds in interface ComponentPeer
- Parameters:
x
- the X coordinate of the upper left corner of the componenty
- the Y coordinate of the upper left corner of the componentwidth
- the width of the componentheight
- the height of the component
public void setBounds(int x, int y, int width, int height, int z)
Set the bounds of this component peer. This is implemented to forward to the swing component.
- Specified by:
- setBounds in interface ComponentPeer
- Parameters:
x
- the new x co-ordinatey
- the new y co-ordinatewidth
- the new widthheight
- the new heightz
- the new stacking level
- Since:
- 1.5
public void setCursor(Cursor cursor)
Sets the cursor of the component. This is called byComponent.setCursor(Cursor)
. This is implemented to call setCursor() on the Swing component.
- Specified by:
- setCursor in interface ComponentPeer
public void setEnabled(boolean enabled)
Sets the enabled/disabled state of this component. This is called byComponent.setEnabled(boolean)
. This is implemented to call setEnabled() on the Swing component.
- Specified by:
- setEnabled in interface ComponentPeer
- Parameters:
enabled
-true
to enable the component,false
to disable it
public void setEventMask(long mask)
Part of an older API, no longer needed.
- Specified by:
- setEventMask in interface ComponentPeer
public void setFont(Font font)
Sets the font of the component. This is called byComponent.setFont(Font)
. This is implemented to call setFont() on the Swing component.
- Specified by:
- setFont in interface ComponentPeer
- Parameters:
font
- the font to set
public void setForeground(Color color)
Sets the foreground color of the component. This is called byComponent.setForeground(Color)
. This is implemented to call setForeground() on the Swing component.
- Specified by:
- setForeground in interface ComponentPeer
- Parameters:
color
- the foreground color to set
public void setVisible(boolean visible)
Sets the visibility state of the component. This is called byComponent.setVisible(boolean)
. This is implemented to call setVisible() on the Swing component.
- Specified by:
- setVisible in interface ComponentPeer
- Parameters:
visible
-true
to make the component visible,false
to make it invisible
public void show()
Makes the component visible. This is called byComponent.show()
. This is implemented to call setVisible(true) on the Swing component.
- Specified by:
- show in interface ComponentPeer
public void updateCursorImmediately()
Updates the cursor. This is not yet implemented.
- Specified by:
- updateCursorImmediately in interface ComponentPeer