Source Code Cross Referenced for Component.java in  » 6.0-JDK-Modules » j2me » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * @(#)Component.java	1.15 06/10/10
0003:         *
0004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
0005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
0006:         * 
0007:         * This program is free software; you can redistribute it and/or
0008:         * modify it under the terms of the GNU General Public License version
0009:         * 2 only, as published by the Free Software Foundation. 
0010:         * 
0011:         * This program is distributed in the hope that it will be useful, but
0012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014:         * General Public License version 2 for more details (a copy is
0015:         * included at /legal/license.txt). 
0016:         * 
0017:         * You should have received a copy of the GNU General Public License
0018:         * version 2 along with this work; if not, write to the Free Software
0019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020:         * 02110-1301 USA 
0021:         * 
0022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0023:         * Clara, CA 95054 or visit www.sun.com if you need additional
0024:         * information or have any questions. 
0025:         *
0026:         */
0027:
0028:        /*
0029:         * Warning :
0030:         * Two versions of this file exist in this workspace.
0031:         * One for Personal Basis, and one for Personal Profile.
0032:         * Don't edit the wrong one !!!
0033:         */
0034:
0035:        package java.awt;
0036:
0037:        import java.io.PrintStream;
0038:        import java.io.PrintWriter;
0039:        import java.util.Vector;
0040:        import java.util.Locale;
0041:        import java.util.Timer;
0042:        import java.util.TimerTask;
0043:        import java.awt.image.ImageObserver;
0044:        import java.awt.image.ImageProducer;
0045:        import java.awt.image.ColorModel;
0046:        import java.awt.event.*;
0047:        import java.io.Serializable;
0048:        import java.io.ObjectOutputStream;
0049:        import java.io.ObjectInputStream;
0050:        import java.io.IOException;
0051:        import java.security.AccessController;
0052:        import sun.awt.im.InputContext;
0053:        import sun.security.action.GetPropertyAction;
0054:        import java.lang.reflect.InvocationTargetException;
0055:
0056:        /**
0057:         * A <em>component</em> is an object having a graphical representation
0058:         * that can be displayed on the screen and that can interact with the
0059:         * user. Examples of components are the buttons, checkboxes, and scrollbars
0060:         * of a typical graphical user interface. <p>
0061:         * The <code>Component</code> class is the abstract superclass of
0062:         * the nonmenu-related Abstract Window Toolkit components. Class
0063:         * <code>Component</code> can also be extended directly to create a
0064:         * lightweight component. A lightweight component is a component that is
0065:         * not associated with a native opaque window.
0066:         *
0067:         * NOTE: Changes to this class need to be synchronized with
0068:         * 	 src/share/optional/pjae/java/awt/Component.java
0069:         *
0070:         * @version 	1.9, 08/19/02
0071:         * @author 	Nicholas Allen
0072:         * @author 	Sami Shaio
0073:         */
0074:        public abstract class Component implements  ImageObserver,
0075:                MenuContainer, Serializable {
0076:            static Timer updateTimer = new Timer();
0077:            /** If this component delegates to another component then this is the component
0078:             it delegates to. */
0079:
0080:            transient Component delegate;
0081:            /** If this component is a delegate for an AWT Component then this represents the
0082:             AWT component that delagtes to it. */
0083:
0084:            transient Component delegateSource;
0085:            /**
0086:             * The XWindow used by this component
0087:             * @see #addNotify
0088:             * @see #removeNotify
0089:             */
0090:            transient ComponentXWindow xwindow;
0091:            /**
0092:             * The parent of the object. It may be null for top-level components.
0093:             * @see #getParent
0094:             */
0095:            transient Container parent;
0096:            /**
0097:             * The x position of the component in the parent's coordinate system.
0098:             * @see #getLocation
0099:             */
0100:            int x;
0101:            /**
0102:             * The y position of the component in the parent's coordinate system.
0103:             * @see #getLocation
0104:             */
0105:            int y;
0106:            /**
0107:             * The width of the component.
0108:             * @see #getSize
0109:             */
0110:            int width;
0111:            /**
0112:             * The height of the component.
0113:             * @see #getSize
0114:             */
0115:            int height;
0116:            /**
0117:             * The foreground color for this component.
0118:             * @see #getForeground
0119:             * @see #setForeground
0120:             */
0121:            Color foreground;
0122:            /**
0123:             * The background color for this component.
0124:             * @see #getBackground
0125:             * @see #setBackground
0126:             */
0127:            Color background;
0128:            /**
0129:             * The font used by this component.
0130:             * @see #getFont
0131:             * @see #setFont
0132:             */
0133:            Font font;
0134:            /**
0135:             * The cursor displayed when pointer is over this component.
0136:             * @see #getCursor
0137:             * @see #setCursor
0138:             */
0139:            Cursor cursor;
0140:            /**
0141:             * The locale for the component.
0142:             * @see #getLocale
0143:             * @see #setLocale
0144:             */
0145:            Locale locale;
0146:            /**
0147:             * True when the object is visible. An object that is not
0148:             * visible is not drawn on the screen.
0149:             * @see #isVisible
0150:             * @see #setVisible
0151:             */
0152:            boolean visible = true;
0153:            /**
0154:             * True when the object is enabled. An object that is not
0155:             * enabled does not interact with the user.
0156:             * @see #isEnabled
0157:             * @see #setEnabled
0158:             */
0159:            boolean enabled = true;
0160:            /**
0161:             * True when the object is valid. An invalid object needs to
0162:             * be layed out. This flag is set to false when the object
0163:             * size is changed.
0164:             * @see #isValid
0165:             * @see #validate
0166:             * @see #invalidate
0167:             */
0168:            boolean valid = false;
0169:            Vector popups;
0170:            private String name;
0171:            private boolean nameExplicitlySet = false;
0172:            /**
0173:             * The locking object for AWT component-tree and layout operations.
0174:             *
0175:             * @see #getTreeLock
0176:             */
0177:            static final Object LOCK = new Object();
0178:            /** Internal, cached size information */
0179:            Dimension minSize;
0180:            /** Internal, cached size information */
0181:            Dimension prefSize;
0182:            static final boolean defaultNewEventsOnly = Boolean
0183:                    .getBoolean("java.awt.newEventsOnly");
0184:            boolean newEventsOnly = defaultNewEventsOnly;
0185:            transient ComponentListener componentListener;
0186:            transient FocusListener focusListener;
0187:            transient KeyListener keyListener;
0188:            transient MouseListener mouseListener;
0189:            transient MouseMotionListener mouseMotionListener;
0190:            /** Internal, constants for serialization */
0191:            final static String actionListenerK = "actionL";
0192:            final static String adjustmentListenerK = "adjustmentL";
0193:            final static String componentListenerK = "componentL";
0194:            final static String containerListenerK = "containerL";
0195:            final static String focusListenerK = "focusL";
0196:            final static String itemListenerK = "itemL";
0197:            final static String keyListenerK = "keyL";
0198:            final static String mouseListenerK = "mouseL";
0199:            final static String mouseMotionListenerK = "mouseMotionL";
0200:            final static String textListenerK = "textL";
0201:            final static String windowListenerK = "windowL";
0202:            transient RuntimeException windowClosingException = null;
0203:            // The eventMask is ONLY set by subclasses via enableEvents.
0204:            // The mask should NOT be set when listeners are registered
0205:            // so that we can distinguish the difference between when
0206:            // listeners request events and subclasses request them.
0207:            long eventMask;
0208:            /**
0209:             * Static properties for incremental drawing.
0210:             * @see #imageUpdate
0211:             */
0212:            static boolean isInc;
0213:            static int incRate;
0214:            static {
0215:                String s = (String) AccessController
0216:                        .doPrivileged(new GetPropertyAction(
0217:                                "awt.image.incrementaldraw"));
0218:                isInc = (s == null || s.equals("true"));
0219:                s = (String) AccessController
0220:                        .doPrivileged(new GetPropertyAction(
0221:                                "awt.image.redrawrate"));
0222:                incRate = (s != null) ? Integer.parseInt(s) : 100;
0223:            }
0224:            /**
0225:             * Ease-of-use constant for <code>getAlignmentY()</code>.  Specifies an
0226:             * alignment to the top of the component.
0227:             * @see     #getAlignmentY
0228:             */
0229:            public static final float TOP_ALIGNMENT = 0.0f;
0230:            /**
0231:             * Ease-of-use constant for <code>getAlignmentY</code> and
0232:             * <code>getAlignmentX</code>. Specifies an alignment to
0233:             * the center of the component
0234:             * @see     #getAlignmentX
0235:             * @see     #getAlignmentY
0236:             */
0237:            public static final float CENTER_ALIGNMENT = 0.5f;
0238:            /**
0239:             * Ease-of-use constant for <code>getAlignmentY</code>.  Specifies an
0240:             * alignment to the bottom of the component.
0241:             * @see     #getAlignmentY
0242:             */
0243:            public static final float BOTTOM_ALIGNMENT = 1.0f;
0244:            /**
0245:             * Ease-of-use constant for <code>getAlignmentX</code>.  Specifies an
0246:             * alignment to the left side of the component.
0247:             * @see     #getAlignmentX
0248:             */
0249:            public static final float LEFT_ALIGNMENT = 0.0f;
0250:            /**
0251:             * Ease-of-use constant for <code>getAlignmentX</code>.  Specifies an
0252:             * alignment to the right side of the component.
0253:             * @see     #getAlignmentX
0254:             */
0255:            public static final float RIGHT_ALIGNMENT = 1.0f;
0256:            /*
0257:             * JDK 1.1 serialVersionUID
0258:             */
0259:            private static final long serialVersionUID = -7644114512714619750L;
0260:
0261:            /** Invokes the supplied Runnable's run method on the event dispatch thread. This is slightly
0262:             different from the EventQueue.invokeAndWait because it can be called from any thread whereas
0263:             EventQueue.invokeAndWait cannot be called from the event dispatch thread. If called from the
0264:             event dispatch thread the run method will be run immediately. Also, any exceptions thrown are
0265:             caught. This method is convienient if you need to invoke code on a delegate component that is
0266:             not thread safe (e.g. Swing components). */
0267:
0268:            static void invokeAndWait(Runnable runnable) {
0269:                if (EventQueue.isDispatchThread())
0270:                    runnable.run();
0271:                else {
0272:                    try {
0273:                        EventQueue.invokeAndWait(runnable);
0274:                    } catch (InvocationTargetException e) {
0275:                        Throwable e1 = e.getTargetException();
0276:                        if (e1 instanceof  RuntimeException)
0277:                            throw (RuntimeException) e1;
0278:                        if (e1 instanceof  Error)
0279:                            throw (Error) e1;
0280:                        e1.printStackTrace();
0281:                        throw new AWTError(e1.toString());
0282:                    } catch (InterruptedException e) {
0283:                        throw new AWTError("Interrupted");
0284:                    }
0285:                }
0286:            }
0287:
0288:            /**
0289:             * Constructs a new component. Class <code>Component</code> can be
0290:             * extended directly to create a lightweight component that does not
0291:             * utilize an opaque native window. A lightweight component must be
0292:             * hosted by a native container somewhere higher up in the component
0293:             * tree (for example, by a <code>Frame</code> object).
0294:             */
0295:            protected Component() {
0296:            } // Component()
0297:
0298:            /**
0299:             * Construct a name for this component.  Called by getName() when the
0300:             * name is null.
0301:             */
0302:            String constructComponentName() {
0303:                return null; // For strict compliance with prior JDKs, a Component
0304:                // that doesn't set its name should return null from
0305:                // getName();
0306:            }
0307:
0308:            /**
0309:             * Gets the name of the component.
0310:             * @return This component's name.
0311:             * @see    #setName
0312:             * @since JDK1.1
0313:             */
0314:            public String getName() {
0315:                if (name == null && !nameExplicitlySet) {
0316:                    synchronized (this ) {
0317:                        if (name == null && !nameExplicitlySet)
0318:                            name = constructComponentName();
0319:                    }
0320:                }
0321:                return name;
0322:            }
0323:
0324:            /**
0325:             * Sets the name of the component to the specified string.
0326:             * @param <code>name</code>  The string that is to be this
0327:             * component's name.
0328:             * @see #getName
0329:             * @since JDK1.1
0330:             */
0331:            public void setName(String name) {
0332:                synchronized (this ) {
0333:                    this .name = name;
0334:                    nameExplicitlySet = true;
0335:                }
0336:            }
0337:
0338:            /**
0339:             * Gets the parent of this component.
0340:             * @return The parent container of this component.
0341:             * @since JDK1.0
0342:             */
0343:            public Container getParent() {
0344:                return parent;
0345:            }
0346:
0347:            /**
0348:             * Gets this component's locking object (the object that owns the thread
0349:             * sychronization monitor) for AWT component-tree and layout
0350:             * operations.
0351:             * @return This component's locking object.
0352:             */
0353:            public final Object getTreeLock() {
0354:                return LOCK;
0355:            }
0356:
0357:            /**
0358:             * Gets this component's toolkit.
0359:             * Note that the frame that contains a component controls which
0360:             * toolkit is used by that component. Therefore if the component
0361:             * is moved from one frame to another, the toolkit it uses may change.
0362:             * <h3>Compatibility</h3>
0363:             * Personal Profile does not require that an AWT implementation use the
0364:             * peer interfaces, so many methods in the toolkit may throw an
0365:             * UnsupportedOperationException.
0366:             * @return  The toolkit of this component.
0367:             * @see #getPeer
0368:             * @see java.awt.Toolkit
0369:             * @since JDK1.0
0370:             */
0371:            public Toolkit getToolkit() {
0372:                return Toolkit.getDefaultToolkit();
0373:            }
0374:
0375:            /**
0376:             * Returns true if this component is completely opaque, returns
0377:             * false by default.
0378:             * <p>
0379:             * An opaque component paints every pixel within its
0380:             * rectangular region. A non-opaque component paints only some of
0381:             * its pixels, allowing the pixels underneath it to "show through".
0382:             * A component that does not fully paint its pixels therefore
0383:             * provides a degree of transparency.  Only lightweight
0384:             * components can be transparent.
0385:             * <p>
0386:             * Subclasses that guarantee to always completely paint their
0387:             * contents should override this method and return true.  All
0388:             * of the "heavyweight" AWT components are opaque.
0389:             *
0390:             * @return true if this component is completely opaque.
0391:             * @see #isLightweight
0392:             * @since 1.2
0393:             */
0394:            public boolean isOpaque() {
0395:                return isDisplayable() ? !isLightweight() : false;
0396:            }
0397:
0398:            public boolean isDisplayable() {
0399:                return xwindow != null;
0400:            }
0401:
0402:            public boolean isLightweight() {
0403:                return (xwindow != null) ? isLightweightWhenDisplayable()
0404:                        : false;
0405:            }
0406:
0407:            /** Returns whether this component is lightweight. This method exists because
0408:             isLightweight is defined to return false when this component is not displayable.
0409:             This allows us to determine if this component is really lightweight, regardless
0410:             of whether it is displayable or not. */
0411:
0412:            boolean isLightweightWhenDisplayable() {
0413:                return true;
0414:            }
0415:
0416:            /*
0417:             * Fetch the native container somewhere higher up in the component
0418:             * tree that contains this component.
0419:             */
0420:            Container getNativeContainer() {
0421:                Container p = parent;
0422:                while (p != null && p.isLightweight()) {
0423:                    p = p.getParent();
0424:                }
0425:                return p;
0426:            }
0427:
0428:            /**
0429:             * Determines whether this component is valid. Components are
0430:             * invalidated when they are first shown on the screen.
0431:             * @return <code>true</code> if the component is valid; <code>false</code>
0432:             * otherwise.
0433:             * @see #validate
0434:             * @see #invalidate
0435:             * @since JDK1.0
0436:             */
0437:            public boolean isValid() {
0438:                return valid;
0439:            }
0440:
0441:            /**
0442:             * Determines whether this component is visible. Components are
0443:             * initially visible, with the exception of top level components such
0444:             * as <code>Frame</code> objects.
0445:             * @return <code>true</code> if the component is visible;
0446:             * <code>false</code> otherwise.
0447:             * @see #setVisible
0448:             * @since JDK1.0
0449:             */
0450:            public boolean isVisible() {
0451:                return visible;
0452:            }
0453:
0454:            /**
0455:             * Determines whether this component is showing on screen. This means
0456:             * that the component must be visible, and it must be in a container
0457:             * that is visible and showing.
0458:             * @return <code>true</code> if the component is showing;
0459:             * <code>false</code> otherwise.
0460:             * @see #setVisible
0461:             * @since JDK1.0
0462:             */
0463:            public boolean isShowing() {
0464:                return (visible && parent != null && parent.isShowing());
0465:            }
0466:
0467:            /**
0468:             * Determines whether this component is enabled. An enabled component
0469:             * can respond to user input and generate events. Components are
0470:             * enabled initially by default. A component may be enabled or disabled by
0471:             * calling its <code>setEnabled</code> method.
0472:             * @return <code>true</code> if the component is enabled;
0473:             * <code>false</code> otherwise.
0474:             * @see #setEnabled
0475:             * @since JDK1.0
0476:             */
0477:            public boolean isEnabled() {
0478:                return enabled;
0479:            }
0480:
0481:            /**
0482:             * Enables or disables this component, depending on the value of the
0483:             * parameter <code>b</code>. An enabled component can respond to user
0484:             * input and generate events. Components are enabled initially by default.
0485:             * @param     <code>b</code>   If <code>true</code>, this component is
0486:             *            enabled; otherwise this component is disabled.
0487:             * @see #isEnabled
0488:             * @since JDK1.1
0489:             */
0490:            public void setEnabled(boolean b) {
0491:                enable(b);
0492:            }
0493:
0494:            /**
0495:             * @deprecated As of JDK version 1.1,
0496:             * replaced by <code>setEnabled(boolean)</code>.
0497:             */
0498:            public void enable() {
0499:                if (enabled != true) {
0500:                    enabled = true;
0501:                }
0502:                if (delegate != null)
0503:                    delegate.enable();
0504:            }
0505:
0506:            /**
0507:             * @deprecated As of JDK version 1.1,
0508:             * replaced by <code>setEnabled(boolean)</code>.
0509:             */
0510:            public void enable(boolean b) {
0511:                if (b) {
0512:                    enable();
0513:                } else {
0514:                    disable();
0515:                }
0516:            }
0517:
0518:            /**
0519:             * @deprecated As of JDK version 1.1,
0520:             * replaced by <code>setEnabled(boolean)</code>.
0521:             */
0522:            public void disable() {
0523:                if (enabled != false) {
0524:                    enabled = false;
0525:                }
0526:                if (delegate != null)
0527:                    delegate.disable();
0528:            }
0529:
0530:            /**
0531:             * Shows or hides this component depending on the value of parameter
0532:             * <code>b</code>.
0533:             * @param <code>b</code>  If <code>true</code>, shows this component;
0534:             * otherwise, hides this component.
0535:             * @see #isVisible
0536:             * @since JDK1.1
0537:             */
0538:            public void setVisible(boolean b) {
0539:                show(b);
0540:            }
0541:
0542:            /**
0543:             * @deprecated As of JDK version 1.1,
0544:             * replaced by <code>setVisible(boolean)</code>.
0545:             */
0546:            public void show() {
0547:                if (visible != true) {
0548:                    visible = true;
0549:                    ComponentXWindow xwindow = this .xwindow;
0550:                    if (delegate != null)
0551:                        delegate.show();
0552:                    if (xwindow != null) {
0553:                        xwindow.map();
0554:                        repaint();
0555:                    }
0556:                    if (componentListener != null
0557:                            || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) {
0558:                        ComponentEvent e = new ComponentEvent(this ,
0559:                                ComponentEvent.COMPONENT_SHOWN);
0560:                        Toolkit.getEventQueue().postEvent(e);
0561:                    }
0562:                    Container parent = this .parent;
0563:                    if (parent != null) {
0564:                        parent.invalidate();
0565:                    }
0566:                }
0567:            }
0568:
0569:            /**
0570:             * @deprecated As of JDK version 1.1,
0571:             * replaced by <code>setVisible(boolean)</code>.
0572:             */
0573:            public void show(boolean b) {
0574:                if (b) {
0575:                    show();
0576:                } else {
0577:                    hide();
0578:                }
0579:            }
0580:
0581:            /**
0582:             * @deprecated As of JDK version 1.1,
0583:             * replaced by <code>setVisible(boolean)</code>.
0584:             */
0585:            public void hide() {
0586:                if (visible != false) {
0587:                    synchronized (getTreeLock()) {
0588:                        visible = false;
0589:                        ComponentXWindow xwindow = this .xwindow;
0590:                        if (delegate != null)
0591:                            delegate.hide();
0592:                        if (xwindow != null) {
0593:                            xwindow.unmap();
0594:                            repaint();
0595:                        }
0596:                        if (componentListener != null
0597:                                || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) {
0598:                            ComponentEvent e = new ComponentEvent(this ,
0599:                                    ComponentEvent.COMPONENT_HIDDEN);
0600:                            Toolkit.getEventQueue().postEvent(e);
0601:                        }
0602:                        Container parent = this .parent;
0603:                        if (parent != null) {
0604:                            parent.invalidate();
0605:                        }
0606:                    }
0607:                }
0608:            }
0609:
0610:            /** Gets the component used to delegate setFont, setBackground, setForeground to. */
0611:
0612:            Component getFontAndColorDelegate() {
0613:                return delegate;
0614:            }
0615:
0616:            /**
0617:             * Gets the foreground color of this component.
0618:             * @return This component's foreground color. If this component does
0619:             * not have a foreground color, the foreground color of its parent
0620:             * is returned.
0621:             * @see #setForeground(java.awt.Color)
0622:             * @since JDK1.0
0623:             */
0624:            public Color getForeground() {
0625:                Color foreground = this .foreground;
0626:                if (foreground != null) {
0627:                    return foreground;
0628:                }
0629:                Component delegate = getFontAndColorDelegate();
0630:                if (delegate != null)
0631:                    return delegate.getForeground();
0632:                Container parent = this .parent;
0633:                return (parent != null) ? parent.getForeground() : null;
0634:            }
0635:
0636:            /**
0637:             * Sets the foreground color of this component.
0638:             * @param <code>c</code> The color to become this component's
0639:             * foreground color.
0640:             * @see #getForeground
0641:             * @since JDK1.0
0642:             */
0643:            public void setForeground(Color c) {
0644:                foreground = c;
0645:                Component delegate = getFontAndColorDelegate();
0646:                if (delegate != null)
0647:                    delegate.setForeground(c);
0648:            }
0649:
0650:            /**
0651:             * Gets the background color of this component.
0652:             * @return This component's background color. If this component does
0653:             * not have a background color, the background color of its parent
0654:             * is returned.
0655:             * @see java.awt.Component#setBackground(java.awt.Color)
0656:             * @since JDK1.0
0657:             */
0658:            public Color getBackground() {
0659:                Color background = this .background;
0660:                if (background != null) {
0661:                    return background;
0662:                }
0663:                Component delegate = getFontAndColorDelegate();
0664:                if (delegate != null)
0665:                    return delegate.getBackground();
0666:                Container parent = this .parent;
0667:                return (parent != null) ? parent.getBackground() : null;
0668:            }
0669:
0670:            /**
0671:             * Sets the background color of this component.
0672:             * @param <code>c</code> The color to become this component's
0673:             * background color.
0674:             * @see #getBackground
0675:             * @since JDK1.0
0676:             */
0677:            public void setBackground(Color c) {
0678:                background = c;
0679:                Component delegate = getFontAndColorDelegate();
0680:                if (delegate != null)
0681:                    delegate.setBackground(c);
0682:            }
0683:
0684:            /**
0685:             * Gets the font of this component.
0686:             * @return This component's font. If a font has not been set
0687:             * for this component, the font of its parent is returned.
0688:             * @see #setFont
0689:             * @since JDK1.0
0690:             */
0691:            public Font getFont() {
0692:                Font font = this .font;
0693:                if (font != null) {
0694:                    return font;
0695:                }
0696:                Component delegate = getFontAndColorDelegate();
0697:                if (delegate != null)
0698:                    return delegate.getFont();
0699:                Container parent = this .parent;
0700:                return (parent != null) ? parent.getFont() : null;
0701:            }
0702:
0703:            /**
0704:             * Sets the font of this component.
0705:             * @param <code>f</code> The font to become this component's font.
0706:             * @see #getFont
0707:             * @since JDK1.0
0708:             */
0709:            public void setFont(Font f) {
0710:                font = f;
0711:                Component delegate = getFontAndColorDelegate();
0712:                if (delegate != null)
0713:                    delegate.setFont(f);
0714:            }
0715:
0716:            /**
0717:             * Gets the locale of this component.
0718:             * @return This component's locale. If this component does not
0719:             * have a locale, the locale of its parent is returned.
0720:             * @see #setLocale
0721:             * @exception IllegalComponentStateException If the Component
0722:             * does not have its own locale and has not yet been added to
0723:             * a containment hierarchy such that the locale can be determined
0724:             * from the containing parent.
0725:             * @since  JDK1.1
0726:             */
0727:            public Locale getLocale() {
0728:                Locale locale = this .locale;
0729:                if (locale != null) {
0730:                    return locale;
0731:                }
0732:                Container parent = this .parent;
0733:                if (parent == null) {
0734:                    throw new IllegalComponentStateException(
0735:                            "This component must have a parent in order to determine its locale");
0736:                } else {
0737:                    return parent.getLocale();
0738:                }
0739:            }
0740:
0741:            /**
0742:             * Sets the locale of this component.
0743:             * @param <code>l</code> The locale to become this component's locale.
0744:             * @see #getLocale
0745:             * @since JDK1.1
0746:             */
0747:            public void setLocale(Locale l) {
0748:                locale = l;
0749:            }
0750:
0751:            /**
0752:             * Gets the instance of <code>ColorModel</code> used to display
0753:             * the component on the output device.
0754:             * @return The color model used by this component.
0755:             * @see java.awt.image.ColorModel
0756:             * @see sun.awt.peer.ComponentPeer#getColorModel()
0757:             * @see java.awt.Toolkit#getColorModel()
0758:             * @since JDK1.0
0759:             */
0760:            public ColorModel getColorModel() {
0761:                return getToolkit().getColorModel();
0762:            }
0763:
0764:            /**
0765:             * Gets the location of this component in the form of a
0766:             * point specifying the component's top-left corner.
0767:             * The location will be relative to the parent's coordinate space.
0768:             * @return An instance of <code>Point</code> representing
0769:             * the top-left corner of the component's bounds in the coordinate
0770:             * space of the component's parent.
0771:             * @see #setLocation
0772:             * @see #getLocationOnScreen
0773:             * @since JDK1.1
0774:             */
0775:            public Point getLocation() {
0776:                return location();
0777:            }
0778:
0779:            /**
0780:             * Gets the location of this component in the form of a point
0781:             * specifying the component's top-left corner in the screen's
0782:             * coordinate space.
0783:             * @return An instance of <code>Point</code> representing
0784:             * the top-left corner of the component's bounds in the
0785:             * coordinate space of the screen.
0786:             * @see #setLocation
0787:             * @see #getLocation
0788:             */
0789:            public Point getLocationOnScreen() {
0790:                synchronized (getTreeLock()) {
0791:                    if (visible && xwindow != null) {
0792:                        return xwindow.getLocationOnScreen();
0793:                    } else {
0794:                        throw new IllegalComponentStateException(
0795:                                "component must be showing on the screen to determine its location");
0796:                    }
0797:                }
0798:            }
0799:
0800:            /**
0801:             * @deprecated As of JDK version 1.1,
0802:             * replaced by <code>getLocation()</code>.
0803:             */
0804:            public Point location() {
0805:                return new Point(x, y);
0806:            }
0807:
0808:            /**
0809:             * Moves this component to a new location. The top-left corner of
0810:             * the new location is specified by the <code>x</code> and <code>y</code>
0811:             * parameters in the coordinate space of this component's parent.
0812:             * @param <code>x</code> The <i>x</i>-coordinate of the new location's
0813:             * top-left corner in the parent's coordinate space.
0814:             * @param <code>y</code> The <i>y</i>-coordinate of the new location's
0815:             * top-left corner in the parent's coordinate space.
0816:             * @see #getLocation
0817:             * @see #setBounds
0818:             * @since JDK1.1
0819:             */
0820:            public void setLocation(int x, int y) {
0821:                move(x, y);
0822:            }
0823:
0824:            /**
0825:             * @deprecated As of JDK version 1.1,
0826:             * replaced by <code>setLocation(int, int)</code>.
0827:             */
0828:            public void move(int x, int y) {
0829:                setBounds(x, y, width, height);
0830:            }
0831:
0832:            /**
0833:             * Moves this component to a new location. The top-left corner of
0834:             * the new location is specified by point <code>p</code>. Point
0835:             * <code>p</code> is given in the parent's coordinate space.
0836:             * @param <code>p</code> The point defining the top-left corner
0837:             * of the new location, given in the coordinate space of this
0838:             * component's parent.
0839:             * @see #getLocation
0840:             * @see #setBounds
0841:             * @since JDK1.1
0842:             */
0843:            public void setLocation(Point p) {
0844:                setLocation(p.x, p.y);
0845:            }
0846:
0847:            /**
0848:             * Returns the size of this component in the form of a
0849:             * <code>Dimension</code> object. The <code>height</code>
0850:             * field of the <code>Dimension</code> object contains
0851:             * this component's height, and the <code>width</code>
0852:             * field of the <code>Dimension</code> object contains
0853:             * this component's width.
0854:             * @return A <code>Dimension</code> object that indicates the
0855:             * size of this component.
0856:             * @see #setSize
0857:             * @since JDK1.1
0858:             */
0859:            public Dimension getSize() {
0860:                return size();
0861:            }
0862:
0863:            /**
0864:             * @deprecated As of JDK version 1.1,
0865:             * replaced by <code>getSize()</code>.
0866:             */
0867:            public Dimension size() {
0868:                return new Dimension(width, height);
0869:            }
0870:
0871:            /**
0872:             * Resizes this component so that it has width <code>width</code>
0873:             * and <code>height</code>.
0874:             * @param <code>width</code> The new width of this component in pixels.
0875:             * @param <code>height</code> The new height of this component in pixels.
0876:             * @see #getSize
0877:             * @see #setBounds
0878:             * @since JDK1.1
0879:             */
0880:            public void setSize(int width, int height) {
0881:                resize(width, height);
0882:            }
0883:
0884:            /**
0885:             * @deprecated As of JDK version 1.1,
0886:             * replaced by <code>setSize(int, int)</code>.
0887:             */
0888:            public void resize(int width, int height) {
0889:                setBounds(x, y, width, height);
0890:            }
0891:
0892:            /**
0893:             * Resizes this component so that it has width <code>d.width</code>
0894:             * and height <code>d.height</code>.
0895:             * @param <code>d</code> The dimension specifying the new size
0896:             * of this component.
0897:             * @see #setSize
0898:             * @see #setBounds
0899:             * @since JDK1.1
0900:             */
0901:            public void setSize(Dimension d) {
0902:                resize(d);
0903:            }
0904:
0905:            /**
0906:             * @deprecated As of JDK version 1.1,
0907:             * replaced by <code>setSize(Dimension)</code>.
0908:             */
0909:            public void resize(Dimension d) {
0910:                setSize(d.width, d.height);
0911:            }
0912:
0913:            /**
0914:             * Gets the bounds of this component in the form of a
0915:             * <code>Rectangle</code> object. The bounds specify this
0916:             * component's width, height, and location relative to
0917:             * its parent.
0918:             * @return A rectangle indicating this component's bounds.
0919:             * @see #setBounds
0920:             * @see #getLocation
0921:             * @see #getSize
0922:             */
0923:            public Rectangle getBounds() {
0924:                return bounds();
0925:            }
0926:
0927:            /**
0928:             * @deprecated As of JDK version 1.1,
0929:             * replaced by <code>getBounds()</code>.
0930:             */
0931:            public Rectangle bounds() {
0932:                return new Rectangle(x, y, width, height);
0933:            }
0934:
0935:            /**
0936:             * Moves and resizes this component. The new location of the top-left
0937:             * corner is specified by <code>x</code> and <code>y</code>, and the
0938:             * new size is specified by <code>width</code> and <code>height</code>.
0939:             * @param <code>x</code> The new <i>x</i>-coordinate of this component.
0940:             * @param <code>y</code> The new <i>y</i>-coordinate of this component.
0941:             * @param <code>width</code> The new <code>width</code> of this component.
0942:             * @param <code>height</code> The new <code>height</code> of this
0943:             * component.
0944:             * @see java.awt.Component#getBounds
0945:             * @see java.awt.Component#setLocation(int, int)
0946:             * @see java.awt.Component#setLocation(java.awt.Point)
0947:             * @see java.awt.Component#setSize(int, int)
0948:             * @see java.awt.Component#setSize(java.awt.Dimension)
0949:             * @JDK1.1
0950:             */
0951:            public void setBounds(int x, int y, int width, int height) {
0952:                reshape(x, y, width, height);
0953:            }
0954:
0955:            /**
0956:             * @deprecated As of JDK version 1.1,
0957:             * replaced by <code>setBounds(int, int, int, int)</code>.
0958:             */
0959:            public void reshape(int x, int y, int width, int height) {
0960:                synchronized (getTreeLock()) {
0961:                    boolean resized = (this .width != width)
0962:                            || (this .height != height);
0963:                    boolean moved = (this .x != x) || (this .y != y);
0964:                    if (resized || moved) {
0965:                        if (visible)
0966:                            repaint();
0967:                        this .x = x;
0968:                        this .y = y;
0969:                        this .width = width;
0970:                        this .height = height;
0971:                        if (delegate != null)
0972:                            delegate.setBounds(x, y, width, height);
0973:                        if (xwindow != null) {
0974:                            xwindow.setBounds(x, y, width, height);
0975:                            if (resized)
0976:                                invalidate();
0977:                            if (parent != null && parent.valid)
0978:                                parent.invalidate();
0979:                        }
0980:                        if (resized
0981:                                && componentListener != null
0982:                                || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) {
0983:                            ComponentEvent e = new ComponentEvent(this ,
0984:                                    ComponentEvent.COMPONENT_RESIZED);
0985:                            Toolkit.getEventQueue().postEvent(e);
0986:                        }
0987:                        if (moved
0988:                                && (componentListener != null || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)) {
0989:                            ComponentEvent e = new ComponentEvent(this ,
0990:                                    ComponentEvent.COMPONENT_MOVED);
0991:                            Toolkit.getEventQueue().postEvent(e);
0992:                        }
0993:                        if (visible) {
0994:                            // Have the parent redraw the area this component *now* occupies.
0995:                            repaint();
0996:                        }
0997:                    }
0998:                }
0999:            }
1000:
1001:            /**
1002:             * Moves and resizes this component to conform to the new
1003:             * bounding rectangle <code>r</code>. This component's new
1004:             * position is specified by <code>r.x</code> and <code>r.y</code>,
1005:             * and its new size is specified by <code>r.width</code> and
1006:             * <code>r.height</code>
1007:             * @param <code>r<code> The new bounding rectangle for this component.
1008:             * @see       java.awt.Component#getBounds
1009:             * @see       java.awt.Component#setLocation(int, int)
1010:             * @see       java.awt.Component#setLocation(java.awt.Point)
1011:             * @see       java.awt.Component#setSize(int, int)
1012:             * @see       java.awt.Component#setSize(java.awt.Dimension)
1013:             * @since     JDK1.1
1014:             */
1015:            public void setBounds(Rectangle r) {
1016:                setBounds(r.x, r.y, r.width, r.height);
1017:            }
1018:
1019:            /**
1020:             * Gets the preferred size of this component.
1021:             * @return A dimension object indicating this component's preferred size.
1022:             * @see #getMinimumSize
1023:             * @see java.awt.LayoutManager
1024:             */
1025:            public Dimension getPreferredSize() {
1026:                return preferredSize();
1027:            }
1028:
1029:            /**
1030:             * @deprecated As of JDK version 1.1,
1031:             * replaced by <code>getPreferredSize()</code>.
1032:             */
1033:            public Dimension preferredSize() {
1034:                /* Avoid grabbing the lock if a reasonable cached size value
1035:                 * is available.
1036:                 */
1037:
1038:                if (delegate != null)
1039:                    return delegate.getPreferredSize();
1040:                Dimension dim = prefSize;
1041:                if (dim != null && isValid()) {
1042:                    return dim;
1043:                }
1044:                synchronized (getTreeLock()) {
1045:                    prefSize = getMinimumSize();
1046:                    return prefSize;
1047:                }
1048:            }
1049:
1050:            /**
1051:             * Gets the mininimum size of this component.
1052:             * @return A dimension object indicating this component's minimum size.
1053:             * @see #getPreferredSize
1054:             * @see java.awt.LayoutManager
1055:             */
1056:            public Dimension getMinimumSize() {
1057:                return minimumSize();
1058:            }
1059:
1060:            /**
1061:             * @deprecated As of JDK version 1.1,
1062:             * replaced by <code>getMinimumSize()</code>.
1063:             */
1064:            public Dimension minimumSize() {
1065:                if (delegate != null)
1066:                    return delegate.getMinimumSize();
1067:                /* Avoid grabbing the lock if a reasonable cached size value
1068:                 * is available.
1069:                 */
1070:                Dimension dim = minSize;
1071:                if (dim != null && isValid()) {
1072:                    return dim;
1073:                }
1074:                synchronized (getTreeLock()) {
1075:                    minSize = new Dimension(0, 0);
1076:                    return minSize;
1077:                }
1078:            }
1079:
1080:            /**
1081:             * Gets the maximum size of this component.
1082:             * @return A dimension object indicating this component's maximum size.
1083:             * @see #getMinimumSize
1084:             * @see #getPreferredSize
1085:             * @see LayoutManager
1086:             */
1087:            public Dimension getMaximumSize() {
1088:                if (delegate != null)
1089:                    return delegate.getMaximumSize();
1090:                return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
1091:            }
1092:
1093:            /**
1094:             * Returns the alignment along the x axis.  This specifies how
1095:             * the component would like to be aligned relative to other
1096:             * components.  The value should be a number between 0 and 1
1097:             * where 0 represents alignment along the origin, 1 is aligned
1098:             * the furthest away from the origin, 0.5 is centered, etc.
1099:             */
1100:            public float getAlignmentX() {
1101:                return CENTER_ALIGNMENT;
1102:            }
1103:
1104:            /**
1105:             * Returns the alignment along the y axis.  This specifies how
1106:             * the component would like to be aligned relative to other
1107:             * components.  The value should be a number between 0 and 1
1108:             * where 0 represents alignment along the origin, 1 is aligned
1109:             * the furthest away from the origin, 0.5 is centered, etc.
1110:             */
1111:            public float getAlignmentY() {
1112:                return CENTER_ALIGNMENT;
1113:            }
1114:
1115:            /**
1116:             * Prompts the layout manager to lay out this component. This is
1117:             * usually called when the component (more specifically, container)
1118:             * is validated.
1119:             * @see #validate
1120:             * @see LayoutManager
1121:             */
1122:            public void doLayout() {
1123:                layout();
1124:            }
1125:
1126:            /**
1127:             * @deprecated As of JDK version 1.1,
1128:             * replaced by <code>doLayout()</code>.
1129:             */
1130:            public void layout() {
1131:            }
1132:
1133:            /**
1134:             * Ensures that this component has a valid layout.  This method is
1135:             * primarily intended to operate on instances of <code>Container</code>.
1136:             * @see       java.awt.Component#invalidate
1137:             * @see       java.awt.Component#doLayout()
1138:             * @see       java.awt.LayoutManager
1139:             * @see       java.awt.Container#validate
1140:             * @since     JDK1.0
1141:             */
1142:            public void validate() {
1143:                if (!valid) {
1144:                    synchronized (getTreeLock()) {
1145:                        valid = true;
1146:                    }
1147:                }
1148:                if (delegate != null)
1149:                    delegate.validate();
1150:            }
1151:
1152:            /**
1153:             * Invalidates this component.  This component and all parents
1154:             * above it are marked as needing to be laid out.  This method can
1155:             * be called often, so it needs to execute quickly.
1156:             * @see       java.awt.Component#validate
1157:             * @see       java.awt.Component#doLayout
1158:             * @see       java.awt.LayoutManager
1159:             * @since     JDK1.0
1160:             */
1161:            public void invalidate() {
1162:                synchronized (getTreeLock()) {
1163:                    /* Nullify cached layout and size information.
1164:                     * For efficiency, propagate invalidate() upwards only if
1165:                     * some other component hasn't already done so first.
1166:                     */
1167:                    valid = false;
1168:                    prefSize = null;
1169:                    minSize = null;
1170:                    if (parent != null && parent.valid) {
1171:                        parent.invalidate();
1172:                    }
1173:                }
1174:            }
1175:
1176:            /**
1177:             * Creates a graphics context for this component. This method will
1178:             * return <code>null</code> if this component is currently not on
1179:             * the screen.
1180:             * @return A graphics context for this component, or <code>null</code>
1181:             *             if it has none.
1182:             * @see       java.awt.Component#paint
1183:             * @since     JDK1.0
1184:             */
1185:            public Graphics getGraphics() {
1186:                Component c = this ;
1187:                int x = 0;
1188:                int y = 0;
1189:                while (c != null) {
1190:                    ComponentXWindow xwindow = c.xwindow;
1191:                    if (xwindow == null)
1192:                        return null;
1193:                    if (xwindow instanceof  HeavyweightComponentXWindow) {
1194:                        X11Graphics g = new X11Graphics(
1195:                                (HeavyweightComponentXWindow) xwindow);
1196:                        g.translate(x, y);
1197:                        g.clipRect(0, 0, width, height);
1198:                        g.setColor(getForeground());
1199:                        g.background = getBackground();
1200:                        g.setFont(getFont());
1201:                        return g;
1202:                    }
1203:                    if (c.delegateSource != null)
1204:                        c = c.delegateSource;
1205:                    else {
1206:                        x += c.x;
1207:                        y += c.y;
1208:                        c = c.parent;
1209:                    }
1210:                }
1211:                return null;
1212:            }
1213:
1214:            /**
1215:             * Gets the font metrics for the specified font.
1216:             * @param <code>font</code> The font for which font metrics is to be
1217:             * obtained.
1218:             * @return The font metrics for <code>font</code>.
1219:             * @param     font   the font.
1220:             * @return    the font metrics for the specified font.
1221:             * @see       java.awt.Component#getFont
1222:             * @see       java.awt.Component#getPeer()
1223:             * @see       sun.awt.peer.ComponentPeer#getFontMetrics(java.awt.Font)
1224:             * @see       java.awt.Toolkit#getFontMetrics(java.awt.Font)
1225:             * @since     JDK1.0
1226:             */
1227:            public FontMetrics getFontMetrics(Font font) {
1228:                return getToolkit().getFontMetrics(font);
1229:            }
1230:
1231:            /**
1232:             * Sets this components cursor image.
1233:             * <h3>Compatibility</h3>
1234:             * In PersonalJava and PersonalProfile, if the underlying platform does
1235:             * not support cursors or has limited cursor support, the setCursor method
1236:             * can be ignored.
1237:             * <p>
1238:             * If the setCuror method ignores some, but not all cursors, it is important
1239:             * that getCursor() returns a cursor that will not be ignored so that an
1240:             * application can restore the cursor accordingly.
1241:             * @param <code>cursor</code> the non-null cursor image.
1242:             * @see       java.awt.Component#getCursor
1243:             * @see       java.awt.Cursor
1244:             * @since     JDK1.1
1245:             */
1246:            public synchronized void setCursor(Cursor cursor) {
1247:                this .cursor = cursor;
1248:                ComponentXWindow xwindow = this .xwindow;
1249:                if (xwindow != null) {
1250:                    xwindow.setCursor(cursor);
1251:                }
1252:                if (delegate != null)
1253:                    delegate.setCursor(cursor);
1254:            }
1255:
1256:            /**
1257:             
1258:             * Gets this component's cursor image.
1259:             * <h3>Compatibility</h3>
1260:             * If setCursor is not always ignored, getCursor() must provide a
1261:             * cursor that will not be ignored when setCursor is called so that an
1262:             * application may restore the cursor after setting it.
1263:             * @return     The cursor for this component.
1264:             * @see        java.awt.Component#setCursor
1265:             * @see        java.awt.Cursor
1266:             * @since      JDK1.1
1267:             */
1268:            public Cursor getCursor() {
1269:                return cursor;
1270:            }
1271:
1272:            /**
1273:             * Paints this component.  This method is called when the contents
1274:             * of the component should be painted in response to the component
1275:             * first being shown or damage needing repair.  The clip rectangle
1276:             * in the Graphics parameter will be set to the area which needs
1277:             * to be painted.
1278:             * @param <code>g</code> The graphics context to use for painting.
1279:             * @see       java.awt.Component#update
1280:             * @since     JDK1.0
1281:             */
1282:            public void paint(Graphics g) {
1283:            }
1284:
1285:            /**
1286:             * Updates this component.
1287:             * <p>
1288:             * The AWT calls the <code>update</code> method in response to a
1289:             * call to <code>repaint</code. The appearance of the
1290:             * component on the screen has not changed since the last call to
1291:             * <code>update</code> or <code>paint</code>. You can assume that
1292:             * the background is not cleared.
1293:             * <p>
1294:             * The <code>update</code>method of <code>Component</code>
1295:             * does the following:
1296:             * <p>
1297:             * <blockquote><ul>
1298:             * <li>Clears this component by filling it
1299:             *      with the background color.
1300:             * <li>Sets the color of the graphics context to be
1301:             *     the foreground color of this component.
1302:             * <li>Calls this component's <code>paint</code>
1303:             *     method to completely redraw this component.
1304:             * </ul></blockquote>
1305:             * <p>
1306:             * The origin of the graphics context, its
1307:             * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
1308:             * top-left corner of this component. The clipping region of the
1309:             * graphics context is the bounding rectangle of this component.
1310:             * @param g the specified context to use for updating.
1311:             * @see       java.awt.Component#paint
1312:             * @see       java.awt.Component#repaint()
1313:             * @since     JDK1.0
1314:             */
1315:            public void update(Graphics g) {
1316:                paint(g);
1317:            }
1318:
1319:            /**
1320:             * Paints this component and all of its subcomponents.
1321:             * <p>
1322:             * The origin of the graphics context, its
1323:             * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
1324:             * top-left corner of this component. The clipping region of the
1325:             * graphics context is the bounding rectangle of this component.
1326:             * @param     g   the graphics context to use for painting.
1327:             * @see       java.awt.Component#paint
1328:             * @since     JDK1.0
1329:             */
1330:            public void paintAll(Graphics g) {
1331:                if (visible && xwindow != null) {
1332:                    validate();
1333:                    paint(g);
1334:                }
1335:            }
1336:
1337:            /**
1338:             * Repaints this component.
1339:             * <p>
1340:             * This method causes a call to this component's <code>update</code>
1341:             * method as soon as possible.
1342:             * @see       java.awt.Component#update(java.awt.Graphics)
1343:             * @since     JDK1.0
1344:             */
1345:            public void repaint() {
1346:                repaint(0, 0, 0, width, height);
1347:            }
1348:
1349:            /**
1350:             * Repaints the component. This will result in a
1351:             * call to <code>update</code> within <em>tm</em> milliseconds.
1352:             * @param tm maximum time in milliseconds before update
1353:             * @see #paint
1354:             * @see java.awt.Component#update(java.awt.Graphics)
1355:             * @since JDK1.0
1356:             */
1357:            public void repaint(long tm) {
1358:                repaint(tm, 0, 0, width, height);
1359:            }
1360:
1361:            /**
1362:             * Repaints the specified rectangle of this component.
1363:             * <p>
1364:             * This method causes a call to this component's <code>update</code>
1365:             * method as soon as possible.
1366:             * @param     x   the <i>x</i> coordinate.
1367:             * @param     y   the <i>y</i> coordinate.
1368:             * @param     width   the width.
1369:             * @param     height  the height.
1370:             * @see       java.awt.Component#update(java.awt.Graphics)
1371:             * @since     JDK1.0
1372:             */
1373:            public void repaint(int x, int y, int width, int height) {
1374:                repaint(0, x, y, width, height);
1375:            }
1376:
1377:            /**
1378:             * Repaints the specified rectangle of this component within
1379:             * <code>tm</code> milliseconds.
1380:             * <p>
1381:             * This method causes a call to this component's
1382:             * <code>update</code> method.
1383:             * @param     tm   maximum time in milliseconds before update.
1384:             * @param     x    the <i>x</i> coordinate.
1385:             * @param     y    the <i>y</i> coordinate.
1386:             * @param     width    the width.
1387:             * @param     height   the height.
1388:             * @see       java.awt.Component#update(java.awt.Graphics)
1389:             * @since     JDK1.0
1390:             */
1391:            public void repaint(long tm, int x, int y, final int width,
1392:                    final int height) {
1393:                Component c = this ;
1394:                /* Find outer most heavyweight component to send an PaintEvent.UPDATE event to.
1395:                 Beacuse Window, Panel and Canvas are traditionally heavyweight components repaints
1396:                 should cause update to be called on these components. Calling repaint on a lightweight
1397:                 component should not call update on that component but its heavyweight ancestor. */
1398:
1399:                while (c != null) {
1400:                    if (!c.visible || c.xwindow == null)
1401:                        return;
1402:                    if (!c.isLightweight()) {
1403:                        if (tm == 0) {
1404:                            Rectangle rect = new Rectangle(x, y, width, height);
1405:                            Toolkit.getEventQueue().postEvent(
1406:                                    new PaintEvent(c, PaintEvent.UPDATE, rect));
1407:                        } else {
1408:                            final int x1 = x;
1409:                            final int y1 = y;
1410:                            final Component c1 = c;
1411:                            updateTimer.schedule(new TimerTask() {
1412:                                public void run() {
1413:                                    repaint(0, x1, y1, width, height);
1414:                                }
1415:                            }, tm);
1416:                        }
1417:                        return;
1418:                    }
1419:                    x += c.x;
1420:                    y += c.y;
1421:                    c = c.parent;
1422:                }
1423:                // Needs to be translated to parent coordinates since
1424:                // a parent native container provides the actual repaint
1425:                // services.  Additionally, the request is restricted to
1426:                // the bounds of the component.
1427:                //		Container parent = this.parent;
1428:                //	  if (parent != null) {
1429:                //	    int px = this.x + ((x < 0) ? 0 : x);
1430:                //	    int py = this.y + ((y < 0) ? 0 : y);
1431:                //	    int pwidth = (width > this.width) ? this.width : width;
1432:                //	    int pheight = (height > this.height) ? this.height : height;
1433:                //	    parent.repaint(tm, px, py, pwidth, pheight);
1434:                //	  }
1435:            }
1436:
1437:            /**
1438:             * Prints this component. Applications should override this method
1439:             * for components that must do special processing before being
1440:             * printed or should be printed differently than they are painted.
1441:             * <p>
1442:             * The default implementation of this method calls the
1443:             * <code>paint</code> method.
1444:             * <p>
1445:             * The origin of the graphics context, its
1446:             * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
1447:             * top-left corner of this component. The clipping region of the
1448:             * graphics context is the bounding rectangle of this component.
1449:             * @param     g   the graphics context to use for printing.
1450:             * @see       java.awt.Component#paint(java.awt.Graphics)
1451:             * @since     JDK1.0
1452:             */
1453:            public void print(Graphics g) {
1454:                paint(g);
1455:            }
1456:
1457:            /**
1458:             * Prints this component and all of its subcomponents.
1459:             * <p>
1460:             * The origin of the graphics context, its
1461:             * (<code>0</code>,&nbsp;<code>0</code>) coordinate point, is the
1462:             * top-left corner of this component. The clipping region of the
1463:             * graphics context is the bounding rectangle of this component.
1464:             * @param     g   the graphics context to use for printing.
1465:             * @see       java.awt.Component#print(java.awt.Graphics)
1466:             * @since     JDK1.0
1467:             */
1468:            public void printAll(Graphics g) {
1469:                if (visible && xwindow != null) {
1470:                    validate();
1471:                    Graphics cg = g.create(0, 0, width, height);
1472:                    cg.setFont(getFont());
1473:                    try {
1474:                        lightweightPrint(g);
1475:                    } finally {
1476:                        cg.dispose();
1477:                    }
1478:                }
1479:            }
1480:
1481:            /**
1482:             * Simulates the peer callbacks into java.awt for printing of
1483:             * lightweight Components.
1484:             * @param     g   the graphics context to use for printing.
1485:             * @see       #printAll
1486:             */
1487:            void lightweightPrint(Graphics g) {
1488:                print(g);
1489:            }
1490:
1491:            /**
1492:             * Repaints the component when the image has changed.
1493:             * This <code>imageUpdate</code> method of an <code>ImageObserver</code>
1494:             * is called when more information about an
1495:             * image which had been previously requested using an asynchronous
1496:             * routine such as the <code>drawImage</code> method of
1497:             * <code>Graphics</code> becomes available.
1498:             * See the definition of <code>imageUpdate</code> for
1499:             * more information on this method and its arguments.
1500:             * <p>
1501:             * The <code>imageUpdate</code> method of <code>Component</code>
1502:             * incrementally draws an image on the component as more of the bits
1503:             * of the image are available.
1504:             * <p>
1505:             * If the system property <code>awt.image.incrementalDraw</code>
1506:             * is missing or has the value <code>true</code>, the image is
1507:             * incrementally drawn, If the system property has any other value,
1508:             * then the image is not drawn until it has been completely loaded.
1509:             * <p>
1510:             * Also, if incremental drawing is in effect, the value of the
1511:             * system property <code>awt.image.redrawrate</code> is interpreted
1512:             * as an integer to give the maximum redraw rate, in milliseconds. If
1513:             * the system property is missing or cannot be interpreted as an
1514:             * integer, the redraw rate is once every 100ms.
1515:             * <p>
1516:             * The interpretation of the <code>x</code>, <code>y</code>,
1517:             * <code>width</code>, and <code>height</code> arguments depends on
1518:             * the value of the <code>infoflags</code> argument.
1519:             * @param     img   the image being observed.
1520:             * @param     infoflags   see <code>imageUpdate</code> for more information.
1521:             * @param     x   the <i>x</i> coordinate.
1522:             * @param     y   the <i>y</i> coordinate.
1523:             * @param     width    the width.
1524:             * @param     height   the height.
1525:             * @return    <code>true</code> if the flags indicate that the
1526:             *            image is completely loaded;
1527:             *            <code>false</code> otherwise.
1528:             * @see     java.awt.image.ImageObserver
1529:             * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, java.awt.Color, java.awt.image.ImageObserver)
1530:             * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
1531:             * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, java.awt.Color, java.awt.image.ImageObserver)
1532:             * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, java.awt.image.ImageObserver)
1533:             * @see     java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
1534:             * @since   JDK1.0
1535:             */
1536:            public boolean imageUpdate(Image img, int flags, int x, int y,
1537:                    int w, int h) {
1538:                int rate = -1;
1539:                if ((flags & (FRAMEBITS | ALLBITS)) != 0) {
1540:                    rate = 0;
1541:                } else if ((flags & SOMEBITS) != 0) {
1542:                    if (isInc) {
1543:                        try {
1544:                            rate = incRate;
1545:                            if (rate < 0)
1546:                                rate = 0;
1547:                        } catch (Exception e) {
1548:                            rate = 100;
1549:                        }
1550:                    }
1551:                }
1552:                if (rate >= 0) {
1553:                    repaint(rate, 0, 0, width, height);
1554:                }
1555:                return (flags & (ALLBITS | ABORT)) == 0;
1556:            }
1557:
1558:            /**
1559:             * Creates an image from the specified image producer.
1560:             * @param     producer  the image producer
1561:             * @return    the image produced.
1562:             * @since     JDK1.0
1563:             */
1564:            public Image createImage(ImageProducer producer) {
1565:                return getToolkit().createImage(producer);
1566:            }
1567:
1568:            /**
1569:             * Creates an off-screen drawable image
1570:             *     to be used for double buffering.
1571:             * @param     width the specified width.
1572:             * @param     height the specified height.
1573:             * @return    an off-screen drawable image,
1574:             *            which can be used for double buffering.
1575:             * @since     JDK1.0
1576:             */
1577:
1578:            /* Some optimization here would be good */
1579:
1580:            public Image createImage(int width, int height) {
1581:                // Have to return null if not had addNotify called to be compliant with TCK.
1582:                return (xwindow != null) ? new X11Image(width, height,
1583:                        getBackground()) : null;
1584:            }
1585:
1586:            //    public Image createImage(int width, int height) {
1587:            //		return parent.createImage(width, height);
1588:            //    }
1589:
1590:            /**
1591:             * Prepares an image for rendering on this component.  The image
1592:             * data is downloaded asynchronously in another thread and the
1593:             * appropriate screen representation of the image is generated.
1594:             * @param     image   the <code>Image</code> for which to
1595:             *                    prepare a screen representation.
1596:             * @param     observer   the <code>ImageObserver</code> object
1597:             *                       to be notified as the image is being prepared.
1598:             * @return    <code>true</code> if the image has already been fully prepared;
1599:             <code>false</code> otherwise.
1600:             * @since     JDK1.0
1601:             */
1602:            public boolean prepareImage(Image image, ImageObserver observer) {
1603:                return prepareImage(image, -1, -1, observer);
1604:            }
1605:
1606:            /**
1607:             * Prepares an image for rendering on this component at the
1608:             * specified width and height.
1609:             * <p>
1610:             * The image data is downloaded asynchronously in another thread,
1611:             * and an appropriately scaled screen representation of the image is
1612:             * generated.
1613:             * @param     image    the instance of <code>Image</code>
1614:             *            for which to prepare a screen representation.
1615:             * @param     width    the width of the desired screen representation.
1616:             * @param     height   the height of the desired screen representation.
1617:             * @param     observer   the <code>ImageObserver</code> object
1618:             *            to be notified as the image is being prepared.
1619:             * @return    <code>true</code> if the image has already been fully prepared;
1620:             <code>false</code> otherwise.
1621:             * @see       java.awt.image.ImageObserver
1622:             * @since     JDK1.0
1623:             */
1624:            public boolean prepareImage(Image image, int width, int height,
1625:                    ImageObserver observer) {
1626:                return ((X11Image) image).prepareImage(width, height, observer);
1627:            }
1628:
1629:            /**
1630:             * Returns the status of the construction of a screen representation
1631:             * of the specified image.
1632:             * <p>
1633:             * This method does not cause the image to begin loading. An
1634:             * application must use the <code>prepareImage</code> method
1635:             * to force the loading of an image.
1636:             * <p>
1637:             * Information on the flags returned by this method can be found
1638:             * with the discussion of the <code>ImageObserver</code> interface.
1639:             * @param     image   the <code>Image</code> object whose status
1640:             *            is being checked.
1641:             * @param     observer   the <code>ImageObserver</code>
1642:             *            object to be notified as the image is being prepared.
1643:             * @return  the bitwise inclusive <b>OR</b> of
1644:             *            <code>ImageObserver</code> flags indicating what
1645:             *            information about the image is currently available.
1646:             * @see      java.awt.Component#prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
1647:             * @see      java.awt.Toolkit#checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
1648:             * @see      java.awt.image.ImageObserver
1649:             * @since    JDK1.0
1650:             */
1651:            public int checkImage(Image image, ImageObserver observer) {
1652:                return checkImage(image, -1, -1, observer);
1653:            }
1654:
1655:            /**
1656:             * Returns the status of the construction of a screen representation
1657:             * of the specified image.
1658:             * <p>
1659:             * This method does not cause the image to begin loading. An
1660:             * application must use the <code>prepareImage</code> method
1661:             * to force the loading of an image.
1662:             * <p>
1663:             * The <code>checkImage</code> method of <code>Component</code>
1664:             * calls its peer's <code>checkImage</code> method to calculate
1665:             * the flags. If this component does not yet have a peer, the
1666:             * component's toolkit's <code>checkImage</code> method is called
1667:             * instead.
1668:             * <p>
1669:             * Information on the flags returned by this method can be found
1670:             * with the discussion of the <code>ImageObserver</code> interface.
1671:             * @param     image   the <code>Image</code> object whose status
1672:             *                    is being checked.
1673:             * @param     width   the width of the scaled version
1674:             *                    whose status is to be checked.
1675:             * @param     height  the height of the scaled version
1676:             *                    whose status is to be checked.
1677:             * @param     observer   the <code>ImageObserver</code> object
1678:             *                    to be notified as the image is being prepared.
1679:             * @return    the bitwise inclusive <b>OR</b> of
1680:             *            <code>ImageObserver</code> flags indicating what
1681:             *            information about the image is currently available.
1682:             * @see      java.awt.Component#prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
1683:             * @see      java.awt.Toolkit#checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
1684:             * @see      java.awt.image.ImageObserver
1685:             * @since    JDK1.0
1686:             */
1687:            public int checkImage(Image image, int width, int height,
1688:                    ImageObserver observer) {
1689:                return ((X11Image) image).getStatus(observer);
1690:                //        return parent.checkImage(image, width, height, observer);
1691:            }
1692:
1693:            /**
1694:             * Checks whether this component "contains" the specified point,
1695:             * where <code>x</code> and <code>y</code> are defined to be
1696:             * relative to the coordinate system of this component.
1697:             * @param     x   the <i>x</i> coordinate of the point.
1698:             * @param     y   the <i>y</i> coordinate of the point.
1699:             * @see       java.awt.Component#getComponentAt(int, int)
1700:             * @since     JDK1.1
1701:             */
1702:            public boolean contains(int x, int y) {
1703:                return inside(x, y);
1704:            }
1705:
1706:            /**
1707:             * @deprecated As of JDK version 1.1,
1708:             * replaced by contains(int, int).
1709:             */
1710:            public boolean inside(int x, int y) {
1711:                return (x >= 0) && (x < width) && (y >= 0) && (y < height);
1712:            }
1713:
1714:            /**
1715:             * Checks whether this component "contains" the specified point,
1716:             * where the point's <i>x</i> and <i>y</i> coordinates are defined
1717:             * to be relative to the coordinate system of this component.
1718:             * @param     p     the point.
1719:             * @see       java.awt.Component#getComponentAt(java.awt.Point)
1720:             * @since     JDK1.1
1721:             */
1722:            public boolean contains(Point p) {
1723:                return contains(p.x, p.y);
1724:            }
1725:
1726:            /**
1727:             * Determines if this component or one of its immediate
1728:             * subcomponents contains the (<i>x</i>,&nbsp;<i>y</i>) location,
1729:             * and if so, returns the containing component. This method only
1730:             * looks one level deep. If the point (<i>x</i>,&nbsp;<i>y</i>) is
1731:             * inside a subcomponent that itself has subcomponents, it does not
1732:             * go looking down the subcomponent tree.
1733:             * <p>
1734:             * The <code>locate</code> method of <code>Component</code> simply
1735:             * returns the component itself if the (<i>x</i>,&nbsp;<i>y</i>)
1736:             * coordinate location is inside its bounding box, and <code>null</code>
1737:             * otherwise.
1738:             * @param     x   the <i>x</i> coordinate.
1739:             * @param     y   the <i>y</i> coordinate.
1740:             * @return    the component or subcomponent that contains the
1741:             *                (<i>x</i>,&nbsp;<i>y</i>) location;
1742:             *                <code>null</code> if the location
1743:             *                is outside this component.
1744:             * @see       java.awt.Component#contains(int, int)
1745:             * @since     JDK1.0
1746:             */
1747:            public Component getComponentAt(int x, int y) {
1748:                return locate(x, y);
1749:            }
1750:
1751:            /**
1752:             * @deprecated As of JDK version 1.1,
1753:             * replaced by getComponentAt(int, int).
1754:             */
1755:            public Component locate(int x, int y) {
1756:                return contains(x, y) ? this  : null;
1757:            }
1758:
1759:            /**
1760:             * Returns the component or subcomponent that contains the
1761:             * specified point.
1762:             * @param     p   the point.
1763:             * @see       java.awt.Component#contains
1764:             * @since     JDK1.1
1765:             */
1766:            public Component getComponentAt(Point p) {
1767:                return getComponentAt(p.x, p.y);
1768:            }
1769:
1770:            /**
1771:             * @deprecated As of JDK version 1.1,
1772:             * replaced by <code>dispatchEvent(AWTEvent e)</code>.
1773:             */
1774:            public void deliverEvent(Event e) {
1775:                postEvent(e);
1776:            }
1777:
1778:            /**
1779:             * Dispatches an event to this component or one of its sub components.
1780:             * @param e the event
1781:             */
1782:            public final void dispatchEvent(AWTEvent e) {
1783:                dispatchEventImpl(e);
1784:            }
1785:
1786:            void dispatchEventImpl(AWTEvent e) {
1787:                int id = e.getID();
1788:                /*
1789:                 * 0. Allow the Toolkit to pass this to AWTEventListeners.
1790:                 */
1791:                getToolkit().notifyAWTEventListeners(e);
1792:                /*
1793:                 * 1. Allow input methods to process the event
1794:                 */
1795:                if (areInputMethodsEnabled() && (
1796:                // Otherwise, we only pass on low-level events, because
1797:                        // a) input methods shouldn't know about semantic events
1798:                        // b) passing on the events takes time
1799:                        // c) isConsumed() is always true for semantic events.
1800:                        // We exclude paint events since they may be numerous and shouldn't matter.
1801:                        (e instanceof  ComponentEvent) && !(e instanceof  PaintEvent))) {
1802:                    InputContext inputContext = getInputContext();
1803:                    if (inputContext != null) {
1804:                        inputContext.dispatchEvent(e);
1805:                        if (e.isConsumed()) {
1806:                            return;
1807:                        }
1808:                    }
1809:                }
1810:                Component focusDelegate = null;
1811:                /*
1812:                 * 2. Pre-process any special events before delivery
1813:                 */
1814:                switch (id) {
1815:                case KeyEvent.KEY_PRESSED:
1816:                case KeyEvent.KEY_RELEASED:
1817:                case KeyEvent.KEY_TYPED:
1818:                    /* Forward key events to the focus delegate if there is one. */
1819:
1820:                    focusDelegate = getFocusDelegate();
1821:                    if (focusDelegate != null) {
1822:                        KeyEvent keyEvent = (KeyEvent) e;
1823:                        focusDelegate.dispatchEvent(new KeyEvent(focusDelegate,
1824:                                keyEvent.id, keyEvent.getWhen(), keyEvent
1825:                                        .getModifiers(), keyEvent.getKeyCode(),
1826:                                keyEvent.getKeyChar()));
1827:                    } /* Otherwise give the Window a chance to pre process the event.
1828:                                We only want to do this for components that aren't being delegated too. */else if (delegateSource != null) {
1829:                        for (Container p = this .parent; p != null; p = p.parent) {
1830:                            if (p.delegateSource != null)
1831:                                break;
1832:                            if (p instanceof  Window) {
1833:                                ((Window) p).preProcessKeyEvent((KeyEvent) e);
1834:                                break;
1835:                            }
1836:                        }
1837:                    }
1838:                    break;
1839:
1840:                case FocusEvent.FOCUS_GAINED:
1841:                case FocusEvent.FOCUS_LOST:
1842:                    /* Forward focus events to the focus delegate if there is one. */
1843:
1844:                    focusDelegate = getFocusDelegate();
1845:                    if (focusDelegate != null)
1846:                        focusDelegate.dispatchEvent(new FocusEvent(
1847:                                focusDelegate, id, ((FocusEvent) e)
1848:                                        .isTemporary()));
1849:                    break;
1850:
1851:                case PaintEvent.PAINT:
1852:                case PaintEvent.UPDATE:
1853:                    Graphics g = getGraphics();
1854:                    if (g != null) {
1855:                        try {
1856:                            Rectangle clip = ((PaintEvent) e).getUpdateRect();
1857:                            g.clipRect(clip.x, clip.y, clip.width, clip.height);
1858:                            if (id == PaintEvent.PAINT) {
1859:                                if (delegate != null)
1860:                                    delegate.paint(g);
1861:                                paint(g);
1862:                            } else
1863:                                update(g);
1864:                            getToolkit().sync();
1865:                        } finally {
1866:                            g.dispose();
1867:                        }
1868:                    }
1869:                    break;
1870:
1871:                default:
1872:                    break;
1873:                }
1874:                /*
1875:                 * 3. Deliver event for normal processing
1876:                 */
1877:                //if (newEventsOnly) {
1878:                // Filtering needs to really be moved to happen at a lower
1879:                // level in order to get maximum performance gain;  it is
1880:                // here temporarily to ensure the API spec is honored.
1881:                //
1882:                if (eventEnabled(e)) {
1883:                    processEvent(e);
1884:                }
1885:                //	}else
1886:                if (!newEventsOnly) {
1887:                    //
1888:                    // backward compatibility
1889:                    //
1890:                    Event olde = e.convertToOld();
1891:                    if (olde != null) {
1892:                        int key = olde.key;
1893:                        int modifiers = olde.modifiers;
1894:                        postEvent(olde);
1895:                        if (olde.isConsumed()) {
1896:                            e.consume();
1897:                        }
1898:                        // if target changed key or modifier values, copy them
1899:                        // back to original event
1900:                        //
1901:                        switch (olde.id) {
1902:                        case Event.KEY_PRESS:
1903:                        case Event.KEY_RELEASE:
1904:                        case Event.KEY_ACTION:
1905:                        case Event.KEY_ACTION_RELEASE:
1906:                            if (olde.key != key) {
1907:                                ((KeyEvent) e).setKeyChar(olde
1908:                                        .getKeyEventChar());
1909:                            }
1910:                            if (olde.modifiers != modifiers) {
1911:                                ((KeyEvent) e).setModifiers(olde.modifiers);
1912:                            }
1913:                            break;
1914:
1915:                        default:
1916:                            break;
1917:                        }
1918:                    }
1919:                }
1920:                /*
1921:                 * 4. If no one has consumed a key event, propagate it
1922:                 * up the containment hierarchy to ensure that menu shortcuts
1923:                 * and keyboard traversal will work properly.
1924:                 */
1925:                if (!e.isConsumed() && e instanceof  java.awt.event.KeyEvent
1926:                        && delegateSource == null) {
1927:                    for (Container c = this .parent; c != null; c = c.parent) {
1928:                        if (c.delegateSource != null)
1929:                            break;
1930:                        if (c instanceof  Window)
1931:                            ((Window) c).postProcessKeyEvent((KeyEvent) e);
1932:                    }
1933:                }
1934:            }
1935:
1936:            protected AWTEvent coalesceEvents(AWTEvent existingEvent,
1937:                    AWTEvent newEvent) {
1938:                int id = existingEvent.id;
1939:                switch (id) {
1940:                case Event.MOUSE_MOVE:
1941:                case Event.MOUSE_DRAG: {
1942:                    MouseEvent e = (MouseEvent) existingEvent;
1943:                    if (e.getModifiers() == ((MouseEvent) newEvent)
1944:                            .getModifiers()) {
1945:                        // Just return the newEvent, causing the old to be
1946:                        // discarded.
1947:                        return newEvent;
1948:                    }
1949:                    break;
1950:                }
1951:
1952:                case PaintEvent.PAINT:
1953:                case PaintEvent.UPDATE: {
1954:                    // This approach to coalescing paint events seems to be
1955:                    // better than any heuristic for unioning rectangles.
1956:                    PaintEvent existingPaintEvent = (PaintEvent) existingEvent;
1957:                    PaintEvent newPaintEvent = (PaintEvent) newEvent;
1958:                    Rectangle existingRect = existingPaintEvent.getUpdateRect();
1959:                    Rectangle newRect = newPaintEvent.getUpdateRect();
1960:                    if (existingRect.contains(newRect)) {
1961:                        return existingEvent;
1962:                    }
1963:                    if (newRect.contains(existingRect)) {
1964:                        return newEvent;
1965:                    }
1966:                    break;
1967:                }
1968:                }
1969:                return null;
1970:            }
1971:
1972:            boolean areInputMethodsEnabled() {
1973:                // in 1.1.x, we assume input method support is required for all
1974:                // components that handle key events. It's not possible to tell
1975:                // whether they're really interested in character input or just
1976:                // in keystrokes.
1977:                return (eventMask & AWTEvent.KEY_EVENT_MASK) != 0
1978:                        || keyListener != null;
1979:            }
1980:
1981:            /**
1982:             * Returns the Window subclass that contains this object. Will
1983:             * return the object itself, if it is a window.
1984:             */
1985:            private Window getWindowForObject(Object obj) {
1986:                if (obj instanceof  Component) {
1987:                    while (obj != null) {
1988:                        if (obj instanceof  Window) {
1989:                            return (Window) obj;
1990:                        }
1991:                        obj = ((Component) obj).getParent();
1992:                    }
1993:                }
1994:                return null;
1995:            } // getWindowForObject()
1996:
1997:            // TODO: remove when filtering is handled at lower level
1998:            boolean eventEnabled(AWTEvent e) {
1999:                switch (e.id) {
2000:                case ComponentEvent.COMPONENT_MOVED:
2001:                case ComponentEvent.COMPONENT_RESIZED:
2002:                case ComponentEvent.COMPONENT_SHOWN:
2003:                case ComponentEvent.COMPONENT_HIDDEN:
2004:                    if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0
2005:                            || componentListener != null) {
2006:                        return true;
2007:                    }
2008:                    break;
2009:
2010:                case FocusEvent.FOCUS_GAINED:
2011:                case FocusEvent.FOCUS_LOST:
2012:                    if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0
2013:                            || focusListener != null) {
2014:                        return true;
2015:                    }
2016:                    break;
2017:
2018:                case KeyEvent.KEY_PRESSED:
2019:                case KeyEvent.KEY_RELEASED:
2020:                case KeyEvent.KEY_TYPED:
2021:                    if ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0
2022:                            || keyListener != null) {
2023:                        return true;
2024:                    }
2025:                    break;
2026:
2027:                case MouseEvent.MOUSE_PRESSED:
2028:                case MouseEvent.MOUSE_RELEASED:
2029:                case MouseEvent.MOUSE_ENTERED:
2030:                case MouseEvent.MOUSE_EXITED:
2031:                case MouseEvent.MOUSE_CLICKED:
2032:                    if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0
2033:                            || mouseListener != null) {
2034:                        return true;
2035:                    }
2036:                    break;
2037:
2038:                case MouseEvent.MOUSE_MOVED:
2039:                case MouseEvent.MOUSE_DRAGGED:
2040:                    if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0
2041:                            || mouseMotionListener != null) {
2042:                        return true;
2043:                    }
2044:                    break;
2045:
2046:                default:
2047:                    break;
2048:                }
2049:                //
2050:                // Always pass on events defined by external programs.
2051:                //
2052:                if (e.id > AWTEvent.RESERVED_ID_MAX) {
2053:                    return true;
2054:                }
2055:                return false;
2056:            }
2057:
2058:            /**
2059:             * @deprecated As of JDK version 1.1,
2060:             * replaced by dispatchEvent(AWTEvent).
2061:             */
2062:            public boolean postEvent(Event e) {
2063:                if (handleEvent(e)) {
2064:                    e.consume();
2065:                    return true;
2066:                }
2067:                Component parent = this .parent;
2068:                int eventx = e.x;
2069:                int eventy = e.y;
2070:                if (parent != null) {
2071:                    e.translate(x, y);
2072:                    if (parent.postEvent(e)) {
2073:                        e.consume();
2074:                        return true;
2075:                    }
2076:                    // restore coords
2077:                    e.x = eventx;
2078:                    e.y = eventy;
2079:                }
2080:                return false;
2081:            }
2082:
2083:            // Event source interfaces
2084:
2085:            /**
2086:             * Adds the specified component listener to receive component events from
2087:             * this component.
2088:             * @param    l   the component listener.
2089:             * @see      java.awt.event.ComponentEvent
2090:             * @see      java.awt.event.ComponentListener
2091:             * @see      java.awt.Component#removeComponentListener
2092:             * @since    JDK1.1
2093:             */
2094:            public synchronized void addComponentListener(ComponentListener l) {
2095:                componentListener = AWTEventMulticaster.add(componentListener,
2096:                        l);
2097:                checkEnableNewEventsOnly(l);
2098:            }
2099:
2100:            /**
2101:             * Removes the specified component listener so that it no longer
2102:             * receives component events from this component.
2103:             * @param    l   the component listener.
2104:             * @see      java.awt.event.ComponentEvent
2105:             * @see      java.awt.event.ComponentListener
2106:             * @see      java.awt.Component#addComponentListener
2107:             * @since    JDK1.1
2108:             */
2109:            public synchronized void removeComponentListener(ComponentListener l) {
2110:                componentListener = AWTEventMulticaster.remove(
2111:                        componentListener, l);
2112:            }
2113:
2114:            /**
2115:             * Adds the specified focus listener to receive focus events from
2116:             * this component.
2117:             * @param    l   the focus listener.
2118:             * @see      java.awt.event.FocusEvent
2119:             * @see      java.awt.event.FocusListener
2120:             * @see      java.awt.Component#removeFocusListener
2121:             * @since    JDK1.1
2122:             */
2123:            public synchronized void addFocusListener(FocusListener l) {
2124:                focusListener = AWTEventMulticaster.add(focusListener, l);
2125:                checkEnableNewEventsOnly(l);
2126:            }
2127:
2128:            /**
2129:             * Removes the specified focus listener so that it no longer
2130:             * receives focus events from this component.
2131:             * @param    l   the focus listener.
2132:             * @see      java.awt.event.FocusEvent
2133:             * @see      java.awt.event.FocusListener
2134:             * @see      java.awt.Component#addFocusListener
2135:             * @since    JDK1.1
2136:             */
2137:            public synchronized void removeFocusListener(FocusListener l) {
2138:                focusListener = AWTEventMulticaster.remove(focusListener, l);
2139:            }
2140:
2141:            /**
2142:             * Adds the specified key listener to receive key events from
2143:             * this component.
2144:             * @param    l   the key listener.
2145:             * @see      java.awt.event.KeyEvent
2146:             * @see      java.awt.event.KeyListener
2147:             * @see      java.awt.Component#removeKeyListener
2148:             * @since    JDK1.1
2149:             */
2150:            public synchronized void addKeyListener(KeyListener l) {
2151:                keyListener = AWTEventMulticaster.add(keyListener, l);
2152:                checkEnableNewEventsOnly(l);
2153:            }
2154:
2155:            /**
2156:             * Removes the specified key listener so that it no longer
2157:             * receives key events from this component.
2158:             * @param    l   the key listener.
2159:             * @see      java.awt.event.KeyEvent
2160:             * @see      java.awt.event.KeyListener
2161:             * @see      java.awt.Component#addKeyListener
2162:             * @since    JDK1.1
2163:             */
2164:            public synchronized void removeKeyListener(KeyListener l) {
2165:                keyListener = AWTEventMulticaster.remove(keyListener, l);
2166:                checkEnableNewEventsOnly(l);
2167:            }
2168:
2169:            /** Checks if newEventsOnly should be enabled when the specified listener is added. */
2170:
2171:            final void checkEnableNewEventsOnly(Object listener) {
2172:                if (!newEventsOnly && listener != null) {
2173:                    Package pkg = listener.getClass().getPackage();
2174:                    if (pkg == null) {
2175:                        newEventsOnly = true;
2176:                        return;
2177:                    }
2178:                    String pkgName = pkg.getName();
2179:                    // Only ebnable new event optimisations if the listener is an application class and not
2180:                    // a system class.
2181:
2182:                    if (!(pkgName.startsWith("java.awt")
2183:                            || pkgName.startsWith("javax.swing")
2184:                            || pkgName.startsWith("com.sun") || pkgName
2185:                            .startsWith("sun.")))
2186:                        newEventsOnly = true;
2187:                }
2188:            }
2189:
2190:            /**
2191:             * Adds the specified mouse listener to receive mouse events from
2192:             * this component.
2193:             * @param    l   the mouse listener.
2194:             * @see      java.awt.event.MouseEvent
2195:             * @see      java.awt.event.MouseListener
2196:             * @see      java.awt.Component#removeMouseListener
2197:             * @since    JDK1.1
2198:             */
2199:            public synchronized void addMouseListener(MouseListener l) {
2200:                ComponentXWindow xwindow = this .xwindow;
2201:                long oldEventMask = 0;
2202:                if (xwindow != null)
2203:                    oldEventMask = getMouseEventMask();
2204:                mouseListener = AWTEventMulticaster.add(mouseListener, l);
2205:                checkEnableNewEventsOnly(l);
2206:                if (xwindow != null) {
2207:                    long newEventMask = getMouseEventMask();
2208:                    if (newEventMask != oldEventMask)
2209:                        xwindow.setMouseEventMask(newEventMask);
2210:                }
2211:            }
2212:
2213:            /**
2214:             * Removes the specified mouse listener so that it no longer
2215:             * receives mouse events from this component.
2216:             * @param    l   the mouse listener.
2217:             * @see      java.awt.event.MouseEvent
2218:             * @see      java.awt.event.MouseListener
2219:             * @see      java.awt.Component#addMouseListener
2220:             * @since    JDK1.1
2221:             */
2222:            public synchronized void removeMouseListener(MouseListener l) {
2223:                ComponentXWindow xwindow = this .xwindow;
2224:                long oldEventMask = 0;
2225:                if (xwindow != null)
2226:                    oldEventMask = getMouseEventMask();
2227:                mouseListener = AWTEventMulticaster.remove(mouseListener, l);
2228:                if (xwindow != null) {
2229:                    long newEventMask = getMouseEventMask();
2230:                    if (newEventMask != oldEventMask)
2231:                        xwindow.setMouseEventMask(newEventMask);
2232:                }
2233:            }
2234:
2235:            /**
2236:             * Adds the specified mouse motion listener to receive mouse motion events from
2237:             * this component.
2238:             * @param    l   the mouse motion listener.
2239:             * @see      java.awt.event.MouseEvent
2240:             * @see      java.awt.event.MouseMotionListener
2241:             * @see      java.awt.Component#removeMouseMotionListener
2242:             * @since    JDK1.1
2243:             */
2244:            public synchronized void addMouseMotionListener(
2245:                    MouseMotionListener l) {
2246:                ComponentXWindow xwindow = this .xwindow;
2247:                long oldMouseEventMask = 0;
2248:                if (xwindow != null)
2249:                    oldMouseEventMask = getMouseEventMask();
2250:                mouseMotionListener = AWTEventMulticaster.add(
2251:                        mouseMotionListener, l);
2252:                checkEnableNewEventsOnly(l);
2253:                if (xwindow != null) {
2254:                    long newEventMask = getMouseEventMask();
2255:                    if (newEventMask != oldMouseEventMask)
2256:                        xwindow.setMouseEventMask(newEventMask);
2257:                }
2258:            }
2259:
2260:            /**
2261:             * Removes the specified mouse motion listener so that it no longer
2262:             * receives mouse motion events from this component.
2263:             * @param    l   the mouse motion listener.
2264:             * @see      java.awt.event.MouseEvent
2265:             * @see      java.awt.event.MouseMotionListener
2266:             * @see      java.awt.Component#addMouseMotionListener
2267:             * @since    JDK1.1
2268:             */
2269:            public synchronized void removeMouseMotionListener(
2270:                    MouseMotionListener l) {
2271:                ComponentXWindow xwindow = this .xwindow;
2272:                long oldEventMask = 0;
2273:                if (xwindow != null)
2274:                    oldEventMask = getMouseEventMask();
2275:                mouseMotionListener = AWTEventMulticaster.remove(
2276:                        mouseMotionListener, l);
2277:                if (xwindow != null) {
2278:                    long newEventMask = getMouseEventMask();
2279:                    if (newEventMask != oldEventMask)
2280:                        xwindow.setMouseEventMask(newEventMask);
2281:                }
2282:            }
2283:
2284:            /**
2285:             * Gets the input context used by this component for handling the communication
2286:             * with input methods when text is entered in this component. By default, the
2287:             * input context used for the parent component is returned. Components may
2288:             * override this to return a private input context.
2289:             *
2290:             * @return The input context used by this component. Null if no context can
2291:             * be determined.
2292:             */
2293:            InputContext getInputContext() {
2294:                Container parent = this .parent;
2295:                if (parent == null) {
2296:                    return null;
2297:                } else {
2298:                    return parent.getInputContext();
2299:                }
2300:            }
2301:
2302:            /**
2303:             * Enables the events defined by the specified event mask parameter
2304:             * to be delivered to this component.
2305:             * <p>
2306:             * Event types are automatically enabled when a listener for
2307:             * that event type is added to the component.
2308:             * <p>
2309:             * This method only needs to be invoked by subclasses of
2310:             * <code>Component</code> which desire to have the specified event
2311:             * types delivered to <code>processEvent</code> regardless of whether
2312:             * or not a listener is registered.
2313:             * @param      eventsToEnable   the event mask defining the event types.
2314:             * @see        java.awt.Component#processEvent
2315:             * @see        java.awt.Component#disableEvents
2316:             * @since      JDK1.1
2317:             */
2318:            protected synchronized final void enableEvents(long eventsToEnable) {
2319:                ComponentXWindow xwindow = this .xwindow;
2320:                long oldEventMask = 0;
2321:                if (xwindow != null)
2322:                    oldEventMask = getMouseEventMask();
2323:                eventMask |= eventsToEnable;
2324:                /* Assume we are using the new event model so we can optimize
2325:                 events without having to convert to the old event model. */
2326:
2327:                newEventsOnly = true;
2328:                /* Notify XWindow of any change in the event mask. */
2329:
2330:                if (xwindow != null) {
2331:                    long newEventMask = getMouseEventMask();
2332:                    if (newEventMask != oldEventMask)
2333:                        xwindow.setMouseEventMask(newEventMask);
2334:                }
2335:            }
2336:
2337:            /** Gets the low level event mask being used by this component. This is
2338:             determined by what events have been enabled by enableEvents and what
2339:             listeners have been added. Low level evbents are mouse events and keyboard events.
2340:             This mask is used by the XWindow to enable the appropriate X events on the window.*/
2341:
2342:            private long getMouseEventMask() {
2343:                if (newEventsOnly) {
2344:                    long eventMask = this .eventMask
2345:                            & (AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
2346:                    if (mouseListener != null)
2347:                        eventMask |= AWTEvent.MOUSE_EVENT_MASK;
2348:                    if (mouseMotionListener != null)
2349:                        eventMask |= AWTEvent.MOUSE_MOTION_EVENT_MASK;
2350:                    return eventMask;
2351:                }
2352:                return AWTEvent.MOUSE_EVENT_MASK
2353:                        | AWTEvent.MOUSE_MOTION_EVENT_MASK;
2354:            }
2355:
2356:            /**
2357:             * Disables the events defined by the specified event mask parameter
2358:             * from being delivered to this component.
2359:             * @param      eventsToDisable   the event mask defining the event types
2360:             * @see        java.awt.Component#enableEvents
2361:             * @since      JDK1.1
2362:             */
2363:            protected final void disableEvents(long eventsToDisable) {
2364:                ComponentXWindow xwindow = this .xwindow;
2365:                long oldEventMask = 0;
2366:                if (xwindow != null)
2367:                    oldEventMask = getMouseEventMask();
2368:                eventMask &= ~eventsToDisable;
2369:                /* Notify XWindow of any change in the event mask. */
2370:
2371:                if (xwindow != null) {
2372:                    long newEventMask = getMouseEventMask();
2373:                    if (newEventMask != oldEventMask)
2374:                        xwindow.setMouseEventMask(newEventMask);
2375:                }
2376:            }
2377:
2378:            /**
2379:             * Processes events occurring on this component. By default this
2380:             * method calls the appropriate
2381:             * <code>process&lt;event&nbsp;type&gt;Event</code>
2382:             * method for the given class of event.
2383:             * @param     e the event.
2384:             * @see       java.awt.Component#processComponentEvent
2385:             * @see       java.awt.Component#processFocusEvent
2386:             * @see       java.awt.Component#processKeyEvent
2387:             * @see       java.awt.Component#processMouseEvent
2388:             * @see       java.awt.Component#processMouseMotionEvent
2389:             * @since     JDK1.1
2390:             */
2391:            protected void processEvent(AWTEvent e) {
2392:                //System.out.println("Component.processEvent:" + e);
2393:                if (e instanceof  FocusEvent) {
2394:                    processFocusEvent((FocusEvent) e);
2395:                } else if (e instanceof  MouseEvent) {
2396:                    switch (e.getID()) {
2397:                    case MouseEvent.MOUSE_PRESSED:
2398:                    case MouseEvent.MOUSE_RELEASED:
2399:                    case MouseEvent.MOUSE_CLICKED:
2400:                    case MouseEvent.MOUSE_ENTERED:
2401:                    case MouseEvent.MOUSE_EXITED:
2402:                        processMouseEvent((MouseEvent) e);
2403:                        break;
2404:
2405:                    case MouseEvent.MOUSE_MOVED:
2406:                    case MouseEvent.MOUSE_DRAGGED:
2407:                        processMouseMotionEvent((MouseEvent) e);
2408:                        break;
2409:                    }
2410:                } else if (e instanceof  KeyEvent) {
2411:                    processKeyEvent((KeyEvent) e);
2412:                } else if (e instanceof  ComponentEvent) {
2413:                    processComponentEvent((ComponentEvent) e);
2414:                }
2415:            }
2416:
2417:            /**
2418:             * Processes component events occurring on this component by
2419:             * dispatching them to any registered
2420:             * <code>ComponentListener</code> objects.
2421:             * <p>
2422:             * This method is not called unless component events are
2423:             * enabled for this component. Component events are enabled
2424:             * when one of the following occurs:
2425:             * <p><ul>
2426:             * <li>A <code>ComponentListener</code> object is registered
2427:             * via <code>addComponentListener</code>.
2428:             * <li>Component events are enabled via <code>enableEvents</code>.
2429:             * </ul>
2430:             * @param       e the component event.
2431:             * @see         java.awt.event.ComponentEvent
2432:             * @see         java.awt.event.ComponentListener
2433:             * @see         java.awt.Component#addComponentListener
2434:             * @see         java.awt.Component#enableEvents
2435:             * @since       JDK1.1
2436:             */
2437:            protected void processComponentEvent(ComponentEvent e) {
2438:                if (componentListener != null) {
2439:                    int id = e.getID();
2440:                    switch (id) {
2441:                    case ComponentEvent.COMPONENT_RESIZED:
2442:                        componentListener.componentResized(e);
2443:                        break;
2444:
2445:                    case ComponentEvent.COMPONENT_MOVED:
2446:                        componentListener.componentMoved(e);
2447:                        break;
2448:
2449:                    case ComponentEvent.COMPONENT_SHOWN:
2450:                        componentListener.componentShown(e);
2451:                        break;
2452:
2453:                    case ComponentEvent.COMPONENT_HIDDEN:
2454:                        componentListener.componentHidden(e);
2455:                        break;
2456:                    }
2457:                }
2458:            }
2459:
2460:            /**
2461:             * Processes focus events occurring on this component by
2462:             * dispatching them to any registered
2463:             * <code>FocusListener</code> objects.
2464:             * <p>
2465:             * This method is not called unless focus events are
2466:             * enabled for this component. Focus events are enabled
2467:             * when one of the following occurs:
2468:             * <p><ul>
2469:             * <li>A <code>FocusListener</code> object is registered
2470:             * via <code>addFocusListener</code>.
2471:             * <li>Focus events are enabled via <code>enableEvents</code>.
2472:             * </ul>
2473:             * @param       e the focus event.
2474:             * @see         java.awt.event.FocusEvent
2475:             * @see         java.awt.event.FocusListener
2476:             * @see         java.awt.Component#addFocusListener
2477:             * @see         java.awt.Component#enableEvents
2478:             * @since       JDK1.1
2479:             */
2480:            protected void processFocusEvent(FocusEvent e) {
2481:                if (focusListener != null) {
2482:                    int id = e.getID();
2483:                    switch (id) {
2484:                    case FocusEvent.FOCUS_GAINED:
2485:                        focusListener.focusGained(e);
2486:                        break;
2487:
2488:                    case FocusEvent.FOCUS_LOST:
2489:                        focusListener.focusLost(e);
2490:                        break;
2491:                    }
2492:                }
2493:            }
2494:
2495:            /**
2496:             * Processes key events occurring on this component by
2497:             * dispatching them to any registered
2498:             * <codeKeyListener</code> objects.
2499:             * <p>
2500:             * This method is not called unless key events are
2501:             * enabled for this component. Key events are enabled
2502:             * when one of the following occurs:
2503:             * <p><ul>
2504:             * <li>A <code>KeyListener</code> object is registered
2505:             * via <code>addKeyListener</code>.
2506:             * <li>Key events are enabled via <code>enableEvents</code>.
2507:             * </ul>
2508:             * @param       e the key event.
2509:             * @see         java.awt.event.KeyEvent
2510:             * @see         java.awt.event.KeyListener
2511:             * @see         java.awt.Component#addKeyListener
2512:             * @see         java.awt.Component#enableEvents
2513:             * @since       JDK1.1
2514:             */
2515:            protected void processKeyEvent(KeyEvent e) {
2516:                if (keyListener != null) {
2517:                    int id = e.getID();
2518:                    switch (id) {
2519:                    case KeyEvent.KEY_TYPED:
2520:                        keyListener.keyTyped(e);
2521:                        break;
2522:
2523:                    case KeyEvent.KEY_PRESSED:
2524:                        keyListener.keyPressed(e);
2525:                        break;
2526:
2527:                    case KeyEvent.KEY_RELEASED:
2528:                        keyListener.keyReleased(e);
2529:                        break;
2530:                    }
2531:                }
2532:            }
2533:
2534:            /**
2535:             * Processes mouse events occurring on this component by
2536:             * dispatching them to any registered
2537:             * <code>MouseListener</code> objects.
2538:             * <p>
2539:             * This method is not called unless mouse events are
2540:             * enabled for this component. Mouse events are enabled
2541:             * when one of the following occurs:
2542:             * <p><ul>
2543:             * <li>A <code>MouseListener</code> object is registered
2544:             * via <code>addMouseListener</code>.
2545:             * <li>Mouse events are enabled via <code>enableEvents</code>.
2546:             * </ul>
2547:             * @param       e the mouse event.
2548:             * @see         java.awt.event.MouseEvent
2549:             * @see         java.awt.event.MouseListener
2550:             * @see         java.awt.Component#addMouseListener
2551:             * @see         java.awt.Component#enableEvents
2552:             * @since       JDK1.1
2553:             */
2554:            protected void processMouseEvent(MouseEvent e) {
2555:                if (mouseListener != null) {
2556:                    int id = e.getID();
2557:                    switch (id) {
2558:                    case MouseEvent.MOUSE_PRESSED:
2559:                        mouseListener.mousePressed(e);
2560:                        break;
2561:
2562:                    case MouseEvent.MOUSE_RELEASED:
2563:                        mouseListener.mouseReleased(e);
2564:                        break;
2565:
2566:                    case MouseEvent.MOUSE_CLICKED:
2567:                        mouseListener.mouseClicked(e);
2568:                        break;
2569:
2570:                    case MouseEvent.MOUSE_EXITED:
2571:                        mouseListener.mouseExited(e);
2572:                        break;
2573:
2574:                    case MouseEvent.MOUSE_ENTERED:
2575:                        mouseListener.mouseEntered(e);
2576:                        break;
2577:                    }
2578:                }
2579:            }
2580:
2581:            /**
2582:             * Processes mouse motion events occurring on this component by
2583:             * dispatching them to any registered
2584:             * <code>MouseMotionListener</code> objects.
2585:             * <p>
2586:             * This method is not called unless mouse motion events are
2587:             * enabled for this component. Mouse motion events are enabled
2588:             * when one of the following occurs:
2589:             * <p><ul>
2590:             * <li>A <code>MouseMotionListener</code> object is registered
2591:             * via <code>addMouseMotionListener</code>.
2592:             * <li>Mouse motion events are enabled via <code>enableEvents</code>.
2593:             * </ul>
2594:             * @param       e the mouse motion event.
2595:             * @see         java.awt.event.MouseEvent
2596:             * @see         java.awt.event.MouseMotionListener
2597:             * @see         java.awt.Component#addMouseMotionListener
2598:             * @see         java.awt.Component#enableEvents
2599:             * @since       JDK1.1
2600:             */
2601:            protected void processMouseMotionEvent(MouseEvent e) {
2602:                if (mouseMotionListener != null) {
2603:                    int id = e.getID();
2604:                    switch (id) {
2605:                    case MouseEvent.MOUSE_MOVED:
2606:                        mouseMotionListener.mouseMoved(e);
2607:                        break;
2608:
2609:                    case MouseEvent.MOUSE_DRAGGED:
2610:                        mouseMotionListener.mouseDragged(e);
2611:                        break;
2612:                    }
2613:                }
2614:            }
2615:
2616:            /**
2617:             * @deprecated As of JDK version 1.1
2618:             * replaced by processEvent(AWTEvent).
2619:             */
2620:            public boolean handleEvent(Event evt) {
2621:                switch (evt.id) {
2622:                case Event.MOUSE_ENTER:
2623:                    return mouseEnter(evt, evt.x, evt.y);
2624:
2625:                case Event.MOUSE_EXIT:
2626:                    return mouseExit(evt, evt.x, evt.y);
2627:
2628:                case Event.MOUSE_MOVE:
2629:                    return mouseMove(evt, evt.x, evt.y);
2630:
2631:                case Event.MOUSE_DOWN:
2632:                    return mouseDown(evt, evt.x, evt.y);
2633:
2634:                case Event.MOUSE_DRAG:
2635:                    return mouseDrag(evt, evt.x, evt.y);
2636:
2637:                case Event.MOUSE_UP:
2638:                    return mouseUp(evt, evt.x, evt.y);
2639:
2640:                case Event.KEY_PRESS:
2641:                case Event.KEY_ACTION:
2642:                    return keyDown(evt, evt.key);
2643:
2644:                case Event.KEY_RELEASE:
2645:                case Event.KEY_ACTION_RELEASE:
2646:                    return keyUp(evt, evt.key);
2647:
2648:                case Event.ACTION_EVENT:
2649:                    return action(evt, evt.arg);
2650:
2651:                case Event.GOT_FOCUS:
2652:                    return gotFocus(evt, evt.arg);
2653:
2654:                case Event.LOST_FOCUS:
2655:                    return lostFocus(evt, evt.arg);
2656:                }
2657:                return false;
2658:            }
2659:
2660:            /**
2661:             * @deprecated As of JDK version 1.1,
2662:             * replaced by processMouseEvent(MouseEvent).
2663:             */
2664:            public boolean mouseDown(Event evt, int x, int y) {
2665:                return false;
2666:            }
2667:
2668:            /**
2669:             * @deprecated As of JDK version 1.1,
2670:             * replaced by processMouseMotionEvent(MouseEvent).
2671:             */
2672:            public boolean mouseDrag(Event evt, int x, int y) {
2673:                return false;
2674:            }
2675:
2676:            /**
2677:             * @deprecated As of JDK version 1.1,
2678:             * replaced by processMouseEvent(MouseEvent).
2679:             */
2680:            public boolean mouseUp(Event evt, int x, int y) {
2681:                return false;
2682:            }
2683:
2684:            /**
2685:             * @deprecated As of JDK version 1.1,
2686:             * replaced by processMouseMotionEvent(MouseEvent).
2687:             */
2688:            public boolean mouseMove(Event evt, int x, int y) {
2689:                return false;
2690:            }
2691:
2692:            /**
2693:             * @deprecated As of JDK version 1.1,
2694:             * replaced by processMouseEvent(MouseEvent).
2695:             */
2696:            public boolean mouseEnter(Event evt, int x, int y) {
2697:                return false;
2698:            }
2699:
2700:            /**
2701:             * @deprecated As of JDK version 1.1,
2702:             * replaced by processMouseEvent(MouseEvent).
2703:             */
2704:            public boolean mouseExit(Event evt, int x, int y) {
2705:                return false;
2706:            }
2707:
2708:            /**
2709:             * @deprecated As of JDK version 1.1,
2710:             * replaced by processKeyEvent(KeyEvent).
2711:             */
2712:            public boolean keyDown(Event evt, int key) {
2713:                return false;
2714:            }
2715:
2716:            /**
2717:             * @deprecated As of JDK version 1.1,
2718:             * replaced by processKeyEvent(KeyEvent).
2719:             */
2720:            public boolean keyUp(Event evt, int key) {
2721:                return false;
2722:            }
2723:
2724:            /**
2725:             * @deprecated As of JDK version 1.1,
2726:             * should register this component as ActionListener on component
2727:             * which fires action events.
2728:             */
2729:            public boolean action(Event evt, Object what) {
2730:                return false;
2731:            }
2732:
2733:            /**
2734:             * Notifies this component that it has been added to a container
2735:             * and if a peer is required, it should be created.
2736:             * This method should be called by <code>Container.add</code>, and
2737:             * not by user code directly.
2738:             * @see #removeNotify
2739:             * @since JDK1.0
2740:             */
2741:            public void addNotify() {
2742:                synchronized (getTreeLock()) {
2743:                    if (xwindow == null) {
2744:                        xwindow = createXWindow();
2745:                        xwindow.setMouseEventMask(getMouseEventMask());
2746:                        xwindow.setBounds(x, y, width, height);
2747:                        if (visible)
2748:                            xwindow.map();
2749:                    }
2750:                    if (delegate != null) {
2751:                        delegate.parent = parent;
2752:                        delegate.addNotify();
2753:                    }
2754:                    invalidate();
2755:                    //			int npopups = (popups != null? popups.size() : 0);
2756:                    //			for (int i = 0 ; i < npopups ; i++) {
2757:                    //				PopupMenu popup = (PopupMenu)popups.elementAt(i);
2758:                    //				popup.addNotify();
2759:                    //			}
2760:                }
2761:            }
2762:
2763:            ComponentXWindow createXWindow() {
2764:                return isLightweightWhenDisplayable() ? new ComponentXWindow(
2765:                        this ) : new HeavyweightComponentXWindow(this );
2766:            }
2767:
2768:            /**
2769:             * Notifies this component that it has been removed from its
2770:             * container and if a peers exists, it destroys it.
2771:             * This method should be called by <code>Container.remove</code>,
2772:             * and not by user code directly.
2773:             * @see #addNotify
2774:             */
2775:            public void removeNotify() {
2776:                synchronized (getTreeLock()) {
2777:                    if (areInputMethodsEnabled()) {
2778:                        InputContext inputContext = getInputContext();
2779:                        if (inputContext != null) {
2780:                            ComponentEvent e = new ComponentEvent(this ,
2781:                                    ComponentEvent.COMPONENT_HIDDEN);
2782:                            inputContext.dispatchEvent(e);
2783:                        }
2784:                    }
2785:                    //			int npopups = (popups != null? popups.size() : 0);
2786:                    //			for (int i = 0 ; i < npopups ; i++) {
2787:                    //				PopupMenu popup = (PopupMenu)popups.elementAt(i);
2788:                    //				popup.removeNotify();
2789:                    //			}
2790:
2791:                    if (delegate != null) {
2792:                        delegate.parent = null;
2793:                        delegate.removeNotify();
2794:                    }
2795:                    if (xwindow != null) {
2796:                        ComponentXWindow w = xwindow;
2797:                        if (visible) {
2798:                            w.unmap(); // Hide peer first to stop system events such as cursor moves.
2799:                        }
2800:                        xwindow = null; // Stop peer updates.
2801:                        w.dispose();
2802:                        Toolkit.getEventQueue().removeSourceEvents(this );
2803:                    }
2804:                }
2805:            }
2806:
2807:            /**
2808:             * @deprecated As of JDK version 1.1,
2809:             * replaced by processFocusEvent(FocusEvent).
2810:             */
2811:            public boolean gotFocus(Event evt, Object what) {
2812:                return false;
2813:            }
2814:
2815:            /**
2816:             * @deprecated As of JDK version 1.1,
2817:             * replaced by processFocusEvent(FocusEvent).
2818:             */
2819:            public boolean lostFocus(Event evt, Object what) {
2820:                return false;
2821:            }
2822:
2823:            /**
2824:             * Returns the value of a flag that indicates whether
2825:             * this component can be traversed using
2826:             * Tab or Shift-Tab keyboard focus traversal.  If this method
2827:             * returns "false", this component may still request the keyboard
2828:             * focus using <code>requestFocus()</code>, but it will not automatically
2829:             * be assigned focus during tab traversal.
2830:             * @return    <code>true</code> if this component is
2831:             *            focus-traverable; <code>false</code> otherwise.
2832:             * @since     JDK1.1
2833:             */
2834:            public boolean isFocusTraversable() {
2835:                return getFocusDelegate() != null;
2836:            }
2837:
2838:            /**
2839:             * Requests that this component get the input focus.
2840:             * <p>
2841:             * This component's <code>gotFocus</code> method is called when this
2842:             * method is successful.  The component must be visible
2843:             * on the screen for this request to be granted
2844:             * @see FocusEvent
2845:             * @see #addFocusListener
2846:             * @see #processFocusEvent
2847:             * @see #isFocusTraversable
2848:             * @since JDK1.0
2849:             */
2850:            public void requestFocus() {
2851:                /* Tell the window that we are requesting focus. */
2852:
2853:                for (Component c = this ; c != null; c = c.parent) {
2854:                    if (!c.visible || c.xwindow == null)
2855:                        return;
2856:                    /* If this component is acting as a delegate for another AWT component
2857:                     then request focus on that component. */
2858:
2859:                    if (c.delegateSource != null) {
2860:                        c.delegateSource.requestFocus();
2861:                        return;
2862:                    }
2863:                    if (c instanceof  Window) {
2864:                        ((Window) c).setFocusOwner(this );
2865:                        return;
2866:                    }
2867:                }
2868:            }
2869:
2870:            /** Gets the component to which key events should be deleagted to when this component
2871:             has the focus. */
2872:
2873:            Component getFocusDelegate() {
2874:                if (delegate != null) {
2875:                    if (delegate.isFocusTraversable())
2876:                        return delegate;
2877:                    if (delegate instanceof  Container) {
2878:                        return findFocusDelegate((Container) delegate);
2879:                    }
2880:                }
2881:                return null;
2882:            }
2883:
2884:            /** Recursively looks for the first component in container that is focus traversable. */
2885:
2886:            Component findFocusDelegate(Container container) {
2887:                synchronized (container.getTreeLock()) {
2888:                    for (int i = 0; i < container.getComponentCount(); i++) {
2889:                        Component c = container.getComponent(i);
2890:                        if (c.visible) {
2891:                            if (c.isFocusTraversable())
2892:                                return c;
2893:                            if (c instanceof  Container) {
2894:                                Component focusDelegate = findFocusDelegate((Container) c);
2895:                                if (focusDelegate != null)
2896:                                    return focusDelegate;
2897:                            }
2898:                        }
2899:                    }
2900:                    return null;
2901:                }
2902:            }
2903:
2904:            /**
2905:             * Transfers the focus to the next component.
2906:             * @see       java.awt.Component#requestFocus
2907:             * @see       java.awt.Component#gotFocus
2908:             * @since     JDK1.1s
2909:             */
2910:            public void transferFocus() {
2911:                nextFocus();
2912:            }
2913:
2914:            /**
2915:             * @deprecated As of JDK version 1.1,
2916:             * replaced by transferFocus().
2917:             */
2918:            public void nextFocus() {
2919:                Container parent = this .parent;
2920:                if (parent != null) {
2921:                    parent.transferFocus(this );
2922:                }
2923:            }
2924:
2925:            /**
2926:             * Adds the specified popup menu to the component.
2927:             * @param     popup the popup menu to be added to the component.
2928:             * @see       java.awt.Component#remove(java.awt.MenuComponent)
2929:             * @since     JDK1.1
2930:             */
2931:            public synchronized void add(PopupMenu popup) {
2932:                if (popup.parent != null) {
2933:                    popup.parent.remove(popup);
2934:                }
2935:                if (popups == null) {
2936:                    popups = new Vector();
2937:                }
2938:                popups.addElement(popup);
2939:                popup.parent = this ;
2940:                if (xwindow != null) {
2941:                    popup.addNotify();
2942:                }
2943:            }
2944:
2945:            /**
2946:             * Removes the specified popup menu from the component.
2947:             * @param     popup the popup menu to be removed.
2948:             * @see       java.awt.Component#add(java.awt.PopupMenu)
2949:             * @since     JDK1.1
2950:             */
2951:            public synchronized void remove(MenuComponent popup) {
2952:                if (popups != null) {
2953:                    int index = popups.indexOf(popup);
2954:                    if (index >= 0) {
2955:                        PopupMenu pmenu = (PopupMenu) popup;
2956:                        pmenu.removeNotify();
2957:                        pmenu.parent = null;
2958:                        popups.removeElementAt(index);
2959:                        if (popups.size() == 0) {
2960:                            popups = null;
2961:                        }
2962:                    }
2963:                }
2964:            }
2965:
2966:            /**
2967:             * Returns the parameter string representing the state of this
2968:             * component. This string is useful for debugging.
2969:             * @return    the parameter string of this component.
2970:             * @since     JDK1.0
2971:             */
2972:            protected String paramString() {
2973:                String this Name = getName();
2974:                String str = (this Name != null ? this Name : "") + "," + x + ","
2975:                        + y + "," + width + "x" + height;
2976:                if (!valid) {
2977:                    str += ",invalid";
2978:                }
2979:                if (!visible) {
2980:                    str += ",hidden";
2981:                }
2982:                if (!enabled) {
2983:                    str += ",disabled";
2984:                }
2985:                return str;
2986:            }
2987:
2988:            /**
2989:             * Returns a string representation of this component and its values.
2990:             * @return    a string representation of this component.
2991:             * @since     JDK1.0
2992:             */
2993:            public String toString() {
2994:                return getClass().getName() + "[" + paramString() + "]";
2995:            }
2996:
2997:            /**
2998:             * Prints a listing of this component to the standard system output
2999:             * stream <code>System.out</code>.
3000:             * @see       java.lang.System#out
3001:             * @since     JDK1.0
3002:             */
3003:            public void list() {
3004:                list(System.out, 0);
3005:            }
3006:
3007:            /**
3008:             * Prints a listing of this component to the specified output
3009:             * stream.
3010:             * @param    out   a print stream.
3011:             * @since    JDK1.0
3012:             */
3013:            public void list(PrintStream out) {
3014:                list(out, 0);
3015:            }
3016:
3017:            /**
3018:             * Prints out a list, starting at the specified indention, to the
3019:             * specified print stream.
3020:             * @param     out      a print stream.
3021:             * @param     indent   number of spaces to indent.
3022:             * @see       java.io.PrintStream#println(java.lang.Object)
3023:             * @since     JDK1.0
3024:             */
3025:            public void list(PrintStream out, int indent) {
3026:                for (int i = 0; i < indent; i++) {
3027:                    out.print(" ");
3028:                }
3029:                out.println(this );
3030:            }
3031:
3032:            /**
3033:             * Prints a listing to the specified print writer.
3034:             * @param  out  The print writer to print to.
3035:             * @since JDK1.1
3036:             */
3037:            public void list(PrintWriter out) {
3038:                list(out, 0);
3039:            }
3040:
3041:            /**
3042:             * Prints out a list, starting at the specified indention, to
3043:             * the specified print writer.
3044:             * @param out The print writer to print to.
3045:             * @param indent The number of spaces to indent.
3046:             * @see       java.io.PrintStream#println(java.lang.Object)
3047:             * @since JDK1.1
3048:             */
3049:            public void list(PrintWriter out, int indent) {
3050:                for (int i = 0; i < indent; i++) {
3051:                    out.print("  ");
3052:                }
3053:                out.println(this );
3054:            }
3055:
3056:            /* Serialization support.
3057:             */
3058:
3059:            private int componentSerializedDataVersion = 1;
3060:
3061:            private void writeObject(ObjectOutputStream s) throws IOException {
3062:                s.defaultWriteObject();
3063:                AWTEventMulticaster.save(s, componentListenerK,
3064:                        componentListener);
3065:                AWTEventMulticaster.save(s, focusListenerK, focusListener);
3066:                AWTEventMulticaster.save(s, keyListenerK, keyListener);
3067:                AWTEventMulticaster.save(s, mouseListenerK, mouseListener);
3068:                AWTEventMulticaster.save(s, mouseMotionListenerK,
3069:                        mouseMotionListener);
3070:                s.writeObject(null);
3071:            }
3072:
3073:            private void readObject(ObjectInputStream s)
3074:                    throws ClassNotFoundException, IOException {
3075:                s.defaultReadObject();
3076:                Object keyOrNull;
3077:                while (null != (keyOrNull = s.readObject())) {
3078:                    String key = ((String) keyOrNull).intern();
3079:                    if (componentListenerK == key)
3080:                        addComponentListener((ComponentListener) (s
3081:                                .readObject()));
3082:                    else if (focusListenerK == key)
3083:                        addFocusListener((FocusListener) (s.readObject()));
3084:                    else if (keyListenerK == key)
3085:                        addKeyListener((KeyListener) (s.readObject()));
3086:                    else if (mouseListenerK == key)
3087:                        addMouseListener((MouseListener) (s.readObject()));
3088:                    else if (mouseMotionListenerK == key)
3089:                        addMouseMotionListener((MouseMotionListener) (s
3090:                                .readObject()));
3091:                    else
3092:                        // skip value for unrecognized key
3093:                        s.readObject();
3094:                }
3095:                if (popups != null) {
3096:                    int npopups = popups.size();
3097:                    for (int i = 0; i < npopups; i++) {
3098:                        PopupMenu popup = (PopupMenu) popups.elementAt(i);
3099:                        popup.parent = this;
3100:                    }
3101:                }
3102:            }
3103:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.