Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / gnu / java / awt / peer / swing / SwingComponentPeer.java
blob5d484e021b28dabef43815b2881aeff12e9fe3ea
1 /* SwingComponentPeer.java -- An abstract base class for Swing based peers
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu.java.awt.peer.swing;
40 import java.awt.AWTEvent;
41 import java.awt.AWTException;
42 import java.awt.BufferCapabilities;
43 import java.awt.Color;
44 import java.awt.Component;
45 import java.awt.Cursor;
46 import java.awt.Dimension;
47 import java.awt.Font;
48 import java.awt.FontMetrics;
49 import java.awt.Graphics;
50 import java.awt.GraphicsConfiguration;
51 import java.awt.Image;
52 import java.awt.Point;
53 import java.awt.Rectangle;
54 import java.awt.Toolkit;
55 import java.awt.BufferCapabilities.FlipContents;
56 import java.awt.event.KeyEvent;
57 import java.awt.event.MouseEvent;
58 import java.awt.event.PaintEvent;
59 import java.awt.image.ColorModel;
60 import java.awt.image.ImageObserver;
61 import java.awt.image.ImageProducer;
62 import java.awt.image.VolatileImage;
63 import java.awt.peer.ComponentPeer;
64 import java.awt.peer.ContainerPeer;
66 /**
67 * The base class for Swing based component peers. This provides the basic
68 * functionality needed for Swing based component peers. Many methods are
69 * implemented to forward to the Swing component. Others however forward
70 * to the component's parent and expect the toplevel component peer to provide
71 * a real implementation of it. These are for example the key methods
72 * {@link #getGraphics()} and {@link #createImage(int, int)}, as well as
73 * {@link #getLocationOnScreen()}.
75 * This class also provides the necesary hooks into the Swing painting and
76 * event handling system. In order to achieve this, it traps paint, mouse and
77 * key events in {@link #handleEvent(AWTEvent)} and calls some special methods
78 * ({@link #peerPaint(Graphics)}, {@link #handleKeyEvent(KeyEvent)},
79 * {@link #handleMouseEvent(MouseEvent)} and
80 * {@link #handleMouseMotionEvent(MouseEvent)}) that call the corresponding
81 * Swing methods.
83 * @author Roman Kennke (kennke@aicas.com)
85 public class SwingComponentPeer
86 implements ComponentPeer
89 /**
90 * The AWT component for this peer.
92 protected Component awtComponent;
94 /**
95 * The Swing component for this peer.
97 protected SwingComponent swingComponent;
99 /**
100 * Creates a SwingComponentPeer instance. Subclasses are expected to call
101 * this constructor and thereafter call {@link #init(Component, JComponent)}
102 * in order to setup the AWT and Swing components properly.
104 protected SwingComponentPeer()
106 // Nothing to do here.
110 * Initializes the AWT and Swing component for this peer. It is expected that
111 * subclasses call this from within their constructor.
113 * @param awtComp the AWT component for this peer
114 * @param swingComp the Swing component for this peer
116 protected void init(Component awtComp, SwingComponent swingComp)
118 awtComponent = awtComp;
119 swingComponent = swingComp;
123 * Returns the construction status of the specified image. This is called
124 * by {@link Component#checkImage(Image, int, int, ImageObserver)}.
126 * @param img the image
127 * @param width the width of the image
128 * @param height the height of the image
129 * @param ob the image observer to be notified of updates of the status
131 * @return a bitwise ORed set of ImageObserver flags
133 public int checkImage(Image img, int width, int height, ImageObserver ob)
135 return Toolkit.getDefaultToolkit().checkImage(img, width, height, ob);
139 * Creates an image by starting the specified image producer. This is called
140 * by {@link Component#createImage(ImageProducer)}.
142 * @param prod the image producer to be used to create the image
144 * @return the created image
146 public Image createImage(ImageProducer prod)
148 Image image = Toolkit.getDefaultToolkit().createImage(prod);
149 return image;
153 * Creates an empty image with the specified <code>width</code> and
154 * <code>height</code>.
156 * This is implemented to let the parent component create the image. This
157 * eventually goes up to the top-level component peer, which is then expected
158 * to deliver the image.
160 * @param width the width of the image to be created
161 * @param height the height of the image to be created
163 * @return the created image
165 public Image createImage(int width, int height)
167 Component parent = awtComponent.getParent();
168 ComponentPeer parentPeer = parent.getPeer();
169 return parentPeer.createImage(width, height);
173 * Disables the component. This is called by {@link Component#disable()}.
175 public void disable()
177 if (swingComponent != null)
178 swingComponent.getJComponent().setEnabled(false);
182 * Disposes the component peer. This should release all resources held by the
183 * peer. This is called when the component is no longer in use.
185 public void dispose()
187 awtComponent = null;
188 swingComponent = null;
192 * Enables the component. This is called by {@link Component#enable()}.
194 public void enable()
196 if (swingComponent != null)
197 swingComponent.getJComponent().setEnabled(true);
201 * Returns the color model of the component. This is currently not used.
203 * @return the color model of the component
205 public ColorModel getColorModel()
207 // FIXME: When this peer method will be used, we need to provide an
208 // implementation of this, probably forwarding to the toplevel peer, like
209 // in the other methods.
210 return null;
214 * Returns the font metrics for the specified font. This is called by
215 * {@link Component#getFontMetrics(Font)}.
217 * This is implemented to query the font metrics from the parent component.
218 * This will eventually call the top-level component peer, which is then
219 * expected to deliver a font metrics object.
221 * @param f the font for which to query the font metrics
223 * @return the font metrics for the specified font
225 public FontMetrics getFontMetrics(Font f)
227 Component parent = awtComponent.getParent();
228 ComponentPeer parentPeer = parent.getPeer();
229 return parentPeer.getFontMetrics(f);
233 * Returns a {@link Graphics} object suitable for drawing on this component.
234 * This is called by {@link Component#getGraphics()}.
236 * This is implemented to query the graphics from the parent component and
237 * adjust the clip and translation to match this component.
238 * This will eventually call the top-level component peer, which is then
239 * expected to deliver a graphics object.
241 * @return a graphics object suitable for drawing on this component
243 public Graphics getGraphics()
245 Component parent = awtComponent.getParent();
246 ComponentPeer parentPeer = parent.getPeer();
247 Graphics g = parentPeer.getGraphics();
248 g.translate(awtComponent.getX(), awtComponent.getY());
249 g.setClip(0, 0, awtComponent.getWidth(), awtComponent.getHeight());
250 return g;
254 * Returns the location of this component in screen coordinates. This is
255 * called by {@link Component#getLocationOnScreen()}.
257 * This is implemented to query the parent component peer for its screen
258 * location and adds the offset of this component to it. This will eventually
259 * call the top-level component's peer, which is then expected to provide
260 * it's screen location.
262 * @return the location of this component in screen coordinates
264 public Point getLocationOnScreen()
266 Component parent = awtComponent.getParent();
267 ComponentPeer parentPeer = parent.getPeer();
268 Point location = parentPeer.getLocationOnScreen();
269 location.x += awtComponent.getX();
270 location.y += awtComponent.getY();
271 return location;
275 * Returns the minimum size for the component. This is called by
276 * {@link Component#getMinimumSize()}.
278 * This is implemented to return the Swing component's minimum size.
280 * @return the minimum size for the component
282 public Dimension getMinimumSize()
284 Dimension retVal;
285 if (swingComponent != null)
286 retVal = swingComponent.getJComponent().getMinimumSize();
287 else
288 retVal = new Dimension(0, 0);
289 return retVal;
293 * Returns the preferred size for the component. This is called by
294 * {@link Component#getPreferredSize()}.
296 * This is implemented to return the Swing component's preferred size.
298 * @return the preferred size for the component
300 public Dimension getPreferredSize()
302 Dimension retVal;
303 if (swingComponent != null)
304 retVal = swingComponent.getJComponent().getPreferredSize();
305 else
306 retVal = new Dimension(0, 0);
307 return retVal;
311 * Returns the toolkit that created this peer.
313 * @return the toolkit that created this peer
315 public Toolkit getToolkit()
317 return Toolkit.getDefaultToolkit();
321 * Handles the given event. This is called from
322 * {@link Component#dispatchEvent(AWTEvent)} to give the peer a chance to
323 * react to events for the component.
325 * @param e the event
327 public void handleEvent(AWTEvent e)
329 switch (e.getID())
331 case PaintEvent.UPDATE:
332 case PaintEvent.PAINT:
333 Graphics g = getGraphics();
334 Rectangle clip = ((PaintEvent)e).getUpdateRect();
335 g.clipRect(clip.x, clip.y, clip.width, clip.height);
336 //if (this instanceof LightweightPeer)
337 // {
338 if (e.getID() == PaintEvent.UPDATE)
339 awtComponent.update(g);
340 else
341 awtComponent.paint(g);
342 // }
343 // We paint the 'heavyweights' at last, so that they appear on top of
344 // everything else.
345 peerPaint(g);
347 g.dispose();
348 break;
349 case MouseEvent.MOUSE_PRESSED:
350 case MouseEvent.MOUSE_RELEASED:
351 case MouseEvent.MOUSE_CLICKED:
352 case MouseEvent.MOUSE_ENTERED:
353 case MouseEvent.MOUSE_EXITED:
354 handleMouseEvent((MouseEvent) e);
355 break;
356 case MouseEvent.MOUSE_MOVED:
357 case MouseEvent.MOUSE_DRAGGED:
358 handleMouseMotionEvent((MouseEvent) e);
359 break;
360 case KeyEvent.KEY_PRESSED:
361 case KeyEvent.KEY_RELEASED:
362 case KeyEvent.KEY_TYPED:
363 handleKeyEvent((KeyEvent) e);
364 break;
365 default:
366 // Other event types are not handled here.
367 break;
372 * Makes the component invisible. This is called from
373 * {@link Component#hide()}.
375 * This is implemented to call setVisible(false) on the Swing component.
377 public void hide()
379 if (swingComponent != null)
380 swingComponent.getJComponent().setVisible(false);
384 * Returns <code>true</code> if the component can receive keyboard input
385 * focus. This is called from {@link Component#isFocusTraversable()}.
387 * This is implemented to return isFocusable() from the Swing component.
389 * @specnote Part of the earlier 1.1 API, replaced by isFocusable().
391 public boolean isFocusTraversable()
393 return swingComponent != null ?
394 swingComponent.getJComponent().isFocusable() : false;
398 * Returns <code>true</code> if the component can receive keyboard input
399 * focus. This is called from {@link Component#isFocusable()}.
401 * This is implemented to return isFocusable() from the Swing component.
403 public boolean isFocusable()
405 return swingComponent != null ?
406 swingComponent.getJComponent().isFocusable() : false;
410 * Returns the minimum size for the component. This is called by
411 * {@link Component#minimumSize()}.
413 * This is implemented to return the Swing component's minimum size.
415 * @return the minimum size for the component
417 public Dimension minimumSize()
419 Dimension retVal;
420 if (swingComponent != null)
421 retVal = swingComponent.getJComponent().getMinimumSize();
422 else
423 retVal = new Dimension(0, 0);
424 return retVal;
428 * Returns the preferred size for the component. This is called by
429 * {@link Component#getPreferredSize()}.
431 * This is implemented to return the Swing component's preferred size.
433 * @return the preferred size for the component
435 public Dimension preferredSize()
437 Dimension retVal;
438 if (swingComponent != null)
439 retVal = swingComponent.getJComponent().getPreferredSize();
440 else
441 retVal = new Dimension(0, 0);
442 return retVal;
446 * Prepares an image for rendering on this component. This is called by
447 * {@link Component#prepareImage(Image, int, int, ImageObserver)}.
449 * @param img the image to prepare
450 * @param width the desired width of the rendered image
451 * @param height the desired height of the rendered image
452 * @param ob the image observer to be notified of updates in the preparation
453 * process
455 * @return <code>true</code> if the image has been fully prepared,
456 * <code>false</code> otherwise (in which case the image observer
457 * receives updates)
459 public void paint(Graphics graphics)
461 // FIXME: I don't know what this method is supposed to do.
465 * Prepares an image for rendering on this component. This is called by
466 * {@link Component#prepareImage(Image, int, int, ImageObserver)}.
468 * @param img the image to prepare
469 * @param width the desired width of the rendered image
470 * @param height the desired height of the rendered image
471 * @param ob the image observer to be notified of updates in the preparation
472 * process
474 * @return <code>true</code> if the image has been fully prepared,
475 * <code>false</code> otherwise (in which case the image observer
476 * receives updates)
478 public boolean prepareImage(Image img, int width, int height, ImageObserver ob)
480 Component parent = awtComponent.getParent();
481 ComponentPeer parentPeer = parent.getPeer();
482 return parentPeer.prepareImage(img, width, height, ob);
485 public void print(Graphics graphics)
487 // FIXME: I don't know what this method is supposed to do.
491 * Repaints the specified rectangle of this component. This is called from
492 * {@link Component#repaint(long, int, int, int, int)}.
494 * This is implemented to call repaint() on the Swing component.
496 * @param tm number of milliseconds to wait with repainting
497 * @param x the X coordinate of the upper left corner of the damaged rectangle
498 * @param y the Y coordinate of the upper left corner of the damaged rectangle
499 * @param width the width of the damaged rectangle
500 * @param height the height of the damaged rectangle
502 public void repaint(long tm, int x, int y, int width, int height)
504 if (swingComponent != null)
505 swingComponent.getJComponent().repaint(tm, x, y, width, height);
506 else
508 PaintEvent ev = new PaintEvent(awtComponent, PaintEvent.UPDATE,
509 new Rectangle(x, y, width, height));
510 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ev);
515 * Requests that this component receives the focus. This is called from
516 * {@link Component#requestFocus()}.
518 * This calls requestFocus() on the Swing component.
520 * @specnote Part of the earlier 1.1 API, apparently replaced by argument
521 * form of the same method.
523 public void requestFocus()
525 if (swingComponent != null)
526 swingComponent.getJComponent().requestFocus();
530 * Requests that this component receives the focus. This is called from
531 * {@link Component#requestFocus()}.
533 * This calls requestFocus() on the Swing component.
535 * @param source TODO
536 * @param bool1 TODO
537 * @param bool2 TODO
538 * @param x TODO
540 * @return TODO
542 public boolean requestFocus(Component source, boolean bool1, boolean bool2, long x)
544 if (swingComponent != null)
545 swingComponent.getJComponent().requestFocus();
546 return swingComponent != null;
550 * Notifies the peer that the bounds of this component have changed. This
551 * is called by {@link Component#reshape(int, int, int, int)}.
553 * This is implemented to call setBounds() on the Swing component.
555 * @param x the X coordinate of the upper left corner of the component
556 * @param y the Y coordinate of the upper left corner of the component
557 * @param width the width of the component
558 * @param height the height of the component
560 public void reshape(int x, int y, int width, int height)
562 if (swingComponent != null)
563 swingComponent.getJComponent().setBounds(x, y, width, height);
567 * Sets the background color of the component. This is called by
568 * {@link Component#setBackground(Color)}.
570 * This is implemented to call setBackground() on the Swing component.
572 * @param color the background color to set
574 public void setBackground(Color color)
576 if (swingComponent != null)
577 swingComponent.getJComponent().setBackground(color);
581 * Notifies the peer that the bounds of this component have changed. This
582 * is called by {@link Component#setBounds(int, int, int, int)}.
584 * This is implemented to call setBounds() on the Swing component.
586 * @param x the X coordinate of the upper left corner of the component
587 * @param y the Y coordinate of the upper left corner of the component
588 * @param width the width of the component
589 * @param height the height of the component
591 public void setBounds(int x, int y, int width, int height)
593 reshape(x, y, width, height);
597 * Sets the cursor of the component. This is called by
598 * {@link Component#setCursor(Cursor)}.
600 * This is implemented to call setCursor() on the Swing component.
602 * @specnote Part of the earlier 1.1 API, apparently no longer needed.
604 public void setCursor(Cursor cursor)
606 if (swingComponent != null)
607 swingComponent.getJComponent().setCursor(cursor);
611 * Sets the enabled/disabled state of this component. This is called by
612 * {@link Component#setEnabled(boolean)}.
614 * This is implemented to call setEnabled() on the Swing component.
616 * @param enabled <code>true</code> to enable the component,
617 * <code>false</code> to disable it
619 public void setEnabled(boolean enabled)
621 if (swingComponent != null)
622 swingComponent.getJComponent().setEnabled(enabled);
626 * Sets the font of the component. This is called by
627 * {@link Component#setFont(Font)}.
629 * This is implemented to call setFont() on the Swing component.
631 * @param font the font to set
633 public void setFont(Font font)
635 if (swingComponent != null)
636 swingComponent.getJComponent().setFont(font);
640 * Sets the foreground color of the component. This is called by
641 * {@link Component#setForeground(Color)}.
643 * This is implemented to call setForeground() on the Swing component.
645 * @param color the foreground color to set
647 public void setForeground(Color color)
649 if (swingComponent != null)
650 swingComponent.getJComponent().setForeground(color);
654 * Sets the visibility state of the component. This is called by
655 * {@link Component#setVisible(boolean)}.
657 * This is implemented to call setVisible() on the Swing component.
659 * @param visible <code>true</code> to make the component visible,
660 * <code>false</code> to make it invisible
662 public void setVisible(boolean visible)
664 if (swingComponent != null)
665 swingComponent.getJComponent().setVisible(visible);
669 * Makes the component visible. This is called by {@link Component#show()}.
671 * This is implemented to call setVisible(true) on the Swing component.
673 public void show()
675 if (swingComponent != null)
676 swingComponent.getJComponent().setVisible(true);
679 /**
680 * Get the graphics configuration of the component. The color model
681 * of the component can be derived from the configuration.
683 * This is implemented to return the GraphicsConfiguration of the parent
684 * component. This will eventually call the toplevel component peer, which
685 * is expected to provide a real implementation.
687 * @return the graphics configuration of the component
689 public GraphicsConfiguration getGraphicsConfiguration()
691 Component parent = awtComponent.getParent();
692 ComponentPeer parentPeer = parent.getPeer();
693 return parentPeer.getGraphicsConfiguration();
697 * Part of an older API, no longer needed.
699 public void setEventMask(long mask)
701 // Nothing to do here.
705 * Returns <code>true</code> if this component has been obscured,
706 * <code>false</code> otherwise. This will only work if
707 * {@link #canDetermineObscurity()} also returns <code>true</code>.
709 * This is not yet implemented.
711 * @return <code>true</code> if this component has been obscured,
712 * <code>false</code> otherwise.
714 public boolean isObscured()
716 return false;
720 * Returns <code>true</code> if this component peer can determine if the
721 * component has been obscured, <code>false</code> otherwise.
723 * This is not yet implemented.
725 * @return <code>true</code> if this component peer can determine if the
726 * component has been obscured, <code>false</code> otherwise
728 public boolean canDetermineObscurity()
730 return false;
734 * Coalesces the specified paint event.
736 * @param e the paint event
738 public void coalescePaintEvent(PaintEvent e)
740 // Nothing to do here yet.
744 * Updates the cursor. This is not yet implemented.
746 public void updateCursorImmediately()
748 // Nothing to do here yet.
752 * Returns true, if this component can handle wheel scrolling,
753 * <code>false</code> otherwise.
755 * This is not yet implemented and returns <code>false</code>.
757 * @return true, if this component can handle wheel scrolling,
758 * <code>false</code> otherwise
760 public boolean handlesWheelScrolling()
762 return false;
766 * A convenience method that creates a volatile image. The volatile
767 * image is created on the screen device on which this component is
768 * displayed, in the device's current graphics configuration.
770 * This is implemented to let the parent component peer create an image.
771 * This eventually ends up in the toplevel component peer, which is then
772 * responsible for creating the real image.
774 * @param width width of the image
775 * @param height height of the image
777 * @see VolatileImage
779 * @since 1.2
781 public VolatileImage createVolatileImage(int width, int height)
783 Component parent = awtComponent.getParent();
784 ComponentPeer parentPeer = parent.getPeer();
785 return parentPeer.createVolatileImage(width, height);
789 * Create a number of image buffers that implement a buffering
790 * strategy according to the given capabilities.
792 * This is implemented to forward to the parent component peer. Eventually
793 * this ends up in the top level component peer, which is then responsible
794 * for doing the real work.
796 * @param numBuffers the number of buffers
797 * @param caps the buffering capabilities
799 * @throws AWTException if the specified buffering strategy is not
800 * implemented
802 * @since 1.2
804 public void createBuffers(int numBuffers, BufferCapabilities caps) throws AWTException
806 Component parent = awtComponent.getParent();
807 ComponentPeer parentPeer = parent.getPeer();
808 parentPeer.createBuffers(numBuffers, caps);
812 * Return the back buffer of this component.
814 * This is implemented to forward to the parent. Eventually this ends
815 * up in the toplevel component, which is then responsible for providing
816 * a back buffer.
818 * @return the back buffer of this component.
820 * @since 1.2
822 public Image getBackBuffer()
824 Component parent = awtComponent.getParent();
825 ComponentPeer parentPeer = parent.getPeer();
826 return parentPeer.getBackBuffer();
830 * Perform a page flip, leaving the contents of the back buffer in
831 * the specified state.
833 * This is implemented to forward to the parent. Eventually this ends
834 * up in the toplevel component, which is then responsible for doing the real
835 * work.
837 * @param contents the state in which to leave the back buffer
839 * @since 1.2
841 public void flip(FlipContents contents)
843 Component parent = awtComponent.getParent();
844 ComponentPeer parentPeer = parent.getPeer();
845 parentPeer.flip(contents);
849 * Destroy the resources created by createBuffers.
851 * This is implemented to forward to the parent component peer. Eventually
852 * this ends up in the top level component peer, which is then responsible
853 * for doing the real work.
855 * @since 1.2
857 public void destroyBuffers()
859 Component parent = awtComponent.getParent();
860 ComponentPeer parentPeer = parent.getPeer();
861 parentPeer.destroyBuffers();
865 * Get the bounds of this component peer.
867 * This is implemented to forward to the Swing component.
869 * @return component peer bounds
870 * @since 1.5
872 public Rectangle getBounds()
874 Rectangle retVal;
875 if (swingComponent != null)
876 retVal = swingComponent.getJComponent().getBounds();
877 else
878 retVal = new Rectangle();
879 return retVal;
883 * Reparent this component under another container.
885 * @param parent
886 * @since 1.5
888 public void reparent(ContainerPeer parent)
890 // Nothing to do here.
894 * Set the bounds of this component peer.
896 * This is implemented to forward to the swing component.
898 * @param x the new x co-ordinate
899 * @param y the new y co-ordinate
900 * @param width the new width
901 * @param height the new height
902 * @param z the new stacking level
903 * @since 1.5
905 public void setBounds(int x, int y, int width, int height, int z)
907 if (swingComponent != null)
908 swingComponent.getJComponent().setBounds(x, y, width, height);
909 // FIXME: Somehow handle the Z order.
913 * Check if this component supports being reparented.
915 * @return true if this component can be reparented,
916 * false otherwise.
917 * @since 1.5
919 public boolean isReparentSupported()
921 return true;
926 * Layout this component peer.
928 * @since 1.5
930 public void layout()
932 if (swingComponent != null)
933 swingComponent.getJComponent().doLayout();
937 * Triggers 'heavyweight' painting of the components. This usually calls
938 * paint() on the Swing component.
940 * @param g the graphics context to use for painting
942 protected void peerPaint(Graphics g)
944 if (swingComponent != null)
945 swingComponent.getJComponent().paint(g);
949 * Handles mouse events on the component. This is usually forwarded to the
950 * SwingComponent's processMouseEvent() method.
952 * @param e the mouse event
954 protected void handleMouseEvent(MouseEvent e)
956 if (swingComponent != null)
957 swingComponent.handleMouseEvent(e);
961 * Handles mouse motion events on the component. This is usually forwarded
962 * to the SwingComponent's processMouseMotionEvent() method.
964 * @param e the mouse motion event
966 protected void handleMouseMotionEvent(MouseEvent e)
968 if (swingComponent != null)
969 swingComponent.handleMouseMotionEvent(e);
973 * Handles key events on the component. This is usually forwarded to the
974 * SwingComponent's processKeyEvent() method.
976 * @param e the key event
978 protected void handleKeyEvent(KeyEvent e)
980 if (swingComponent != null)
981 swingComponent.handleKeyEvent(e);
985 * Returns the AWT component for this peer.
987 * @return the AWT component for this peer
989 public Component getComponent()
991 return awtComponent;