src/java.desktop/share/classes/java/awt/Component.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58309 c6f8b2c3dc66
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55172
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
     2
 * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    25
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    28
import java.applet.Applet;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    29
import java.awt.dnd.DropTarget;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    30
import java.awt.event.ActionEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    31
import java.awt.event.AdjustmentEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    32
import java.awt.event.ComponentEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    33
import java.awt.event.ComponentListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    34
import java.awt.event.FocusEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    35
import java.awt.event.FocusListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    36
import java.awt.event.HierarchyBoundsListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    37
import java.awt.event.HierarchyEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    38
import java.awt.event.HierarchyListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    39
import java.awt.event.InputEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    40
import java.awt.event.InputMethodEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    41
import java.awt.event.InputMethodListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    42
import java.awt.event.ItemEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    43
import java.awt.event.KeyEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    44
import java.awt.event.KeyListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    45
import java.awt.event.MouseEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    46
import java.awt.event.MouseListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    47
import java.awt.event.MouseMotionListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    48
import java.awt.event.MouseWheelEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    49
import java.awt.event.MouseWheelListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    50
import java.awt.event.PaintEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    51
import java.awt.event.TextEvent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    52
import java.awt.im.InputContext;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    53
import java.awt.im.InputMethodRequests;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    54
import java.awt.image.BufferStrategy;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    55
import java.awt.image.ColorModel;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    56
import java.awt.image.ImageObserver;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    57
import java.awt.image.ImageProducer;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    58
import java.awt.image.VolatileImage;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.awt.peer.ContainerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.beans.PropertyChangeSupport;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
    64
import java.beans.Transient;
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    65
import java.io.IOException;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    66
import java.io.ObjectInputStream;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    67
import java.io.ObjectOutputStream;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    68
import java.io.PrintStream;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    69
import java.io.PrintWriter;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    70
import java.io.Serializable;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    71
import java.security.AccessControlContext;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import java.security.AccessController;
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    73
import java.util.Collections;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    74
import java.util.EventListener;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    75
import java.util.HashSet;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    76
import java.util.Locale;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    77
import java.util.Map;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    78
import java.util.Objects;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    79
import java.util.Set;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    80
import java.util.Vector;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    81
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    82
import javax.accessibility.Accessible;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    83
import javax.accessibility.AccessibleComponent;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    84
import javax.accessibility.AccessibleContext;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    85
import javax.accessibility.AccessibleRole;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    86
import javax.accessibility.AccessibleSelection;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    87
import javax.accessibility.AccessibleState;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    88
import javax.accessibility.AccessibleStateSet;
40719
4ae72a69bd3b 8129854: Remove reflection from AWT/Swing classes
alexsch
parents: 38390
diff changeset
    89
import javax.swing.JComponent;
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43724
diff changeset
    90
import javax.swing.JRootPane;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    92
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
import sun.awt.AppContext;
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    94
import sun.awt.ComponentFactory;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
import sun.awt.ConstrainableGraphics;
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    96
import sun.awt.EmbeddedFrame;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
    97
import sun.awt.RequestFocusController;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
import sun.awt.SubRegionShowable;
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
    99
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
import sun.awt.dnd.SunDropTargetEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
import sun.awt.im.CompositionArea;
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
   102
import sun.awt.image.VSyncedBSManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
   103
import sun.font.FontManager;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
   104
import sun.font.FontManagerFactory;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
   105
import sun.font.SunFontManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
import sun.java2d.SunGraphics2D;
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
   107
import sun.java2d.SunGraphicsEnvironment;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
import sun.java2d.pipe.Region;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
   109
import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
   110
import sun.security.action.GetPropertyAction;
40719
4ae72a69bd3b 8129854: Remove reflection from AWT/Swing classes
alexsch
parents: 38390
diff changeset
   111
import sun.swing.SwingAccessor;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   112
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
   114
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_DEFAULT;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
   115
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
   116
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * A <em>component</em> is an object having a graphical representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * that can be displayed on the screen and that can interact with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * user. Examples of components are the buttons, checkboxes, and scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * of a typical graphical user interface. <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   122
 * The {@code Component} class is the abstract superclass of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * the nonmenu-related Abstract Window Toolkit components. Class
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   124
 * {@code Component} can also be extended directly to create a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * lightweight component. A lightweight component is a component that is
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   126
 * not associated with a native window. On the contrary, a heavyweight
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   127
 * component is associated with a native window. The {@link #isLightweight()}
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   128
 * method may be used to distinguish between the two kinds of the components.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   129
 * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   130
 * Lightweight and heavyweight components may be mixed in a single component
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   131
 * hierarchy. However, for correct operating of such a mixed hierarchy of
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   132
 * components, the whole hierarchy must be valid. When the hierarchy gets
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   133
 * invalidated, like after changing the bounds of components, or
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   134
 * adding/removing components to/from containers, the whole hierarchy must be
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   135
 * validated afterwards by means of the {@link Container#validate()} method
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
   136
 * invoked on the top-most invalid container of the hierarchy.
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
   137
 *
54397
65030bbf5ac1 8220250: fix headings in java.desktop
psadhukhan
parents: 52752
diff changeset
   138
 * <h2>Serialization</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * It is important to note that only AWT listeners which conform
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   140
 * to the {@code Serializable} protocol will be saved when
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * the object is stored.  If an AWT object has listeners that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * aren't marked serializable, they will be dropped at
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   143
 * {@code writeObject} time.  Developers will need, as always,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * to consider the implications of making an object serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * One situation to watch out for is this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *    import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *    import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *    import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *    class MyApp implements ActionListener, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *        BigObjectThatShouldNotBeSerializedWithAButton bigOne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *        Button aButton = new Button();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *        MyApp()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *            // Oops, now aButton has a listener with a reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *            // to bigOne!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *            aButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *        public void actionPerformed(ActionEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *            System.out.println("Hello There");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * </pre>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   169
 * In this example, serializing {@code aButton} by itself
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   170
 * will cause {@code MyApp} and everything it refers to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * to be serialized as well.  The problem is that the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * is serializable by coincidence, not by design.  To separate
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   173
 * the decisions about {@code MyApp} and the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   174
 * {@code ActionListener} being serializable one can use a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * nested class, as in the following example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 *    import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *    import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *    import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *
13549
d3ec89e4a9ab 7193169: The code example in javadoc of Component.java misses 'implements' keyword
zhouyx
parents: 12666
diff changeset
   181
 *    class MyApp implements java.io.Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 *    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *         BigObjectThatShouldNotBeSerializedWithAButton bigOne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 *         Button aButton = new Button();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 *         static class MyActionListener implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 *         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 *             public void actionPerformed(ActionEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 *             {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 *                 System.out.println("Hello There");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 *             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *         MyApp()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 *             aButton.addActionListener(new MyActionListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * <p>
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   201
 * <b>Note</b>: For more information on the paint mechanisms utilized
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * efficient painting code, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20172
diff changeset
   204
 * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * For details on the focus subsystem, see
52752
5e7dba63836d 8212882: links to tutorial should be updated to use https:
kaddepalli
parents: 51010
diff changeset
   207
 * <a href="https://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * a section in <em>The Java Tutorial</em>, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
public abstract class Component implements ImageObserver, MenuContainer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                           Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   220
    private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Component");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   221
    private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Component");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   222
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.Component");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
   223
    private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Component");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * The peer of the component. The peer implements the component's
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   227
     * behavior. The peer is set when the {@code Component} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * added to a container that also is a peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @see #addNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @see #removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
   232
    transient volatile ComponentPeer peer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   235
     * The parent of the object. It may be {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * for top-level components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see #getParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    transient Container parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   242
     * The {@code AppContext} of the component. Applets/Plugin may
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * change the AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    transient AppContext appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * The x position of the component in the parent's coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * The y position of the component in the parent's coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * The width of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * The height of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * The foreground color for this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   281
     * {@code foreground} can be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see #getForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see #setForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    Color       foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * The background color for this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   291
     * {@code background} can be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @see #getBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @see #setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    Color       background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * The font used by this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   301
     * The {@code font} can be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see #setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
21265
d037a0675f8d 8026356: [macosx] Found one Java-level deadlock:"AWT-EventQueue-0" && main
serb
parents: 20465
diff changeset
   307
    volatile Font font;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * The font which the peer is currently using.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   311
     * ({@code null} if no peer exists.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    Font        peerFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * The cursor displayed when pointer is over this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   317
     * This value can be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @see #getCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @see #setCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    Cursor      cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * The locale for the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @see #getLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    Locale      locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   335
     * A reference to a {@code GraphicsConfiguration} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * used to describe the characteristics of a graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * destination.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   338
     * This value can be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see #getGraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
33510
1895624f2983 8138764: In some cases the usage of TreeLock can be replaced by other synchronization
serb
parents: 33504
diff changeset
   345
    private transient volatile GraphicsConfiguration graphicsConfig;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   348
     * A reference to a {@code BufferStrategy} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * used to manipulate the buffers on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @see java.awt.image.BufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see #getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
55172
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
   355
    private transient BufferStrategy bufferStrategy = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * True when the object should ignore all repaint events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @see #setIgnoreRepaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @see #getIgnoreRepaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    boolean ignoreRepaint = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * True when the object is visible. An object that is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * visible is not drawn on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see #isVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see #setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    boolean visible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * True when the object is enabled. An object that is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * enabled does not interact with the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @see #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @see #setEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    boolean enabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * True when the object is valid. An invalid object needs to
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   389
     * be laid out. This flag is set to false when the object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * size is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see #isValid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see #invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
   397
    private volatile boolean valid = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   400
     * The {@code DropTarget} associated with this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see #setDropTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see #getDropTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    DropTarget dropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @see #add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   413
    Vector<PopupMenu> popups;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * A component's name.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   417
     * This field can be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @see #getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see #setName(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * A bool to determine whether the name has
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   427
     * been set explicitly. {@code nameExplicitlySet} will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * be false if the name has not been set and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * true if it has.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @see #getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @see #setName(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    private boolean nameExplicitlySet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Indicates whether this Component can be focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @see #setFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    private boolean focusable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    private static final int FOCUS_TRAVERSABLE_UNKNOWN = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    private static final int FOCUS_TRAVERSABLE_DEFAULT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    private static final int FOCUS_TRAVERSABLE_SET = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /**
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   452
     * Tracks whether this Component is relying on default focus traversability.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    private int isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * The focus traversal keys. These keys will generate focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * behavior for Components for which focus traversal keys are enabled. If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * value of null is specified for a traversal key, this Component inherits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * that traversal key from its parent. If all ancestors of this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * have null specified for that traversal key, then the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * KeyboardFocusManager's default traversal key is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @see #setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @see #getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 55172
diff changeset
   472
    @SuppressWarnings("serial") // Not statically typed as Serializable
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   473
    Set<AWTKeyStroke>[] focusTraversalKeys;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    private static final String[] focusTraversalKeyPropertyNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        "forwardFocusTraversalKeys",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        "backwardFocusTraversalKeys",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        "upCycleFocusTraversalKeys",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        "downCycleFocusTraversalKeys"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Indicates whether focus traversal keys are enabled for this Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * Components for which focus traversal keys are disabled receive key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * events for focus traversal keys. Components for which focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * keys are enabled do not see these events; instead, the events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * automatically converted to traversal operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @see #setFocusTraversalKeysEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @see #getFocusTraversalKeysEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    private boolean focusTraversalKeysEnabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * The locking object for AWT component-tree and layout operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @see #getTreeLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    static final Object LOCK = new AWTTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    static class AWTTreeLock {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   504
    /*
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   505
     * The component's AccessControlContext.
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   506
     */
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   507
    private transient volatile AccessControlContext acc =
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   508
        AccessController.getContext();
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   509
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Minimum size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * (This field perhaps should have been transient).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    Dimension minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Whether or not setMinimumSize has been invoked with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    boolean minSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * (This field perhaps should have been transient).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    Dimension prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Whether or not setPreferredSize has been invoked with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    boolean prefSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * Maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    Dimension maxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * Whether or not setMaximumSize has been invoked with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    boolean maxSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * The orientation for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @see #getComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @see #setComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    transient ComponentOrientation componentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    = ComponentOrientation.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   557
     * {@code newEventsOnly} will be true if the event is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * one of the event types enabled for the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * It will then allow for normal processing to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * continue.  If it is false the event is passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * to the component's parent and up the ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * tree until the event has been consumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @see #dispatchEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    boolean newEventsOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    transient ComponentListener componentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    transient FocusListener focusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    transient HierarchyListener hierarchyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    transient HierarchyBoundsListener hierarchyBoundsListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    transient KeyListener keyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    transient MouseListener mouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    transient MouseMotionListener mouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    transient MouseWheelListener mouseWheelListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    transient InputMethodListener inputMethodListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /** Internal, constants for serialization */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   579
    static final String actionListenerK = "actionL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   580
    static final String adjustmentListenerK = "adjustmentL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   581
    static final String componentListenerK = "componentL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   582
    static final String containerListenerK = "containerL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   583
    static final String focusListenerK = "focusL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   584
    static final String itemListenerK = "itemL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   585
    static final String keyListenerK = "keyL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   586
    static final String mouseListenerK = "mouseL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   587
    static final String mouseMotionListenerK = "mouseMotionL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   588
    static final String mouseWheelListenerK = "mouseWheelL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   589
    static final String textListenerK = "textL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   590
    static final String ownedWindowK = "ownedL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   591
    static final String windowListenerK = "windowL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   592
    static final String inputMethodListenerK = "inputMethodL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   593
    static final String hierarchyListenerK = "hierarchyL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   594
    static final String hierarchyBoundsListenerK = "hierarchyBoundsL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   595
    static final String windowStateListenerK = "windowStateL";
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
   596
    static final String windowFocusListenerK = "windowFocusL";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   599
     * The {@code eventMask} is ONLY set by subclasses via
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   600
     * {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * The mask should NOT be set when listeners are registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * so that we can distinguish the difference between when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * listeners request events and subclasses request them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * One bit is used to indicate whether input methods are
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   605
     * enabled; this bit is set by {@code enableInputMethods} and is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * on by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @see #enableInputMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @see AWTEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * Static properties for incremental drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @see #imageUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    static boolean isInc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    static int incRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        /* initialize JNI field and method ids */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   628
        String s = java.security.AccessController.doPrivileged(
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   629
                                                               new GetPropertyAction("awt.image.incrementaldraw"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        isInc = (s == null || s.equals("true"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   632
        s = java.security.AccessController.doPrivileged(
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
   633
                                                        new GetPropertyAction("awt.image.redrawrate"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        incRate = (s != null) ? Integer.parseInt(s) : 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   638
     * Ease-of-use constant for {@code getAlignmentY()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * Specifies an alignment to the top of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @see     #getAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public static final float TOP_ALIGNMENT = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   645
     * Ease-of-use constant for {@code getAlignmentY} and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   646
     * {@code getAlignmentX}. Specifies an alignment to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * the center of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @see     #getAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @see     #getAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public static final float CENTER_ALIGNMENT = 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   654
     * Ease-of-use constant for {@code getAlignmentY}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Specifies an alignment to the bottom of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @see     #getAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    public static final float BOTTOM_ALIGNMENT = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   661
     * Ease-of-use constant for {@code getAlignmentX}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Specifies an alignment to the left side of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * @see     #getAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    public static final float LEFT_ALIGNMENT = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   668
     * Ease-of-use constant for {@code getAlignmentX}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * Specifies an alignment to the right side of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @see     #getAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public static final float RIGHT_ALIGNMENT = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    private static final long serialVersionUID = -7644114512714619750L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   680
     * If any {@code PropertyChangeListeners} have been registered,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   681
     * the {@code changeSupport} field describes them.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @see #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @see #firePropertyChange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    private PropertyChangeSupport changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   691
    /*
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   692
     * In some cases using "this" as an object to synchronize by
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   693
     * can lead to a deadlock if client code also uses synchronization
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   694
     * by a component object. For every such situation revealed we should
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   695
     * consider possibility of replacing "this" with the package private
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   696
     * objectLock object introduced below. So far there are 3 issues known:
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   697
     * - CR 6708322 (the getName/setName methods);
11094
1f244f2719d3 7108598: Pogo Table Games freeze with JDK 7
bagiras
parents: 11083
diff changeset
   698
     * - CR 6608764 (the PropertyChangeListener machinery);
1f244f2719d3 7108598: Pogo Table Games freeze with JDK 7
bagiras
parents: 11083
diff changeset
   699
     * - CR 7108598 (the Container.paint/KeyboardFocusManager.clearMostRecentFocusOwner methods).
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   700
     *
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   701
     * Note: this field is considered final, though readObject() prohibits
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   702
     * initializing final fields.
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   703
     */
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   704
    private transient Object objectLock = new Object();
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   705
    Object getObjectLock() {
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
   706
        return objectLock;
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
   707
    }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
   708
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   709
    /*
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   710
     * Returns the acc this component was constructed with.
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   711
     */
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   712
    final AccessControlContext getAccessControlContext() {
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   713
        if (acc == null) {
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   714
            throw new SecurityException("Component is missing AccessControlContext");
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   715
        }
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   716
        return acc;
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   717
    }
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   718
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    boolean isPacked = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * Pseudoparameter for direct Geometry API (setLocation, setBounds setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * to signal setBounds what's changing. Should be used under TreeLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * This is only needed due to the inability to change the cross-calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * order of public and deprecated methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    private int boundsOp = ComponentPeer.DEFAULT_OPERATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * Enumeration of the common ways the baseline of a component can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * change as the size changes.  The baseline resize behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * primarily for layout managers that need to know how the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * position of the baseline changes as the component size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * In general the baseline resize behavior will be valid for sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * greater than or equal to the minimum size (the actual minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * size; not a developer specified minimum size).  For sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * smaller than the minimum size the baseline may change in a way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * other than the baseline resize behavior indicates.  Similarly,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   739
     * as the size approaches {@code Integer.MAX_VALUE} and/or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   740
     * {@code Short.MAX_VALUE} the baseline may change in a way
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * other than the baseline resize behavior indicates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @see #getBaselineResizeBehavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @see #getBaseline(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    public enum BaselineResizeBehavior {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
         * Indicates the baseline remains fixed relative to the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   750
         * y-origin.  That is, {@code getBaseline} returns
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
         * the same value regardless of the height or width.  For example, a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   752
         * {@code JLabel} containing non-empty text with a
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   753
         * vertical alignment of {@code TOP} should have a
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   754
         * baseline type of {@code CONSTANT_ASCENT}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        CONSTANT_ASCENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         * Indicates the baseline remains fixed relative to the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
         * and does not change as the width is varied.  That is, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
         * any height H the difference between H and
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   762
         * {@code getBaseline(w, H)} is the same.  For example, a
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   763
         * {@code JLabel} containing non-empty text with a
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   764
         * vertical alignment of {@code BOTTOM} should have a
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   765
         * baseline type of {@code CONSTANT_DESCENT}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        CONSTANT_DESCENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
         * Indicates the baseline remains a fixed distance from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
         * the center of the component.  That is, for any height H the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   772
         * difference between {@code getBaseline(w, H)} and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   773
         * {@code H / 2} is the same (plus or minus one depending upon
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
         * rounding error).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * Because of possible rounding errors it is recommended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         * you ask for the baseline with two consecutive heights and use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         * the return value to determine if you need to pad calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         * by 1.  The following shows how to calculate the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         * any height:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         *   Dimension preferredSize = component.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         *   int baseline = getBaseline(preferredSize.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         *                              preferredSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
         *   int nextBaseline = getBaseline(preferredSize.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
         *                                  preferredSize.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
         *   // Amount to add to height when calculating where baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
         *   // lands for a particular height:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
         *   int padding = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
         *   // Where the baseline is relative to the mid point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
         *   int baselineOffset = baseline - height / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
         *   if (preferredSize.height % 2 == 0 &amp;&amp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         *       baseline != nextBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
         *       padding = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
         *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
         *   else if (preferredSize.height % 2 == 1 &amp;&amp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
         *            baseline == nextBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
         *       baselineOffset--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
         *       padding = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
         *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
         *   // The following calculates where the baseline lands for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
         *   // the height z:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
         *   int calculatedBaseline = (z + padding) / 2 + baselineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
         * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        CENTER_OFFSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
         * Indicates the baseline resize behavior can not be expressed using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
         * any of the other constants.  This may also indicate the baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
         * varies with the width of the component.  This is also returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
         * by components that do not have a baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        OTHER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    /*
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   818
     * The shape set with the applyCompoundShape() method. It includes the result
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * of the HW/LW mixing related shape computation. It may also include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * the user-specified shape of the component.
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   821
     * The 'null' value means the component has normal shape (or has no shape at all)
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   822
     * and applyCompoundShape() will skip the following shape identical to normal.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    private transient Region compoundShape = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    /*
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   827
     * Represents the shape of this lightweight component to be cut out from
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   828
     * heavyweight components should they intersect. Possible values:
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   829
     *    1. null - consider the shape rectangular
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   830
     *    2. EMPTY_REGION - nothing gets cut out (children still get cut out)
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   831
     *    3. non-empty - this shape gets cut out.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   832
     */
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   833
    private transient Region mixingCutoutRegion = null;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   834
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   835
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * Indicates whether addNotify() is complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * (i.e. the peer is created).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    private transient boolean isAddNotifyComplete = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * Should only be used in subclass getBounds to check that part of bounds
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   843
     * is actually changing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    int getBoundsOp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        assert Thread.holdsLock(getTreeLock());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        return boundsOp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    void setBoundsOp(int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        assert Thread.holdsLock(getTreeLock());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if (op == ComponentPeer.RESET_OPERATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            boundsOp = ComponentPeer.DEFAULT_OPERATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            if (boundsOp == ComponentPeer.DEFAULT_OPERATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                boundsOp = op;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   860
    // Whether this Component has had the background erase flag
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   861
    // specified via SunToolkit.disableBackgroundErase(). This is
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   862
    // needed in order to make this function work on X11 platforms,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   863
    // where currently there is no chance to interpose on the creation
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   864
    // of the peer and therefore the call to XSetBackground.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   865
    transient boolean backgroundEraseDisabled;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   866
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   867
    static {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   868
        AWTAccessor.setComponentAccessor(new AWTAccessor.ComponentAccessor() {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   869
            public void setBackgroundEraseDisabled(Component comp, boolean disabled) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   870
                comp.backgroundEraseDisabled = disabled;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   871
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   872
            public boolean getBackgroundEraseDisabled(Component comp) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   873
                return comp.backgroundEraseDisabled;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   874
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   875
            public Rectangle getBounds(Component comp) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   876
                return new Rectangle(comp.x, comp.y, comp.width, comp.height);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
   877
            }
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   878
            public void setGraphicsConfiguration(Component comp,
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   879
                    GraphicsConfiguration gc)
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   880
            {
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   881
                comp.setGraphicsConfiguration(gc);
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   882
            }
41805
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
   883
            public void requestFocus(Component comp, FocusEvent.Cause cause) {
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
   884
                comp.requestFocus(cause);
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   885
            }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   886
            public boolean canBeFocusOwner(Component comp) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   887
                return comp.canBeFocusOwner();
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   888
            }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   889
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   890
            public boolean isVisible(Component comp) {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   891
                return comp.isVisible_NoClientCode();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   892
            }
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   893
            public void setRequestFocusController
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   894
                (RequestFocusController requestController)
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   895
            {
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   896
                 Component.setRequestFocusController(requestController);
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   897
            }
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   898
            public AppContext getAppContext(Component comp) {
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   899
                 return comp.appContext;
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   900
            }
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   901
            public void setAppContext(Component comp, AppContext appContext) {
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   902
                 comp.appContext = appContext;
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2805
diff changeset
   903
            }
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   904
            public Container getParent(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   905
                return comp.getParent_NoClientCode();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   906
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   907
            public void setParent(Component comp, Container parent) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   908
                comp.parent = parent;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   909
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   910
            public void setSize(Component comp, int width, int height) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   911
                comp.width = width;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   912
                comp.height = height;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   913
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   914
            public Point getLocation(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   915
                return comp.location_NoClientCode();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   916
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   917
            public void setLocation(Component comp, int x, int y) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   918
                comp.x = x;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   919
                comp.y = y;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   920
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   921
            public boolean isEnabled(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   922
                return comp.isEnabledImpl();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   923
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   924
            public boolean isDisplayable(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   925
                return comp.peer != null;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   926
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   927
            public Cursor getCursor(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   928
                return comp.getCursor_NoClientCode();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   929
            }
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
   930
            @SuppressWarnings("unchecked")
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
   931
            public <T extends ComponentPeer> T getPeer(Component comp) {
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
   932
                return (T) comp.peer;
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   933
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   934
            public void setPeer(Component comp, ComponentPeer peer) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   935
                comp.peer = peer;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   936
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   937
            public boolean isLightweight(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   938
                return (comp.peer instanceof LightweightPeer);
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   939
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   940
            public boolean getIgnoreRepaint(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   941
                return comp.ignoreRepaint;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   942
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   943
            public int getWidth(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   944
                return comp.width;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   945
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   946
            public int getHeight(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   947
                return comp.height;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   948
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   949
            public int getX(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   950
                return comp.x;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   951
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   952
            public int getY(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   953
                return comp.y;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   954
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   955
            public Color getForeground(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   956
                return comp.foreground;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   957
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   958
            public Color getBackground(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   959
                return comp.background;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   960
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   961
            public void setBackground(Component comp, Color background) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   962
                comp.background = background;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   963
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   964
            public Font getFont(Component comp) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   965
                return comp.getFont_NoClientCode();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   966
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   967
            public void processEvent(Component comp, AWTEvent e) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   968
                comp.processEvent(e);
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4285
diff changeset
   969
            }
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   970
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   971
            public AccessControlContext getAccessControlContext(Component comp) {
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   972
                return comp.getAccessControlContext();
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   973
            }
20097
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
   974
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
   975
            public void revalidateSynchronously(Component comp) {
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
   976
                comp.revalidateSynchronously();
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
   977
            }
23297
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   978
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   979
            @Override
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   980
            public void createBufferStrategy(Component comp, int numBuffers,
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   981
                    BufferCapabilities caps) throws AWTException {
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   982
                comp.createBufferStrategy(numBuffers, caps);
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   983
            }
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   984
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   985
            @Override
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   986
            public BufferStrategy getBufferStrategy(Component comp) {
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   987
                return comp.getBufferStrategy();
2946ef51ee24 8029960: Remove reflection from Swing classes
alexsch
parents: 21957
diff changeset
   988
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   989
        });
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   990
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
   991
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   993
     * Constructs a new component. Class {@code Component} can be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * extended directly to create a lightweight component that does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * utilize an opaque native window. A lightweight component must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * hosted by a native container somewhere higher up in the component
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
   997
     * tree (for example, by a {@code Frame} object).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    protected Component() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        appContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1003
    @SuppressWarnings({"rawtypes", "unchecked"})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    void initializeFocusTraversalKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        focusTraversalKeys = new Set[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1009
     * Constructs a name for this component.  Called by {@code getName}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1010
     * when the name is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        return null; // For strict compliance with prior platform versions, a Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                     // that doesn't set its name should return null from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                     // getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * Gets the name of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @return this component's name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @see    #setName
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1022
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        if (name == null && !nameExplicitlySet) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  1026
            synchronized(getObjectLock()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                if (name == null && !nameExplicitlySet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                    name = constructComponentName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * Sets the name of the component to the specified string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * @param name  the string that is to be this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     *           component's name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * @see #getName
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1039
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    public void setName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        String oldName;
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  1043
        synchronized(getObjectLock()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            oldName = this.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            nameExplicitlySet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        firePropertyChange("name", oldName, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * Gets the parent of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * @return the parent container of this component
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1054
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    public Container getParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        return getParent_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    final Container getParent_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
17150
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 15506
diff changeset
  1068
    // This method is overridden in the Window class to return null,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    //    because the parent field of the Window object contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    //    the owner of the window, not its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    Container getContainer() {
17150
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 15506
diff changeset
  1072
        return getParent_NoClientCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1076
     * Associate a {@code DropTarget} with this component.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1077
     * The {@code Component} will receive drops only if it
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * @see #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * @param dt The DropTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    public synchronized void setDropTarget(DropTarget dt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        DropTarget old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        if ((old = dropTarget) != null) {
30470
bd197b8eda21 8074763: Remove API references to java.awt.dnd.peer
serb
parents: 30469
diff changeset
  1091
            dropTarget.removeNotify();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            DropTarget t = dropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            dropTarget = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                t.setComponent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                // ignore it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        // if we have a new one, and we have a peer, add it!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        if ((dropTarget = dt) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                dropTarget.setComponent(this);
30470
bd197b8eda21 8074763: Remove API references to java.awt.dnd.peer
serb
parents: 30469
diff changeset
  1109
                dropTarget.addNotify();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                        old.setComponent(this);
30470
bd197b8eda21 8074763: Remove API references to java.awt.dnd.peer
serb
parents: 30469
diff changeset
  1114
                        dropTarget.addNotify();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                    } catch (IllegalArgumentException iae1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                        // ignore it!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1124
     * Gets the {@code DropTarget} associated with this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1125
     * {@code Component}.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1126
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1127
     * @return the drop target
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    public synchronized DropTarget getDropTarget() { return dropTarget; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1133
     * Gets the {@code GraphicsConfiguration} associated with this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1134
     * {@code Component}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1135
     * If the {@code Component} has not been assigned a specific
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1136
     * {@code GraphicsConfiguration},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1137
     * the {@code GraphicsConfiguration} of the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1138
     * {@code Component} object's top-level container is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * returned.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1140
     * If the {@code Component} has been created, but not yet added
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1141
     * to a {@code Container}, this method returns {@code null}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1142
     *
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1143
     * @return the {@code GraphicsConfiguration} used by this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1144
     *          {@code Component} or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    public GraphicsConfiguration getGraphicsConfiguration() {
33510
1895624f2983 8138764: In some cases the usage of TreeLock can be replaced by other synchronization
serb
parents: 33504
diff changeset
  1148
        return getGraphicsConfiguration_NoClientCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    final GraphicsConfiguration getGraphicsConfiguration_NoClientCode() {
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1152
        return graphicsConfig;
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1153
    }
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1154
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
  1155
    void setGraphicsConfiguration(GraphicsConfiguration gc) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        synchronized(getTreeLock()) {
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1157
            if (updateGraphicsData(gc)) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1158
                removeNotify();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1159
                addNotify();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1160
            }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1161
        }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1162
    }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1163
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1164
    final boolean updateGraphicsData(GraphicsConfiguration gc) {
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1165
        GraphicsConfiguration oldConfig = graphicsConfig;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1166
        // First, update own graphics configuration
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1167
        boolean ret = updateSelfGraphicsData(gc);
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1168
        // Second, update children graphics configurations
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1169
        ret |= updateChildGraphicsData(gc);
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1170
        // Third, fire PropertyChange if needed
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1171
        if (oldConfig != gc) {
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1172
            /*
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1173
             * If component is moved from one screen to another screen or shown
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1174
             * for the first time graphicsConfiguration property is fired to
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1175
             * enable the component to recalculate any rendering data, if needed
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1176
             */
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1177
            firePropertyChange("graphicsConfiguration", oldConfig, gc);
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1178
        }
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1179
        return ret;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1180
    }
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1181
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1182
    private boolean updateSelfGraphicsData(GraphicsConfiguration gc) {
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1183
        checkTreeLock();
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10442
diff changeset
  1184
        if (graphicsConfig == gc) {
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10442
diff changeset
  1185
            return false;
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 10442
diff changeset
  1186
        }
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1187
        graphicsConfig = gc;
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1188
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  1189
        ComponentPeer peer = this.peer;
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1190
        if (peer != null) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1191
            return peer.updateGraphicsData(gc);
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1192
        }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2647
diff changeset
  1193
        return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
50917
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1196
    boolean updateChildGraphicsData(GraphicsConfiguration gc) {
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1197
        return false;
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1198
    }
55a43beaa529 8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
serb
parents: 48726
diff changeset
  1199
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1201
     * Checks that this component's {@code GraphicsDevice}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1202
     * {@code idString} matches the string argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    void checkGD(String stringID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        if (graphicsConfig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            if (!graphicsConfig.getDevice().getIDstring().equals(stringID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                                                   "adding a container to a container on a different GraphicsDevice");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * Gets this component's locking object (the object that owns the thread
435
30ae000d9354 6615015: Typo in javadoc for Component.getTreeLock()
dcherepanov
parents: 432
diff changeset
  1215
     * synchronization monitor) for AWT component-tree and layout
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * @return this component's locking object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    public final Object getTreeLock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        return LOCK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    final void checkTreeLock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        if (!Thread.holdsLock(getTreeLock())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            throw new IllegalStateException("This function should be called while holding treeLock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * Gets the toolkit of this component. Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * the frame that contains a component controls which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * toolkit is used by that component. Therefore if the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * is moved from one frame to another, the toolkit it uses may change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * @return  the toolkit of this component
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1235
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    public Toolkit getToolkit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        return getToolkitImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * This is called by the native code, so client code can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * be called on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    final Toolkit getToolkitImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            return parent.getToolkitImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        return Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1253
    final ComponentFactory getComponentFactory() {
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1254
        final Toolkit toolkit = getToolkit();
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1255
        if (toolkit instanceof ComponentFactory) {
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1256
            return (ComponentFactory) toolkit;
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1257
        }
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1258
        throw new AWTError("UI components are unsupported by: " + toolkit);
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1259
    }
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1260
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * Determines whether this component is valid. A component is valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * when it is correctly sized and positioned within its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * container and all its children are also valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * In order to account for peers' size requirements, components are invalidated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * before they are first shown on the screen. By the time the parent container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * is fully realized, all its components will be valid.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1268
     * @return {@code true} if the component is valid, {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1272
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    public boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        return (peer != null) && valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * Determines whether this component is displayable. A component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * displayable when it is connected to a native screen resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * A component is made displayable either when it is added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * a displayable containment hierarchy or when its containment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * hierarchy is made displayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * A containment hierarchy is made displayable when its ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * window is either packed or made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * A component is made undisplayable either when it is removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * a displayable containment hierarchy or when its containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * is made undisplayable.  A containment hierarchy is made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * undisplayable when its ancestor window is disposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1293
     * @return {@code true} if the component is displayable,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1294
     * {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * @see Container#add(Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * @see Window#pack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * @see Window#show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * @see Container#remove(Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * @see Window#dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    public boolean isDisplayable() {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  1303
        return peer != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * Determines whether this component should be visible when its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * parent is visible. Components are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * initially visible, with the exception of top level components such
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1310
     * as {@code Frame} objects.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1311
     * @return {@code true} if the component is visible,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1312
     * {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * @see #setVisible
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1314
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
  1316
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
    public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        return isVisible_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    final boolean isVisible_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        return visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * Determines whether this component will be displayed on the screen.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1326
     * @return {@code true} if the component and all of its ancestors
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     *          until a toplevel window or null parent are visible,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1328
     *          {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    boolean isRecursivelyVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        return visible && (parent == null || parent.isRecursivelyVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    /**
30947
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1335
     * Determines the bounds of a visible part of the component relative to its
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1336
     * parent.
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1337
     *
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1338
     * @return the visible part of bounds
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1339
     */
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1340
    private Rectangle getRecursivelyVisibleBounds() {
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1341
        final Component container = getContainer();
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1342
        final Rectangle bounds = getBounds();
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1343
        if (container == null) {
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1344
            // we are top level window or haven't a container, return our bounds
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1345
            return bounds;
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1346
        }
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1347
        // translate the container's bounds to our coordinate space
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1348
        final Rectangle parentsBounds = container.getRecursivelyVisibleBounds();
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1349
        parentsBounds.setLocation(0, 0);
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1350
        return parentsBounds.intersection(bounds);
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1351
    }
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1352
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1353
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * Translates absolute coordinates into coordinates in the coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * space of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    Point pointRelativeToComponent(Point absolute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        Point compCoords = getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        return new Point(absolute.x - compCoords.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                         absolute.y - compCoords.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * Assuming that mouse location is stored in PointerInfo passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * to this method, it finds a Component that is in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     * Window as this Component and is located under the mouse pointer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * If no such Component exists, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * NOTE: this method should be called under the protection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * tree lock, as it is done in Component.getMousePosition() and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * Container.getMousePosition(boolean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    Component findUnderMouseInWindow(PointerInfo pi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        if (!isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        Window win = getContainingWindow();
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1377
        Toolkit toolkit = Toolkit.getDefaultToolkit();
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1378
        if (!(toolkit instanceof ComponentFactory)) {
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1379
            return null;
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1380
        }
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  1381
        if (!((ComponentFactory) toolkit).getMouseInfoPeer().isWindowUnderMouse(win)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        final boolean INCLUDE_DISABLED = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        Point relativeToWindow = win.pointRelativeToComponent(pi.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        Component inTheSameWindow = win.findComponentAt(relativeToWindow.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                                                        relativeToWindow.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                                                        INCLUDE_DISABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        return inTheSameWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1393
     * Returns the position of the mouse pointer in this {@code Component}'s
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1394
     * coordinate space if the {@code Component} is directly under the mouse
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1395
     * pointer, otherwise returns {@code null}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1396
     * If the {@code Component} is not showing on the screen, this method
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1397
     * returns {@code null} even if the mouse pointer is above the area
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1398
     * where the {@code Component} would be displayed.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1399
     * If the {@code Component} is partially or fully obscured by other
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1400
     * {@code Component}s or native windows, this method returns a non-null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * value only if the mouse pointer is located above the unobscured part of the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1402
     * {@code Component}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1403
     * <p>
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1404
     * For {@code Container}s it returns a non-null value if the mouse is
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1405
     * above the {@code Container} itself or above any of its descendants.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * Use {@link Container#getMousePosition(boolean)} if you need to exclude children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * Sometimes the exact mouse coordinates are not important, and the only thing
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1409
     * that matters is whether a specific {@code Component} is under the mouse
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1410
     * pointer. If the return value of this method is {@code null}, mouse
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1411
     * pointer is not directly above the {@code Component}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * @see       #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * @see       Container#getMousePosition
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1416
     * @return    mouse coordinates relative to this {@code Component}, or null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * @since     1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    public Point getMousePosition() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1424
        PointerInfo pi = java.security.AccessController.doPrivileged(
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1425
                                                                     new java.security.PrivilegedAction<PointerInfo>() {
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1426
                                                                         public PointerInfo run() {
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1427
                                                                             return MouseInfo.getPointerInfo();
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1428
                                                                         }
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1429
                                                                     }
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  1430
                                                                     );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            Component inTheSameWindow = findUnderMouseInWindow(pi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            if (!isSameOrAncestorOf(inTheSameWindow, true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            return pointRelativeToComponent(pi.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * Overridden in Container. Must be called under TreeLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    boolean isSameOrAncestorOf(Component comp, boolean allowChildren) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        return comp == this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * Determines whether this component is showing on screen. This means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * that the component must be visible, and it must be in a container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * that is visible and showing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * <strong>Note:</strong> sometimes there is no way to detect whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * {@code Component} is actually visible to the user.  This can happen when:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * <li>the component has been added to a visible {@code ScrollPane} but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     * the {@code Component} is not currently in the scroll pane's view port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * <li>the {@code Component} is obscured by another {@code Component} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * {@code Container}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1461
     * @return {@code true} if the component is showing,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1462
     *          {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * @see #setVisible
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1464
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        if (visible && (peer != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            return (parent == null) || parent.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * Determines whether this component is enabled. An enabled component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * can respond to user input and generate events. Components are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * enabled initially by default. A component may be enabled or disabled by
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1478
     * calling its {@code setEnabled} method.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1479
     * @return {@code true} if the component is enabled,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1480
     *          {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * @see #setEnabled
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1482
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        return isEnabledImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     * This is called by the native code, so client code can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     * be called on the toolkit thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    final boolean isEnabledImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        return enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     * Enables or disables this component, depending on the value of the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1498
     * parameter {@code b}. An enabled component can respond to user
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * input and generate events. Components are enabled initially by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * <p>Note: Disabling a lightweight component does not prevent it from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * receiving MouseEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     * <p>Note: Disabling a heavyweight container prevents all components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     * in this container from receiving any input events.  But disabling a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * lightweight container affects only this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1507
     * @param     b   If {@code true}, this component is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     *            enabled; otherwise this component is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * @see #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * @see #isLightweight
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1511
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
    public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        enable(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1519
     * replaced by {@code setEnabled(boolean)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    public void enable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        if (!enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                enabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  1528
                    peer.setEnabled(true);
30947
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1529
                    if (visible && !getRecursivelyVisibleBounds().isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                        updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                                                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                                                     null, AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1543
     * Enables or disables this component.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1544
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1545
     * @param  b {@code true} to enable this component;
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1546
     *         otherwise {@code false}
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1547
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1549
     * replaced by {@code setEnabled(boolean)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    public void enable(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
            disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1562
     * replaced by {@code setEnabled(boolean)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    public void disable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        if (enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
            KeyboardFocusManager.clearMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                enabled = false;
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1570
                // A disabled lw container is allowed to contain a focus owner.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1571
                if ((isFocusOwner() || (containsFocus() && !isLightweight())) &&
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1572
                    KeyboardFocusManager.isAutoFocusTransferEnabled())
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1573
                {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                    // Don't clear the global focus owner. If transferFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                    // fails, we want the focus to stay on the disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                    // Component so that keyboard traversal, et. al. still
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                    // makes sense to the user.
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1578
                    transferFocus(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  1582
                    peer.setEnabled(false);
30947
8dae2913daf4 8071306: GUI perfomance are very slow compared java 1.6.0_45
serb
parents: 30471
diff changeset
  1583
                    if (visible && !getRecursivelyVisibleBounds().isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                        updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                                                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                                                     null, AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
     * Returns true if this component is painted to an offscreen image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * ("buffer") that's copied to the screen later.  Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     * subclasses that support double buffering should override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * method to return true if double buffering is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * @return false by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    public boolean isDoubleBuffered() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     * Enables or disables input method support for this component. If input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     * method support is enabled and the component also processes key events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * incoming events are offered to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * the current input method and will only be processed by the component or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * dispatched to its listeners if the input method does not consume them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * By default, input method support is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     * @param enable true to enable, false to disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * @see #processKeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    public void enableInputMethods(boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        if (enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
            if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            // If this component already has focus, then activate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            // input method by dispatching a synthesized focus gained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            // event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            if (isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                if (inputContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                    FocusEvent focusGainedEvent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                        new FocusEvent(this, FocusEvent.FOCUS_GAINED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                    inputContext.dispatchEvent(focusGainedEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                if (inputContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                    inputContext.endComposition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                    inputContext.removeNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            eventMask &= ~AWTEvent.INPUT_METHODS_ENABLED_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     * Shows or hides this component depending on the value of parameter
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1652
     * {@code b}.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1653
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1654
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1655
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1656
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1657
     * @param b  if {@code true}, shows this component;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     * otherwise, hides this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     * @see #isVisible
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1660
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1661
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        show(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1669
     * replaced by {@code setVisible(boolean)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        if (!visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                visible = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                mixOnShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  1679
                    peer.setVisible(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                    createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                                          this, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                                          HierarchyEvent.SHOWING_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                                          Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                    if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                    updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                if (componentListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                    (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                    Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                    ComponentEvent e = new ComponentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                                                          ComponentEvent.COMPONENT_SHOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                    Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                parent.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1706
     * Makes this component visible or invisible.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1707
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1708
     * @param  b {@code true} to make this component visible;
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1709
     *         otherwise {@code false}
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  1710
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1712
     * replaced by {@code setVisible(boolean)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
    public void show(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    boolean containsFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
        return isFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
    void clearMostRecentFocusOwnerOnHide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        KeyboardFocusManager.clearMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
    void clearCurrentFocusCycleRootOnHide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        /* do nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1737
     * replaced by {@code setVisible(boolean)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
    public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        isPacked = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            clearCurrentFocusCycleRootOnHide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            clearMostRecentFocusOwnerOnHide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                visible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                mixOnHiding(isLightweight());
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1749
                if (containsFocus() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  1750
                    transferFocus(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  1754
                    peer.setVisible(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                    createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                                          this, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                                          HierarchyEvent.SHOWING_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                                          Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                    if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                    updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                if (componentListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                    (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                    Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                    ComponentEvent e = new ComponentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                                                          ComponentEvent.COMPONENT_HIDDEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                    Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                parent.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     * Gets the foreground color of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * @return this component's foreground color; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * not have a foreground color, the foreground color of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     * is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     * @see #setForeground
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1785
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
  1787
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
    public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        Color foreground = this.foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
        if (foreground != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            return foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
        return (parent != null) ? parent.getForeground() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     * Sets the foreground color of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * @param c the color to become this component's
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1800
     *          foreground color; if this parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     *          then this component will inherit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     *          the foreground color of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * @see #getForeground
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1804
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        Color oldColor = foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        foreground = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
            c = getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                peer.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        firePropertyChange("foreground", oldColor, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * Returns whether the foreground color has been explicitly set for this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1823
     * Component. If this method returns {@code false}, this Component is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * inheriting its foreground color from an ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1826
     * @return {@code true} if the foreground color has been explicitly
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1827
     *         set for this Component; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
    public boolean isForegroundSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
        return (foreground != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * Gets the background color of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     * @return this component's background color; if this component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     *          not have a background color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     *          the background color of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     * @see #setBackground
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1840
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
  1842
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
    public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        Color background = this.background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
        if (background != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
            return background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
        return (parent != null) ? parent.getBackground() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     * Sets the background color of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     * The background color affects each component differently and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     * parts of the component that are affected by the background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * may differ between operating systems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * @param c the color to become this component's color;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1860
     *          if this parameter is {@code null}, then this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     *          component will inherit the background color of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * @see #getBackground
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1863
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
        Color oldColor = background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
        background = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            c = getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                peer.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
        firePropertyChange("background", oldColor, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     * Returns whether the background color has been explicitly set for this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1882
     * Component. If this method returns {@code false}, this Component is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     * inheriting its background color from an ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1885
     * @return {@code true} if the background color has been explicitly
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1886
     *         set for this Component; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
    public boolean isBackgroundSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        return (background != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     * Gets the font of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     * @return this component's font; if a font has not been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * for this component, the font of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * @see #setFont
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1898
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 130
diff changeset
  1900
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
    public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        return getFont_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
    final Font getFont_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        Font font = this.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        if (font != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
            return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        return (parent != null) ? parent.getFont_NoClientCode() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     * Sets the font of this component.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1920
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1921
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1922
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1923
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
     * @param f the font to become this component's font;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1925
     *          if this parameter is {@code null} then this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     *          component will inherit the font of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * @see #getFont
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1928
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1929
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
        Font oldFont, newFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        synchronized(getTreeLock()) {
21265
d037a0675f8d 8026356: [macosx] Found one Java-level deadlock:"AWT-EventQueue-0" && main
serb
parents: 20465
diff changeset
  1934
            oldFont = font;
d037a0675f8d 8026356: [macosx] Found one Java-level deadlock:"AWT-EventQueue-0" && main
serb
parents: 20465
diff changeset
  1935
            newFont = font = f;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                f = getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                    peer.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                    peerFont = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
        firePropertyChange("font", oldFont, newFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
        // This could change the preferred size of the Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
        // Fix for 6213660. Should compare old and new fonts and do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
        // call invalidate() if they are equal.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  1952
        if (f != oldFont && (oldFont == null ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                                      !oldFont.equals(f))) {
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  1954
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * Returns whether the font has been explicitly set for this Component. If
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1960
     * this method returns {@code false}, this Component is inheriting its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     * font from an ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1963
     * @return {@code true} if the font has been explicitly set for this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1964
     *         Component; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
    public boolean isFontSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        return (font != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     * Gets the locale of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * @return this component's locale; if this component does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     *          have a locale, the locale of its parent is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * @see #setLocale
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1976
     * @exception IllegalComponentStateException if the {@code Component}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     *          does not have its own locale and has not yet been added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
     *          a containment hierarchy such that the locale can be determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     *          from the containing parent
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  1980
     * @since  1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
    public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        Locale locale = this.locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        if (locale != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            return locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            throw new IllegalComponentStateException("This component must have a parent in order to determine its locale");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
            return parent.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * Sets the locale of this component.  This is a bound property.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1998
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  1999
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2000
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2001
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     * @param l the locale to become this component's locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     * @see #getLocale
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2004
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2005
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
    public void setLocale(Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        Locale oldValue = locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        locale = l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        firePropertyChange("locale", oldValue, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2016
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2020
     * Gets the instance of {@code ColorModel} used to display
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
     * the component on the output device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
     * @return the color model used by this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
     * @see java.awt.image.ColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
     * @see java.awt.peer.ComponentPeer#getColorModel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
     * @see Toolkit#getColorModel()
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2026
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
    public ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        if ((peer != null) && ! (peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            return peer.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        } else if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
            return ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
        } // else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
        return getToolkit().getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * Gets the location of this component in the form of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * point specifying the component's top-left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * The location will be relative to the parent's coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * Due to the asynchronous nature of native event handling, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * method can return outdated values (for instance, after several calls
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2045
     * of {@code setLocation()} in rapid succession).  For this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * reason, the recommended method of obtaining a component's position is
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2047
     * within {@code java.awt.event.ComponentListener.componentMoved()},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * which is called after the operating system has finished moving the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * </p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2051
     * @return an instance of {@code Point} representing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     *          the top-left corner of the component's bounds in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     *          the coordinate space of the component's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     * @see #setLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * @see #getLocationOnScreen
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2056
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
    public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
        return location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     * Gets the location of this component in the form of a point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     * specifying the component's top-left corner in the screen's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * coordinate space.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2066
     * @return an instance of {@code Point} representing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     *          the top-left corner of the component's bounds in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     *          coordinate space of the screen
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 20097
diff changeset
  2069
     * @throws IllegalComponentStateException if the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     *          component is not showing on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     * @see #setLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
    public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
            return getLocationOnScreen_NoTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
     * a package private version of getLocationOnScreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
     * used by GlobalCursormanager to update cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
    final Point getLocationOnScreen_NoTreeLock() {
47970
1c8b81ff863e 8189204: Possible NPE in Component::getLocationOnScreen()
ssadetsky
parents: 47960
diff changeset
  2085
        ComponentPeer peer = this.peer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        if (peer != null && isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
            if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                // lightweight component location needs to be translated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
                // relative to a native component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                Container host = getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                Point pt = host.peer.getLocationOnScreen();
47970
1c8b81ff863e 8189204: Possible NPE in Component::getLocationOnScreen()
ssadetsky
parents: 47960
diff changeset
  2092
                for(Component c = this; c != host; c = c.getContainer()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                    pt.x += c.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                    pt.y += c.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                return pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                Point pt = peer.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                return pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
            throw new IllegalComponentStateException("component must be showing on the screen to determine its location");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2108
     * Returns the location of this component's top left corner.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2109
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2110
     * @return the location of this component's top left corner
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2112
     * replaced by {@code getLocation()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
    public Point location() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
        return location_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
    private Point location_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        return new Point(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     * Moves this component to a new location. The top-left corner of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2125
     * the new location is specified by the {@code x} and {@code y}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
     * parameters in the coordinate space of this component's parent.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2127
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2128
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2129
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2130
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
     * @param x the <i>x</i>-coordinate of the new location's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
     *          top-left corner in the parent's coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
     * @param y the <i>y</i>-coordinate of the new location's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     *          top-left corner in the parent's coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     * @see #setBounds
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2137
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2138
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
    public void setLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
        move(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2145
     * Moves this component to a new location.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2146
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2147
     * @param  x the <i>x</i>-coordinate of the new location's
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2148
     *           top-left corner in the parent's coordinate space
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2149
     * @param  y the <i>y</i>-coordinate of the new location's
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2150
     *           top-left corner in the parent's coordinate space
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2151
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2153
     * replaced by {@code setLocation(int, int)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
    public void move(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            setBoundsOp(ComponentPeer.SET_LOCATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     * Moves this component to a new location. The top-left corner of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2165
     * the new location is specified by point {@code p}. Point
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2166
     * {@code p} is given in the parent's coordinate space.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2167
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2168
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2169
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2170
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
     * @param p the point defining the top-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
     *          of the new location, given in the coordinate space of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     *          component's parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     * @see #setBounds
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2176
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2177
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
    public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
        setLocation(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
     * Returns the size of this component in the form of a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2185
     * {@code Dimension} object. The {@code height}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2186
     * field of the {@code Dimension} object contains
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2187
     * this component's height, and the {@code width}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2188
     * field of the {@code Dimension} object contains
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * this component's width.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2190
     * @return a {@code Dimension} object that indicates the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     *          size of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * @see #setSize
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2193
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
    public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
        return size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2200
     * Returns the size of this component in the form of a
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2201
     * {@code Dimension} object.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2202
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2203
     * @return the {@code Dimension} object that indicates the
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2204
     *         size of this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2206
     * replaced by {@code getSize()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
    public Dimension size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
        return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2214
     * Resizes this component so that it has width {@code width}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2215
     * and height {@code height}.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2216
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2217
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2218
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2219
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * @param width the new width of this component in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * @param height the new height of this component in pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     * @see #setBounds
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2224
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2225
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
    public void setSize(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
        resize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2232
     * Resizes this component.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2233
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2234
     * @param  width the new width of the component
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2235
     * @param  height the new height of the component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2237
     * replaced by {@code setSize(int, int)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
    public void resize(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
            setBoundsOp(ComponentPeer.SET_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
            setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2248
     * Resizes this component so that it has width {@code d.width}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2249
     * and height {@code d.height}.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2250
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2251
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2252
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2253
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     * @param d the dimension specifying the new size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
     *          of this component
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  2256
     * @throws NullPointerException if {@code d} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
     * @see #setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
     * @see #setBounds
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2259
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2260
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
    public void setSize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
        resize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2267
     * Resizes this component so that it has width {@code d.width}
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2268
     * and height {@code d.height}.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2269
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2270
     * @param  d the new size of this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2272
     * replaced by {@code setSize(Dimension)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
    public void resize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
        setSize(d.width, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
     * Gets the bounds of this component in the form of a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2281
     * {@code Rectangle} object. The bounds specify this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
     * component's width, height, and location relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     * its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     * @return a rectangle indicating this component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     * @see #setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     * @see #getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        return bounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2294
     * Returns the bounding rectangle of this component.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2295
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2296
     * @return the bounding rectangle for this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2298
     * replaced by {@code getBounds()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
    public Rectangle bounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        return new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
     * Moves and resizes this component. The new location of the top-left
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2307
     * corner is specified by {@code x} and {@code y}, and the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2308
     * new size is specified by {@code width} and {@code height}.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2309
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2310
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2311
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2312
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * @param x the new <i>x</i>-coordinate of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * @param y the new <i>y</i>-coordinate of this component
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2315
     * @param width the new {@code width} of this component
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2316
     * @param height the new {@code height} of this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     *          component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     * @see #setLocation(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     * @see #setLocation(Point)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     * @see #setSize(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     * @see #setSize(Dimension)
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2323
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2324
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
    public void setBounds(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        reshape(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2331
     * Reshapes the bounding rectangle for this component.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2332
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2333
     * @param  x the <i>x</i> coordinate of the upper left corner of the rectangle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2334
     * @param  y the <i>y</i> coordinate of the upper left corner of the rectangle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2335
     * @param  width the width of the rectangle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2336
     * @param  height the height of the rectangle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2337
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2339
     * replaced by {@code setBounds(int, int, int, int)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
    public void reshape(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
                setBoundsOp(ComponentPeer.SET_BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
                boolean resized = (this.width != width) || (this.height != height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
                boolean moved = (this.x != x) || (this.y != y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
                if (!resized && !moved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
                int oldX = this.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
                int oldY = this.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
                int oldWidth = this.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
                int oldHeight = this.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
                this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
                this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
                this.width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
                this.height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
                if (resized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
                    isPacked = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                boolean needNotify = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                mixOnReshaping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
                if (peer != null) {
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  2367
                    // LightweightPeer is an empty stub so can skip peer.reshape
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
                    if (!(peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
                        reshapeNativePeer(x, y, width, height, getBoundsOp());
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  2370
                        // Check peer actually changed coordinates
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
                        resized = (oldWidth != this.width) || (oldHeight != this.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
                        moved = (oldX != this.x) || (oldY != this.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                        // fix for 5025858: do not send ComponentEvents for toplevel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
                        // windows here as it is done from peer or native code when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
                        // the window is really resized or moved, otherwise some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                        // events may be sent twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
                        if (this instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
                            needNotify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
                    if (resized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
                        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
                    }
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2384
                    if (parent != null) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2385
                        parent.invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
                if (needNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
                    notifyNewBounds(resized, moved);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
                repaintParentIfNeeded(oldX, oldY, oldWidth, oldHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
                setBoundsOp(ComponentPeer.RESET_OPERATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
    private void repaintParentIfNeeded(int oldX, int oldY, int oldWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
                                       int oldHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
        if (parent != null && peer instanceof LightweightPeer && isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
            // Have the parent redraw the area this component occupied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
            parent.repaint(oldX, oldY, oldWidth, oldHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
            // Have the parent redraw the area this component *now* occupies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
    private void reshapeNativePeer(int x, int y, int width, int height, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
        // native peer might be offset by more than direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
        // parent since parent might be lightweight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
        int nativeX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
        int nativeY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
        for (Component c = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
             (c != null) && (c.peer instanceof LightweightPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
             c = c.parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
            nativeX += c.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
            nativeY += c.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
        peer.setBounds(nativeX, nativeY, width, height, op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  2424
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
    private void notifyNewBounds(boolean resized, boolean moved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
        if (componentListener != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
            || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
            || Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                if (resized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
                    ComponentEvent e = new ComponentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
                                                          ComponentEvent.COMPONENT_RESIZED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
                    Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
                if (moved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
                    ComponentEvent e = new ComponentEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
                                                          ComponentEvent.COMPONENT_MOVED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
                    Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
            } else {
1172
a1d23c450f84 6616323: consider benefits of replacing a componen array with other collection from the awt.Container class
dav
parents: 1171
diff changeset
  2441
                if (this instanceof Container && ((Container)this).countComponents() > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
                    boolean enabledOnToolkit =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
                        Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
                    if (resized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
                        ((Container)this).createChildHierarchyEvents(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
                                                                     HierarchyEvent.ANCESTOR_RESIZED, 0, enabledOnToolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
                    if (moved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
                        ((Container)this).createChildHierarchyEvents(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
                                                                     HierarchyEvent.ANCESTOR_MOVED, 0, enabledOnToolkit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
     * Moves and resizes this component to conform to the new
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2459
     * bounding rectangle {@code r}. This component's new
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2460
     * position is specified by {@code r.x} and {@code r.y},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2461
     * and its new size is specified by {@code r.width} and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2462
     * {@code r.height}
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2463
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2464
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2465
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2466
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
     * @param r the new bounding rectangle for this component
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  2468
     * @throws NullPointerException if {@code r} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
     * @see       #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
     * @see       #setLocation(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
     * @see       #setLocation(Point)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
     * @see       #setSize(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
     * @see       #setSize(Dimension)
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  2474
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2475
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
    public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
        setBounds(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
     * Returns the current x coordinate of the components origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
     * This method is preferable to writing
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2485
     * {@code component.getBounds().x},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2486
     * or {@code component.getLocation().x} because it doesn't
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * cause any heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * @return the current x coordinate of the components origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
    public int getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
     * Returns the current y coordinate of the components origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
     * This method is preferable to writing
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2500
     * {@code component.getBounds().y},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2501
     * or {@code component.getLocation().y} because it
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
     * doesn't cause any heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
     * @return the current y coordinate of the components origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
    public int getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
        return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
     * Returns the current width of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
     * This method is preferable to writing
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2515
     * {@code component.getBounds().width},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2516
     * or {@code component.getSize().width} because it
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
     * doesn't cause any heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
     * @return the current width of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
     * Returns the current height of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
     * This method is preferable to writing
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2530
     * {@code component.getBounds().height},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2531
     * or {@code component.getSize().height} because it
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
     * doesn't cause any heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
     * @return the current height of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
     * Stores the bounds of this component into "return value" <b>rv</b> and
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2543
     * return <b>rv</b>.  If rv is {@code null} a new
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2544
     * {@code Rectangle} is allocated.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2545
     * This version of {@code getBounds} is useful if the caller
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2546
     * wants to avoid allocating a new {@code Rectangle} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
     * on the heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
     * @param rv the return value, modified to the components bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
     * @return rv
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
    public Rectangle getBounds(Rectangle rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
            return new Rectangle(getX(), getY(), getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
            rv.setBounds(getX(), getY(), getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
     * Stores the width/height of this component into "return value" <b>rv</b>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2564
     * and return <b>rv</b>.   If rv is {@code null} a new
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2565
     * {@code Dimension} object is allocated.  This version of
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2566
     * {@code getSize} is useful if the caller wants to avoid
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2567
     * allocating a new {@code Dimension} object on the heap.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     * @param rv the return value, modified to the components size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     * @return rv
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
    public Dimension getSize(Dimension rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
            return new Dimension(getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
            rv.setSize(getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
     * Stores the x,y origin of this component into "return value" <b>rv</b>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2584
     * and return <b>rv</b>.   If rv is {@code null} a new
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2585
     * {@code Point} is allocated.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2586
     * This version of {@code getLocation} is useful if the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2587
     * caller wants to avoid allocating a new {@code Point}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
     * object on the heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
     * @param rv the return value, modified to the components location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
     * @return rv
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
    public Point getLocation(Point rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
            return new Point(getX(), getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
            rv.setLocation(getX(), getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
     * Returns true if this component is completely opaque, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
     * false by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
     * An opaque component paints every pixel within its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
     * rectangular region. A non-opaque component paints only some of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
     * its pixels, allowing the pixels underneath it to "show through".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
     * A component that does not fully paint its pixels therefore
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3084
diff changeset
  2611
     * provides a degree of transparency.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
     * Subclasses that guarantee to always completely paint their
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3084
diff changeset
  2614
     * contents should override this method and return true.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
     * @return true if this component is completely opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
     * @see #isLightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
    public boolean isOpaque() {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  2621
        if (peer == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
            return !isLightweight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
     * A lightweight component doesn't have a native toolkit peer.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2632
     * Subclasses of {@code Component} and {@code Container},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2633
     * other than the ones defined in this package like {@code Button}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2634
     * or {@code Scrollbar}, are lightweight.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     * All of the Swing components are lightweights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2637
     * This method will always return {@code false} if this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     * is not displayable because it is impossible to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     * weight of an undisplayable component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     * @return true if this component has a lightweight peer; false if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     *         it has a native peer or no peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
    public boolean isLightweight() {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  2647
        return peer instanceof LightweightPeer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
     * Sets the preferred size of this component to a constant
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2653
     * value.  Subsequent calls to {@code getPreferredSize} will always
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2654
     * return this value.  Setting the preferred size to {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
     * restores the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
     * @param preferredSize The new preferred size, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
     * @see #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
     * @see #isPreferredSizeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
    public void setPreferredSize(Dimension preferredSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
        Dimension old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
        // If the preferred size was set, use it as the old value, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
        // use null to indicate we didn't previously have a set preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
        // size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
        if (prefSizeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
            old = this.prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
            old = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
        this.prefSize = preferredSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
        prefSizeSet = (preferredSize != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
        firePropertyChange("preferredSize", old, preferredSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
     * Returns true if the preferred size has been set to a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2681
     * non-{@code null} value otherwise returns false.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2682
     *
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2683
     * @return true if {@code setPreferredSize} has been invoked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
     *         with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
    public boolean isPreferredSizeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
        return prefSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
     * Gets the preferred size of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
     * @return a dimension object indicating this component's preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
        return preferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2704
     * Returns the component's preferred size.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2705
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2706
     * @return the component's preferred size
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2708
     * replaced by {@code getPreferredSize()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
    public Dimension preferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
        /* Avoid grabbing the lock if a reasonable cached size value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
         * is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
        Dimension dim = prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
        if (dim == null || !(isPreferredSizeSet() || isValid())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
                prefSize = (peer != null) ?
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  2719
                    peer.getPreferredSize() :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
                    getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
                dim = prefSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
        return new Dimension(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
     * Sets the minimum size of this component to a constant
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2729
     * value.  Subsequent calls to {@code getMinimumSize} will always
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2730
     * return this value.  Setting the minimum size to {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
     * restores the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     * @param minimumSize the new minimum size of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
     * @see #isMinimumSizeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
    public void setMinimumSize(Dimension minimumSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
        Dimension old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
        // If the minimum size was set, use it as the old value, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
        // use null to indicate we didn't previously have a set minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
        // size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
        if (minSizeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
            old = this.minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
            old = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
        this.minSize = minimumSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
        minSizeSet = (minimumSize != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
        firePropertyChange("minimumSize", old, minimumSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2755
     * Returns whether or not {@code setMinimumSize} has been
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
     * invoked with a non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2758
     * @return true if {@code setMinimumSize} has been invoked with a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
     *              non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
    public boolean isMinimumSizeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
        return minSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21265
diff changeset
  2767
     * Gets the minimum size of this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
     * @return a dimension object indicating this component's minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
     * @see #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
        return minimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2777
     * Returns the minimum size of this component.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2778
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2779
     * @return the minimum size of this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2781
     * replaced by {@code getMinimumSize()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
        /* Avoid grabbing the lock if a reasonable cached size value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
         * is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
        Dimension dim = minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
        if (dim == null || !(isMinimumSizeSet() || isValid())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
                minSize = (peer != null) ?
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  2792
                    peer.getMinimumSize() :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
                    size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
                dim = minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
        return new Dimension(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
     * Sets the maximum size of this component to a constant
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2802
     * value.  Subsequent calls to {@code getMaximumSize} will always
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2803
     * return this value.  Setting the maximum size to {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
     * restores the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2806
     * @param maximumSize a {@code Dimension} containing the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
     *          desired maximum allowable size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
     * @see #getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
     * @see #isMaximumSizeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
    public void setMaximumSize(Dimension maximumSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        // If the maximum size was set, use it as the old value, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
        // use null to indicate we didn't previously have a set maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
        // size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
        Dimension old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
        if (maxSizeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
            old = this.maxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
            old = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
        this.maxSize = maximumSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
        maxSizeSet = (maximumSize != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
        firePropertyChange("maximumSize", old, maximumSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2829
     * Returns true if the maximum size has been set to a non-{@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
     * value otherwise returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2832
     * @return true if {@code maximumSize} is non-{@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
     *          false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
    public boolean isMaximumSizeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
        return maxSizeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
     * Gets the maximum size of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
     * @return a dimension object indicating this component's maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
     * @see #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
    public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
        if (isMaximumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            return new Dimension(maxSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
        return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
     * Returns the alignment along the x axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
     * the furthest away from the origin, 0.5 is centered, etc.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2860
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2861
     * @return the horizontal alignment of this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
    public float getAlignmentX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
        return CENTER_ALIGNMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
     * Returns the alignment along the y axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
     * the furthest away from the origin, 0.5 is centered, etc.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2873
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  2874
     * @return the vertical alignment of this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
    public float getAlignmentY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
        return CENTER_ALIGNMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
     * Returns the baseline.  The baseline is measured from the top of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
     * the component.  This method is primarily meant for
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2883
     * {@code LayoutManager}s to align components along their
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
     * baseline.  A return value less than 0 indicates this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
     * does not have a reasonable baseline and that
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2886
     * {@code LayoutManager}s should not align this component on
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
     * its baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
     * The default implementation returns -1.  Subclasses that support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
     * baseline should override appropriately.  If a value &gt;= 0 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
     * returned, then the component has a valid baseline for any
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2892
     * size &gt;= the minimum size and {@code getBaselineResizeBehavior}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
     * can be used to determine how the baseline changes with size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
     * @param width the width to get the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
     * @param height the height to get the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
     * @return the baseline or &lt; 0 indicating there is no reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
     *         baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
     * @throws IllegalArgumentException if width or height is &lt; 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
     * @see #getBaselineResizeBehavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
     * @see java.awt.FontMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
    public int getBaseline(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
        if (width < 0 || height < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
                    "Width and height must be >= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
     * changes as the size changes.  This method is primarily meant for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
     * layout managers and GUI builders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
     * The default implementation returns
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2918
     * {@code BaselineResizeBehavior.OTHER}.  Subclasses that have a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
     * baseline should override appropriately.  Subclasses should
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2920
     * never return {@code null}; if the baseline can not be
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2921
     * calculated return {@code BaselineResizeBehavior.OTHER}.  Callers
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
     * should first ask for the baseline using
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2923
     * {@code getBaseline} and if a value &gt;= 0 is returned use
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
     * this method.  It is acceptable for this method to return a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2925
     * value other than {@code BaselineResizeBehavior.OTHER} even if
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2926
     * {@code getBaseline} returns a value less than 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
     * @return an enum indicating how the baseline changes as the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
     *         size changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     * @see #getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
    public BaselineResizeBehavior getBaselineResizeBehavior() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
        return BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
     * Prompts the layout manager to lay out this component. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
     * usually called when the component (more specifically, container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
     * is validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
     * @see #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
     * @see LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
    public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
        layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  2950
     * replaced by {@code doLayout()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
    public void layout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
    /**
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2957
     * Validates this component.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2958
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2959
     * The meaning of the term <i>validating</i> is defined by the ancestors of
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2960
     * this class. See {@link Container#validate} for more details.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2961
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
     * @see       #invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
     * @see       #doLayout()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
     * @see       LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
     * @see       Container#validate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  2966
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
    public void validate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
            ComponentPeer peer = this.peer;
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2971
            boolean wasValid = isValid();
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2972
            if (!wasValid && peer != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
                Font newfont = getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
                Font oldfont = peerFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
                if (newfont != oldfont && (oldfont == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
                                           || !oldfont.equals(newfont))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
                    peer.setFont(newfont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
                    peerFont = newfont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
                peer.layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
            valid = true;
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2983
            if (!wasValid) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2984
                mixOnValidating();
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  2985
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
    /**
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2990
     * Invalidates this component and its ancestors.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2991
     * <p>
9658
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2992
     * By default, all the ancestors of the component up to the top-most
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2993
     * container of the hierarchy are marked invalid. If the {@code
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2994
     * java.awt.smartInvalidate} system property is set to {@code true},
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2995
     * invalidation stops on the nearest validate root of this component.
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2996
     * Marking a container <i>invalid</i> indicates that the container needs to
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
  2997
     * be laid out.
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2998
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  2999
     * This method is called automatically when any layout-related information
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3000
     * changes (e.g. setting the bounds of the component, or adding the
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3001
     * component to a container).
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3002
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3003
     * This method might be called often, so it should work fast.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3004
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
     * @see       #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
     * @see       #doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
     * @see       LayoutManager
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3008
     * @see       java.awt.Container#isValidateRoot
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3009
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
    public void invalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
            /* Nullify cached layout and size information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
             * For efficiency, propagate invalidate() upwards only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
             * some other component hasn't already done so first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
            if (!isPreferredSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
                prefSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
            if (!isMinimumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
                minSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
            if (!isMaximumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
                maxSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
            }
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3027
            invalidateParent();
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3028
        }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3029
    }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3030
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3031
    /**
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3032
     * Invalidates the parent of this component if any.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3033
     *
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3034
     * This method MUST BE invoked under the TreeLock.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3035
     */
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3036
    void invalidateParent() {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3037
        if (parent != null) {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4259
diff changeset
  3038
            parent.invalidateIfValid();
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  3039
        }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  3040
    }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  3041
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  3042
    /** Invalidates the component unless it is already invalid.
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  3043
     */
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  3044
    final void invalidateIfValid() {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  3045
        if (isValid()) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  3046
            invalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
    /**
9471
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3051
     * Revalidates the component hierarchy up to the nearest validate root.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3052
     * <p>
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3053
     * This method first invalidates the component hierarchy starting from this
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3054
     * component up to the nearest validate root. Afterwards, the component
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3055
     * hierarchy is validated starting from the nearest validate root.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3056
     * <p>
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3057
     * This is a convenience method supposed to help application developers
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3058
     * avoid looking for validate roots manually. Basically, it's equivalent to
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3059
     * first calling the {@link #invalidate()} method on this component, and
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3060
     * then calling the {@link #validate()} method on the nearest validate
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3061
     * root.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3062
     *
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3063
     * @see Container#isValidateRoot
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3064
     * @since 1.7
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3065
     */
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3066
    public void revalidate() {
20097
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
  3067
        revalidateSynchronously();
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
  3068
    }
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
  3069
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
  3070
    /**
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
  3071
     * Revalidates the component synchronously.
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
  3072
     */
a4a07c4ead5f 8023474: First mousepress doesn't start editing in JTree
dmarkov
parents: 18178
diff changeset
  3073
    final void revalidateSynchronously() {
9471
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3074
        synchronized (getTreeLock()) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3075
            invalidate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3076
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3077
            Container root = getContainer();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3078
            if (root == null) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3079
                // There's no parents. Just validate itself.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3080
                validate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3081
            } else {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3082
                while (!root.isValidateRoot()) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3083
                    if (root.getContainer() == null) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3084
                        // If there's no validate roots, we'll validate the
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3085
                        // topmost container
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3086
                        break;
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3087
                    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3088
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3089
                    root = root.getContainer();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3090
                }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3091
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3092
                root.validate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3093
            }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3094
        }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3095
    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3096
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 9050
diff changeset
  3097
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
     * Creates a graphics context for this component. This method will
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3099
     * return {@code null} if this component is currently not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
     * displayable.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3101
     * @return a graphics context for this component, or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
     *             if it has none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
     * @see       #paint
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3104
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
    public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
            // This is for a lightweight component, need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
            // translate coordinate spaces and clip relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
            // to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
            if (parent == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
            Graphics g = parent.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
            if (g == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
            if (g instanceof ConstrainableGraphics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
                ((ConstrainableGraphics) g).constrain(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
                g.translate(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
                g.setClip(0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
            g.setFont(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
            return g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
            ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
            return (peer != null) ? peer.getGraphics() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
    final Graphics getGraphics_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
            // This is for a lightweight component, need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
            // translate coordinate spaces and clip relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
            // to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
            if (parent == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
            Graphics g = parent.getGraphics_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
            if (g == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
            if (g instanceof ConstrainableGraphics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
                ((ConstrainableGraphics) g).constrain(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
                g.translate(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
                g.setClip(0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
            g.setFont(getFont_NoClientCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
            return g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
            return (peer != null) ? peer.getGraphics() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
     * Gets the font metrics for the specified font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
     * Warning: Since Font metrics are affected by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
     * {@link java.awt.font.FontRenderContext FontRenderContext} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
     * this method does not provide one, it can return only metrics for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
     * the default render context which may not match that used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
     * rendering on the Component if {@link Graphics2D} functionality is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
     * used. Instead metrics can be obtained at rendering time by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
     * {@link Graphics#getFontMetrics()} or text measurement APIs on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
     * {@link Font Font} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
     * @param font the font for which font metrics is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
     *          obtained
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3163
     * @return the font metrics for {@code font}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
     * @see       #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
     * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
     * @see       Toolkit#getFontMetrics(Font)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3167
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
    public FontMetrics getFontMetrics(Font font) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3170
        // This is an unsupported hack, but left in for a customer.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3171
        // Do not remove.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3172
        FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3173
        if (fm instanceof SunFontManager
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3174
            && ((SunFontManager) fm).usePlatformFontMetrics()) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3237
diff changeset
  3175
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
            if (peer != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
                !(peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
                return peer.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
        return sun.font.FontDesignMetrics.getMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
     * Sets the cursor image to the specified cursor.  This cursor
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3186
     * image is displayed when the {@code contains} method for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
     * this component returns true for the current cursor location, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
     * this Component is visible, displayable, and enabled. Setting the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3189
     * cursor of a {@code Container} causes that cursor to be displayed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
     * within all of the container's subcomponents, except for those
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3191
     * that have a non-{@code null} cursor.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
     * The method may have no visual effect if the Java platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
     * implementation and/or the native system do not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
     * changing the mouse cursor shape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
     * @param cursor One of the constants defined
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3197
     *          by the {@code Cursor} class;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3198
     *          if this parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
     *          then this component will inherit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
     *          the cursor of its parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
     * @see       #isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
     * @see       #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
     * @see       #getCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
     * @see       #contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
     * @see       Toolkit#createCustomCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
     * @see       Cursor
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3207
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
    public void setCursor(Cursor cursor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
        this.cursor = cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
        updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
     * Updates the cursor.  May not be invoked from the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
     * message pump.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
    final void updateCursorImmediately() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
            Container nativeContainer = getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
            if (nativeContainer == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  3224
            ComponentPeer cPeer = nativeContainer.peer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
            if (cPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
                cPeer.updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
        } else if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
            peer.updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
     * Gets the cursor set in the component. If the component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
     * not have a cursor set, the cursor of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
     * If no cursor is set in the entire hierarchy,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3238
     * {@code Cursor.DEFAULT_CURSOR} is returned.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  3239
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  3240
     * @return the cursor for this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
     * @see #setCursor
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  3242
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
    public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
        return getCursor_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
    final Cursor getCursor_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
        Cursor cursor = this.cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
        if (cursor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
            return cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
            return parent.getCursor_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
            return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
     * Returns whether the cursor has been explicitly set for this Component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3263
     * If this method returns {@code false}, this Component is inheriting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
     * its cursor from an ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3266
     * @return {@code true} if the cursor has been explicitly set for this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3267
     *         Component; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
    public boolean isCursorSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
        return (cursor != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
     * Paints this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
     * This method is called when the contents of the component should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
     * be painted; such as when the component is first being shown or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
     * is damaged and in need of repair.  The clip rectangle in the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3280
     * {@code Graphics} parameter is set to the area
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
     * which needs to be painted.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3282
     * Subclasses of {@code Component} that override this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3283
     * method need not call {@code super.paint(g)}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3284
     * <p>
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3285
     * For performance reasons, {@code Component}s with zero width
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
     * or height aren't considered to need painting when they are first shown,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
     * and also aren't considered to need repair.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
     * efficient painting code, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20172
diff changeset
  3292
     * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
     * @param g the graphics context to use for painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
     * @see       #update
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3296
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
     * Updates this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
     * If this component is not a lightweight component, the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3305
     * AWT calls the {@code update} method in response to
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3306
     * a call to {@code repaint}.  You can assume that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
     * the background is not cleared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3309
     * The {@code update} method of {@code Component}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3310
     * calls this component's {@code paint} method to redraw
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
     * this component.  This method is commonly overridden by subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
     * which need to do additional work in response to a call to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3313
     * {@code repaint}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
     * Subclasses of Component that override this method should either
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3315
     * call {@code super.update(g)}, or call {@code paint(g)}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3316
     * directly from their {@code update} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
     * The origin of the graphics context, its
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3319
     * ({@code 0},&nbsp;{@code 0}) coordinate point, is the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
     * top-left corner of this component. The clipping region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
     * graphics context is the bounding rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
     * efficient painting code, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20172
diff changeset
  3327
     * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
     * @param g the specified context to use for updating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
     * @see       #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
     * @see       #repaint()
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3332
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
    public void update(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
        paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
     * Paints this component and all of its subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
     * The origin of the graphics context, its
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3342
     * ({@code 0},&nbsp;{@code 0}) coordinate point, is the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
     * top-left corner of this component. The clipping region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
     * graphics context is the bounding rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
     * @param     g   the graphics context to use for painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
     * @see       #paint
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3348
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
    public void paintAll(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
            GraphicsCallback.PeerPaintCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
                runOneComponent(this, new Rectangle(0, 0, width, height),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
                                g, g.getClip(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
                                GraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
                                GraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
     * Simulates the peer callbacks into java.awt for painting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
     * lightweight Components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
     * @param     g   the graphics context to use for painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
     * @see       #paintAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
    void lightweightPaint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
        paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
     * Paints all the heavyweight subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
    void paintHeavyweightComponents(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
     * Repaints this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
     * If this component is a lightweight component, this method
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3380
     * causes a call to this component's {@code paint}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
     * method as soon as possible.  Otherwise, this method causes
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3382
     * a call to this component's {@code update} method as soon
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
     * as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
     * efficient painting code, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20172
diff changeset
  3388
     * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
     * @see       #update(Graphics)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3392
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
    public void repaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
        repaint(0, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
     * Repaints the component.  If this component is a lightweight
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3400
     * component, this results in a call to {@code paint}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3401
     * within {@code tm} milliseconds.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
     * efficient painting code, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20172
diff changeset
  3406
     * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
     * @param tm maximum time in milliseconds before update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
     * @see #update(Graphics)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3411
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
    public void repaint(long tm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
        repaint(tm, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
     * Repaints the specified rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
     * If this component is a lightweight component, this method
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3421
     * causes a call to this component's {@code paint} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
     * as soon as possible.  Otherwise, this method causes a call to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3423
     * this component's {@code update} method as soon as possible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
     * efficient painting code, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20172
diff changeset
  3428
     * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
     * @param     x   the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
     * @param     y   the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
     * @param     width   the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
     * @param     height  the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
     * @see       #update(Graphics)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3435
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
    public void repaint(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
        repaint(0, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
     * Repaints the specified rectangle of this component within
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3443
     * {@code tm} milliseconds.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
     * If this component is a lightweight component, this method causes
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3446
     * a call to this component's {@code paint} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
     * Otherwise, this method causes a call to this component's
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3448
     * {@code update} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
     * <b>Note</b>: For more information on the paint mechanisms utilitized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
     * by AWT and Swing, including information on how to write the most
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
     * efficient painting code, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20172
diff changeset
  3453
     * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
     * @param     tm   maximum time in milliseconds before update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
     * @param     x    the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
     * @param     y    the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
     * @param     width    the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
     * @param     height   the height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
     * @see       #update(Graphics)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3461
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
    public void repaint(long tm, int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
        if (this.peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
            // Needs to be translated to parent coordinates since
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
            // a parent native container provides the actual repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
            // services.  Additionally, the request is restricted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
            // the bounds of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
            if (parent != null) {
634
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3470
                if (x < 0) {
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3471
                    width += x;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3472
                    x = 0;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3473
                }
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3474
                if (y < 0) {
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3475
                    height += y;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3476
                    y = 0;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3477
                }
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3478
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
                int pwidth = (width > this.width) ? this.width : width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
                int pheight = (height > this.height) ? this.height : height;
634
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3481
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3482
                if (pwidth <= 0 || pheight <= 0) {
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3483
                    return;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3484
                }
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3485
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3486
                int px = this.x + x;
34d4a2d5b8cb 6644301: lightweight components can repaint outside request bounds
son
parents: 441
diff changeset
  3487
                int py = this.y + y;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
                parent.repaint(tm, px, py, pwidth, pheight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
            if (isVisible() && (this.peer != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
                (width > 0) && (height > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
                PaintEvent e = new PaintEvent(this, PaintEvent.UPDATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
                                              new Rectangle(x, y, width, height));
25104
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24549
diff changeset
  3495
                SunToolkit.postEvent(SunToolkit.targetToAppContext(this), e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
     * Prints this component. Applications should override this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
     * for components that must do special processing before being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
     * printed or should be printed differently than they are painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
     * The default implementation of this method calls the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3506
     * {@code paint} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
     * The origin of the graphics context, its
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3509
     * ({@code 0},&nbsp;{@code 0}) coordinate point, is the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
     * top-left corner of this component. The clipping region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
     * graphics context is the bounding rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
     * @param     g   the graphics context to use for printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
     * @see       #paint(Graphics)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3514
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
        paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
     * Prints this component and all of its subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
     * The origin of the graphics context, its
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3524
     * ({@code 0},&nbsp;{@code 0}) coordinate point, is the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
     * top-left corner of this component. The clipping region of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
     * graphics context is the bounding rectangle of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
     * @param     g   the graphics context to use for printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
     * @see       #print(Graphics)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3529
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
    public void printAll(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
        if (isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
            GraphicsCallback.PeerPrintCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
                runOneComponent(this, new Rectangle(0, 0, width, height),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
                                g, g.getClip(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
                                GraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
                                GraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
     * Simulates the peer callbacks into java.awt for printing of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
     * lightweight Components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
     * @param     g   the graphics context to use for printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
     * @see       #printAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
    void lightweightPrint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
        print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
     * Prints all the heavyweight subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
    void printHeavyweightComponents(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
    private Insets getInsets_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
        if (peer instanceof ContainerPeer) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  3560
            return (Insets)((ContainerPeer)peer).getInsets().clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
        return new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
     * Repaints the component when the image has changed.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3567
     * This {@code imageUpdate} method of an {@code ImageObserver}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
     * is called when more information about an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
     * image which had been previously requested using an asynchronous
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3570
     * routine such as the {@code drawImage} method of
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3571
     * {@code Graphics} becomes available.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3572
     * See the definition of {@code imageUpdate} for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
     * more information on this method and its arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3575
     * The {@code imageUpdate} method of {@code Component}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
     * incrementally draws an image on the component as more of the bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
     * of the image are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3579
     * If the system property {@code awt.image.incrementaldraw}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3580
     * is missing or has the value {@code true}, the image is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
     * incrementally drawn. If the system property has any other value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
     * then the image is not drawn until it has been completely loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
     * Also, if incremental drawing is in effect, the value of the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3585
     * system property {@code awt.image.redrawrate} is interpreted
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
     * as an integer to give the maximum redraw rate, in milliseconds. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
     * the system property is missing or cannot be interpreted as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
     * integer, the redraw rate is once every 100ms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3590
     * The interpretation of the {@code x}, {@code y},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3591
     * {@code width}, and {@code height} arguments depends on
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3592
     * the value of the {@code infoflags} argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
     * @param     img   the image being observed
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3595
     * @param     infoflags   see {@code imageUpdate} for more information
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
     * @param     x   the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
     * @param     y   the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
     * @param     w   the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
     * @param     h   the height
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3600
     * @return    {@code false} if the infoflags indicate that the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3601
     *            image is completely loaded; {@code true} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
     * @see     java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
     * @see     Graphics#drawImage(Image, int, int, Color, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
     * @see     Graphics#drawImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
     * @see     Graphics#drawImage(Image, int, int, int, int, Color, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
     * @see     Graphics#drawImage(Image, int, int, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
     * @see     java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3609
     * @since   1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
    public boolean imageUpdate(Image img, int infoflags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
        int rate = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
        if ((infoflags & (FRAMEBITS|ALLBITS)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
            rate = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
        } else if ((infoflags & SOMEBITS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
            if (isInc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
                rate = incRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
                if (rate < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
                    rate = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
        if (rate >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
            repaint(rate, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
        return (infoflags & (ALLBITS|ABORT)) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
     * Creates an image from the specified image producer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
     * @param     producer  the image producer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
     * @return    the image produced
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3634
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
    public Image createImage(ImageProducer producer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
        if ((peer != null) && ! (peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
            return peer.createImage(producer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
        return getToolkit().createImage(producer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
    /**
33504
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3645
     * Creates an off-screen drawable image to be used for double buffering.
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3646
     *
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3647
     * @param  width the specified width
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3648
     * @param  height the specified height
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3649
     * @return an off-screen drawable image, which can be used for double
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3650
     *         buffering. The {@code null} value if the component is not
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3651
     *         displayable or {@code GraphicsEnvironment.isHeadless()} returns
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3652
     *         {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
     * @see GraphicsEnvironment#isHeadless
33504
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3655
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
    public Image createImage(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
            if (parent != null) { return parent.createImage(width, height); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
            else { return null;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
            return (peer != null) ? peer.createImage(width, height) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
    /**
33504
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3668
     * Creates a volatile off-screen drawable image to be used for double
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3669
     * buffering.
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3670
     *
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3671
     * @param  width the specified width
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3672
     * @param  height the specified height
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3673
     * @return an off-screen drawable image, which can be used for double
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3674
     *         buffering. The {@code null} value if the component is not
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3675
     *         displayable or {@code GraphicsEnvironment.isHeadless()} returns
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3676
     *         {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
     * @see java.awt.image.VolatileImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
     * @see GraphicsEnvironment#isHeadless
33504
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3680
     * @since 1.4
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
    public VolatileImage createVolatileImage(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
                return parent.createVolatileImage(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
            else { return null;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
            return (peer != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
                peer.createVolatileImage(width, height) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
    /**
33504
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3696
     * Creates a volatile off-screen drawable image, with the given
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3697
     * capabilities. The contents of this image may be lost at any time due to
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3698
     * operating system issues, so the image must be managed via the
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3699
     * {@code VolatileImage} interface.
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3700
     *
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3701
     * @param  width the specified width
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3702
     * @param  height the specified height
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3703
     * @param  caps the image capabilities
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3704
     * @return a VolatileImage object, which can be used to manage surface
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3705
     *         contents loss and capabilities. The {@code null} value if the
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3706
     *         component is not displayable or
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3707
     *         {@code GraphicsEnvironment.isHeadless()} returns {@code true}.
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3708
     * @throws AWTException if an image with the specified capabilities cannot
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3709
     *         be created
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
     * @see java.awt.image.VolatileImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
    public VolatileImage createVolatileImage(int width, int height,
33504
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3714
                                             ImageCapabilities caps)
f9cbfcddf862 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality
serb
parents: 33253
diff changeset
  3715
            throws AWTException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
        // REMIND : check caps
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
        return createVolatileImage(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
     * Prepares an image for rendering on this component.  The image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
     * data is downloaded asynchronously in another thread and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
     * appropriate screen representation of the image is generated.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3724
     * @param     image   the {@code Image} for which to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
     *                    prepare a screen representation
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3726
     * @param     observer   the {@code ImageObserver} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
     *                       to be notified as the image is being prepared
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3728
     * @return    {@code true} if the image has already been fully
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3729
     *           prepared; {@code false} otherwise
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3730
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
    public boolean prepareImage(Image image, ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
        return prepareImage(image, -1, -1, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
     * Prepares an image for rendering on this component at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
     * specified width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
     * The image data is downloaded asynchronously in another thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
     * and an appropriately scaled screen representation of the image is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
     * generated.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3743
     * @param     image    the instance of {@code Image}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
     *            for which to prepare a screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
     * @param     width    the width of the desired screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
     * @param     height   the height of the desired screen representation
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3747
     * @param     observer   the {@code ImageObserver} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
     *            to be notified as the image is being prepared
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3749
     * @return    {@code true} if the image has already been fully
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3750
     *          prepared; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
     * @see       java.awt.image.ImageObserver
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3752
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
    public boolean prepareImage(Image image, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
                                ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
            return (parent != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
                ? parent.prepareImage(image, width, height, observer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
                : getToolkit().prepareImage(image, width, height, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
            return (peer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
                ? peer.prepareImage(image, width, height, observer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
                : getToolkit().prepareImage(image, width, height, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
     * Returns the status of the construction of a screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
     * of the specified image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
     * This method does not cause the image to begin loading. An
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3773
     * application must use the {@code prepareImage} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
     * to force the loading of an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
     * Information on the flags returned by this method can be found
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3777
     * with the discussion of the {@code ImageObserver} interface.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3778
     * @param     image   the {@code Image} object whose status
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
     *            is being checked
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3780
     * @param     observer   the {@code ImageObserver}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
     *            object to be notified as the image is being prepared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
     * @return  the bitwise inclusive <b>OR</b> of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3783
     *            {@code ImageObserver} flags indicating what
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
     *            information about the image is currently available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
     * @see      #prepareImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
     * @see      Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
     * @see      java.awt.image.ImageObserver
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3788
     * @since    1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
    public int checkImage(Image image, ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
        return checkImage(image, -1, -1, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
     * Returns the status of the construction of a screen representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
     * of the specified image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
     * This method does not cause the image to begin loading. An
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3799
     * application must use the {@code prepareImage} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
     * to force the loading of an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3802
     * The {@code checkImage} method of {@code Component}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3803
     * calls its peer's {@code checkImage} method to calculate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
     * the flags. If this component does not yet have a peer, the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3805
     * component's toolkit's {@code checkImage} method is called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
     * Information on the flags returned by this method can be found
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3809
     * with the discussion of the {@code ImageObserver} interface.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3810
     * @param     image   the {@code Image} object whose status
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
     *                    is being checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
     * @param     width   the width of the scaled version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
     *                    whose status is to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
     * @param     height  the height of the scaled version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
     *                    whose status is to be checked
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3816
     * @param     observer   the {@code ImageObserver} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
     *                    to be notified as the image is being prepared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
     * @return    the bitwise inclusive <b>OR</b> of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3819
     *            {@code ImageObserver} flags indicating what
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
     *            information about the image is currently available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
     * @see      #prepareImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
     * @see      Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
     * @see      java.awt.image.ImageObserver
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  3824
     * @since    1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
    public int checkImage(Image image, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
                          ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
            return (parent != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
                ? parent.checkImage(image, width, height, observer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
                : getToolkit().checkImage(image, width, height, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
            return (peer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
                ? peer.checkImage(image, width, height, observer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
                : getToolkit().checkImage(image, width, height, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
     * Creates a new strategy for multi-buffering on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
     * Multi-buffering is useful for rendering performance.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
     * attempts to create the best strategy available with the number of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3844
     * buffers supplied.  It will always create a {@code BufferStrategy}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
     * with that number of buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
     * A page-flipping strategy is attempted first, then a blitting strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
     * using accelerated buffers.  Finally, an unaccelerated blitting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
     * strategy is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
     * Each time this method is called,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
     * the existing buffer strategy for this component is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
     * @param numBuffers number of buffers to create, including the front buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
     * @exception IllegalArgumentException if numBuffers is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
     * @exception IllegalStateException if the component is not displayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
     * @see Window#getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
     * @see Canvas#getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
    void createBufferStrategy(int numBuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
        BufferCapabilities bufferCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
        if (numBuffers > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
            // Try to create a page-flipping strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
            bufferCaps = new BufferCapabilities(new ImageCapabilities(true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
                                                new ImageCapabilities(true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
                                                BufferCapabilities.FlipContents.UNDEFINED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
                createBufferStrategy(numBuffers, bufferCaps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
                return; // Success
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
            } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
                // Failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
        // Try a blitting (but still accelerated) strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
        bufferCaps = new BufferCapabilities(new ImageCapabilities(true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
                                            new ImageCapabilities(true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
                                            null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
            createBufferStrategy(numBuffers, bufferCaps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
            return; // Success
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
        } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
            // Failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
        // Try an unaccelerated blitting strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
        bufferCaps = new BufferCapabilities(new ImageCapabilities(false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
                                            new ImageCapabilities(false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
                                            null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
            createBufferStrategy(numBuffers, bufferCaps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
            return; // Success
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
        } catch (AWTException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9658
diff changeset
  3892
            // Code should never reach here (an unaccelerated blitting
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9658
diff changeset
  3893
            // strategy should always work)
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9658
diff changeset
  3894
            throw new InternalError("Could not create a buffer strategy", e);
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9658
diff changeset
  3895
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
     * Creates a new strategy for multi-buffering on this component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
     * required buffer capabilities.  This is useful, for example, if only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
     * accelerated memory or page flipping is desired (as specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
     * buffer capabilities).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
     * Each time this method
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3905
     * is called, {@code dispose} will be invoked on the existing
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3906
     * {@code BufferStrategy}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
     * @param numBuffers number of buffers to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
     * @param caps the required capabilities for creating the buffer strategy;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3909
     * cannot be {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
     * @exception AWTException if the capabilities supplied could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
     * supported or met; this may happen, for example, if there is not enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
     * accelerated memory currently available, or if page flipping is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
     * but not possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
     * @exception IllegalArgumentException if numBuffers is less than 1, or if
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  3915
     * caps is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
     * @see Window#getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
     * @see Canvas#getBufferStrategy()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
    void createBufferStrategy(int numBuffers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
                              BufferCapabilities caps) throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
        // Check arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
        if (numBuffers < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
                "Number of buffers must be at least 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
        if (caps == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
            throw new IllegalArgumentException("No capabilities specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
        // Destroy old buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
        if (bufferStrategy != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
            bufferStrategy.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
        if (numBuffers == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
            bufferStrategy = new SingleBufferStrategy(caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
        } else {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3937
            SunGraphicsEnvironment sge = (SunGraphicsEnvironment)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3938
                GraphicsEnvironment.getLocalGraphicsEnvironment();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3939
            if (!caps.isPageFlipping() && sge.isFlipStrategyPreferred(peer)) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3940
                caps = new ProxyCapabilities(caps);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3941
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
            // assert numBuffers > 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
            if (caps.isPageFlipping()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
                bufferStrategy = new FlipSubRegionBufferStrategy(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
                bufferStrategy = new BltSubRegionBufferStrategy(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
    /**
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3952
     * This is a proxy capabilities class used when a FlipBufferStrategy
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3953
     * is created instead of the requested Blit strategy.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3954
     *
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  3955
     * @see sun.java2d.SunGraphicsEnvironment#isFlipStrategyPreferred(ComponentPeer)
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3956
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3957
    private class ProxyCapabilities extends ExtendedBufferCapabilities {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3958
        private BufferCapabilities orig;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3959
        private ProxyCapabilities(BufferCapabilities orig) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3960
            super(orig.getFrontBufferCapabilities(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3961
                  orig.getBackBufferCapabilities(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3962
                  orig.getFlipContents() ==
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3963
                      BufferCapabilities.FlipContents.BACKGROUND ?
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3964
                      BufferCapabilities.FlipContents.BACKGROUND :
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3965
                      BufferCapabilities.FlipContents.COPIED);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3966
            this.orig = orig;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3967
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3968
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3969
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  3970
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
     * @return the buffer strategy used by this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
     * @see Window#createBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
     * @see Canvas#createBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
    BufferStrategy getBufferStrategy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
        return bufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
     * @return the back buffer currently used by this component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
     * BufferStrategy.  If there is no BufferStrategy or no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
     * back buffer, this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
    Image getBackBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
        if (bufferStrategy != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
            if (bufferStrategy instanceof BltBufferStrategy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
                BltBufferStrategy bltBS = (BltBufferStrategy)bufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
                return bltBS.getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
            } else if (bufferStrategy instanceof FlipBufferStrategy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
                FlipBufferStrategy flipBS = (FlipBufferStrategy)bufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
                return flipBS.getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
     * Inner class for flipping buffers on a component.  That component must
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4000
     * be a {@code Canvas} or {@code Window} or {@code Applet}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
     * @see Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
     * @see Window
31897
7be531b4df44 8130390: Applet fails to launch on virtual desktop
ssadetsky
parents: 30947
diff changeset
  4003
     * @see Applet
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
     * @see java.awt.image.BufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
     * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
    protected class FlipBufferStrategy extends BufferStrategy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
         * The number of buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
        protected int numBuffers; // = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
         * The buffering capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
        protected BufferCapabilities caps; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
         * The drawing buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
        protected Image drawBuffer; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
         * The drawing buffer as a volatile image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
        protected VolatileImage drawVBuffer; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
         * Whether or not the drawing buffer has been recently restored from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
         * a lost state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
        protected boolean validatedContents; // = false
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4030
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
         * Size of the back buffers.  (Note: these fields were added in 6.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
         * but kept package-private to avoid exposing them in the spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
         * None of these fields/methods really should have been marked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
         * protected when they were introduced in 1.4, but now we just have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
         * to live with that decision.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
         */
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4038
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4039
         /**
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4040
          * The width of the back buffers
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4041
          */
55172
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4042
        private int width;
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4043
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4044
        /**
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4045
         * The height of the back buffers
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4046
         */
55172
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4047
        private int height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
         * Creates a new flipping buffer strategy for this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4051
         * The component must be a {@code Canvas} or {@code Window} or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4052
         * {@code Applet}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
         * @see Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
         * @see Window
31897
7be531b4df44 8130390: Applet fails to launch on virtual desktop
ssadetsky
parents: 30947
diff changeset
  4055
         * @see Applet
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
         * @param numBuffers the number of buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
         * @param caps the capabilities of the buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
         * @exception AWTException if the capabilities supplied could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
         * supported or met
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
         * @exception ClassCastException if the component is not a canvas or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
         * window.
8752
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  4062
         * @exception IllegalStateException if the component has no peer
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  4063
         * @exception IllegalArgumentException if {@code numBuffers} is less than two,
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  4064
         * or if {@code BufferCapabilities.isPageFlipping} is not
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  4065
         * {@code true}.
b8b7c54b0c7a 7023019: Constructor of class java.awt.Component.FlipBufferStrategy throws unspecified IAE
dav
parents: 7668
diff changeset
  4066
         * @see #createBuffers(int, BufferCapabilities)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
         */
42198
6ff366cc096b 8168316: Suppress deprecation warnings for Applet classes in java.desktop
prr
parents: 41805
diff changeset
  4068
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
        protected FlipBufferStrategy(int numBuffers, BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
            throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
            if (!(Component.this instanceof Window) &&
31897
7be531b4df44 8130390: Applet fails to launch on virtual desktop
ssadetsky
parents: 30947
diff changeset
  4073
                !(Component.this instanceof Canvas) &&
7be531b4df44 8130390: Applet fails to launch on virtual desktop
ssadetsky
parents: 30947
diff changeset
  4074
                !(Component.this instanceof Applet))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
                throw new ClassCastException(
31897
7be531b4df44 8130390: Applet fails to launch on virtual desktop
ssadetsky
parents: 30947
diff changeset
  4077
                        "Component must be a Canvas or Window or Applet");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
            this.numBuffers = numBuffers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
            this.caps = caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
            createBuffers(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
         * Creates one or more complex, flipping buffers with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
         * capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
         * @param numBuffers number of buffers to create; must be greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
         * one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
         * @param caps the capabilities of the buffers.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4090
         * {@code BufferCapabilities.isPageFlipping} must be
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4091
         * {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
         * @exception AWTException if the capabilities supplied could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
         * supported or met
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
         * @exception IllegalStateException if the component has no peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
         * @exception IllegalArgumentException if numBuffers is less than two,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4096
         * or if {@code BufferCapabilities.isPageFlipping} is not
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4097
         * {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
         * @see java.awt.BufferCapabilities#isPageFlipping()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
        protected void createBuffers(int numBuffers, BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
            throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
            if (numBuffers < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
                    "Number of buffers cannot be less than two");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
            } else if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
                    "Component must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
            } else if (caps == null || !caps.isPageFlipping()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
                    "Page flipping capabilities must be specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
            // save the current bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
            width = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
            height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4118
            if (drawBuffer != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
                // dispose the existing backbuffers
55172
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4120
                invalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
                // ... then recreate the backbuffers
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4122
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4123
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4124
            if (caps instanceof ExtendedBufferCapabilities) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4125
                ExtendedBufferCapabilities ebc =
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4126
                    (ExtendedBufferCapabilities)caps;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4127
                if (ebc.getVSync() == VSYNC_ON) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4128
                    // if this buffer strategy is not allowed to be v-synced,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4129
                    // change the caps that we pass to the peer but keep on
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4130
                    // trying to create v-synced buffers;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4131
                    // do not throw IAE here in case it is disallowed, see
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4132
                    // ExtendedBufferCapabilities for more info
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4133
                    if (!VSyncedBSManager.vsyncAllowed(this)) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4134
                        caps = ebc.derive(VSYNC_DEFAULT);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4135
                    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4136
                }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4137
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4138
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4139
            peer.createBuffers(numBuffers, caps);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
            updateInternalBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
         * Updates internal buffers (both volatile and non-volatile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
         * by requesting the back-buffer from the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
        private void updateInternalBuffers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
            // get the images associated with the draw buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
            drawBuffer = getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
            if (drawBuffer instanceof VolatileImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
                drawVBuffer = (VolatileImage)drawBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
                drawVBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
         * @return direct access to the back buffer, as an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
         * @exception IllegalStateException if the buffers have not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
         * been created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
        protected Image getBackBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
                return peer.getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
                    "Component must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
         * Flipping moves the contents of the back buffer to the front buffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
         * either by copying or by moving the video pointer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
         * @param flipAction an integer value describing the flipping action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
         * for the contents of the back buffer.  This should be one of the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4176
         * values of the {@code BufferCapabilities.FlipContents}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
         * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
         * @exception IllegalStateException if the buffers have not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
         * been created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
         * @see java.awt.BufferCapabilities#getFlipContents()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
        protected void flip(BufferCapabilities.FlipContents flipAction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
            if (peer != null) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4184
                Image backBuffer = getBackBuffer();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4185
                if (backBuffer != null) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4186
                    peer.flip(0, 0,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4187
                              backBuffer.getWidth(null),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4188
                              backBuffer.getHeight(null), flipAction);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4189
                }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4190
            } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4191
                throw new IllegalStateException(
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4192
                    "Component must have a valid peer");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4193
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4194
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4195
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4196
        void flipSubRegion(int x1, int y1, int x2, int y2,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4197
                      BufferCapabilities.FlipContents flipAction)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4198
        {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4199
            if (peer != null) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4200
                peer.flip(x1, y1, x2, y2, flipAction);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
                    "Component must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
        /**
55172
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4208
         * Destroys the buffers and invalidates the state of FlipBufferStrategy.
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4209
         */
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4210
        private void invalidate() {
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4211
            drawBuffer = null;
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4212
            drawVBuffer = null;
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4213
            destroyBuffers();
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4214
        }
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4215
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4216
        /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
         * Destroys the buffers created through this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
        protected void destroyBuffers() {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4220
            VSyncedBSManager.releaseVsync(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
                peer.destroyBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
                throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
                    "Component must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
         * @return the buffering capabilities of this strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
        public BufferCapabilities getCapabilities() {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4233
            if (caps instanceof ProxyCapabilities) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4234
                return ((ProxyCapabilities)caps).orig;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4235
            } else {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4236
                return caps;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4237
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
         * @return the graphics on the drawing buffer.  This method may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
         * be synchronized for performance reasons; use of this method by multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
         * threads should be handled at the application level.  Disposal of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
         * graphics object must be handled by the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
        public Graphics getDrawGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
            return drawBuffer.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
         * Restore the drawing buffer if it has been lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
        protected void revalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
            validatedContents = false;
55172
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4256
            if (getWidth() != width || getHeight() != height
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4257
                    || drawBuffer == null) {
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4258
                // component has been resized or the peer was recreated;
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4259
                // recreate the backbuffers
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
                    createBuffers(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
                } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
                    // shouldn't be possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
                validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
            // get the buffers from the peer every time since they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
            // might have been replaced in response to a display change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
            updateInternalBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
            // now validate the backbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
            if (drawVBuffer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
                GraphicsConfiguration gc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
                        getGraphicsConfiguration_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
                int returnCode = drawVBuffer.validate(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
                if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
                        createBuffers(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
                    } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
                        // shouldn't be possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
                    if (drawVBuffer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
                        // backbuffers were recreated, so validate again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
                        drawVBuffer.validate(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
                    validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
                } else if (returnCode == VolatileImage.IMAGE_RESTORED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
                    validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
         * @return whether the drawing buffer was lost since the last call to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4296
         * {@code getDrawGraphics}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
        public boolean contentsLost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
            if (drawVBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
            return drawVBuffer.contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
         * @return whether the drawing buffer was recently restored from a lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
         * state and reinitialized to the default background color (white)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
        public boolean contentsRestored() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
            return validatedContents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
         * Makes the next available buffer visible by either blitting or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
         * flipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
            flip(caps.getFlipContents());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
        /**
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 27502
diff changeset
  4322
         * Makes specified region of the next available buffer visible
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4323
         * by either blitting or flipping.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4324
         */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4325
        void showSubRegion(int x1, int y1, int x2, int y2) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4326
            flipSubRegion(x1, y1, x2, y2, caps.getFlipContents());
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4327
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4328
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4329
        /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
            if (Component.this.bufferStrategy == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
                Component.this.bufferStrategy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
                if (peer != null) {
55172
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  4337
                    invalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
    } // Inner class FlipBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
     * Inner class for blitting offscreen surfaces to a component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
     * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
    protected class BltBufferStrategy extends BufferStrategy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
         * The buffering capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
        protected BufferCapabilities caps; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
         * The back buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
        protected VolatileImage[] backBuffers; // = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
         * Whether or not the drawing buffer has been recently restored from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
         * a lost state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
        protected boolean validatedContents; // = false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
        /**
29886
545c0c3809b8 8075081: Fix missing doclint warnings in java.awt
darcy
parents: 28985
diff changeset
  4366
         * Width of the back buffers
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
        protected int width;
29886
545c0c3809b8 8075081: Fix missing doclint warnings in java.awt
darcy
parents: 28985
diff changeset
  4369
        /**
545c0c3809b8 8075081: Fix missing doclint warnings in java.awt
darcy
parents: 28985
diff changeset
  4370
         * Height of the back buffers
545c0c3809b8 8075081: Fix missing doclint warnings in java.awt
darcy
parents: 28985
diff changeset
  4371
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
        protected int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
         * Insets for the hosting Component.  The size of the back buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
         * is constrained by these.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
        private Insets insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
         * Creates a new blt buffer strategy around a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
         * @param numBuffers number of buffers to create, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
         * front buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
         * @param caps the capabilities of the buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
        protected BltBufferStrategy(int numBuffers, BufferCapabilities caps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
            this.caps = caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
            createBackBuffers(numBuffers - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
            if (backBuffers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
                for (int counter = backBuffers.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
                     counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
                    if (backBuffers[counter] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
                        backBuffers[counter].flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
                        backBuffers[counter] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
            if (Component.this.bufferStrategy == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
                Component.this.bufferStrategy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
         * Creates the back buffers
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4412
         *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4413
         * @param numBuffers the number of buffers to create
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
        protected void createBackBuffers(int numBuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
            if (numBuffers == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
                backBuffers = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
                // save the current bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
                width = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
                height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
                insets = getInsets_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
                int iWidth = width - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
                int iHeight = height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
                // It is possible for the component's width and/or height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
                // to be 0 here.  Force the size of the backbuffers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
                // be > 0 so that creating the image won't fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
                iWidth = Math.max(1, iWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
                iHeight = Math.max(1, iHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
                if (backBuffers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
                    backBuffers = new VolatileImage[numBuffers];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
                    // flush any existing backbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
                    for (int i = 0; i < numBuffers; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
                        if (backBuffers[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
                            backBuffers[i].flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
                            backBuffers[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
                // create the backbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
                for (int i = 0; i < numBuffers; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
                    backBuffers[i] = createVolatileImage(iWidth, iHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
         * @return the buffering capabilities of this strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
        public BufferCapabilities getCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
            return caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
         * @return the draw graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
        public Graphics getDrawGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
            Image backBuffer = getBackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
            if (backBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
                return getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
            SunGraphics2D g = (SunGraphics2D)backBuffer.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
            g.constrain(-insets.left, -insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
                        backBuffer.getWidth(null) + insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
                        backBuffer.getHeight(null) + insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
            return g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
         * @return direct access to the back buffer, as an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
         * If there is no back buffer, returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
        Image getBackBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
            if (backBuffers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
                return backBuffers[backBuffers.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
         * Makes the next available buffer visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
            showSubRegion(insets.left, insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
                          width - insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
                          height - insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
         * Package-private method to present a specific rectangular area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
         * of this buffer.  This class currently shows only the entire
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
         * buffer, by calling showSubRegion() with the full dimensions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
         * the buffer.  Subclasses (e.g., BltSubRegionBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
         * and FlipSubRegionBufferStrategy) may have region-specific show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
         * methods that call this method with actual sub regions of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
         * buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
        void showSubRegion(int x1, int y1, int x2, int y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
            if (backBuffers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
            // Adjust location to be relative to client area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
            x1 -= insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
            x2 -= insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
            y1 -= insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
            y2 -= insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
            Graphics g = getGraphics_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
            if (g == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
                // Not showing, bail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
                // First image copy is in terms of Frame's coordinates, need
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
                // to translate to client area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
                g.translate(insets.left, insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
                for (int i = 0; i < backBuffers.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
                    g.drawImage(backBuffers[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
                                x1, y1, x2, y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
                                x1, y1, x2, y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
                                null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
                    g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
                    g = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
                    g = backBuffers[i].getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
                if (g != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
                    g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
         * Restore the drawing buffer if it has been lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
        protected void revalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
            revalidate(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
        void revalidate(boolean checkSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
            validatedContents = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
            if (backBuffers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
            if (checkSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
                Insets insets = getInsets_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
                if (getWidth() != width || getHeight() != height ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
                    !insets.equals(this.insets)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
                    // component has been resized; recreate the backbuffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
                    createBackBuffers(backBuffers.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
                    validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
            // now validate the backbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
            GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
            int returnCode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
                backBuffers[backBuffers.length - 1].validate(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
            if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
                if (checkSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
                    createBackBuffers(backBuffers.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
                    // backbuffers were recreated, so validate again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
                    backBuffers[backBuffers.length - 1].validate(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
                // else case means we're called from Swing on the toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
                // thread, don't recreate buffers as that'll deadlock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
                // (creating VolatileImages invokes getting GraphicsConfig
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
                // which grabs treelock).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
                validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
            } else if (returnCode == VolatileImage.IMAGE_RESTORED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
                validatedContents = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
         * @return whether the drawing buffer was lost since the last call to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4583
         * {@code getDrawGraphics}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
        public boolean contentsLost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
            if (backBuffers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
                return backBuffers[backBuffers.length - 1].contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
         * @return whether the drawing buffer was recently restored from a lost
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
         * state and reinitialized to the default background color (white)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
        public boolean contentsRestored() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
            return validatedContents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
    } // Inner class BltBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
     * Private class to perform sub-region flipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
    private class FlipSubRegionBufferStrategy extends FlipBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
        implements SubRegionShowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
        protected FlipSubRegionBufferStrategy(int numBuffers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
                                              BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
            throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
            super(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
        public void show(int x1, int y1, int x2, int y2) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4617
            showSubRegion(x1, y1, x2, y2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
        // This is invoked by Swing on the toolkit thread.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4621
        public boolean showIfNotLost(int x1, int y1, int x2, int y2) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4622
            if (!contentsLost()) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4623
                showSubRegion(x1, y1, x2, y2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
                return !contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
     * Private class to perform sub-region blitting.  Swing will use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
     * this subclass via the SubRegionShowable interface in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
     * copy only the area changed during a repaint.
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  4634
     * See javax.swing.BufferStrategyPaintManager.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
    private class BltSubRegionBufferStrategy extends BltBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
        implements SubRegionShowable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
        protected BltSubRegionBufferStrategy(int numBuffers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
                                             BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
            super(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
        public void show(int x1, int y1, int x2, int y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
            showSubRegion(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
        // This method is called by Swing on the toolkit thread.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4651
        public boolean showIfNotLost(int x1, int y1, int x2, int y2) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 467
diff changeset
  4652
            if (!contentsLost()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
                showSubRegion(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
                return !contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
     * Inner class for flipping buffers on a component.  That component must
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4662
     * be a {@code Canvas} or {@code Window}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
     * @see Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
     * @see Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
     * @see java.awt.image.BufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
     * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
    private class SingleBufferStrategy extends BufferStrategy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
        private BufferCapabilities caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
        public SingleBufferStrategy(BufferCapabilities caps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
            this.caps = caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
        public BufferCapabilities getCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
            return caps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
        public Graphics getDrawGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
            return getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
        public boolean contentsLost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
        public boolean contentsRestored() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
        public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
            // Do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
    } // Inner class SingleBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
     * Sets whether or not paint messages received from the operating system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
     * should be ignored.  This does not affect paint events generated in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
     * software by the AWT, unless they are an immediate response to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
     * OS-level paint message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
     * This is useful, for example, if running under full-screen mode and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
     * better performance is desired, or if page-flipping is used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
     * buffer strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4703
     * @param ignoreRepaint {@code true} if the paint messages from the OS
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4704
     *                      should be ignored; otherwise {@code false}
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4705
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
     * @see #getIgnoreRepaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
     * @see Canvas#createBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
     * @see Window#createBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
     * @see java.awt.image.BufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
     * @see GraphicsDevice#setFullScreenWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
    public void setIgnoreRepaint(boolean ignoreRepaint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
        this.ignoreRepaint = ignoreRepaint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
     * @return whether or not paint messages received from the operating system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
     * should be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
     * @see #setIgnoreRepaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
    public boolean getIgnoreRepaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
        return ignoreRepaint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
     * Checks whether this component "contains" the specified point,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4730
     * where {@code x} and {@code y} are defined to be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
     * relative to the coordinate system of this component.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4732
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
     * @param     x   the <i>x</i> coordinate of the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
     * @param     y   the <i>y</i> coordinate of the point
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4735
     * @return {@code true} if the point is within the component;
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4736
     *         otherwise {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
     * @see       #getComponentAt(int, int)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  4738
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
    public boolean contains(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
        return inside(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4745
     * Checks whether the point is inside of this component.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4746
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4747
     * @param  x the <i>x</i> coordinate of the point
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4748
     * @param  y the <i>y</i> coordinate of the point
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4749
     * @return {@code true} if the point is within the component;
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4750
     *         otherwise {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
     * replaced by contains(int, int).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
    public boolean inside(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
        return (x >= 0) && (x < width) && (y >= 0) && (y < height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
     * Checks whether this component "contains" the specified point,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
     * where the point's <i>x</i> and <i>y</i> coordinates are defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
     * to be relative to the coordinate system of this component.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4763
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
     * @param     p     the point
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4765
     * @return {@code true} if the point is within the component;
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4766
     *         otherwise {@code false}
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  4767
     * @throws    NullPointerException if {@code p} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
     * @see       #getComponentAt(Point)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  4769
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
    public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
        return contains(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
     * Determines if this component or one of its immediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
     * subcomponents contains the (<i>x</i>,&nbsp;<i>y</i>) location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
     * and if so, returns the containing component. This method only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
     * looks one level deep. If the point (<i>x</i>,&nbsp;<i>y</i>) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
     * inside a subcomponent that itself has subcomponents, it does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
     * go looking down the subcomponent tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4783
     * The {@code locate} method of {@code Component} simply
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
     * returns the component itself if the (<i>x</i>,&nbsp;<i>y</i>)
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4785
     * coordinate location is inside its bounding box, and {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
     * @param     x   the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
     * @param     y   the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
     * @return    the component or subcomponent that contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
     *                (<i>x</i>,&nbsp;<i>y</i>) location;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4791
     *                {@code null} if the location
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
     *                is outside this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
     * @see       #contains(int, int)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  4794
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
    public Component getComponentAt(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
        return locate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4801
     * Returns the component occupying the position specified (this component,
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4802
     * or immediate child component, or null if neither
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4803
     * of the first two occupies the location).
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4804
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4805
     * @param  x the <i>x</i> coordinate to search for components at
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4806
     * @param  y the <i>y</i> coordinate to search for components at
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4807
     * @return the component at the specified location or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
     * replaced by getComponentAt(int, int).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
    public Component locate(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
        return contains(x, y) ? this : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
     * Returns the component or subcomponent that contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
     * specified point.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4819
     * @param  p the point
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4820
     * @return the component at the specified location or {@code null}
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4821
     * @see java.awt.Component#contains
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4822
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
    public Component getComponentAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
        return getComponentAt(p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  4829
     * @param  e the event to deliver
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
     * @deprecated As of JDK version 1.1,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4831
     * replaced by {@code dispatchEvent(AWTEvent e)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
    public void deliverEvent(Event e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
        postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
     * Dispatches an event to this component or one of its sub components.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4840
     * Calls {@code processEvent} before returning for 1.1-style
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  4841
     * events which have been enabled for the {@code Component}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4842
     * @param e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
    public final void dispatchEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
        dispatchEventImpl(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  4848
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
    void dispatchEventImpl(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
        // Check that this component belongs to this app-context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
        AppContext compContext = appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
        if (compContext != null && !compContext.equals(AppContext.getAppContext())) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  4855
            if (eventLog.isLoggable(PlatformLogger.Level.FINE)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4856
                eventLog.fine("Event " + e + " is being dispatched on the wrong AppContext");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4857
            }
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4858
        }
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4859
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  4860
        if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4861
            eventLog.finest("{0}", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
         * 0. Set timestamp and modifiers of current event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
         */
13652
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  4867
        if (!(e instanceof KeyEvent)) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  4868
            // Timestamp of a key event is set later in DKFM.preDispatchKeyEvent(KeyEvent).
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  4869
            EventQueue.setCurrentEventAndMostRecentTime(e);
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  4870
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
         * 1. Pre-dispatchers. Do any necessary retargeting/reordering here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
         *    before we notify AWTEventListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
        if (e instanceof SunDropTargetEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
            ((SunDropTargetEvent)e).dispatch();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
        if (!e.focusManagerIsDispatching) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
            // Invoke the private focus retargeting method which provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
            // lightweight Component support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
            if (e.isPosted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
                e = KeyboardFocusManager.retargetFocusEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
                e.isPosted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4890
            // Now, with the event properly targeted to a lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
            // descendant if necessary, invoke the public focus retargeting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
            // and dispatching function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
            if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
                dispatchEvent(e))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4896
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  4899
        if ((e instanceof FocusEvent) && focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4900
            focusLog.finest("" + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
        // MouseWheel may need to be retargeted here so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
        // AWTEventListener sees the event go to the correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
        // Component.  If the MouseWheelEvent needs to go to an ancestor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
        // the event is dispatched to the ancestor, and dispatching here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
        // stops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
        if (id == MouseEvent.MOUSE_WHEEL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
            (!eventTypeEnabled(id)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
            (peer != null && !peer.handlesWheelScrolling()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4910
            (dispatchMouseWheelToAncestor((MouseWheelEvent)e)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4911
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4912
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4915
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
         * 2. Allow the Toolkit to pass this to AWTEventListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
        Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
        toolkit.notifyAWTEventListeners(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
         * 3. If no one has consumed a key event, allow the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
         *    KeyboardFocusManager to process it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
        if (!e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
            if (e instanceof java.awt.event.KeyEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
                KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
                    processKeyEvent(this, (KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4930
                if (e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4931
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4932
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
         * 4. Allow input methods to process the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
        if (areInputMethodsEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
            // We need to pass on InputMethodEvents since some host
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
            // input method adapters send them through the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
            // event queue instead of directly to the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
            // and the input context also handles the Java composition window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
            if(((e instanceof InputMethodEvent) && !(this instanceof CompositionArea))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
               ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
               // Otherwise, we only pass on input and focus events, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
               // a) input methods shouldn't know about semantic or component-level events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
               // b) passing on the events takes time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
               // c) isConsumed() is always true for semantic events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
               (e instanceof InputEvent) || (e instanceof FocusEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4954
                if (inputContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4955
                    inputContext.dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4956
                    if (e.isConsumed()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  4957
                        if ((e instanceof FocusEvent) && focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4958
                            focusLog.finest("3579: Skipping " + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4964
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4965
            // When non-clients get focus, we need to explicitly disable the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4966
            // input method. The native input method is actually not disabled when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4967
            // the active/passive/peered clients loose focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4968
            if (id == FocusEvent.FOCUS_GAINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4969
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4970
                if (inputContext != null && inputContext instanceof sun.awt.im.InputContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
                    ((sun.awt.im.InputContext)inputContext).disableNativeIM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4978
         * 5. Pre-process any special events before delivery
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4979
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4980
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4981
            // Handling of the PAINT and UPDATE events is now done in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4982
            // peer's handleEvent() method so the background can be cleared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4983
            // selectively for non-native components on Windows only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4984
            // - Fred.Ecks@Eng.sun.com, 5-8-98
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4985
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
              Container p = (Container)((this instanceof Container) ? this : parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
              if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4990
                  p.preProcessKeyEvent((KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4991
                  if (e.isConsumed()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  4992
                        if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  4993
                            focusLog.finest("Pre-process consumed event");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5000
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5001
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5004
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5005
         * 6. Deliver event for normal processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5006
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5007
        if (newEventsOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5008
            // Filtering needs to really be moved to happen at a lower
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
            // level in order to get maximum performance gain;  it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
            // here temporarily to ensure the API spec is honored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5011
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5012
            if (eventEnabled(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5013
                processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
        } else if (id == MouseEvent.MOUSE_WHEEL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
            // newEventsOnly will be false for a listenerless ScrollPane, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5017
            // MouseWheelEvents still need to be dispatched to it so scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5018
            // can be done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5019
            autoProcessMouseWheel((MouseWheelEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5020
        } else if (!(e instanceof MouseEvent && !postsOldMouseEvents())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5021
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5022
            // backward compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5023
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5024
            Event olde = e.convertToOld();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
            if (olde != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5026
                int key = olde.key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
                int modifiers = olde.modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
                postEvent(olde);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
                if (olde.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
                    e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5032
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
                // if target changed key or modifier values, copy them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
                // back to original event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
                switch(olde.id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
                  case Event.KEY_PRESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
                  case Event.KEY_RELEASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
                  case Event.KEY_ACTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
                  case Event.KEY_ACTION_RELEASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
                      if (olde.key != key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
                          ((KeyEvent)e).setKeyChar(olde.getKeyEventChar());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
                      if (olde.modifiers != modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
                          ((KeyEvent)e).setModifiers(olde.modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
         * 9. Allow the peer to process the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
         * Except KeyEvents, they will be processed by peer after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
         * all KeyEventPostProcessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
         * (see DefaultKeyboardFocusManager.dispatchKeyEvent())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
        if (!(e instanceof KeyEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
            ComponentPeer tpeer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
            if (e instanceof FocusEvent && (tpeer == null || tpeer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5063
                // if focus owner is lightweight then its native container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5064
                // processes event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
                Component source = (Component)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5066
                if (source != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
                    Container target = source.getNativeContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5068
                    if (target != null) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  5069
                        tpeer = target.peer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
            if (tpeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
                tpeer.handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
        }
47384
3b244a98d5ab 8166772: Touch keyboard is not shown for text components on a screen touch
alitvinov
parents: 47216
diff changeset
  5077
3b244a98d5ab 8166772: Touch keyboard is not shown for text components on a screen touch
alitvinov
parents: 47216
diff changeset
  5078
        if (SunToolkit.isTouchKeyboardAutoShowEnabled() &&
3b244a98d5ab 8166772: Touch keyboard is not shown for text components on a screen touch
alitvinov
parents: 47216
diff changeset
  5079
            (toolkit instanceof SunToolkit) &&
3b244a98d5ab 8166772: Touch keyboard is not shown for text components on a screen touch
alitvinov
parents: 47216
diff changeset
  5080
            ((e instanceof MouseEvent) || (e instanceof FocusEvent))) {
3b244a98d5ab 8166772: Touch keyboard is not shown for text components on a screen touch
alitvinov
parents: 47216
diff changeset
  5081
            ((SunToolkit)toolkit).showOrHideTouchKeyboard(this, e);
3b244a98d5ab 8166772: Touch keyboard is not shown for text components on a screen touch
alitvinov
parents: 47216
diff changeset
  5082
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
    } // dispatchEventImpl()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
     * If newEventsOnly is false, method is called so that ScrollPane can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
     * override it and handle common-case mouse wheel scrolling.  NOP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
     * for Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
    void autoProcessMouseWheel(MouseWheelEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
     * Dispatch given MouseWheelEvent to the first ancestor for which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
     * MouseWheelEvents are enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
     * Returns whether or not event was dispatched to an ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
     */
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 42198
diff changeset
  5098
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5099
    boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
        int newX, newY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
        newX = e.getX() + getX(); // Coordinates take into account at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
        newY = e.getY() + getY(); // the cursor's position relative to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
                                  // Component (e.getX()), and this Component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
                                  // position relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
        MouseWheelEvent newMWE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  5107
        if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5108
            eventLog.finest("dispatchMouseWheelToAncestor");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5109
            eventLog.finest("orig event src is of " + e.getSource().getClass());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
        /* parent field for Window refers to the owning Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
         * MouseWheelEvents should NOT be propagated into owning Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5115
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5116
            Container anc = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
            while (anc != null && !anc.eventEnabled(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5118
                // fix coordinates to be relative to new event source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5119
                newX += anc.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5120
                newY += anc.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5122
                if (!(anc instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
                    anc = anc.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  5130
            if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5131
                eventLog.finest("new event src is " + anc.getClass());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5134
            if (anc != null && anc.eventEnabled(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5135
                // Change event to be from new source, with new x,y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5136
                // For now, just create a new event - yucky
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
                newMWE = new MouseWheelEvent(anc, // new source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
                                             e.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
                                             e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
                                             e.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
                                             newX, // x relative to new source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
                                             newY, // y relative to new source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
                                             e.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
                                             e.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
                                             e.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
                                             e.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
                                             e.getScrollType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
                                             e.getScrollAmount(),
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 119
diff changeset
  5150
                                             e.getWheelRotation(),
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 119
diff changeset
  5151
                                             e.getPreciseWheelRotation());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
                ((AWTEvent)e).copyPrivateDataInto(newMWE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
                // When dispatching a wheel event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5154
                // ancestor, there is no need trying to find descendant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5155
                // lightweights to dispatch event to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5156
                // If we dispatch the event to toplevel ancestor,
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  5157
                // this could enclose the loop: 6480024.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
                anc.dispatchEventToSelf(newMWE);
5277
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5159
                if (newMWE.isConsumed()) {
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5160
                    e.consume();
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5161
                }
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5162
                return true;
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5163
            }
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5164
        }
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 4371
diff changeset
  5165
        return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
    boolean areInputMethodsEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
        // in 1.2, we assume input method support is required for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
        // components that handle key events, but components can turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
        // input methods by calling enableInputMethods(false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
        return ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
            ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || keyListener != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
    // REMIND: remove when filtering is handled at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5178
        return eventTypeEnabled(e.id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
    boolean eventTypeEnabled(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
        switch(type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
          case ComponentEvent.COMPONENT_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
          case ComponentEvent.COMPONENT_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
          case ComponentEvent.COMPONENT_SHOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
          case ComponentEvent.COMPONENT_HIDDEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
              if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
                  componentListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
          case FocusEvent.FOCUS_GAINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
          case FocusEvent.FOCUS_LOST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
              if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
                  focusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5201
          case KeyEvent.KEY_TYPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
              if ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
                  keyListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5205
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5206
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5207
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5208
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5209
          case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5210
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5211
          case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5212
              if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5213
                  mouseListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5214
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5215
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5216
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5217
          case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5218
          case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5219
              if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5220
                  mouseMotionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5221
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5222
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5223
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
          case MouseEvent.MOUSE_WHEEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5225
              if ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5226
                  mouseWheelListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
          case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
          case InputMethodEvent.CARET_POSITION_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
              if ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
                  inputMethodListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
          case HierarchyEvent.HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
              if ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
                  hierarchyListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
          case HierarchyEvent.ANCESTOR_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
          case HierarchyEvent.ANCESTOR_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5245
              if ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5246
                  hierarchyBoundsListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5247
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5248
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5249
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5250
          case ActionEvent.ACTION_PERFORMED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5251
              if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5252
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5253
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5254
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5255
          case TextEvent.TEXT_VALUE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5256
              if ((eventMask & AWTEvent.TEXT_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5257
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5258
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5259
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5260
          case ItemEvent.ITEM_STATE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5261
              if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5262
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5263
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5264
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5265
          case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5266
              if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5267
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5268
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5269
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5270
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5271
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5273
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5274
        // Always pass on events defined by external programs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5275
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5276
        if (type > AWTEvent.RESERVED_ID_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5277
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5279
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5283
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5284
     * replaced by dispatchEvent(AWTEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5286
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5287
    public boolean postEvent(Event e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5288
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5290
        if (handleEvent(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5291
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5292
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5295
        Component parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5296
        int eventx = e.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5297
        int eventy = e.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5298
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5299
            e.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5300
            if (parent.postEvent(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5301
                e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5302
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5304
            // restore coords
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5305
            e.x = eventx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5306
            e.y = eventy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5308
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5311
    // Event source interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5314
     * Adds the specified component listener to receive component events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5315
     * this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5316
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5317
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5318
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5319
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5321
     * @param    l   the component listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5322
     * @see      java.awt.event.ComponentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5323
     * @see      java.awt.event.ComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5324
     * @see      #removeComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5325
     * @see      #getComponentListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5326
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5328
    public synchronized void addComponentListener(ComponentListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5329
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5330
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5332
        componentListener = AWTEventMulticaster.add(componentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5333
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5337
     * Removes the specified component listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5338
     * receives component events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5339
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5340
     * specified by the argument was not previously added to this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5341
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5342
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5343
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5344
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5345
     * @param    l   the component listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5346
     * @see      java.awt.event.ComponentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5347
     * @see      java.awt.event.ComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5348
     * @see      #addComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5349
     * @see      #getComponentListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5350
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5352
    public synchronized void removeComponentListener(ComponentListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5353
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5354
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5356
        componentListener = AWTEventMulticaster.remove(componentListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5360
     * Returns an array of all the component listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5361
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5362
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5363
     * @return all {@code ComponentListener}s of this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5364
     *         or an empty array if no component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5365
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5367
     * @see #addComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5368
     * @see #removeComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5369
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5371
    public synchronized ComponentListener[] getComponentListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5372
        return getListeners(ComponentListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5376
     * Adds the specified focus listener to receive focus events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5377
     * this component when this component gains input focus.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5378
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5379
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5380
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5381
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5383
     * @param    l   the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5384
     * @see      java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5385
     * @see      java.awt.event.FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5386
     * @see      #removeFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5387
     * @see      #getFocusListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5388
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5390
    public synchronized void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5391
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5392
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5394
        focusListener = AWTEventMulticaster.add(focusListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5395
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5397
        // if this is a lightweight component, enable focus events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5398
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5399
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5400
            parent.proxyEnableEvents(AWTEvent.FOCUS_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5405
     * Removes the specified focus listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5406
     * receives focus events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5407
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5408
     * specified by the argument was not previously added to this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5409
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5410
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5411
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5412
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5414
     * @param    l   the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5415
     * @see      java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5416
     * @see      java.awt.event.FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5417
     * @see      #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5418
     * @see      #getFocusListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5419
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5421
    public synchronized void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5422
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5423
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5425
        focusListener = AWTEventMulticaster.remove(focusListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5429
     * Returns an array of all the focus listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5430
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5431
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5432
     * @return all of this component's {@code FocusListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5433
     *         or an empty array if no component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5434
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5436
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5437
     * @see #removeFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5438
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5440
    public synchronized FocusListener[] getFocusListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5441
        return getListeners(FocusListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5445
     * Adds the specified hierarchy listener to receive hierarchy changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5446
     * events from this component when the hierarchy to which this container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5447
     * belongs changes.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5448
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5449
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5450
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5451
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5453
     * @param    l   the hierarchy listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5454
     * @see      java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5455
     * @see      java.awt.event.HierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5456
     * @see      #removeHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5457
     * @see      #getHierarchyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5458
     * @since    1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5460
    public void addHierarchyListener(HierarchyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5461
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5462
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5464
        boolean notifyAncestors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5465
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5466
            notifyAncestors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5467
                (hierarchyListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5468
                 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5469
            hierarchyListener = AWTEventMulticaster.add(hierarchyListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5470
            notifyAncestors = (notifyAncestors && hierarchyListener != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5471
            newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5473
        if (notifyAncestors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5474
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5475
                adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5476
                                                1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5482
     * Removes the specified hierarchy listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5483
     * receives hierarchy changed events from this component. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5484
     * performs no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5485
     * specified by the argument was not previously added to this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5486
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5487
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5488
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5489
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5491
     * @param    l   the hierarchy listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5492
     * @see      java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5493
     * @see      java.awt.event.HierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5494
     * @see      #addHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5495
     * @see      #getHierarchyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5496
     * @since    1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5498
    public void removeHierarchyListener(HierarchyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5499
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5500
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5502
        boolean notifyAncestors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5503
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5504
            notifyAncestors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5505
                (hierarchyListener != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5506
                 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5507
            hierarchyListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5508
                AWTEventMulticaster.remove(hierarchyListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5509
            notifyAncestors = (notifyAncestors && hierarchyListener == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5511
        if (notifyAncestors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5512
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5513
                adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5514
                                                -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5520
     * Returns an array of all the hierarchy listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5521
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5522
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5523
     * @return all of this component's {@code HierarchyListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5524
     *         or an empty array if no hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5525
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5527
     * @see      #addHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5528
     * @see      #removeHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5529
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5531
    public synchronized HierarchyListener[] getHierarchyListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5532
        return getListeners(HierarchyListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5536
     * Adds the specified hierarchy bounds listener to receive hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5537
     * bounds events from this component when the hierarchy to which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5538
     * container belongs changes.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5539
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5540
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5541
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5542
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5544
     * @param    l   the hierarchy bounds listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5545
     * @see      java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5546
     * @see      java.awt.event.HierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5547
     * @see      #removeHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5548
     * @see      #getHierarchyBoundsListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5549
     * @since    1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5551
    public void addHierarchyBoundsListener(HierarchyBoundsListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5552
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5553
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5555
        boolean notifyAncestors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5556
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5557
            notifyAncestors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5558
                (hierarchyBoundsListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5559
                 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5560
            hierarchyBoundsListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5561
                AWTEventMulticaster.add(hierarchyBoundsListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5562
            notifyAncestors = (notifyAncestors &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5563
                               hierarchyBoundsListener != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5564
            newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5566
        if (notifyAncestors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5567
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5568
                adjustListeningChildrenOnParent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5569
                                                AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5575
     * Removes the specified hierarchy bounds listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5576
     * receives hierarchy bounds events from this component. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5577
     * performs no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5578
     * specified by the argument was not previously added to this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5579
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5580
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5581
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5582
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5584
     * @param    l   the hierarchy bounds listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5585
     * @see      java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5586
     * @see      java.awt.event.HierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5587
     * @see      #addHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5588
     * @see      #getHierarchyBoundsListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5589
     * @since    1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5591
    public void removeHierarchyBoundsListener(HierarchyBoundsListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5592
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5593
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5595
        boolean notifyAncestors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5596
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5597
            notifyAncestors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5598
                (hierarchyBoundsListener != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5599
                 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5600
            hierarchyBoundsListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5601
                AWTEventMulticaster.remove(hierarchyBoundsListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5602
            notifyAncestors = (notifyAncestors &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5603
                               hierarchyBoundsListener == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5605
        if (notifyAncestors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5606
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5607
                adjustListeningChildrenOnParent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5608
                                                AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5613
    // Should only be called while holding the tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5614
    int numListening(long mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5615
        // One mask or the other, but not neither or both.
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  5616
        if (eventLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5617
            if ((mask != AWTEvent.HIERARCHY_EVENT_MASK) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5618
                (mask != AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5619
            {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5620
                eventLog.fine("Assertion failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5623
        if ((mask == AWTEvent.HIERARCHY_EVENT_MASK &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5624
             (hierarchyListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5625
              (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5626
            (mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5627
             (hierarchyBoundsListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5628
              (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5629
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5630
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5631
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5635
    // Should only be called while holding tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5636
    int countHierarchyMembers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5637
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5639
    // Should only be called while holding the tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5640
    int createHierarchyEvents(int id, Component changed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5641
                              Container changedParent, long changeFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5642
                              boolean enabledOnToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5643
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5644
          case HierarchyEvent.HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5645
              if (hierarchyListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5646
                  (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5647
                  enabledOnToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5648
                  HierarchyEvent e = new HierarchyEvent(this, id, changed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5649
                                                        changedParent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5650
                                                        changeFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5651
                  dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5652
                  return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5653
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5654
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5655
          case HierarchyEvent.ANCESTOR_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5656
          case HierarchyEvent.ANCESTOR_RESIZED:
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  5657
              if (eventLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5658
                  if (changeFlags != 0) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5659
                      eventLog.fine("Assertion (changeFlags == 0) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5660
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5661
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5662
              if (hierarchyBoundsListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5663
                  (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5664
                  enabledOnToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5665
                  HierarchyEvent e = new HierarchyEvent(this, id, changed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5666
                                                        changedParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5667
                  dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5668
                  return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5669
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5670
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5671
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5672
              // assert false
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  5673
              if (eventLog.isLoggable(PlatformLogger.Level.FINE)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  5674
                  eventLog.fine("This code must never be reached");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5675
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5676
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5678
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5681
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5682
     * Returns an array of all the hierarchy bounds listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5683
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5684
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5685
     * @return all of this component's {@code HierarchyBoundsListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5686
     *         or an empty array if no hierarchy bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5687
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5688
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5689
     * @see      #addHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5690
     * @see      #removeHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5691
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5692
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5693
    public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5694
        return getListeners(HierarchyBoundsListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5697
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5698
     * Should only be called while holding the tree lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5699
     * It's added only for overriding in java.awt.Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5700
     * because parent in Window is owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5702
    void adjustListeningChildrenOnParent(long mask, int num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5703
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5704
            parent.adjustListeningChildren(mask, num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5709
     * Adds the specified key listener to receive key events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5710
     * this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5711
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5712
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5713
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5715
     * @param    l   the key listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5716
     * @see      java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5717
     * @see      java.awt.event.KeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5718
     * @see      #removeKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5719
     * @see      #getKeyListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5720
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5721
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5722
    public synchronized void addKeyListener(KeyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5723
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5724
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5726
        keyListener = AWTEventMulticaster.add(keyListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5727
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5729
        // if this is a lightweight component, enable key events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5730
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5731
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5732
            parent.proxyEnableEvents(AWTEvent.KEY_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5737
     * Removes the specified key listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5738
     * receives key events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5739
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5740
     * specified by the argument was not previously added to this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5741
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5742
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5743
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5744
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5745
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5746
     * @param    l   the key listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5747
     * @see      java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5748
     * @see      java.awt.event.KeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5749
     * @see      #addKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5750
     * @see      #getKeyListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5751
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5752
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5753
    public synchronized void removeKeyListener(KeyListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5754
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5755
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5757
        keyListener = AWTEventMulticaster.remove(keyListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5760
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5761
     * Returns an array of all the key listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5762
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5763
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5764
     * @return all of this component's {@code KeyListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5765
     *         or an empty array if no key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5766
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5767
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5768
     * @see      #addKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5769
     * @see      #removeKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5770
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5771
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5772
    public synchronized KeyListener[] getKeyListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5773
        return getListeners(KeyListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5777
     * Adds the specified mouse listener to receive mouse events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5778
     * this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5779
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5780
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5781
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5782
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5784
     * @param    l   the mouse listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5785
     * @see      java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5786
     * @see      java.awt.event.MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5787
     * @see      #removeMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5788
     * @see      #getMouseListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5789
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5790
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5791
    public synchronized void addMouseListener(MouseListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5792
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5793
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5795
        mouseListener = AWTEventMulticaster.add(mouseListener,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5796
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5798
        // if this is a lightweight component, enable mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5799
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5800
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5801
            parent.proxyEnableEvents(AWTEvent.MOUSE_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5805
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5806
     * Removes the specified mouse listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5807
     * receives mouse events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5808
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5809
     * specified by the argument was not previously added to this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5810
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5811
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5812
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5813
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5814
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5815
     * @param    l   the mouse listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5816
     * @see      java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5817
     * @see      java.awt.event.MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5818
     * @see      #addMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5819
     * @see      #getMouseListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5820
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5821
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5822
    public synchronized void removeMouseListener(MouseListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5823
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5824
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5826
        mouseListener = AWTEventMulticaster.remove(mouseListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5829
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5830
     * Returns an array of all the mouse listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5831
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5832
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5833
     * @return all of this component's {@code MouseListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5834
     *         or an empty array if no mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5835
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5836
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5837
     * @see      #addMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5838
     * @see      #removeMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5839
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5840
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5841
    public synchronized MouseListener[] getMouseListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5842
        return getListeners(MouseListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5845
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5846
     * Adds the specified mouse motion listener to receive mouse motion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5847
     * events from this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5848
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5849
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5850
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5851
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5852
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5853
     * @param    l   the mouse motion listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5854
     * @see      java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5855
     * @see      java.awt.event.MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5856
     * @see      #removeMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5857
     * @see      #getMouseMotionListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5858
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5860
    public synchronized void addMouseMotionListener(MouseMotionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5861
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5862
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5864
        mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5865
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5867
        // if this is a lightweight component, enable mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5868
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5869
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5870
            parent.proxyEnableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5873
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5874
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5875
     * Removes the specified mouse motion listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5876
     * receives mouse motion events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5877
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5878
     * specified by the argument was not previously added to this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5879
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5880
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5881
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5882
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5883
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5884
     * @param    l   the mouse motion listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5885
     * @see      java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5886
     * @see      java.awt.event.MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5887
     * @see      #addMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5888
     * @see      #getMouseMotionListeners
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  5889
     * @since    1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5890
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5891
    public synchronized void removeMouseMotionListener(MouseMotionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5892
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5893
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5895
        mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5897
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5898
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5899
     * Returns an array of all the mouse motion listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5900
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5901
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5902
     * @return all of this component's {@code MouseMotionListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5903
     *         or an empty array if no mouse motion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5904
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5905
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5906
     * @see      #addMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5907
     * @see      #removeMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5908
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5909
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5910
    public synchronized MouseMotionListener[] getMouseMotionListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5911
        return getListeners(MouseMotionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5915
     * Adds the specified mouse wheel listener to receive mouse wheel events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5916
     * from this component.  Containers also receive mouse wheel events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5917
     * sub-components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5918
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5919
     * For information on how mouse wheel events are dispatched, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5920
     * the class description for {@link MouseWheelEvent}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5921
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5922
     * If l is {@code null}, no exception is thrown and no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5923
     * action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5924
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5925
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5926
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5927
     * @param    l   the mouse wheel listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5928
     * @see      java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5929
     * @see      java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5930
     * @see      #removeMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5931
     * @see      #getMouseWheelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5932
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5933
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5934
    public synchronized void addMouseWheelListener(MouseWheelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5935
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5936
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5938
        mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener,l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5939
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5940
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5941
        // if this is a lightweight component, enable mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5942
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5943
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5944
            parent.proxyEnableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5948
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5949
     * Removes the specified mouse wheel listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5950
     * receives mouse wheel events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5951
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5952
     * specified by the argument was not previously added to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5953
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5954
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5955
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5956
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5957
     * @param    l   the mouse wheel listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5958
     * @see      java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5959
     * @see      java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5960
     * @see      #addMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5961
     * @see      #getMouseWheelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5962
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5963
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5964
    public synchronized void removeMouseWheelListener(MouseWheelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5965
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5966
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5968
        mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5971
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5972
     * Returns an array of all the mouse wheel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5973
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5974
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5975
     * @return all of this component's {@code MouseWheelListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5976
     *         or an empty array if no mouse wheel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5977
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5979
     * @see      #addMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5980
     * @see      #removeMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5981
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5982
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5983
    public synchronized MouseWheelListener[] getMouseWheelListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  5984
        return getListeners(MouseWheelListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5987
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5988
     * Adds the specified input method listener to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5989
     * input method events from this component. A component will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5990
     * only receive input method events from input methods
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5991
     * if it also overrides {@code getInputMethodRequests} to return an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5992
     * {@code InputMethodRequests} instance.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  5993
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5994
     * no exception is thrown and no action is performed.
51010
29be48779807 8201611: Broken links in java.desktop javadoc
serb
parents: 50917
diff changeset
  5995
     * <p>Refer to
29be48779807 8201611: Broken links in java.desktop javadoc
serb
parents: 50917
diff changeset
  5996
     * <a href="{@docRoot}/java.desktop/java/awt/doc-files/AWTThreadIssues.html#ListenersThreads"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5997
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5998
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5999
     * @param    l   the input method listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6000
     * @see      java.awt.event.InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6001
     * @see      java.awt.event.InputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6002
     * @see      #removeInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6003
     * @see      #getInputMethodListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6004
     * @see      #getInputMethodRequests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6005
     * @since    1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6006
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6007
    public synchronized void addInputMethodListener(InputMethodListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6008
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6009
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6010
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6011
        inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6012
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6015
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6016
     * Removes the specified input method listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6017
     * receives input method events from this component. This method performs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6018
     * no function, nor does it throw an exception, if the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6019
     * specified by the argument was not previously added to this component.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6020
     * If listener {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6021
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6022
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6023
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6024
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6025
     * @param    l   the input method listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6026
     * @see      java.awt.event.InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6027
     * @see      java.awt.event.InputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6028
     * @see      #addInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6029
     * @see      #getInputMethodListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6030
     * @since    1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6031
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6032
    public synchronized void removeInputMethodListener(InputMethodListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6033
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6034
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6035
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6036
        inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6039
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6040
     * Returns an array of all the input method listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6041
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6042
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6043
     * @return all of this component's {@code InputMethodListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6044
     *         or an empty array if no input method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6045
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6046
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6047
     * @see      #addInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6048
     * @see      #removeInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6049
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6050
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6051
    public synchronized InputMethodListener[] getInputMethodListeners() {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  6052
        return getListeners(InputMethodListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6055
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6056
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6057
     * as <code><em>Foo</em>Listener</code>s
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6058
     * upon this {@code Component}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6059
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6060
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6061
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6062
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6063
     * You can specify the {@code listenerType} argument
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6064
     * with a class literal, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6065
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6066
     * For example, you can query a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6067
     * {@code Component c}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6068
     * for its mouse listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6069
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6070
     * <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6071
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6072
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6073
     *
29886
545c0c3809b8 8075081: Fix missing doclint warnings in java.awt
darcy
parents: 28985
diff changeset
  6074
     * @param <T> the type of the listeners
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6075
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6076
     *          should specify an interface that descends from
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6077
     *          {@code java.util.EventListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6078
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6079
     *          <code><em>Foo</em>Listener</code>s on this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6080
     *          or an empty array if no such listeners have been added
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6081
     * @exception ClassCastException if {@code listenerType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6082
     *          doesn't specify a class or interface that implements
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6083
     *          {@code java.util.EventListener}
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  6084
     * @throws NullPointerException if {@code listenerType} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6085
     * @see #getComponentListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6086
     * @see #getFocusListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6087
     * @see #getHierarchyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6088
     * @see #getHierarchyBoundsListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6089
     * @see #getKeyListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6090
     * @see #getMouseListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6091
     * @see #getMouseMotionListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6092
     * @see #getMouseWheelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6093
     * @see #getInputMethodListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6094
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6095
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6096
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6097
     */
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  6098
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6099
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6100
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6101
        if  (listenerType == ComponentListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6102
            l = componentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6103
        } else if (listenerType == FocusListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6104
            l = focusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6105
        } else if (listenerType == HierarchyListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6106
            l = hierarchyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6107
        } else if (listenerType == HierarchyBoundsListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6108
            l = hierarchyBoundsListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6109
        } else if (listenerType == KeyListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6110
            l = keyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6111
        } else if (listenerType == MouseListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6112
            l = mouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6113
        } else if (listenerType == MouseMotionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6114
            l = mouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6115
        } else if (listenerType == MouseWheelListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6116
            l = mouseWheelListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6117
        } else if (listenerType == InputMethodListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6118
            l = inputMethodListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6119
        } else if (listenerType == PropertyChangeListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6120
            return (T[])getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6122
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6126
     * Gets the input method request handler which supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6127
     * requests from input methods for this component. A component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6128
     * that supports on-the-spot text input must override this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6129
     * method to return an {@code InputMethodRequests} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6130
     * At the same time, it also has to handle input method events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6132
     * @return the input method request handler for this component,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6133
     *          {@code null} by default
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6134
     * @see #addInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6135
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6137
    public InputMethodRequests getInputMethodRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6138
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6142
     * Gets the input context used by this component for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6143
     * the communication with input methods when text is entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6144
     * in this component. By default, the input context used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6145
     * the parent component is returned. Components may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6146
     * override this to return a private input context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6148
     * @return the input context used by this component;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6149
     *          {@code null} if no context can be determined
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6150
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6152
    public InputContext getInputContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6153
        Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6154
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6155
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6156
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6157
            return parent.getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6162
     * Enables the events defined by the specified event mask parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6163
     * to be delivered to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6164
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6165
     * Event types are automatically enabled when a listener for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6166
     * that event type is added to the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6167
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6168
     * This method only needs to be invoked by subclasses of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6169
     * {@code Component} which desire to have the specified event
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6170
     * types delivered to {@code processEvent} regardless of whether
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6171
     * or not a listener is registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6172
     * @param      eventsToEnable   the event mask defining the event types
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6173
     * @see        #processEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6174
     * @see        #disableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6175
     * @see        AWTEvent
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  6176
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6178
    protected final void enableEvents(long eventsToEnable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6179
        long notifyAncestors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6180
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6181
            if ((eventsToEnable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6182
                hierarchyListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6183
                (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6184
                notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6186
            if ((eventsToEnable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6187
                hierarchyBoundsListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6188
                (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6189
                notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6191
            eventMask |= eventsToEnable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6192
            newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6195
        // if this is a lightweight component, enable mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6196
        // in the native container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6197
        if (peer instanceof LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6198
            parent.proxyEnableEvents(eventMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6200
        if (notifyAncestors != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6201
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6202
                adjustListeningChildrenOnParent(notifyAncestors, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6208
     * Disables the events defined by the specified event mask parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6209
     * from being delivered to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6210
     * @param      eventsToDisable   the event mask defining the event types
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6211
     * @see        #enableEvents
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  6212
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6214
    protected final void disableEvents(long eventsToDisable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6215
        long notifyAncestors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6216
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6217
            if ((eventsToDisable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6218
                hierarchyListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6219
                (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6220
                notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6222
            if ((eventsToDisable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)!=0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6223
                hierarchyBoundsListener == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6224
                (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6225
                notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6227
            eventMask &= ~eventsToDisable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6229
        if (notifyAncestors != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6230
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6231
                adjustListeningChildrenOnParent(notifyAncestors, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6235
1181
c5971dbeaaaa 6693974: Unify EventQueue$EventQueueItem and SunToolkit.$EventQueueItem classes
dav
parents: 1172
diff changeset
  6236
    transient sun.awt.EventQueueItem[] eventCache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6239
     * @see #isCoalescingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6240
     * @see #checkCoalescing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6241
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
  6242
    private transient boolean coalescingEnabled = checkCoalescing();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6245
     * Weak map of known coalesceEvent overriders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6246
     * Value indicates whether overriden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6247
     * Bootstrap classes are not included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6249
    private static final Map<Class<?>, Boolean> coalesceMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6250
        new java.util.WeakHashMap<Class<?>, Boolean>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6253
     * Indicates whether this class overrides coalesceEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6254
     * It is assumed that all classes that are loaded from the bootstrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6255
     *   do not.
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  6256
     * The bootstrap class loader is assumed to be represented by null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6257
     * We do not check that the method really overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6258
     *   (it might be static, private or package private).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6260
     private boolean checkCoalescing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6261
         if (getClass().getClassLoader()==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6262
             return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6263
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6264
         final Class<? extends Component> clazz = getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6265
         synchronized (coalesceMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6266
             // Check cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6267
             Boolean value = coalesceMap.get(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6268
             if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6269
                 return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6270
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6272
             // Need to check non-bootstraps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6273
             Boolean enabled = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6274
                 new java.security.PrivilegedAction<Boolean>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6275
                     public Boolean run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6276
                         return isCoalesceEventsOverriden(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6277
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6278
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6279
                 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6280
             coalesceMap.put(clazz, enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6281
             return enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6282
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6283
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6286
     * Parameter types of coalesceEvents(AWTEvent,AWTEVent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6287
     */
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23299
diff changeset
  6288
    private static final Class<?>[] coalesceEventsParams = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6289
        AWTEvent.class, AWTEvent.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6290
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6293
     * Indicates whether a class or its superclasses override coalesceEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6294
     * Must be called with lock on coalesceMap and privileged.
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43724
diff changeset
  6295
     * @see #checkCoalescing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6297
    private static boolean isCoalesceEventsOverriden(Class<?> clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6298
        assert Thread.holdsLock(coalesceMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6300
        // First check superclass - we may not need to bother ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6301
        Class<?> superclass = clazz.getSuperclass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6302
        if (superclass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6303
            // Only occurs on implementations that
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  6304
            //   do not use null to represent the bootstrap class loader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6305
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6307
        if (superclass.getClassLoader() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6308
            Boolean value = coalesceMap.get(superclass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6309
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6310
                // Not done already - recurse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6311
                if (isCoalesceEventsOverriden(superclass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6312
                    coalesceMap.put(superclass, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6313
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6315
            } else if (value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6316
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6320
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6321
            // Throws if not overriden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6322
            clazz.getDeclaredMethod(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6323
                "coalesceEvents", coalesceEventsParams
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6324
                );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6325
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6326
        } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6327
            // Not present in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6328
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6333
     * Indicates whether coalesceEvents may do something.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6335
    final boolean isCoalescingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6336
        return coalescingEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6337
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6341
     * Potentially coalesce an event being posted with an existing
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6342
     * event.  This method is called by {@code EventQueue.postEvent}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6343
     * if an event with the same ID as the event to be posted is found in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6344
     * the queue (both events must have this component as their source).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6345
     * This method either returns a coalesced event which replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6346
     * the existing event (and the new event is then discarded), or
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6347
     * {@code null} to indicate that no combining should be done
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6348
     * (add the second event to the end of the queue).  Either event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6349
     * parameter may be modified and returned, as the other one is discarded
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6350
     * unless {@code null} is returned.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6351
     * <p>
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6352
     * This implementation of {@code coalesceEvents} coalesces
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6353
     * two event types: mouse move (and drag) events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6354
     * and paint (and update) events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6355
     * For mouse move events the last event is always returned, causing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6356
     * intermediate moves to be discarded.  For paint events, the new
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6357
     * event is coalesced into a complex {@code RepaintArea} in the peer.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6358
     * The new {@code AWTEvent} is always returned.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6359
     *
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6360
     * @param  existingEvent  the event already on the {@code EventQueue}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6361
     * @param  newEvent       the event being posted to the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6362
     *          {@code EventQueue}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6363
     * @return a coalesced event, or {@code null} indicating that no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6364
     *          coalescing was done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6366
    protected AWTEvent coalesceEvents(AWTEvent existingEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6367
                                      AWTEvent newEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6368
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6372
     * Processes events occurring on this component. By default this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6373
     * method calls the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6374
     * <code>process&lt;event&nbsp;type&gt;Event</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6375
     * method for the given class of event.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6376
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6377
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6378
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6380
     * @param     e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6381
     * @see       #processComponentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6382
     * @see       #processFocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6383
     * @see       #processKeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6384
     * @see       #processMouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6385
     * @see       #processMouseMotionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6386
     * @see       #processInputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6387
     * @see       #processHierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6388
     * @see       #processMouseWheelEvent
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  6389
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6391
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6392
        if (e instanceof FocusEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6393
            processFocusEvent((FocusEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6395
        } else if (e instanceof MouseEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6396
            switch(e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6397
              case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6398
              case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6399
              case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6400
              case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6401
              case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6402
                  processMouseEvent((MouseEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6403
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6404
              case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6405
              case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6406
                  processMouseMotionEvent((MouseEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6407
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6408
              case MouseEvent.MOUSE_WHEEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6409
                  processMouseWheelEvent((MouseWheelEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6410
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6413
        } else if (e instanceof KeyEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6414
            processKeyEvent((KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6416
        } else if (e instanceof ComponentEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6417
            processComponentEvent((ComponentEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6418
        } else if (e instanceof InputMethodEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6419
            processInputMethodEvent((InputMethodEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6420
        } else if (e instanceof HierarchyEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6421
            switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6422
              case HierarchyEvent.HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6423
                  processHierarchyEvent((HierarchyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6424
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6425
              case HierarchyEvent.ANCESTOR_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6426
              case HierarchyEvent.ANCESTOR_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6427
                  processHierarchyBoundsEvent((HierarchyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6428
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6434
     * Processes component events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6435
     * dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6436
     * {@code ComponentListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6437
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6438
     * This method is not called unless component events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6439
     * enabled for this component. Component events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6440
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  6441
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6442
     * <li>A {@code ComponentListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6443
     * via {@code addComponentListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6444
     * <li>Component events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6445
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6446
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6447
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6448
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6450
     * @param       e the component event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6451
     * @see         java.awt.event.ComponentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6452
     * @see         java.awt.event.ComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6453
     * @see         #addComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6454
     * @see         #enableEvents
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  6455
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6457
    protected void processComponentEvent(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6458
        ComponentListener listener = componentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6459
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6460
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6461
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6462
              case ComponentEvent.COMPONENT_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6463
                  listener.componentResized(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6464
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6465
              case ComponentEvent.COMPONENT_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6466
                  listener.componentMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6467
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6468
              case ComponentEvent.COMPONENT_SHOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6469
                  listener.componentShown(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6470
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6471
              case ComponentEvent.COMPONENT_HIDDEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6472
                  listener.componentHidden(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6473
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6479
     * Processes focus events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6480
     * dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6481
     * {@code FocusListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6482
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6483
     * This method is not called unless focus events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6484
     * enabled for this component. Focus events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6485
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  6486
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6487
     * <li>A {@code FocusListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6488
     * via {@code addFocusListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6489
     * <li>Focus events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6490
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6491
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6492
     * If focus events are enabled for a {@code Component},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6493
     * the current {@code KeyboardFocusManager} determines
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6494
     * whether or not a focus event should be dispatched to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6495
     * registered {@code FocusListener} objects.  If the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6496
     * events are to be dispatched, the {@code KeyboardFocusManager}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6497
     * calls the {@code Component}'s {@code dispatchEvent}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6498
     * method, which results in a call to the {@code Component}'s
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6499
     * {@code processFocusEvent} method.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6500
     * <p>
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6501
     * If focus events are enabled for a {@code Component}, calling
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6502
     * the {@code Component}'s {@code dispatchEvent} method
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6503
     * with a {@code FocusEvent} as the argument will result in a
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6504
     * call to the {@code Component}'s {@code processFocusEvent}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6505
     * method regardless of the current {@code KeyboardFocusManager}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6506
     *
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6507
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6508
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6509
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6511
     * @param       e the focus event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6512
     * @see         java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6513
     * @see         java.awt.event.FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6514
     * @see         java.awt.KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6515
     * @see         #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6516
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6517
     * @see         #dispatchEvent
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  6518
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6519
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6520
    protected void processFocusEvent(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6521
        FocusListener listener = focusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6522
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6523
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6524
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6525
              case FocusEvent.FOCUS_GAINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6526
                  listener.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6527
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6528
              case FocusEvent.FOCUS_LOST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6529
                  listener.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6530
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6536
     * Processes key events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6537
     * dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6538
     * {@code KeyListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6539
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6540
     * This method is not called unless key events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6541
     * enabled for this component. Key events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6542
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  6543
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6544
     * <li>A {@code KeyListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6545
     * via {@code addKeyListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6546
     * <li>Key events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6547
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6549
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6550
     * If key events are enabled for a {@code Component},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6551
     * the current {@code KeyboardFocusManager} determines
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6552
     * whether or not a key event should be dispatched to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6553
     * registered {@code KeyListener} objects.  The
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6554
     * {@code DefaultKeyboardFocusManager} will not dispatch
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6555
     * key events to a {@code Component} that is not the focus
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6556
     * owner or is not showing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6557
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6558
     * As of J2SE 1.4, {@code KeyEvent}s are redirected to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6559
     * the focus owner. Please see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6560
     * <a href="doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6561
     * for further information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6562
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6563
     * Calling a {@code Component}'s {@code dispatchEvent}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6564
     * method with a {@code KeyEvent} as the argument will
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6565
     * result in a call to the {@code Component}'s
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6566
     * {@code processKeyEvent} method regardless of the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6567
     * current {@code KeyboardFocusManager} as long as the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6568
     * component is showing, focused, and enabled, and key events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6569
     * are enabled on it.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6570
     * <p>If the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6571
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6572
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6574
     * @param       e the key event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6575
     * @see         java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6576
     * @see         java.awt.event.KeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6577
     * @see         java.awt.KeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6578
     * @see         java.awt.DefaultKeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6579
     * @see         #processEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6580
     * @see         #dispatchEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6581
     * @see         #addKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6582
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6583
     * @see         #isShowing
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  6584
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6586
    protected void processKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6587
        KeyListener listener = keyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6588
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6589
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6590
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6591
              case KeyEvent.KEY_TYPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6592
                  listener.keyTyped(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6593
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6594
              case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6595
                  listener.keyPressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6596
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6597
              case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6598
                  listener.keyReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6599
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6605
     * Processes mouse events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6606
     * dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6607
     * {@code MouseListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6608
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6609
     * This method is not called unless mouse events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6610
     * enabled for this component. Mouse events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6611
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  6612
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6613
     * <li>A {@code MouseListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6614
     * via {@code addMouseListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6615
     * <li>Mouse events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6616
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6617
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6618
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6619
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6620
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6621
     * @param       e the mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6622
     * @see         java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6623
     * @see         java.awt.event.MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6624
     * @see         #addMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6625
     * @see         #enableEvents
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  6626
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6628
    protected void processMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6629
        MouseListener listener = mouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6630
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6631
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6632
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6633
              case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6634
                  listener.mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6635
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6636
              case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6637
                  listener.mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6638
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6639
              case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6640
                  listener.mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6641
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6642
              case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6643
                  listener.mouseExited(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6644
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6645
              case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6646
                  listener.mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6647
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6648
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6653
     * Processes mouse motion events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6654
     * dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6655
     * {@code MouseMotionListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6656
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6657
     * This method is not called unless mouse motion events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6658
     * enabled for this component. Mouse motion events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6659
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  6660
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6661
     * <li>A {@code MouseMotionListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6662
     * via {@code addMouseMotionListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6663
     * <li>Mouse motion events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6664
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6665
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6666
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6667
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6669
     * @param       e the mouse motion event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6670
     * @see         java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6671
     * @see         java.awt.event.MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6672
     * @see         #addMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6673
     * @see         #enableEvents
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  6674
     * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6675
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6676
    protected void processMouseMotionEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6677
        MouseMotionListener listener = mouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6678
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6679
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6680
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6681
              case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6682
                  listener.mouseMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6683
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6684
              case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6685
                  listener.mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6686
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6691
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6692
     * Processes mouse wheel events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6693
     * dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6694
     * {@code MouseWheelListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6695
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6696
     * This method is not called unless mouse wheel events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6697
     * enabled for this component. Mouse wheel events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6698
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  6699
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6700
     * <li>A {@code MouseWheelListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6701
     * via {@code addMouseWheelListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6702
     * <li>Mouse wheel events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6703
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6704
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6705
     * For information on how mouse wheel events are dispatched, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6706
     * the class description for {@link MouseWheelEvent}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6707
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6708
     * Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6709
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6710
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6712
     * @param       e the mouse wheel event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6713
     * @see         java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6714
     * @see         java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6715
     * @see         #addMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6716
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6717
     * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6719
    protected void processMouseWheelEvent(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6720
        MouseWheelListener listener = mouseWheelListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6721
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6722
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6723
            switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6724
              case MouseEvent.MOUSE_WHEEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6725
                  listener.mouseWheelMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6726
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6727
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6731
    boolean postsOldMouseEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6732
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6736
     * Processes input method events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6737
     * dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6738
     * {@code InputMethodListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6739
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6740
     * This method is not called unless input method events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6741
     * are enabled for this component. Input method events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6742
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  6743
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6744
     * <li>An {@code InputMethodListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6745
     * via {@code addInputMethodListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6746
     * <li>Input method events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6747
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6748
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6749
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6750
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6752
     * @param       e the input method event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6753
     * @see         java.awt.event.InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6754
     * @see         java.awt.event.InputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6755
     * @see         #addInputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6756
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6757
     * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6759
    protected void processInputMethodEvent(InputMethodEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6760
        InputMethodListener listener = inputMethodListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6761
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6762
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6763
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6764
              case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6765
                  listener.inputMethodTextChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6766
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6767
              case InputMethodEvent.CARET_POSITION_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6768
                  listener.caretPositionChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6769
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6774
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6775
     * Processes hierarchy events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6776
     * dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6777
     * {@code HierarchyListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6778
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6779
     * This method is not called unless hierarchy events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6780
     * are enabled for this component. Hierarchy events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6781
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  6782
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6783
     * <li>An {@code HierarchyListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6784
     * via {@code addHierarchyListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6785
     * <li>Hierarchy events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6786
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6787
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6788
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6789
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6790
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6791
     * @param       e the hierarchy event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6792
     * @see         java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6793
     * @see         java.awt.event.HierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6794
     * @see         #addHierarchyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6795
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6796
     * @since       1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6798
    protected void processHierarchyEvent(HierarchyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6799
        HierarchyListener listener = hierarchyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6800
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6801
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6802
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6803
              case HierarchyEvent.HIERARCHY_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6804
                  listener.hierarchyChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6805
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6806
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6810
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6811
     * Processes hierarchy bounds events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6812
     * dispatching them to any registered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6813
     * {@code HierarchyBoundsListener} objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6814
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6815
     * This method is not called unless hierarchy bounds events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6816
     * are enabled for this component. Hierarchy bounds events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6817
     * when one of the following occurs:
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21279
diff changeset
  6818
     * <ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6819
     * <li>An {@code HierarchyBoundsListener} object is registered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6820
     * via {@code addHierarchyBoundsListener}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6821
     * <li>Hierarchy bounds events are enabled via {@code enableEvents}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6822
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  6823
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6824
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6825
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6826
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6827
     * @param       e the hierarchy event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6828
     * @see         java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6829
     * @see         java.awt.event.HierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6830
     * @see         #addHierarchyBoundsListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6831
     * @see         #enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6832
     * @since       1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6834
    protected void processHierarchyBoundsEvent(HierarchyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6835
        HierarchyBoundsListener listener = hierarchyBoundsListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6836
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6837
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6838
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6839
              case HierarchyEvent.ANCESTOR_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6840
                  listener.ancestorMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6841
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6842
              case HierarchyEvent.ANCESTOR_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6843
                  listener.ancestorResized(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6844
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6849
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6850
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6851
     * @return {@code true} if the event was handled, {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6852
     * @deprecated As of JDK version 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6853
     * replaced by processEvent(AWTEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6854
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6855
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6856
    public boolean handleEvent(Event evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6857
        switch (evt.id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6858
          case Event.MOUSE_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6859
              return mouseEnter(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6861
          case Event.MOUSE_EXIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6862
              return mouseExit(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6864
          case Event.MOUSE_MOVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6865
              return mouseMove(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6867
          case Event.MOUSE_DOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6868
              return mouseDown(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6870
          case Event.MOUSE_DRAG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6871
              return mouseDrag(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6873
          case Event.MOUSE_UP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6874
              return mouseUp(evt, evt.x, evt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6876
          case Event.KEY_PRESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6877
          case Event.KEY_ACTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6878
              return keyDown(evt, evt.key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6880
          case Event.KEY_RELEASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6881
          case Event.KEY_ACTION_RELEASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6882
              return keyUp(evt, evt.key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6884
          case Event.ACTION_EVENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6885
              return action(evt, evt.arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6886
          case Event.GOT_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6887
              return gotFocus(evt, evt.arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6888
          case Event.LOST_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6889
              return lostFocus(evt, evt.arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6891
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6893
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6894
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6895
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6896
     * @param  x the x coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6897
     * @param  y the y coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6898
     * @return {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6899
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6900
     * replaced by processMouseEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6901
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6902
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6903
    public boolean mouseDown(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6904
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6907
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6908
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6909
     * @param  x the x coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6910
     * @param  y the y coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6911
     * @return {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6912
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6913
     * replaced by processMouseMotionEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6915
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6916
    public boolean mouseDrag(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6917
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6920
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6921
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6922
     * @param  x the x coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6923
     * @param  y the y coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6924
     * @return {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6925
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6926
     * replaced by processMouseEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6928
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6929
    public boolean mouseUp(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6930
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6932
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6933
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6934
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6935
     * @param  x the x coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6936
     * @param  y the y coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6937
     * @return {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6938
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6939
     * replaced by processMouseMotionEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6940
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6941
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6942
    public boolean mouseMove(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6943
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6946
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6947
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6948
     * @param  x the x coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6949
     * @param  y the y coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6950
     * @return {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6951
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6952
     * replaced by processMouseEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6953
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6954
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6955
    public boolean mouseEnter(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6956
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6959
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6960
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6961
     * @param  x the x coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6962
     * @param  y the y coordinate
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6963
     * @return {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6964
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6965
     * replaced by processMouseEvent(MouseEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6967
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6968
    public boolean mouseExit(Event evt, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6969
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6970
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6972
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6973
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6974
     * @param  key the key pressed
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6975
     * @return {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6976
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6977
     * replaced by processKeyEvent(KeyEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6978
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6979
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6980
    public boolean keyDown(Event evt, int key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6981
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6982
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6984
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6985
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6986
     * @param  key the key pressed
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6987
     * @return {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6988
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6989
     * replaced by processKeyEvent(KeyEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6990
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6991
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6992
    public boolean keyUp(Event evt, int key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6993
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6996
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6997
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6998
     * @param  what the object acted on
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  6999
     * @return {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7000
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7001
     * should register this component as ActionListener on component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7002
     * which fires action events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7003
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7004
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7005
    public boolean action(Event evt, Object what) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7006
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7007
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7009
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7010
     * Makes this {@code Component} displayable by connecting it to a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7011
     * native screen resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7012
     * This method is called internally by the toolkit and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7013
     * not be called directly by programs.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  7014
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  7015
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  7016
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  7017
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7018
     * @see       #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7019
     * @see       #removeNotify
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  7020
     * @see #invalidate
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  7021
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7022
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7023
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7024
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7025
            ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7026
            if (peer == null || peer instanceof LightweightPeer){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7027
                if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7028
                    // Update both the Component's peer variable and the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7029
                    // variable we use for thread safety.
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30470
diff changeset
  7030
                    this.peer = peer = getComponentFactory().createComponent(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7031
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7033
                // This is a lightweight component which means it won't be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7034
                // able to get window-related events by itself.  If any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7035
                // have been enabled, then the nearest native container must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7036
                // be enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7037
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7038
                    long mask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7039
                    if ((mouseListener != null) || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7040
                        mask |= AWTEvent.MOUSE_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7041
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7042
                    if ((mouseMotionListener != null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7043
                        ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7044
                        mask |= AWTEvent.MOUSE_MOTION_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7045
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7046
                    if ((mouseWheelListener != null ) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7047
                        ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7048
                        mask |= AWTEvent.MOUSE_WHEEL_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7049
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7050
                    if (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7051
                        mask |= AWTEvent.FOCUS_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7052
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7053
                    if (keyListener != null || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7054
                        mask |= AWTEvent.KEY_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7055
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7056
                    if (mask != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7057
                        parent.proxyEnableEvents(mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7058
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7059
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7060
            } else {
4257
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  7061
                // It's native. If the parent is lightweight it will need some
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  7062
                // help.
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  7063
                Container parent = getContainer();
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  7064
                if (parent != null && parent.isLightweight()) {
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  7065
                    relocateComponent();
4257
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  7066
                    if (!parent.isRecursivelyVisibleUpToHeavyweightContainer())
c447aed67cec 6885735: closed/java/awt/Component/DisablingLWDisabledHW/DisablingLWDisabledHW.html fails
anthony
parents: 3966
diff changeset
  7067
                    {
3729
80d0cf73598d 6689468: test/closed/java/awt/Component/VisibleHwInLwContTest/VisibleHwInLwContTest.html fails
anthony
parents: 3727
diff changeset
  7068
                        peer.setVisible(false);
80d0cf73598d 6689468: test/closed/java/awt/Component/VisibleHwInLwContTest/VisibleHwInLwContTest.html fails
anthony
parents: 3727
diff changeset
  7069
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7070
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7071
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7072
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7074
            int npopups = (popups != null? popups.size() : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7075
            for (int i = 0 ; i < npopups ; i++) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7076
                PopupMenu popup = popups.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7077
                popup.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7078
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7079
30470
bd197b8eda21 8074763: Remove API references to java.awt.dnd.peer
serb
parents: 30469
diff changeset
  7080
            if (dropTarget != null) dropTarget.addNotify();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7082
            peerFont = getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7084
            if (getContainer() != null && !isAddNotifyComplete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7085
                getContainer().increaseComponentCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7086
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7089
            // Update stacking order
2647
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
  7090
            updateZOrder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7092
            if (!isAddNotifyComplete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7093
                mixOnShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7094
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7096
            isAddNotifyComplete = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7098
            if (hierarchyListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7099
                (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7100
                Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7101
                HierarchyEvent e =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7102
                    new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7103
                                       this, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7104
                                       HierarchyEvent.DISPLAYABILITY_CHANGED |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7105
                                       ((isRecursivelyVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7106
                                        ? HierarchyEvent.SHOWING_CHANGED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7107
                                        : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7108
                dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7113
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7114
     * Makes this {@code Component} undisplayable by destroying it native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7115
     * screen resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7116
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7117
     * This method is called by the toolkit internally and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7118
     * not be called directly by programs. Code overriding
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7119
     * this method should call {@code super.removeNotify} as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7120
     * the first line of the overriding method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7122
     * @see       #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7123
     * @see       #addNotify
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  7124
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7126
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7127
        KeyboardFocusManager.clearMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7128
        if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7129
            getPermanentFocusOwner() == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7130
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7131
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7132
                setGlobalPermanentFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7135
        synchronized (getTreeLock()) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7136
            if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabledFor(this)) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7137
                transferFocus(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7140
            if (getContainer() != null && isAddNotifyComplete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7141
                getContainer().decreaseComponentCount(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7144
            int npopups = (popups != null? popups.size() : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7145
            for (int i = 0 ; i < npopups ; i++) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7146
                PopupMenu popup = popups.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7147
                popup.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7149
            // If there is any input context for this component, notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7150
            // that this component is being removed. (This has to be done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7151
            // before hiding peer.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7152
            if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7153
                InputContext inputContext = getInputContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7154
                if (inputContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7155
                    inputContext.removeNotify(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7156
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7159
            ComponentPeer p = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7160
            if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7161
                boolean isLightweight = isLightweight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7163
                if (bufferStrategy instanceof FlipBufferStrategy) {
55172
1a80806e7d15 6933331: (d3d/ogl) java.lang.IllegalStateException: Buffers have not been created
serb
parents: 54397
diff changeset
  7164
                    ((FlipBufferStrategy)bufferStrategy).invalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7165
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7166
30470
bd197b8eda21 8074763: Remove API references to java.awt.dnd.peer
serb
parents: 30469
diff changeset
  7167
                if (dropTarget != null) dropTarget.removeNotify();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7169
                // Hide peer first to stop system events such as cursor moves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7170
                if (visible) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1188
diff changeset
  7171
                    p.setVisible(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7172
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7174
                peer = null; // Stop peer updates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7175
                peerFont = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7177
                Toolkit.getEventQueue().removeSourceEvents(this, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7178
                KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7179
                    discardKeyEvents(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7181
                p.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7183
                mixOnHiding(isLightweight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7185
                isAddNotifyComplete = false;
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  7186
                // Nullifying compoundShape means that the component has normal shape
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  7187
                // (or has no shape at all).
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
  7188
                this.compoundShape = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7191
            if (hierarchyListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7192
                (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7193
                Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7194
                HierarchyEvent e =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7195
                    new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7196
                                       this, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7197
                                       HierarchyEvent.DISPLAYABILITY_CHANGED |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7198
                                       ((isRecursivelyVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7199
                                        ? HierarchyEvent.SHOWING_CHANGED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7200
                                        : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7201
                dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7206
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  7207
     * @param  evt the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  7208
     * @param  what the object focused
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  7209
     * @return  {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7210
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7211
     * replaced by processFocusEvent(FocusEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7213
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7214
    public boolean gotFocus(Event evt, Object what) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7215
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7218
    /**
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  7219
     * @param evt  the event to handle
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  7220
     * @param what the object focused
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  7221
     * @return  {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7222
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7223
     * replaced by processFocusEvent(FocusEvent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7225
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7226
    public boolean lostFocus(Event evt, Object what) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7227
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7230
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7231
     * Returns whether this {@code Component} can become the focus
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7232
     * owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7233
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7234
     * @return {@code true} if this {@code Component} is
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7235
     * focusable; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7236
     * @see #setFocusable
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  7237
     * @since 1.1
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7238
     * @deprecated As of 1.4, replaced by {@code isFocusable()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7240
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7241
    public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7242
        if (isFocusTraversableOverridden == FOCUS_TRAVERSABLE_UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7243
            isFocusTraversableOverridden = FOCUS_TRAVERSABLE_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7245
        return focusable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7249
     * Returns whether this Component can be focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7250
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7251
     * @return {@code true} if this Component is focusable;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7252
     *         {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7253
     * @see #setFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7254
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7256
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7257
        return isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7261
     * Sets the focusable state of this Component to the specified value. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7262
     * value overrides the Component's default focusability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7264
     * @param focusable indicates whether this Component is focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7265
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7266
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7268
    public void setFocusable(boolean focusable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7269
        boolean oldFocusable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7270
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7271
            oldFocusable = this.focusable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7272
            this.focusable = focusable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7274
        isFocusTraversableOverridden = FOCUS_TRAVERSABLE_SET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7276
        firePropertyChange("focusable", oldFocusable, focusable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7277
        if (oldFocusable && !focusable) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7278
            if (isFocusOwner() && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  7279
                transferFocus(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7281
            KeyboardFocusManager.clearMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7285
    final boolean isFocusTraversableOverridden() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7286
        return (isFocusTraversableOverridden != FOCUS_TRAVERSABLE_DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7290
     * Sets the focus traversal keys for a given traversal operation for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7291
     * Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7292
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7293
     * The default values for a Component's focus traversal keys are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7294
     * implementation-dependent. Sun recommends that all implementations for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7295
     * particular native platform use the same default values. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7296
     * recommendations for Windows and Unix are listed below. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7297
     * recommendations are used in the Sun AWT implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7298
     *
45648
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 44655
diff changeset
  7299
     * <table class="striped">
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 44655
diff changeset
  7300
     * <caption>Recommended default values for a Component's focus traversal
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 44655
diff changeset
  7301
     * keys</caption>
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 44655
diff changeset
  7302
     * <thead>
47498
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7303
     *   <tr>
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7304
     *     <th scope="col">Identifier
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7305
     *     <th scope="col">Meaning
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7306
     *     <th scope="col">Default
45648
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 44655
diff changeset
  7307
     * </thead>
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 44655
diff changeset
  7308
     * <tbody>
47498
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7309
     *   <tr>
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7310
     *     <th scope="row">KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7311
     *     <td>Normal forward keyboard traversal
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7312
     *     <td>TAB on KEY_PRESSED, CTRL-TAB on KEY_PRESSED
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7313
     *   <tr>
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7314
     *     <th scope="row">KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7315
     *     <td>Normal reverse keyboard traversal
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7316
     *     <td>SHIFT-TAB on KEY_PRESSED, CTRL-SHIFT-TAB on KEY_PRESSED
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7317
     *   <tr>
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7318
     *     <th scope="row">KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7319
     *     <td>Go up one focus traversal cycle
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47384
diff changeset
  7320
     *     <td>none
45648
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 44655
diff changeset
  7321
     * </tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7322
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7324
     * To disable a traversal key, use an empty Set; Collections.EMPTY_SET is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7325
     * recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7326
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7327
     * Using the AWTKeyStroke API, client code can specify on which of two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7328
     * specific KeyEvents, KEY_PRESSED or KEY_RELEASED, the focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7329
     * operation will occur. Regardless of which KeyEvent is specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7330
     * however, all KeyEvents related to the focus traversal key, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7331
     * associated KEY_TYPED event, will be consumed, and will not be dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7332
     * to any Component. It is a runtime error to specify a KEY_TYPED event as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7333
     * mapping to a focus traversal operation, or to map the same event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7334
     * multiple default focus traversal operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7335
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7336
     * If a value of null is specified for the Set, this Component inherits the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7337
     * Set from its parent. If all ancestors of this Component have null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7338
     * specified for the Set, then the current KeyboardFocusManager's default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7339
     * Set is used.
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 11982
diff changeset
  7340
     * <p>
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 11982
diff changeset
  7341
     * This method may throw a {@code ClassCastException} if any {@code Object}
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 11982
diff changeset
  7342
     * in {@code keystrokes} is not an {@code AWTKeyStroke}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7344
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7345
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7346
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7347
     * @param keystrokes the Set of AWTKeyStroke for the specified operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7348
     * @see #getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7349
     * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7350
     * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7351
     * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7352
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7353
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7354
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7355
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 11982
diff changeset
  7356
     *         contains null, or if any keystroke represents a KEY_TYPED event,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7357
     *         or if any keystroke already maps to another focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7358
     *         operation for this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7359
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7361
    public void setFocusTraversalKeys(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7362
                                      Set<? extends AWTKeyStroke> keystrokes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7363
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7364
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7365
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7368
        setFocusTraversalKeys_NoIDCheck(id, keystrokes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7372
     * Returns the Set of focus traversal keys for a given traversal operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7373
     * for this Component. (See
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7374
     * {@code setFocusTraversalKeys} for a full description of each key.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7375
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7376
     * If a Set of traversal keys has not been explicitly defined for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7377
     * Component, then this Component's parent's Set is returned. If no Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7378
     * has been explicitly defined for any of this Component's ancestors, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7379
     * the current KeyboardFocusManager's default Set is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7381
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7382
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7383
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7384
     * @return the Set of AWTKeyStrokes for the specified operation. The Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7385
     *         will be unmodifiable, and may be empty. null will never be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7386
     *         returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7387
     * @see #setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7388
     * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7389
     * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7390
     * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7391
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7392
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7393
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7394
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7395
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7397
    public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7398
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7399
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7402
        return getFocusTraversalKeys_NoIDCheck(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7405
    // We define these methods so that Container does not need to repeat this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7406
    // code. Container cannot call super.<method> because Container allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7407
    // DOWN_CYCLE_TRAVERSAL_KEY while Component does not. The Component method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7408
    // would erroneously generate an IllegalArgumentException for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7409
    // DOWN_CYCLE_TRAVERSAL_KEY.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7410
    final void setFocusTraversalKeys_NoIDCheck(int id, Set<? extends AWTKeyStroke> keystrokes) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7411
        Set<AWTKeyStroke> oldKeys;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7413
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7414
            if (focusTraversalKeys == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7415
                initializeFocusTraversalKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7418
            if (keystrokes != null) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7419
                for (AWTKeyStroke keystroke : keystrokes ) {
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7420
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7421
                    if (keystroke == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7422
                        throw new IllegalArgumentException("cannot set null focus traversal key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7423
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7425
                    if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7426
                        throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7427
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7429
                    for (int i = 0; i < focusTraversalKeys.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7430
                        if (i == id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7431
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7432
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7434
                        if (getFocusTraversalKeys_NoIDCheck(i).contains(keystroke))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7435
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7436
                            throw new IllegalArgumentException("focus traversal keys must be unique for a Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7437
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7438
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7439
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7442
            oldKeys = focusTraversalKeys[id];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7443
            focusTraversalKeys[id] = (keystrokes != null)
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7444
                ? Collections.unmodifiableSet(new HashSet<AWTKeyStroke>(keystrokes))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7445
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7448
        firePropertyChange(focusTraversalKeyPropertyNames[id], oldKeys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7449
                           keystrokes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7450
    }
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7451
    final Set<AWTKeyStroke> getFocusTraversalKeys_NoIDCheck(int id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7452
        // Okay to return Set directly because it is an unmodifiable view
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 13652
diff changeset
  7453
        @SuppressWarnings("unchecked")
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  7454
        Set<AWTKeyStroke> keystrokes = (focusTraversalKeys != null)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7455
            ? focusTraversalKeys[id]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7456
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7458
        if (keystrokes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7459
            return keystrokes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7460
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7461
            Container parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7462
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7463
                return parent.getFocusTraversalKeys(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7464
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7465
                return KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7466
                    getDefaultFocusTraversalKeys(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7472
     * Returns whether the Set of focus traversal keys for the given focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7473
     * traversal operation has been explicitly defined for this Component. If
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7474
     * this method returns {@code false}, this Component is inheriting the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7475
     * Set from an ancestor, or from the current KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7477
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7478
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7479
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7480
     * @return {@code true} if the Set of focus traversal keys for the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7481
     *         given focus traversal operation has been explicitly defined for
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7482
     *         this Component; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7483
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7484
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7485
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7486
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7487
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7489
    public boolean areFocusTraversalKeysSet(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7490
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7491
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7494
        return (focusTraversalKeys != null && focusTraversalKeys[id] != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7498
     * Sets whether focus traversal keys are enabled for this Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7499
     * Components for which focus traversal keys are disabled receive key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7500
     * events for focus traversal keys. Components for which focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7501
     * keys are enabled do not see these events; instead, the events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7502
     * automatically converted to traversal operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7504
     * @param focusTraversalKeysEnabled whether focus traversal keys are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7505
     *        enabled for this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7506
     * @see #getFocusTraversalKeysEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7507
     * @see #setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7508
     * @see #getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7509
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7511
    public void setFocusTraversalKeysEnabled(boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7512
                                             focusTraversalKeysEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7513
        boolean oldFocusTraversalKeysEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7514
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7515
            oldFocusTraversalKeysEnabled = this.focusTraversalKeysEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7516
            this.focusTraversalKeysEnabled = focusTraversalKeysEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7518
        firePropertyChange("focusTraversalKeysEnabled",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7519
                           oldFocusTraversalKeysEnabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7520
                           focusTraversalKeysEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7524
     * Returns whether focus traversal keys are enabled for this Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7525
     * Components for which focus traversal keys are disabled receive key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7526
     * events for focus traversal keys. Components for which focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7527
     * keys are enabled do not see these events; instead, the events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7528
     * automatically converted to traversal operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7529
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7530
     * @return whether focus traversal keys are enabled for this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7531
     * @see #setFocusTraversalKeysEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7532
     * @see #setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7533
     * @see #getFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7534
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7536
    public boolean getFocusTraversalKeysEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7537
        return focusTraversalKeysEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7541
     * Requests that this Component get the input focus, and that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7542
     * Component's top-level ancestor become the focused Window. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7543
     * component must be displayable, focusable, visible and all of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7544
     * its ancestors (with the exception of the top-level Window) must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7545
     * be visible for the request to be granted. Every effort will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7546
     * made to honor the request; however, in some cases it may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7547
     * impossible to do so. Developers must never assume that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7548
     * Component is the focus owner until this Component receives a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7549
     * FOCUS_GAINED event. If this request is denied because this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7550
     * Component's top-level Window cannot become the focused Window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7551
     * the request will be remembered and will be granted when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7552
     * Window is later focused by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7553
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7554
     * This method cannot be used to set the focus owner to no Component at
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7555
     * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7556
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7557
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7558
     * Because the focus behavior of this method is platform-dependent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7559
     * developers are strongly encouraged to use
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7560
     * {@code requestFocusInWindow} when possible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7561
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7562
     * <p>Note: Not all focus transfers result from invoking this method. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7563
     * such, a component may receive focus without this or any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7564
     * {@code requestFocus} methods of {@code Component} being invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7565
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7566
     * @see #requestFocusInWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7567
     * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7568
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7569
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7570
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7571
     * @see KeyboardFocusManager#clearGlobalFocusOwner
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  7572
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7573
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7574
    public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7575
        requestFocusHelper(false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7577
41805
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7578
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7579
    /**
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7580
     * Requests by the reason of {@code cause} that this Component get the input
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7581
     * focus, and that this Component's top-level ancestor become the
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7582
     * focused Window. This component must be displayable, focusable, visible
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7583
     * and all of its ancestors (with the exception of the top-level Window)
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7584
     * must be visible for the request to be granted. Every effort will be
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7585
     * made to honor the request; however, in some cases it may be
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7586
     * impossible to do so. Developers must never assume that this
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7587
     * Component is the focus owner until this Component receives a
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7588
     * FOCUS_GAINED event.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7589
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7590
     * The focus request effect may also depend on the provided
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7591
     * cause value. If this request is succeed the {@code FocusEvent}
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7592
     * generated in the result will receive the cause value specified as the
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7593
     * argument of method. If this request is denied because this Component's
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7594
     * top-level Window cannot become the focused Window, the request will be
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7595
     * remembered and will be granted when the Window is later focused by the
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7596
     * user.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7597
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7598
     * This method cannot be used to set the focus owner to no Component at
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7599
     * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner()}
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7600
     * instead.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7601
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7602
     * Because the focus behavior of this method is platform-dependent,
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7603
     * developers are strongly encouraged to use
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7604
     * {@code requestFocusInWindow(FocusEvent.Cause)} when possible.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7605
     *
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7606
     * <p>Note: Not all focus transfers result from invoking this method. As
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7607
     * such, a component may receive focus without this or any of the other
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7608
     * {@code requestFocus} methods of {@code Component} being invoked.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7609
     *
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7610
     * @param  cause the cause why the focus is requested
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7611
     * @see FocusEvent
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7612
     * @see FocusEvent.Cause
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7613
     * @see #requestFocusInWindow(FocusEvent.Cause)
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7614
     * @see java.awt.event.FocusEvent
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7615
     * @see #addFocusListener
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7616
     * @see #isFocusable
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7617
     * @see #isDisplayable
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7618
     * @see KeyboardFocusManager#clearGlobalFocusOwner
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7619
     * @since 9
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7620
     */
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7621
    public void requestFocus(FocusEvent.Cause cause) {
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7622
        requestFocusHelper(false, true, cause);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7625
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7626
     * Requests that this {@code Component} get the input focus,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7627
     * and that this {@code Component}'s top-level ancestor
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7628
     * become the focused {@code Window}. This component must be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7629
     * displayable, focusable, visible and all of its ancestors (with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7630
     * the exception of the top-level Window) must be visible for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7631
     * request to be granted. Every effort will be made to honor the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7632
     * request; however, in some cases it may be impossible to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7633
     * so. Developers must never assume that this component is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7634
     * focus owner until this component receives a FOCUS_GAINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7635
     * event. If this request is denied because this component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7636
     * top-level window cannot become the focused window, the request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7637
     * will be remembered and will be granted when the window is later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7638
     * focused by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7639
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7640
     * This method returns a boolean value. If {@code false} is returned,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7641
     * the request is <b>guaranteed to fail</b>. If {@code true} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7642
     * returned, the request will succeed <b>unless</b> it is vetoed, or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7643
     * extraordinary event, such as disposal of the component's peer, occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7644
     * before the request can be granted by the native windowing system. Again,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7645
     * while a return value of {@code true} indicates that the request is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7646
     * likely to succeed, developers must never assume that this component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7647
     * the focus owner until this component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7648
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7649
     * This method cannot be used to set the focus owner to no component at
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7650
     * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7651
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7652
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7653
     * Because the focus behavior of this method is platform-dependent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7654
     * developers are strongly encouraged to use
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7655
     * {@code requestFocusInWindow} when possible.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7656
     * <p>
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7657
     * Every effort will be made to ensure that {@code FocusEvent}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7658
     * generated as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7659
     * result of this request will have the specified temporary value. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7660
     * because specifying an arbitrary temporary state may not be implementable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7661
     * on all native windowing systems, correct behavior for this method can be
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7662
     * guaranteed only for lightweight {@code Component}s.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7663
     * This method is not intended
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7664
     * for general use, but exists instead as a hook for lightweight component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7665
     * libraries, such as Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7666
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7667
     * <p>Note: Not all focus transfers result from invoking this method. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7668
     * such, a component may receive focus without this or any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7669
     * {@code requestFocus} methods of {@code Component} being invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7670
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7671
     * @param temporary true if the focus change is temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7672
     *        such as when the window loses the focus; for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7673
     *        more information on temporary focus changes see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7674
     *<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7675
     * @return {@code false} if the focus change request is guaranteed to
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7676
     *         fail; {@code true} if it is likely to succeed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7677
     * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7678
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7679
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7680
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7681
     * @see KeyboardFocusManager#clearGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7682
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7684
    protected boolean requestFocus(boolean temporary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7685
        return requestFocusHelper(temporary, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7687
41805
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7688
    /**
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7689
     * Requests by the reason of {@code cause} that this {@code Component} get
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7690
     * the input focus, and that this {@code Component}'s top-level ancestor
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7691
     * become the focused {@code Window}. This component must be
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7692
     * displayable, focusable, visible and all of its ancestors (with
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7693
     * the exception of the top-level Window) must be visible for the
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7694
     * request to be granted. Every effort will be made to honor the
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7695
     * request; however, in some cases it may be impossible to do
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7696
     * so. Developers must never assume that this component is the
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7697
     * focus owner until this component receives a FOCUS_GAINED
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7698
     * event. If this request is denied because this component's
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7699
     * top-level window cannot become the focused window, the request
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7700
     * will be remembered and will be granted when the window is later
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7701
     * focused by the user.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7702
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7703
     * This method returns a boolean value. If {@code false} is returned,
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7704
     * the request is <b>guaranteed to fail</b>. If {@code true} is
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7705
     * returned, the request will succeed <b>unless</b> it is vetoed, or an
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7706
     * extraordinary event, such as disposal of the component's peer, occurs
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7707
     * before the request can be granted by the native windowing system. Again,
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7708
     * while a return value of {@code true} indicates that the request is
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7709
     * likely to succeed, developers must never assume that this component is
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7710
     * the focus owner until this component receives a FOCUS_GAINED event.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7711
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7712
     * The focus request effect may also depend on the provided
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7713
     * cause value. If this request is succeed the {FocusEvent}
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7714
     * generated in the result will receive the cause value specified as the
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7715
     * argument of the method.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7716
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7717
     * This method cannot be used to set the focus owner to no component at
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7718
     * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner}
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7719
     * instead.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7720
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7721
     * Because the focus behavior of this method is platform-dependent,
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7722
     * developers are strongly encouraged to use
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7723
     * {@code requestFocusInWindow} when possible.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7724
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7725
     * Every effort will be made to ensure that {@code FocusEvent}s
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7726
     * generated as a
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7727
     * result of this request will have the specified temporary value. However,
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7728
     * because specifying an arbitrary temporary state may not be implementable
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7729
     * on all native windowing systems, correct behavior for this method can be
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7730
     * guaranteed only for lightweight {@code Component}s.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7731
     * This method is not intended
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7732
     * for general use, but exists instead as a hook for lightweight component
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7733
     * libraries, such as Swing.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7734
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7735
     * Note: Not all focus transfers result from invoking this method. As
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7736
     * such, a component may receive focus without this or any of the other
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7737
     * {@code requestFocus} methods of {@code Component} being invoked.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7738
     *
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7739
     * @param temporary true if the focus change is temporary,
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7740
     *        such as when the window loses the focus; for
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7741
     *        more information on temporary focus changes see the
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7742
     *<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7743
     *
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7744
     * @param  cause the cause why the focus is requested
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7745
     * @return {@code false} if the focus change request is guaranteed to
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7746
     *         fail; {@code true} if it is likely to succeed
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7747
     * @see FocusEvent
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7748
     * @see FocusEvent.Cause
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7749
     * @see #addFocusListener
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7750
     * @see #isFocusable
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7751
     * @see #isDisplayable
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7752
     * @see KeyboardFocusManager#clearGlobalFocusOwner
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7753
     * @since 9
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7754
     */
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7755
    protected boolean requestFocus(boolean temporary, FocusEvent.Cause cause) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7756
        return requestFocusHelper(temporary, true, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7757
    }
41805
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7758
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7760
     * Requests that this Component get the input focus, if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7761
     * Component's top-level ancestor is already the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7762
     * Window. This component must be displayable, focusable, visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7763
     * and all of its ancestors (with the exception of the top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7764
     * Window) must be visible for the request to be granted. Every
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7765
     * effort will be made to honor the request; however, in some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7766
     * cases it may be impossible to do so. Developers must never
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7767
     * assume that this Component is the focus owner until this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7768
     * Component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7769
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7770
     * This method returns a boolean value. If {@code false} is returned,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7771
     * the request is <b>guaranteed to fail</b>. If {@code true} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7772
     * returned, the request will succeed <b>unless</b> it is vetoed, or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7773
     * extraordinary event, such as disposal of the Component's peer, occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7774
     * before the request can be granted by the native windowing system. Again,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7775
     * while a return value of {@code true} indicates that the request is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7776
     * likely to succeed, developers must never assume that this Component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7777
     * the focus owner until this Component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7778
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7779
     * This method cannot be used to set the focus owner to no Component at
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7780
     * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7781
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7782
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7783
     * The focus behavior of this method can be implemented uniformly across
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7784
     * platforms, and thus developers are strongly encouraged to use this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7785
     * method over {@code requestFocus} when possible. Code which relies
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7786
     * on {@code requestFocus} may exhibit different focus behavior on
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7787
     * different platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7788
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7789
     * <p>Note: Not all focus transfers result from invoking this method. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7790
     * such, a component may receive focus without this or any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7791
     * {@code requestFocus} methods of {@code Component} being invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7792
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7793
     * @return {@code false} if the focus change request is guaranteed to
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7794
     *         fail; {@code true} if it is likely to succeed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7795
     * @see #requestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7796
     * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7797
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7798
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7799
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7800
     * @see KeyboardFocusManager#clearGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7801
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7802
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7803
    public boolean requestFocusInWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7804
        return requestFocusHelper(false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7806
41805
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7807
    /**
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7808
     * Requests by the reason of {@code cause} that this Component get the input
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7809
     * focus, if this Component's top-level ancestor is already the focused
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7810
     * Window. This component must be displayable, focusable, visible
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7811
     * and all of its ancestors (with the exception of the top-level
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7812
     * Window) must be visible for the request to be granted. Every
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7813
     * effort will be made to honor the request; however, in some
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7814
     * cases it may be impossible to do so. Developers must never
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7815
     * assume that this Component is the focus owner until this
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7816
     * Component receives a FOCUS_GAINED event.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7817
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7818
     * This method returns a boolean value. If {@code false} is returned,
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7819
     * the request is <b>guaranteed to fail</b>. If {@code true} is
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7820
     * returned, the request will succeed <b>unless</b> it is vetoed, or an
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7821
     * extraordinary event, such as disposal of the Component's peer, occurs
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7822
     * before the request can be granted by the native windowing system. Again,
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7823
     * while a return value of {@code true} indicates that the request is
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7824
     * likely to succeed, developers must never assume that this Component is
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7825
     * the focus owner until this Component receives a FOCUS_GAINED event.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7826
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7827
     * The focus request effect may also depend on the provided
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7828
     * cause value. If this request is succeed the {@code FocusEvent}
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7829
     * generated in the result will receive the cause value specified as the
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7830
     * argument of the method.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7831
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7832
     * This method cannot be used to set the focus owner to no Component at
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7833
     * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner()}
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7834
     * instead.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7835
     * <p>
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7836
     * The focus behavior of this method can be implemented uniformly across
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7837
     * platforms, and thus developers are strongly encouraged to use this
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7838
     * method over {@code requestFocus(FocusEvent.Cause)} when possible.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7839
     * Code which relies on {@code requestFocus(FocusEvent.Cause)} may exhibit
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7840
     * different focus behavior on different platforms.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7841
     *
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7842
     * <p>Note: Not all focus transfers result from invoking this method. As
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7843
     * such, a component may receive focus without this or any of the other
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7844
     * {@code requestFocus} methods of {@code Component} being invoked.
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7845
     *
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7846
     * @param  cause the cause why the focus is requested
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7847
     * @return {@code false} if the focus change request is guaranteed to
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7848
     *         fail; {@code true} if it is likely to succeed
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7849
     * @see #requestFocus(FocusEvent.Cause)
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7850
     * @see FocusEvent
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7851
     * @see FocusEvent.Cause
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7852
     * @see java.awt.event.FocusEvent
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7853
     * @see #addFocusListener
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7854
     * @see #isFocusable
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7855
     * @see #isDisplayable
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7856
     * @see KeyboardFocusManager#clearGlobalFocusOwner
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7857
     * @since 9
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7858
     */
d30817604de5 8154434: Open the request focus methods of the java.awt.Component which accept FocusEvent.Cause
ssadetsky
parents: 41004
diff changeset
  7859
    public boolean requestFocusInWindow(FocusEvent.Cause cause) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7860
        return requestFocusHelper(false, false, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7861
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7862
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7863
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7864
     * Requests that this {@code Component} get the input focus,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7865
     * if this {@code Component}'s top-level ancestor is already
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7866
     * the focused {@code Window}.  This component must be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7867
     * displayable, focusable, visible and all of its ancestors (with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7868
     * the exception of the top-level Window) must be visible for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7869
     * request to be granted. Every effort will be made to honor the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7870
     * request; however, in some cases it may be impossible to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7871
     * so. Developers must never assume that this component is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7872
     * focus owner until this component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7873
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7874
     * This method returns a boolean value. If {@code false} is returned,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7875
     * the request is <b>guaranteed to fail</b>. If {@code true} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7876
     * returned, the request will succeed <b>unless</b> it is vetoed, or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7877
     * extraordinary event, such as disposal of the component's peer, occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7878
     * before the request can be granted by the native windowing system. Again,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7879
     * while a return value of {@code true} indicates that the request is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7880
     * likely to succeed, developers must never assume that this component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7881
     * the focus owner until this component receives a FOCUS_GAINED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7882
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7883
     * This method cannot be used to set the focus owner to no component at
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7884
     * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7885
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7886
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7887
     * The focus behavior of this method can be implemented uniformly across
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7888
     * platforms, and thus developers are strongly encouraged to use this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7889
     * method over {@code requestFocus} when possible. Code which relies
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7890
     * on {@code requestFocus} may exhibit different focus behavior on
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7891
     * different platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7892
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7893
     * Every effort will be made to ensure that {@code FocusEvent}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7894
     * generated as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7895
     * result of this request will have the specified temporary value. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7896
     * because specifying an arbitrary temporary state may not be implementable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7897
     * on all native windowing systems, correct behavior for this method can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7898
     * guaranteed only for lightweight components. This method is not intended
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7899
     * for general use, but exists instead as a hook for lightweight component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7900
     * libraries, such as Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7901
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7902
     * <p>Note: Not all focus transfers result from invoking this method. As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7903
     * such, a component may receive focus without this or any of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7904
     * {@code requestFocus} methods of {@code Component} being invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7905
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7906
     * @param temporary true if the focus change is temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7907
     *        such as when the window loses the focus; for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7908
     *        more information on temporary focus changes see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7909
     *<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7910
     * @return {@code false} if the focus change request is guaranteed to
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  7911
     *         fail; {@code true} if it is likely to succeed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7912
     * @see #requestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7913
     * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7914
     * @see #addFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7915
     * @see #isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7916
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7917
     * @see KeyboardFocusManager#clearGlobalFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7918
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7919
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7920
    protected boolean requestFocusInWindow(boolean temporary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7921
        return requestFocusHelper(temporary, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7923
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  7924
    boolean requestFocusInWindow(boolean temporary, FocusEvent.Cause cause) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7925
        return requestFocusHelper(temporary, false, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7928
    final boolean requestFocusHelper(boolean temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7929
                                     boolean focusedWindowChangeAllowed) {
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  7930
        return requestFocusHelper(temporary, focusedWindowChangeAllowed, FocusEvent.Cause.UNKNOWN);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7932
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7933
    final boolean requestFocusHelper(boolean temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7934
                                     boolean focusedWindowChangeAllowed,
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  7935
                                     FocusEvent.Cause cause)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7936
    {
13652
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7937
        // 1) Check if the event being dispatched is a system-generated mouse event.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7938
        AWTEvent currentEvent = EventQueue.getCurrentEvent();
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7939
        if (currentEvent instanceof MouseEvent &&
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7940
            SunToolkit.isSystemGenerated(currentEvent))
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7941
        {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7942
            // 2) Sanity check: if the mouse event component source belongs to the same containing window.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7943
            Component source = ((MouseEvent)currentEvent).getComponent();
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7944
            if (source == null || source.getContainingWindow() == getContainingWindow()) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7945
                focusLog.finest("requesting focus by mouse event \"in window\"");
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7946
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7947
                // If both the conditions are fulfilled the focus request should be strictly
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7948
                // bounded by the toplevel window. It's assumed that the mouse event activates
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7949
                // the window (if it wasn't active) and this makes it possible for a focus
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7950
                // request with a strong in-window requirement to change focus in the bounds
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7951
                // of the toplevel. If, by any means, due to asynchronous nature of the event
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7952
                // dispatching mechanism, the window happens to be natively inactive by the time
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7953
                // this focus request is eventually handled, it should not re-activate the
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7954
                // toplevel. Otherwise the result may not meet user expectations. See 6981400.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7955
                focusedWindowChangeAllowed = false;
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7956
            }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7957
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7958
        if (!isRequestFocusAccepted(temporary, focusedWindowChangeAllowed, cause)) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  7959
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7960
                focusLog.finest("requestFocus is not accepted");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7961
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7962
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7964
        // Update most-recent map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7965
        KeyboardFocusManager.setMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7967
        Component window = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7968
        while ( (window != null) && !(window instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7969
            if (!window.isVisible()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  7970
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  7971
                    focusLog.finest("component is recursively invisible");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7972
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7973
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7974
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7975
            window = window.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7976
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7978
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7979
        Component heavyweight = (peer instanceof LightweightPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7980
            ? getNativeContainer() : this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7981
        if (heavyweight == null || !heavyweight.isVisible()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  7982
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7983
                focusLog.finest("Component is not a part of visible hierarchy");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7985
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7987
        peer = heavyweight.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7988
        if (peer == null) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  7989
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  7990
                focusLog.finest("Peer is null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7991
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7992
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  7995
        // Focus this Component
13652
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7996
        long time = 0;
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7997
        if (EventQueue.isDispatchThread()) {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7998
            time = Toolkit.getEventQueue().getMostRecentKeyEventTime();
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  7999
        } else {
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  8000
            // A focus request made from outside EDT should not be associated with any event
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  8001
            // and so its time stamp is simply set to the current time.
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  8002
            time = System.currentTimeMillis();
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  8003
        }
42544e68dc39 6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents: 13549
diff changeset
  8004
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8005
        boolean success = peer.requestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8006
            (this, temporary, focusedWindowChangeAllowed, time, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8007
        if (!success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8008
            KeyboardFocusManager.getCurrentKeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8009
                (appContext).dequeueKeyEvents(time, this);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8010
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  8011
                focusLog.finest("Peer request failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8013
        } else {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8014
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  8015
                focusLog.finest("Pass for " + this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8017
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8018
        return success;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8021
    private boolean isRequestFocusAccepted(boolean temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8022
                                           boolean focusedWindowChangeAllowed,
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  8023
                                           FocusEvent.Cause cause)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8024
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8025
        if (!isFocusable() || !isVisible()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8026
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  8027
                focusLog.finest("Not focusable or not visible");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8028
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8029
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8030
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8032
        ComponentPeer peer = this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8033
        if (peer == null) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8034
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  8035
                focusLog.finest("peer is null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8036
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8037
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8040
        Window window = getContainingWindow();
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8041
        if (window == null || !window.isFocusableWindow()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8042
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  8043
                focusLog.finest("Component doesn't have toplevel");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8044
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8045
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8046
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8048
        // We have passed all regular checks for focus request,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8049
        // now let's call RequestFocusController and see what it says.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8050
        Component focusOwner = KeyboardFocusManager.getMostRecentFocusOwner(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8051
        if (focusOwner == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8052
            // sometimes most recent focus owner may be null, but focus owner is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8053
            // e.g. we reset most recent focus owner if user removes focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8054
            focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
  8055
            if (focusOwner != null && focusOwner.getContainingWindow() != window) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8056
                focusOwner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8060
        if (focusOwner == this || focusOwner == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8061
            // Controller is supposed to verify focus transfers and for this it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8062
            // should know both from and to components.  And it shouldn't verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8063
            // transfers from when these components are equal.
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8064
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  8065
                focusLog.finest("focus owner is null or this");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8067
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8069
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  8070
        if (FocusEvent.Cause.ACTIVATION == cause) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8071
            // we shouldn't call RequestFocusController in case we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8072
            // in activation.  We do request focus on component which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8073
            // has got temporary focus lost and then on component which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8074
            // most recent focus owner.  But most recent focus owner can be
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  8075
            // changed by requestFocusXXX() call only, so this transfer has
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8076
            // been already approved.
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8077
            if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  8078
                focusLog.finest("cause is activation");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8079
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8080
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8083
        boolean ret = Component.requestFocusController.acceptRequestFocus(focusOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8084
                                                                          this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8085
                                                                          temporary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8086
                                                                          focusedWindowChangeAllowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8087
                                                                          cause);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8088
        if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
  8089
            focusLog.finest("RequestFocusController returns {0}", ret);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8092
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8095
    private static RequestFocusController requestFocusController = new DummyRequestFocusController();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8097
    // Swing access this method through reflection to implement InputVerifier's functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8098
    // Perhaps, we should make this method public (later ;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8099
    private static class DummyRequestFocusController implements RequestFocusController {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8100
        public boolean acceptRequestFocus(Component from, Component to,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8101
                                          boolean temporary, boolean focusedWindowChangeAllowed,
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  8102
                                          FocusEvent.Cause cause)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8103
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8104
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8106
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8107
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
  8108
    static synchronized void setRequestFocusController(RequestFocusController requestController)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8109
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8110
        if (requestController == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8111
            requestFocusController = new DummyRequestFocusController();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8112
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8113
            requestFocusController = requestController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8118
     * Returns the Container which is the focus cycle root of this Component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8119
     * focus traversal cycle. Each focus traversal cycle has only a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8120
     * focus cycle root and each Component which is not a Container belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8121
     * only a single focus traversal cycle. Containers which are focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8122
     * roots belong to two cycles: one rooted at the Container itself, and one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8123
     * rooted at the Container's nearest focus-cycle-root ancestor. For such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8124
     * Containers, this method will return the Container's nearest focus-cycle-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8125
     * root ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8127
     * @return this Component's nearest focus-cycle-root ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8128
     * @see Container#isFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8129
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8131
    public Container getFocusCycleRootAncestor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8132
        Container rootAncestor = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8133
        while (rootAncestor != null && !rootAncestor.isFocusCycleRoot()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8134
            rootAncestor = rootAncestor.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8136
        return rootAncestor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8140
     * Returns whether the specified Container is the focus cycle root of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8141
     * Component's focus traversal cycle. Each focus traversal cycle has only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8142
     * a single focus cycle root and each Component which is not a Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8143
     * belongs to only a single focus traversal cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8145
     * @param container the Container to be tested
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8146
     * @return {@code true} if the specified Container is a focus-cycle-
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8147
     *         root of this Component; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8148
     * @see Container#isFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8149
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8151
    public boolean isFocusCycleRoot(Container container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8152
        Container rootAncestor = getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8153
        return (rootAncestor == container);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8155
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8156
    Container getTraversalRoot() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8157
        return getFocusCycleRootAncestor();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8158
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8159
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8160
    /**
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8161
     * Transfers the focus to the next component, as though this Component were
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8162
     * the focus owner.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8163
     * @see       #requestFocus()
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8164
     * @since     1.1
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8165
     */
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8166
    public void transferFocus() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8167
        nextFocus();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8168
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8169
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8171
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8172
     * replaced by transferFocus().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8174
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8175
    public void nextFocus() {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8176
        transferFocus(false);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8177
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8178
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8179
    boolean transferFocus(boolean clearOnFailure) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8180
        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8181
            focusLog.finer("clearOnFailure = " + clearOnFailure);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8182
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8183
        Component toFocus = getNextFocusCandidate();
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8184
        boolean res = false;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8185
        if (toFocus != null && !toFocus.isFocusOwner() && toFocus != this) {
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  8186
            res = toFocus.requestFocusInWindow(FocusEvent.Cause.TRAVERSAL_FORWARD);
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8187
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8188
        if (clearOnFailure && !res) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8189
            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8190
                focusLog.finer("clear global focus owner");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8191
            }
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  8192
            KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwnerPriv();
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8193
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8194
        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8195
            focusLog.finer("returning result: " + res);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8196
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8197
        return res;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8198
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8199
42198
6ff366cc096b 8168316: Suppress deprecation warnings for Applet classes in java.desktop
prr
parents: 41805
diff changeset
  8200
    @SuppressWarnings("deprecation")
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8201
    final Component getNextFocusCandidate() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8202
        Container rootAncestor = getTraversalRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8203
        Component comp = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8204
        while (rootAncestor != null &&
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8205
               !(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8206
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8207
            comp = rootAncestor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8208
            rootAncestor = comp.getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8209
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8210
        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8211
            focusLog.finer("comp = " + comp + ", root = " + rootAncestor);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8212
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8213
        Component candidate = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8214
        if (rootAncestor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8215
            FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8216
            Component toFocus = policy.getComponentAfter(rootAncestor, comp);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8217
            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8218
                focusLog.finer("component after is " + toFocus);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8220
            if (toFocus == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8221
                toFocus = policy.getDefaultComponent(rootAncestor);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8222
                if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8223
                    focusLog.finer("default component is " + toFocus);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8224
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8226
            if (toFocus == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8227
                Applet applet = EmbeddedFrame.getAppletIfAncestorOf(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8228
                if (applet != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8229
                    toFocus = applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8230
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8231
            }
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8232
            candidate = toFocus;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8233
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8234
        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8235
            focusLog.finer("Focus transfer candidate: " + candidate);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8236
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8237
        return candidate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8241
     * Transfers the focus to the previous component, as though this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8242
     * were the focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8243
     * @see       #requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8244
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8246
    public void transferFocusBackward() {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8247
        transferFocusBackward(false);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8248
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8249
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8250
    boolean transferFocusBackward(boolean clearOnFailure) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8251
        Container rootAncestor = getTraversalRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8252
        Component comp = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8253
        while (rootAncestor != null &&
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  8254
               !(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8255
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8256
            comp = rootAncestor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8257
            rootAncestor = comp.getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8258
        }
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8259
        boolean res = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8260
        if (rootAncestor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8261
            FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8262
            Component toFocus = policy.getComponentBefore(rootAncestor, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8263
            if (toFocus == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8264
                toFocus = policy.getDefaultComponent(rootAncestor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8266
            if (toFocus != null) {
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  8267
                res = toFocus.requestFocusInWindow(FocusEvent.Cause.TRAVERSAL_BACKWARD);
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8268
            }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8269
        }
10410
ebae41687d0b 7081012: REGRESSION:Component.transferFocusBackward invokes clearGlobalFocusOwner()
denis
parents: 9658
diff changeset
  8270
        if (clearOnFailure && !res) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8271
            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8272
                focusLog.finer("clear global focus owner");
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8273
            }
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  8274
            KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwnerPriv();
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8275
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
  8276
        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8277
            focusLog.finer("returning result: " + res);
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8278
        }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8279
        return res;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8283
     * Transfers the focus up one focus traversal cycle. Typically, the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8284
     * owner is set to this Component's focus cycle root, and the current focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8285
     * cycle root is set to the new focus owner's focus cycle root. If,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8286
     * however, this Component's focus cycle root is a Window, then the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8287
     * owner is set to the focus cycle root's default Component to focus, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8288
     * the current focus cycle root is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8290
     * @see       #requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8291
     * @see       Container#isFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8292
     * @see       Container#setFocusCycleRoot(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8293
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8295
    public void transferFocusUpCycle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8296
        Container rootAncestor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8297
        for (rootAncestor = getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8298
             rootAncestor != null && !(rootAncestor.isShowing() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8299
                                       rootAncestor.isFocusable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8300
                                       rootAncestor.isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8301
             rootAncestor = rootAncestor.getFocusCycleRootAncestor()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8304
        if (rootAncestor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8305
            Container rootAncestorRootAncestor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8306
                rootAncestor.getFocusCycleRootAncestor();
12666
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  8307
            Container fcr = (rootAncestorRootAncestor != null) ?
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  8308
                rootAncestorRootAncestor : rootAncestor;
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 12643
diff changeset
  8309
12666
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  8310
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  8311
                setGlobalCurrentFocusCycleRootPriv(fcr);
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  8312
            rootAncestor.requestFocus(FocusEvent.Cause.TRAVERSAL_UP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8313
        } else {
12666
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  8314
            Window window = getContainingWindow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8316
            if (window != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8317
                Component toFocus = window.getFocusTraversalPolicy().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8318
                    getDefaultComponent(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8319
                if (toFocus != null) {
12666
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  8320
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
0799075de9d6 7170427: setGlobalCurrentFocusCycleRoot unexpectedly throws SecurityException
ant
parents: 12651
diff changeset
  8321
                        setGlobalCurrentFocusCycleRootPriv(window);
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  8322
                    toFocus.requestFocus(FocusEvent.Cause.TRAVERSAL_UP);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8323
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8328
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8329
     * Returns {@code true} if this {@code Component} is the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8330
     * focus owner.  This method is obsolete, and has been replaced by
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8331
     * {@code isFocusOwner()}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8332
     *
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8333
     * @return {@code true} if this {@code Component} is the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8334
     *         focus owner; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8335
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8337
    public boolean hasFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8338
        return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8339
                getFocusOwner() == this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8342
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8343
     * Returns {@code true} if this {@code Component} is the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8344
     *    focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8345
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8346
     * @return {@code true} if this {@code Component} is the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8347
     *     focus owner; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8348
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8350
    public boolean isFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8351
        return hasFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8353
441
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8354
    /*
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8355
     * Used to disallow auto-focus-transfer on disposal of the focus owner
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8356
     * in the process of disposing its parent container.
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8357
     */
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8358
    private boolean autoFocusTransferOnDisposal = true;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8359
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8360
    void setAutoFocusTransferOnDisposal(boolean value) {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8361
        autoFocusTransferOnDisposal = value;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8362
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8363
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8364
    boolean isAutoFocusTransferOnDisposal() {
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8365
        return autoFocusTransferOnDisposal;
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8366
    }
f5da1014ed23 6607170: Focus not set by requestFocus
ant
parents: 435
diff changeset
  8367
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8369
     * Adds the specified popup menu to the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8370
     * @param     popup the popup menu to be added to the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8371
     * @see       #remove(MenuComponent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8372
     * @exception NullPointerException if {@code popup} is {@code null}
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8373
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8375
    public void add(PopupMenu popup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8376
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8377
            if (popup.parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8378
                popup.parent.remove(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8380
            if (popups == null) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8381
                popups = new Vector<PopupMenu>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8383
            popups.addElement(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8384
            popup.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8386
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8387
                if (popup.peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8388
                    popup.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8395
     * Removes the specified popup menu from the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8396
     * @param     popup the popup menu to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8397
     * @see       #add(PopupMenu)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8398
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8399
     */
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8400
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8401
    public void remove(MenuComponent popup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8402
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8403
            if (popups == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8404
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8406
            int index = popups.indexOf(popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8407
            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8408
                PopupMenu pmenu = (PopupMenu)popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8409
                if (pmenu.peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8410
                    pmenu.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8412
                pmenu.parent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8413
                popups.removeElementAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8414
                if (popups.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8415
                    popups = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8416
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8422
     * Returns a string representing the state of this component. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8423
     * method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8424
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8425
     * implementations. The returned string may be empty but may not be
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8426
     * {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8428
     * @return  a string representation of this component's state
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8429
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8431
    protected String paramString() {
23299
6a715c2969cf 8034068: Label.toString performance improvement
serb
parents: 23297
diff changeset
  8432
        final String thisName = Objects.toString(getName(), "");
6a715c2969cf 8034068: Label.toString performance improvement
serb
parents: 23297
diff changeset
  8433
        final String invalid = isValid() ? "" : ",invalid";
6a715c2969cf 8034068: Label.toString performance improvement
serb
parents: 23297
diff changeset
  8434
        final String hidden = visible ? "" : ",hidden";
6a715c2969cf 8034068: Label.toString performance improvement
serb
parents: 23297
diff changeset
  8435
        final String disabled = enabled ? "" : ",disabled";
6a715c2969cf 8034068: Label.toString performance improvement
serb
parents: 23297
diff changeset
  8436
        return thisName + ',' + x + ',' + y + ',' + width + 'x' + height
6a715c2969cf 8034068: Label.toString performance improvement
serb
parents: 23297
diff changeset
  8437
                + invalid + hidden + disabled;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8441
     * Returns a string representation of this component and its values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8442
     * @return    a string representation of this component
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8443
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8445
    public String toString() {
23299
6a715c2969cf 8034068: Label.toString performance improvement
serb
parents: 23297
diff changeset
  8446
        return getClass().getName() + '[' + paramString() + ']';
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8450
     * Prints a listing of this component to the standard system output
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8451
     * stream {@code System.out}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8452
     * @see       java.lang.System#out
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8453
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8455
    public void list() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8456
        list(System.out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8459
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8460
     * Prints a listing of this component to the specified output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8461
     * stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8462
     * @param    out   a print stream
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  8463
     * @throws   NullPointerException if {@code out} is {@code null}
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8464
     * @since    1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8466
    public void list(PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8467
        list(out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8471
     * Prints out a list, starting at the specified indentation, to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8472
     * specified print stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8473
     * @param     out      a print stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8474
     * @param     indent   number of spaces to indent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8475
     * @see       java.io.PrintStream#println(java.lang.Object)
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  8476
     * @throws    NullPointerException if {@code out} is {@code null}
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8477
     * @since     1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8479
    public void list(PrintStream out, int indent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8480
        for (int i = 0 ; i < indent ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8481
            out.print(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8483
        out.println(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8487
     * Prints a listing to the specified print writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8488
     * @param  out  the print writer to print to
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  8489
     * @throws NullPointerException if {@code out} is {@code null}
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8490
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8492
    public void list(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8493
        list(out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8497
     * Prints out a list, starting at the specified indentation, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8498
     * the specified print writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8499
     * @param out the print writer to print to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8500
     * @param indent the number of spaces to indent
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 5506
diff changeset
  8501
     * @throws NullPointerException if {@code out} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8502
     * @see       java.io.PrintStream#println(java.lang.Object)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24549
diff changeset
  8503
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8505
    public void list(PrintWriter out, int indent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8506
        for (int i = 0 ; i < indent ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8507
            out.print(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8509
        out.println(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8512
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8513
     * Fetches the native container somewhere higher up in the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8514
     * tree that contains this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8515
     */
17150
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 15506
diff changeset
  8516
    final Container getNativeContainer() {
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 15506
diff changeset
  8517
        Container p = getContainer();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8518
        while (p != null && p.peer instanceof LightweightPeer) {
17150
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 15506
diff changeset
  8519
            p = p.getContainer();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8521
        return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8524
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8525
     * Adds a PropertyChangeListener to the listener list. The listener is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8526
     * registered for all bound properties of this class, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8527
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8528
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8529
     *    <li>this Component's font ("font")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8530
     *    <li>this Component's background color ("background")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8531
     *    <li>this Component's foreground color ("foreground")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8532
     *    <li>this Component's focusability ("focusable")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8533
     *    <li>this Component's focus traversal keys enabled state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8534
     *        ("focusTraversalKeysEnabled")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8535
     *    <li>this Component's Set of FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8536
     *        ("forwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8537
     *    <li>this Component's Set of BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8538
     *        ("backwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8539
     *    <li>this Component's Set of UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8540
     *        ("upCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8541
     *    <li>this Component's preferred size ("preferredSize")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8542
     *    <li>this Component's minimum size ("minimumSize")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8543
     *    <li>this Component's maximum size ("maximumSize")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8544
     *    <li>this Component's name ("name")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8545
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8546
     * Note that if this {@code Component} is inheriting a bound property, then no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8547
     * event will be fired in response to a change in the inherited property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8548
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8549
     * If {@code listener} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8550
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8551
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8552
     * @param    listener  the property change listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8554
     * @see #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8555
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8556
     * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8557
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8558
    public void addPropertyChangeListener(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8559
                                                       PropertyChangeListener listener) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8560
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8561
            if (listener == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8562
                return;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8563
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8564
            if (changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8565
                changeSupport = new PropertyChangeSupport(this);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8566
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8567
            changeSupport.addPropertyChangeListener(listener);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8568
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8572
     * Removes a PropertyChangeListener from the listener list. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8573
     * should be used to remove PropertyChangeListeners that were registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8574
     * for all bound properties of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8575
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8576
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8578
     * @param listener the PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8580
     * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8581
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8582
     * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8583
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8584
    public void removePropertyChangeListener(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8585
                                                          PropertyChangeListener listener) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8586
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8587
            if (listener == null || changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8588
                return;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8589
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8590
            changeSupport.removePropertyChangeListener(listener);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8591
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8593
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8595
     * Returns an array of all the property change listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8596
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8597
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8598
     * @return all of this component's {@code PropertyChangeListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8599
     *         or an empty array if no property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8600
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8601
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8602
     * @see      #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8603
     * @see      #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8604
     * @see      #getPropertyChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8605
     * @see      java.beans.PropertyChangeSupport#getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8606
     * @since    1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8607
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8608
    public PropertyChangeListener[] getPropertyChangeListeners() {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8609
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8610
            if (changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8611
                return new PropertyChangeListener[0];
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8612
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8613
            return changeSupport.getPropertyChangeListeners();
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8614
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8617
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8618
     * Adds a PropertyChangeListener to the listener list for a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8619
     * property. The specified property may be user-defined, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8620
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8621
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8622
     *    <li>this Component's font ("font")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8623
     *    <li>this Component's background color ("background")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8624
     *    <li>this Component's foreground color ("foreground")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8625
     *    <li>this Component's focusability ("focusable")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8626
     *    <li>this Component's focus traversal keys enabled state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8627
     *        ("focusTraversalKeysEnabled")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8628
     *    <li>this Component's Set of FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8629
     *        ("forwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8630
     *    <li>this Component's Set of BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8631
     *        ("backwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8632
     *    <li>this Component's Set of UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8633
     *        ("upCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8634
     * </ul>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8635
     * Note that if this {@code Component} is inheriting a bound property, then no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8636
     * event will be fired in response to a change in the inherited property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8637
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8638
     * If {@code propertyName} or {@code listener} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8639
     * no exception is thrown and no action is taken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8640
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8641
     * @param propertyName one of the property names listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8642
     * @param listener the property change listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8643
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8644
     * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8645
     * @see #getPropertyChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8646
     * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8647
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8648
    public void addPropertyChangeListener(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8649
                                                       String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8650
                                                       PropertyChangeListener listener) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8651
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8652
            if (listener == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8653
                return;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8654
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8655
            if (changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8656
                changeSupport = new PropertyChangeSupport(this);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8657
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8658
            changeSupport.addPropertyChangeListener(propertyName, listener);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8659
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8662
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8663
     * Removes a {@code PropertyChangeListener} from the listener
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8664
     * list for a specific property. This method should be used to remove
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8665
     * {@code PropertyChangeListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8666
     * that were registered for a specific bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8667
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8668
     * If {@code propertyName} or {@code listener} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8669
     * no exception is thrown and no action is taken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8670
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8671
     * @param propertyName a valid property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8672
     * @param listener the PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8673
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8674
     * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8675
     * @see #getPropertyChangeListeners(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8676
     * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8677
     */
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8678
    public void removePropertyChangeListener(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8679
                                                          String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8680
                                                          PropertyChangeListener listener) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8681
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8682
            if (listener == null || changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8683
                return;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8684
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8685
            changeSupport.removePropertyChangeListener(propertyName, listener);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8686
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8689
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8690
     * Returns an array of all the listeners which have been associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8691
     * with the named property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8692
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  8693
     * @param  propertyName the property name
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8694
     * @return all of the {@code PropertyChangeListener}s associated with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8695
     *         the named property; if no such listeners have been added or
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8696
     *         if {@code propertyName} is {@code null}, an empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8697
     *         array is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8699
     * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8700
     * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8701
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8702
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8703
     */
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  8704
    public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8705
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8706
            if (changeSupport == null) {
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8707
                return new PropertyChangeListener[0];
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8708
            }
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8709
            return changeSupport.getPropertyChangeListeners(propertyName);
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8710
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8713
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8714
     * Support for reporting bound property changes for Object properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8715
     * This method can be called when a bound property has changed and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8716
     * send the appropriate PropertyChangeEvent to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8717
     * PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8719
     * @param propertyName the property whose value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8720
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8721
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8723
    protected void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8724
                                      Object oldValue, Object newValue) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8725
        PropertyChangeSupport changeSupport;
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  8726
        synchronized (getObjectLock()) {
123
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8727
            changeSupport = this.changeSupport;
96a10460ed63 6608764: PropertyChangeListeners machinery should have a better locking scheme
anthony
parents: 121
diff changeset
  8728
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8729
        if (changeSupport == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8730
            (oldValue != null && newValue != null && oldValue.equals(newValue))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8731
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8733
        changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8737
     * Support for reporting bound property changes for boolean properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8738
     * This method can be called when a bound property has changed and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8739
     * send the appropriate PropertyChangeEvent to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8740
     * PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8741
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8742
     * @param propertyName the property whose value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8743
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8744
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8745
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8747
    protected void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8748
                                      boolean oldValue, boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8749
        PropertyChangeSupport changeSupport = this.changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8750
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8751
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8753
        changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8756
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8757
     * Support for reporting bound property changes for integer properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8758
     * This method can be called when a bound property has changed and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8759
     * send the appropriate PropertyChangeEvent to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8760
     * PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8761
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8762
     * @param propertyName the property whose value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8763
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8764
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8765
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8767
    protected void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8768
                                      int oldValue, int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8769
        PropertyChangeSupport changeSupport = this.changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8770
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8771
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8773
        changeSupport.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8777
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8778
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8779
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8780
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8781
     * @param oldValue the old value of the property (as a byte)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8782
     * @param newValue the new value of the property (as a byte)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8783
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8784
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8785
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8786
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8787
    public void firePropertyChange(String propertyName, byte oldValue, byte newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8788
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8789
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8791
        firePropertyChange(propertyName, Byte.valueOf(oldValue), Byte.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8794
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8795
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8796
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8797
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8798
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8799
     * @param oldValue the old value of the property (as a char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8800
     * @param newValue the new value of the property (as a char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8801
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8802
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8803
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8805
    public void firePropertyChange(String propertyName, char oldValue, char newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8806
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8807
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8808
        }
25187
08aff438def8 8048874: Replace uses of 'new Byte', 'new Short' and 'new Character' with appropriate alternative across core classes
prappo
parents: 25162
diff changeset
  8809
        firePropertyChange(propertyName, Character.valueOf(oldValue), Character.valueOf(newValue));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8811
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8812
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8813
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8814
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8815
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8816
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8817
     * @param oldValue the old value of the property (as a short)
27502
4a8eca9c6f19 8061592: wrong javadoc parameters for firePropertyChange()
alexsch
parents: 26749
diff changeset
  8818
     * @param newValue the new value of the property (as a short)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8819
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8820
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8821
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8823
    public void firePropertyChange(String propertyName, short oldValue, short newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8824
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8825
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8827
        firePropertyChange(propertyName, Short.valueOf(oldValue), Short.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8831
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8832
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8833
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8834
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8835
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8836
     * @param oldValue the old value of the property (as a long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8837
     * @param newValue the new value of the property (as a long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8838
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8839
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8840
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8841
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8842
    public void firePropertyChange(String propertyName, long oldValue, long newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8843
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8844
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8846
        firePropertyChange(propertyName, Long.valueOf(oldValue), Long.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8849
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8850
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8852
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8853
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8854
     * @param oldValue the old value of the property (as a float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8855
     * @param newValue the new value of the property (as a float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8856
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8857
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8858
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8860
    public void firePropertyChange(String propertyName, float oldValue, float newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8861
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8862
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8864
        firePropertyChange(propertyName, Float.valueOf(oldValue), Float.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8867
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8868
     * Reports a bound property change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8869
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8870
     * @param propertyName the programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8871
     *          that was changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8872
     * @param oldValue the old value of the property (as a double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8873
     * @param newValue the new value of the property (as a double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8874
     * @see #firePropertyChange(java.lang.String, java.lang.Object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8875
     *          java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8876
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8877
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8878
    public void firePropertyChange(String propertyName, double oldValue, double newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8879
        if (changeSupport == null || oldValue == newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8880
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8882
        firePropertyChange(propertyName, Double.valueOf(oldValue), Double.valueOf(newValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8883
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8886
    // Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8887
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8888
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8889
     * Component Serialized Data Version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8890
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8891
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8892
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8893
    private int componentSerializedDataVersion = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8895
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8896
     * This hack is for Swing serialization. It will invoke
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8897
     * the Swing package private method {@code compWriteObjectNotify}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8898
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8899
    private void doSwingSerialization() {
40719
4ae72a69bd3b 8129854: Remove reflection from AWT/Swing classes
alexsch
parents: 38390
diff changeset
  8900
        if (!(this instanceof JComponent)) {
4ae72a69bd3b 8129854: Remove reflection from AWT/Swing classes
alexsch
parents: 38390
diff changeset
  8901
            return;
4ae72a69bd3b 8129854: Remove reflection from AWT/Swing classes
alexsch
parents: 38390
diff changeset
  8902
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35667
diff changeset
  8903
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8904
        Package swingPackage = Package.getPackage("javax.swing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8905
        // For Swing serialization to correctly work Swing needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8906
        // be notified before Component does it's serialization.  This
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  8907
        // hack accommodates this.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8908
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8909
        // Swing classes MUST be loaded by the bootstrap class loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8910
        // otherwise we don't consider them.
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  8911
        for (Class<?> klass = Component.this.getClass(); klass != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8912
                   klass = klass.getSuperclass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8913
            if (klass.getPackage() == swingPackage &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8914
                      klass.getClassLoader() == null) {
40719
4ae72a69bd3b 8129854: Remove reflection from AWT/Swing classes
alexsch
parents: 38390
diff changeset
  8915
4ae72a69bd3b 8129854: Remove reflection from AWT/Swing classes
alexsch
parents: 38390
diff changeset
  8916
                SwingAccessor.getJComponentAccessor()
4ae72a69bd3b 8129854: Remove reflection from AWT/Swing classes
alexsch
parents: 38390
diff changeset
  8917
                        .compWriteObjectNotify((JComponent) this);
4ae72a69bd3b 8129854: Remove reflection from AWT/Swing classes
alexsch
parents: 38390
diff changeset
  8918
                return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8919
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8923
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8924
     * Writes default serializable fields to stream.  Writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8925
     * a variety of serializable listeners as optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8926
     * The non-serializable listeners are detected and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8927
     * no attempt is made to serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8928
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8929
     * @param s the {@code ObjectOutputStream} to write
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8930
     * @serialData {@code null} terminated sequence of
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8931
     *   0 or more pairs; the pair consists of a {@code String}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8932
     *   and an {@code Object}; the {@code String} indicates
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8933
     *   the type of object and is one of the following (as of 1.4):
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8934
     *   {@code componentListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8935
     *     {@code ComponentListener} object;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8936
     *   {@code focusListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8937
     *     {@code FocusListener} object;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8938
     *   {@code keyListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8939
     *     {@code KeyListener} object;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8940
     *   {@code mouseListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8941
     *     {@code MouseListener} object;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8942
     *   {@code mouseMotionListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8943
     *     {@code MouseMotionListener} object;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8944
     *   {@code inputMethodListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8945
     *     {@code InputMethodListener} object;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8946
     *   {@code hierarchyListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8947
     *     {@code HierarchyListener} object;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8948
     *   {@code hierarchyBoundsListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8949
     *     {@code HierarchyBoundsListener} object;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8950
     *   {@code mouseWheelListenerK} indicating an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8951
     *     {@code MouseWheelListener} object
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8952
     * @serialData an optional {@code ComponentOrientation}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8953
     *    (after {@code inputMethodListener}, as of 1.2)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8954
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8955
     * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8956
     * @see #componentListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8957
     * @see #focusListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8958
     * @see #keyListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8959
     * @see #mouseListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8960
     * @see #mouseMotionListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8961
     * @see #inputMethodListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8962
     * @see #hierarchyListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8963
     * @see #hierarchyBoundsListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8964
     * @see #mouseWheelListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8965
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8967
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8968
      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8969
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8970
        doSwingSerialization();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8972
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8974
        AWTEventMulticaster.save(s, componentListenerK, componentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8975
        AWTEventMulticaster.save(s, focusListenerK, focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8976
        AWTEventMulticaster.save(s, keyListenerK, keyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8977
        AWTEventMulticaster.save(s, mouseListenerK, mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8978
        AWTEventMulticaster.save(s, mouseMotionListenerK, mouseMotionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8979
        AWTEventMulticaster.save(s, inputMethodListenerK, inputMethodListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8980
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8981
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8982
        s.writeObject(componentOrientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8984
        AWTEventMulticaster.save(s, hierarchyListenerK, hierarchyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8985
        AWTEventMulticaster.save(s, hierarchyBoundsListenerK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8986
                                 hierarchyBoundsListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8987
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8989
        AWTEventMulticaster.save(s, mouseWheelListenerK, mouseWheelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8990
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8991
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8994
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8995
     * Reads the {@code ObjectInputStream} and if it isn't
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  8996
     * {@code null} adds a listener to receive a variety
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8997
     * of events fired by the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8998
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  8999
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9000
     * @param s the {@code ObjectInputStream} to read
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9001
     * @see #writeObject(ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9002
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9003
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9004
      throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9005
    {
1169
23b1850f7d73 6708322: test/closed/java/awt/Focus/TemporaryLostComponentDeadlock fails
ant
parents: 635
diff changeset
  9006
        objectLock = new Object();
432
ff3aa6ee3572 6681889: JSN security test headline/noWarningApp failed with NPE exception
anthony
parents: 130
diff changeset
  9007
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
  9008
        acc = AccessController.getContext();
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
  9009
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9010
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9012
        appContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9013
        coalescingEnabled = checkCoalescing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9014
        if (componentSerializedDataVersion < 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9015
            // These fields are non-transient and rely on default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9016
            // serialization. However, the default values are insufficient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9017
            // so we need to set them explicitly for object data streams prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9018
            // to 1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9019
            focusable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9020
            isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9021
            initializeFocusTraversalKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9022
            focusTraversalKeysEnabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9025
        Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9026
        while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9027
            String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9029
            if (componentListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9030
                addComponentListener((ComponentListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9032
            else if (focusListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9033
                addFocusListener((FocusListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9035
            else if (keyListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9036
                addKeyListener((KeyListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9038
            else if (mouseListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9039
                addMouseListener((MouseListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9041
            else if (mouseMotionListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9042
                addMouseMotionListener((MouseMotionListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9044
            else if (inputMethodListenerK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9045
                addInputMethodListener((InputMethodListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9047
            else // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9048
                s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9050
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9052
        // Read the component's orientation if it's present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9053
        Object orient = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9055
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9056
            orient = s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9057
        } catch (java.io.OptionalDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9058
            // JDK 1.1 instances will not have this optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9059
            // e.eof will be true to indicate that there is no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9060
            // data available for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9061
            // If e.eof is not true, throw the exception as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9062
            // might have been caused by reasons unrelated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9063
            // componentOrientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9065
            if (!e.eof)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9066
                throw (e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9067
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9070
        if (orient != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9071
            componentOrientation = (ComponentOrientation)orient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9072
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9073
            componentOrientation = ComponentOrientation.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9076
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9077
            while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9078
                String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9080
                if (hierarchyListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9081
                    addHierarchyListener((HierarchyListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9082
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9083
                else if (hierarchyBoundsListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9084
                    addHierarchyBoundsListener((HierarchyBoundsListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9085
                                               (s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9086
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9087
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9088
                    // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9089
                    s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9090
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9091
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9092
        } catch (java.io.OptionalDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9093
            // JDK 1.1/1.2 instances will not have this optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9094
            // e.eof will be true to indicate that there is no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9095
            // data available for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9096
            // If e.eof is not true, throw the exception as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9097
            // might have been caused by reasons unrelated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9098
            // hierarchy and hierarchyBounds listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9100
            if (!e.eof)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9101
                throw (e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9105
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9106
            while (null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9107
                String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9109
                if (mouseWheelListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9110
                    addMouseWheelListener((MouseWheelListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9111
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9112
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9113
                    // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9114
                    s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9117
        } catch (java.io.OptionalDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9118
            // pre-1.3 instances will not have this optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9119
            // e.eof will be true to indicate that there is no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9120
            // data available for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9121
            // If e.eof is not true, throw the exception as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9122
            // might have been caused by reasons unrelated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9123
            // mouse wheel listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9125
            if (!e.eof)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9126
                throw (e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9130
        if (popups != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9131
            int npopups = popups.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9132
            for (int i = 0 ; i < npopups ; i++) {
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
  9133
                PopupMenu popup = popups.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9134
                popup.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9140
     * Sets the language-sensitive orientation that is to be used to order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9141
     * the elements or text within this component.  Language-sensitive
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9142
     * {@code LayoutManager} and {@code Component}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9143
     * subclasses will use this property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9144
     * determine how to lay out and draw components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9145
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9146
     * At construction time, a component's orientation is set to
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9147
     * {@code ComponentOrientation.UNKNOWN},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9148
     * indicating that it has not been specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9149
     * explicitly.  The UNKNOWN orientation behaves the same as
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9150
     * {@code ComponentOrientation.LEFT_TO_RIGHT}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9151
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9152
     * To set the orientation of a single component, use this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9153
     * To set the orientation of an entire component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9154
     * hierarchy, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9155
     * {@link #applyComponentOrientation applyComponentOrientation}.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9156
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9157
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9158
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9159
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9160
     * @param  o the orientation to be set
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9162
     * @see ComponentOrientation
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9163
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9165
     * @author Laura Werner, IBM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9167
    public void setComponentOrientation(ComponentOrientation o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9168
        ComponentOrientation oldValue = componentOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9169
        componentOrientation = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9171
        // This is a bound property, so report the change to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9172
        // any registered listeners.  (Cheap if there are none.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9173
        firePropertyChange("componentOrientation", oldValue, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9175
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
  9176
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9180
     * Retrieves the language-sensitive orientation that is to be used to order
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9181
     * the elements or text within this component.  {@code LayoutManager}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9182
     * and {@code Component}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9183
     * subclasses that wish to respect orientation should call this method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9184
     * get the component's orientation before performing layout or drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9185
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9186
     * @return the orientation to order the elements or text
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9187
     * @see ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9189
     * @author Laura Werner, IBM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9191
    public ComponentOrientation getComponentOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9192
        return componentOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9195
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9196
     * Sets the {@code ComponentOrientation} property of this component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9197
     * and all components contained within it.
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9198
     * <p>
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9199
     * This method changes layout-related information, and therefore,
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9200
     * invalidates the component hierarchy.
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9201
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9203
     * @param orientation the new component orientation of this component and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9204
     *        the components contained within it.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9205
     * @exception NullPointerException if {@code orientation} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9206
     * @see #setComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9207
     * @see #getComponentOrientation
3966
0ce65d9e45e2 6868255: Requirements for correct operating of the HW/LW Mixing feature need to be specified
anthony
parents: 3729
diff changeset
  9208
     * @see #invalidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9209
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9211
    public void applyComponentOrientation(ComponentOrientation orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9212
        if (orientation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9213
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9215
        setComponentOrientation(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9217
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9218
    final boolean canBeFocusOwner() {
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9219
        // It is enabled, visible, focusable.
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9220
        if (isEnabled() && isDisplayable() && isVisible() && isFocusable()) {
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9221
            return true;
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9222
        }
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9223
        return false;
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9224
    }
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9225
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9226
    /**
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  9227
     * Checks that this component meets the prerequisites to be focus owner:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9228
     * - it is enabled, visible, focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9229
     * - it's parents are all enabled and showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9230
     * - top-level window is focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9231
     * - if focus cycle root has DefaultFocusTraversalPolicy then it also checks that this policy accepts
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9232
     * this component as focus owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9233
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9234
     */
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9235
    final boolean canBeFocusOwnerRecursively() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9236
        // - it is enabled, visible, focusable
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 1169
diff changeset
  9237
        if (!canBeFocusOwner()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9238
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9241
        // - it's parents are all enabled and showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9242
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9243
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9244
                return parent.canContainFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9247
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9250
    /**
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9251
     * Fix the location of the HW component in a LW container hierarchy.
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9252
     */
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9253
    final void relocateComponent() {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9254
        synchronized (getTreeLock()) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9255
            if (peer == null) {
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9256
                return;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9257
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9258
            int nativeX = x;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9259
            int nativeY = y;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9260
            for (Component cont = getContainer();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9261
                    cont != null && cont.isLightweight();
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9262
                    cont = cont.getContainer())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9263
            {
130
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9264
                nativeX += cont.x;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9265
                nativeY += cont.y;
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9266
            }
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9267
            peer.setBounds(nativeX, nativeY, width, height,
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9268
                    ComponentPeer.SET_LOCATION);
11eb29307cfb 4993545: NativeInLightFixer adds asynchronousity
anthony
parents: 126
diff changeset
  9269
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9272
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9273
     * Returns the {@code Window} ancestor of the component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9274
     * @return Window ancestor of the component or component by itself if it is Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9275
     *         null, if component is not a part of window hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9277
    Window getContainingWindow() {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
  9278
        return SunToolkit.getContainingWindow(this);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
  9279
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9282
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9284
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9286
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9287
     * --- Accessibility Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9289
     *  Component will contain all of the methods in interface Accessible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9290
     *  though it won't actually implement the interface - that will be up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9291
     *  to the individual objects which extend Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9293
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9294
    /**
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9295
     * The {@code AccessibleContext} associated with this {@code Component}.
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9296
     */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 55172
diff changeset
  9297
    @SuppressWarnings("serial") // Not statically typed as Serializable
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9298
    protected AccessibleContext accessibleContext = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9300
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9301
     * Gets the {@code AccessibleContext} associated
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9302
     * with this {@code Component}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9303
     * The method implemented by this base
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9304
     * class returns null.  Classes that extend {@code Component}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9305
     * should implement this method to return the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9306
     * {@code AccessibleContext} associated with the subclass.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9307
     *
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9308
     *
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9309
     * @return the {@code AccessibleContext} of this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9310
     *    {@code Component}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9311
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9313
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9314
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9318
     * Inner class of Component used to provide default support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9319
     * accessibility.  This class is not meant to be used directly by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9320
     * application developers, but is instead meant only to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9321
     * subclassed by component developers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9322
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9323
     * The class used to obtain the accessible role for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9324
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9326
    protected abstract class AccessibleAWTComponent extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9327
        implements Serializable, AccessibleComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9329
        private static final long serialVersionUID = 642321655757800191L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9331
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9332
         * Though the class is abstract, this should be called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9333
         * all sub-classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9334
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9335
        protected AccessibleAWTComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9337
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9338
        /**
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9339
         * Number of PropertyChangeListener objects registered. It's used
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9340
         * to add/remove ComponentListener and FocusListener to track
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9341
         * target Component's state.
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9342
         */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31897
diff changeset
  9343
        private transient volatile int propertyListenersCount = 0;
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9344
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9345
        /**
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9346
         * A component listener to track show/hide/resize events
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9347
         * and convert them to PropertyChange events.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9348
         */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 55172
diff changeset
  9349
        @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9350
        protected ComponentListener accessibleAWTComponentHandler = null;
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9351
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9352
        /**
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9353
         * A listener to track focus events
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9354
         * and convert them to PropertyChange events.
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
  9355
         */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 55172
diff changeset
  9356
        @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9357
        protected FocusListener accessibleAWTFocusHandler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9359
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9360
         * Fire PropertyChange listener, if one is registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9361
         * when shown/hidden..
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9362
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9363
         */
48726
4b622ca57277 8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents: 47971
diff changeset
  9364
        protected class AccessibleAWTComponentHandler implements ComponentListener, Serializable {
4b622ca57277 8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents: 47971
diff changeset
  9365
            private static final long serialVersionUID = -1009684107426231869L;
4b622ca57277 8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents: 47971
diff changeset
  9366
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9367
            public void componentHidden(ComponentEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9368
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9369
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9370
                                                         AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9371
                                                         AccessibleState.VISIBLE, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9375
            public void componentShown(ComponentEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9376
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9377
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9378
                                                         AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9379
                                                         null, AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9380
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9383
            public void componentMoved(ComponentEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9386
            public void componentResized(ComponentEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9388
        } // inner class AccessibleAWTComponentHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9391
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9392
         * Fire PropertyChange listener, if one is registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9393
         * when focus events happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9394
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9395
         */
48726
4b622ca57277 8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents: 47971
diff changeset
  9396
        protected class AccessibleAWTFocusHandler implements FocusListener, Serializable {
4b622ca57277 8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents: 47971
diff changeset
  9397
            private static final long serialVersionUID = 3150908257351582233L;
4b622ca57277 8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents: 47971
diff changeset
  9398
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9399
            public void focusGained(FocusEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9400
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9401
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9402
                                                         AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9403
                                                         null, AccessibleState.FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9404
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9406
            public void focusLost(FocusEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9407
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9408
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9409
                                                         AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9410
                                                         AccessibleState.FOCUSED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9413
        }  // inner class AccessibleAWTFocusHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9416
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9417
         * Adds a {@code PropertyChangeListener} to the listener list.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9418
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9419
         * @param listener  the property change listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9420
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9421
        public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9422
            if (accessibleAWTComponentHandler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9423
                accessibleAWTComponentHandler = new AccessibleAWTComponentHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9425
            if (accessibleAWTFocusHandler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9426
                accessibleAWTFocusHandler = new AccessibleAWTFocusHandler();
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9427
            }
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9428
            if (propertyListenersCount++ == 0) {
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9429
                Component.this.addComponentListener(accessibleAWTComponentHandler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9430
                Component.this.addFocusListener(accessibleAWTFocusHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9432
            super.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9435
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9436
         * Remove a PropertyChangeListener from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9437
         * This removes a PropertyChangeListener that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9438
         * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9439
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9440
         * @param listener  The PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9441
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9442
        public void removePropertyChangeListener(PropertyChangeListener listener) {
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 15318
diff changeset
  9443
            if (--propertyListenersCount == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9444
                Component.this.removeComponentListener(accessibleAWTComponentHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9445
                Component.this.removeFocusListener(accessibleAWTFocusHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9447
            super.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9450
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9451
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9452
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9453
         * Gets the accessible name of this object.  This should almost never
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9454
         * return {@code java.awt.Component.getName()},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9455
         * as that generally isn't a localized name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9456
         * and doesn't have meaning for the user.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9457
         * object is fundamentally a text object (e.g. a menu item), the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9458
         * accessible name should be the text of the object (e.g. "save").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9459
         * If the object has a tooltip, the tooltip text may also be an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9460
         * appropriate String to return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9461
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9462
         * @return the localized name of the object -- can be
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9463
         *         {@code null} if this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9464
         *         object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9465
         * @see javax.accessibility.AccessibleContext#setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9466
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9467
        public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9468
            return accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9471
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9472
         * Gets the accessible description of this object.  This should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9473
         * a concise, localized description of what this object is - what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9474
         * is its meaning to the user.  If the object has a tooltip, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9475
         * tooltip text may be an appropriate string to return, assuming
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9476
         * it contains a concise description of the object (instead of just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9477
         * the name of the object - e.g. a "Save" icon on a toolbar that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9478
         * had "save" as the tooltip text shouldn't return the tooltip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9479
         * text as the description, but something like "Saves the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9480
         * text document" instead).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9481
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9482
         * @return the localized description of the object -- can be
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9483
         *        {@code null} if this object does not have a description
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9484
         * @see javax.accessibility.AccessibleContext#setAccessibleDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9485
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9486
        public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9487
            return accessibleDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9490
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9491
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9492
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9493
         * @return an instance of {@code AccessibleRole}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9494
         *      describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9495
         * @see javax.accessibility.AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9496
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9497
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9498
            return AccessibleRole.AWT_COMPONENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9501
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9502
         * Gets the state of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9503
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9504
         * @return an instance of {@code AccessibleStateSet}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9505
         *       containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9506
         * @see javax.accessibility.AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9507
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9508
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9509
            return Component.this.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9512
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9513
         * Gets the {@code Accessible} parent of this object.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9514
         * If the parent of this object implements {@code Accessible},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9515
         * this method should simply return {@code getParent}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9516
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9517
         * @return the {@code Accessible} parent of this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9518
         *      object -- can be {@code null} if this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9519
         *      object does not have an {@code Accessible} parent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9520
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9521
        public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9522
            if (accessibleParent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9523
                return accessibleParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9524
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9525
                Container parent = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9526
                if (parent instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9527
                    return (Accessible) parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9530
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9533
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9534
         * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9535
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9536
         * @return the index of this object in its parent; or -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9537
         *    object does not have an accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9538
         * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9539
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9540
        public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9541
            return Component.this.getAccessibleIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9544
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9545
         * Returns the number of accessible children in the object.  If all
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9546
         * of the children of this object implement {@code Accessible},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9547
         * then this method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9548
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9549
         * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9550
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9551
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9552
            return 0; // Components don't have children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9555
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9556
         * Returns the nth {@code Accessible} child of the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9557
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9558
         * @param i zero-based index of child
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9559
         * @return the nth {@code Accessible} child of the object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9560
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9561
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9562
            return null; // Components don't have children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9565
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9566
         * Returns the locale of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9567
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9568
         * @return the locale of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9569
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9570
        public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9571
            return Component.this.getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9574
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9575
         * Gets the {@code AccessibleComponent} associated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9576
         * with this object if one exists.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9577
         * Otherwise return {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9578
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9579
         * @return the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9580
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9581
        public AccessibleComponent getAccessibleComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9582
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9586
        // AccessibleComponent methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9587
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9588
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9589
         * Gets the background color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9590
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9591
         * @return the background color, if supported, of the object;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9592
         *      otherwise, {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9593
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9594
        public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9595
            return Component.this.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9598
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9599
         * Sets the background color of this object.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9600
         * (For transparency, see {@code isOpaque}.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9601
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9602
         * @param c the new {@code Color} for the background
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9603
         * @see Component#isOpaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9604
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9605
        public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9606
            Component.this.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9609
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9610
         * Gets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9611
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9612
         * @return the foreground color, if supported, of the object;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9613
         *     otherwise, {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9614
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9615
        public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9616
            return Component.this.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9619
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9620
         * Sets the foreground color of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9621
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9622
         * @param c the new {@code Color} for the foreground
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9623
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9624
        public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9625
            Component.this.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9628
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9629
         * Gets the {@code Cursor} of this object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9630
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9631
         * @return the {@code Cursor}, if supported,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9632
         *     of the object; otherwise, {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9633
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9634
        public Cursor getCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9635
            return Component.this.getCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9638
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9639
         * Sets the {@code Cursor} of this object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9640
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9641
         * The method may have no visual effect if the Java platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9642
         * implementation and/or the native system do not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9643
         * changing the mouse cursor shape.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9644
         * @param cursor the new {@code Cursor} for the object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9645
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9646
        public void setCursor(Cursor cursor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9647
            Component.this.setCursor(cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9650
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9651
         * Gets the {@code Font} of this object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9652
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9653
         * @return the {@code Font}, if supported,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9654
         *    for the object; otherwise, {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9655
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9656
        public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9657
            return Component.this.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9660
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9661
         * Sets the {@code Font} of this object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9662
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9663
         * @param f the new {@code Font} for the object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9664
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9665
        public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9666
            Component.this.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9669
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9670
         * Gets the {@code FontMetrics} of this object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9671
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9672
         * @param f the {@code Font}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9673
         * @return the {@code FontMetrics}, if supported,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9674
         *     the object; otherwise, {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9675
         * @see #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9676
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9677
        public FontMetrics getFontMetrics(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9678
            if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9679
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9680
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9681
                return Component.this.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9682
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9683
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9685
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9686
         * Determines if the object is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9687
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9688
         * @return true if object is enabled; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9689
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9690
        public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9691
            return Component.this.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9693
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9694
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9695
         * Sets the enabled state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9696
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9697
         * @param b if true, enables this object; otherwise, disables it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9698
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9699
        public void setEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9700
            boolean old = Component.this.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9701
            Component.this.setEnabled(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9702
            if (b != old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9703
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9704
                    if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9705
                        accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9706
                                                             AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9707
                                                             null, AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9708
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9709
                        accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9710
                                                             AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9711
                                                             AccessibleState.ENABLED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9712
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9713
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9717
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9718
         * Determines if the object is visible.  Note: this means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9719
         * object intends to be visible; however, it may not in fact be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9720
         * showing on the screen because one of the objects that this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9721
         * is contained by is not visible.  To determine if an object is
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9722
         * showing on the screen, use {@code isShowing}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9723
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9724
         * @return true if object is visible; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9725
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9726
        public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9727
            return Component.this.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9730
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9731
         * Sets the visible state of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9732
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9733
         * @param b if true, shows this object; otherwise, hides it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9734
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9735
        public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9736
            boolean old = Component.this.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9737
            Component.this.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9738
            if (b != old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9739
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9740
                    if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9741
                        accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9742
                                                             AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9743
                                                             null, AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9744
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9745
                        accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9746
                                                             AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9747
                                                             AccessibleState.VISIBLE, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9748
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9749
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9753
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9754
         * Determines if the object is showing.  This is determined by checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9755
         * the visibility of the object and ancestors of the object.  Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9756
         * this will return true even if the object is obscured by another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9757
         * (for example, it happens to be underneath a menu that was pulled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9758
         * down).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9759
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9760
         * @return true if object is showing; otherwise, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9761
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9762
        public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9763
            return Component.this.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9766
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9767
         * Checks whether the specified point is within this object's bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9768
         * where the point's x and y coordinates are defined to be relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9769
         * the coordinate system of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9770
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9771
         * @param p the {@code Point} relative to the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9772
         *     coordinate system of the object
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9773
         * @return true if object contains {@code Point}; otherwise false
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9774
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9775
        public boolean contains(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9776
            return Component.this.contains(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9779
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9780
         * Returns the location of the object on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9781
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9782
         * @return location of object on screen -- can be
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9783
         *    {@code null} if this object is not on the screen
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9784
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9785
        public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9786
            synchronized (Component.this.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9787
                if (Component.this.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9788
                    return Component.this.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9789
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9790
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9791
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9795
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9796
         * Gets the location of the object relative to the parent in the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9797
         * of a point specifying the object's top-left corner in the screen's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9798
         * coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9799
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9800
         * @return an instance of Point representing the top-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9801
         * the object's bounds in the coordinate space of the screen;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9802
         * {@code null} if this object or its parent are not on the screen
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9803
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9804
        public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9805
            return Component.this.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9806
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9808
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9809
         * Sets the location of the object relative to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9810
         * @param p  the coordinates of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9811
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9812
        public void setLocation(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9813
            Component.this.setLocation(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9816
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9817
         * Gets the bounds of this object in the form of a Rectangle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9818
         * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9819
         * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9820
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9821
         * @return a rectangle indicating this component's bounds;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9822
         *   {@code null} if this object is not on the screen
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9823
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9824
        public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9825
            return Component.this.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9828
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9829
         * Sets the bounds of this object in the form of a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9830
         * {@code Rectangle} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9831
         * The bounds specify this object's width, height, and location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9832
         * relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9833
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9834
         * @param r a rectangle indicating this component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9835
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9836
        public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9837
            Component.this.setBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9840
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9841
         * Returns the size of this object in the form of a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9842
         * {@code Dimension} object. The height field of the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9843
         * {@code Dimension} object contains this object's
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9844
         * height, and the width field of the {@code Dimension}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9845
         * object contains this object's width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9846
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9847
         * @return a {@code Dimension} object that indicates
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9848
         *     the size of this component; {@code null} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9849
         *     this object is not on the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9850
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9851
        public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9852
            return Component.this.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9855
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9856
         * Resizes this object so that it has width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9857
         *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9858
         * @param d the dimension specifying the new size of the object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9859
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9860
        public void setSize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9861
            Component.this.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9864
        /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9865
         * Returns the {@code Accessible} child,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9866
         * if one exists, contained at the local
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9867
         * coordinate {@code Point}.  Otherwise returns
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9868
         * {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9869
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9870
         * @param p the point defining the top-left corner of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9871
         *      the {@code Accessible}, given in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9872
         *      coordinate space of the object's parent
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9873
         * @return the {@code Accessible}, if it exists,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9874
         *      at the specified location; else {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9875
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9876
        public Accessible getAccessibleAt(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9877
            return null; // Components don't have children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9880
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9881
         * Returns whether this object can accept focus or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9882
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9883
         * @return true if object can accept focus; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9884
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9885
        public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9886
            return Component.this.isFocusTraversable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9889
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9890
         * Requests focus for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9891
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9892
        public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9893
            Component.this.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9896
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9897
         * Adds the specified focus listener to receive focus events from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9898
         * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9899
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9900
         * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9901
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9902
        public void addFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9903
            Component.this.addFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9905
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9906
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9907
         * Removes the specified focus listener so it no longer receives focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9908
         * events from this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9909
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9910
         * @param l the focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9911
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9912
        public void removeFocusListener(FocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9913
            Component.this.removeFocusListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9916
    } // inner class AccessibleAWTComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9920
     * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9921
     * If this object does not have an accessible parent, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9922
     * -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9923
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9924
     * @return the index of this object in its accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9925
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9926
    int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9927
        synchronized (getTreeLock()) {
38390
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9928
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9929
            AccessibleContext accContext = getAccessibleContext();
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9930
            if (accContext == null) {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9931
                return -1;
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9932
            }
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9933
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9934
            Accessible parent = accContext.getAccessibleParent();
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9935
            if (parent == null) {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9936
                return -1;
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9937
            }
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9938
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9939
            accContext = parent.getAccessibleContext();
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9940
            for (int i = 0; i < accContext.getAccessibleChildrenCount(); i++) {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9941
                if (this.equals(accContext.getAccessibleChild(i))) {
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9942
                    return i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9943
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9944
            }
38390
233b57868492 8017112: JTabbedPane components have inconsistent accessibility tree
alexsch
parents: 37694
diff changeset
  9945
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9946
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9949
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9950
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9951
     * Gets the current state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9952
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  9953
     * @return an instance of {@code AccessibleStateSet}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9954
     *    containing the current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9955
     * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9956
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9957
    AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9958
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9959
            AccessibleStateSet states = new AccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9960
            if (this.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9961
                states.add(AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9963
            if (this.isFocusTraversable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9964
                states.add(AccessibleState.FOCUSABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9966
            if (this.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9967
                states.add(AccessibleState.VISIBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9969
            if (this.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9970
                states.add(AccessibleState.SHOWING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9971
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9972
            if (this.isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9973
                states.add(AccessibleState.FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9974
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9975
            if (this instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9976
                AccessibleContext ac = ((Accessible) this).getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9977
                if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9978
                    Accessible ap = ac.getAccessibleParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9979
                    if (ap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9980
                        AccessibleContext pac = ap.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9981
                        if (pac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9982
                            AccessibleSelection as = pac.getAccessibleSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9983
                            if (as != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9984
                                states.add(AccessibleState.SELECTABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9985
                                int i = ac.getAccessibleIndexInParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9986
                                if (i >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9987
                                    if (as.isAccessibleChildSelected(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9988
                                        states.add(AccessibleState.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9989
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9990
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9991
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9992
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9993
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9994
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9996
            if (Component.isInstanceOf(this, "javax.swing.JComponent")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9997
                if (((javax.swing.JComponent) this).isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9998
                    states.add(AccessibleState.OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  9999
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10000
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10001
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10003
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10004
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10005
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10006
     * Checks that the given object is instance of the given class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10007
     * @param obj Object to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10008
     * @param className The name of the class. Must be fully-qualified class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10009
     * @return true, if this object is instanceof given class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10010
     *         false, otherwise, or if obj or className is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10011
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10012
    static boolean isInstanceOf(Object obj, String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10013
        if (obj == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10014
        if (className == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10015
11270
d7b0b63bd082 7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents: 11094
diff changeset
 10016
        Class<?> cls = obj.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10017
        while (cls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10018
            if (cls.getName().equals(className)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10019
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10021
            cls = cls.getSuperclass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10023
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10024
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10025
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10026
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10027
    // ************************** MIXING CODE *******************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10028
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10029
    /**
126
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10030
     * Check whether we can trust the current bounds of the component.
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10031
     * The return value of false indicates that the container of the
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
 10032
     * component is invalid, and therefore needs to be laid out, which would
126
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10033
     * probably mean changing the bounds of its children.
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10034
     * Null-layout of the container or absence of the container mean
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10035
     * the bounds of the component are final and can be trusted.
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10036
     */
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10037
    final boolean areBoundsValid() {
126
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10038
        Container cont = getContainer();
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10039
        return cont == null || cont.isValid() || cont.getLayout() == null;
126
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10040
    }
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10041
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10042
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10043
     * Applies the shape to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10044
     * @param shape Shape to be applied to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10045
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10046
    void applyCompoundShape(Region shape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10047
        checkTreeLock();
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10048
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10049
        if (!areBoundsValid()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10050
            if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10051
                mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10052
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10053
            return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10054
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10055
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10056
        if (!isLightweight()) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
 10057
            ComponentPeer peer = this.peer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10058
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10059
                // The Region class has some optimizations. That's why
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10060
                // we should manually check whether it's empty and
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10061
                // substitute the object ourselves. Otherwise we end up
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10062
                // with some incorrect Region object with loX being
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10063
                // greater than the hiX for instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10064
                if (shape.isEmpty()) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10065
                    shape = Region.EMPTY_REGION;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10066
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10067
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10068
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10069
                // Note: the shape is not really copied/cloned. We create
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10070
                // the Region object ourselves, so there's no any possibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10071
                // to modify the object outside of the mixing code.
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10072
                // Nullifying compoundShape means that the component has normal shape
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10073
                // (or has no shape at all).
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10074
                if (shape.equals(getNormalShape())) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10075
                    if (this.compoundShape == null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10076
                        return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10077
                    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10078
                    this.compoundShape = null;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10079
                    peer.applyShape(null);
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10080
                } else {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10081
                    if (shape.equals(getAppliedShape())) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10082
                        return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10083
                    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10084
                    this.compoundShape = shape;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10085
                    Point compAbsolute = getLocationOnWindow();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10086
                    if (mixingLog.isLoggable(PlatformLogger.Level.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10087
                        mixingLog.fine("this = " + this +
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10088
                                "; compAbsolute=" + compAbsolute + "; shape=" + shape);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10089
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10090
                    peer.applyShape(shape.getTranslatedRegion(-compAbsolute.x, -compAbsolute.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10091
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10092
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10093
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10094
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10095
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10096
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10097
     * Returns the shape previously set with applyCompoundShape().
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10098
     * If the component is LW or no shape was applied yet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10099
     * the method returns the normal shape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10101
    private Region getAppliedShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10102
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10103
        //XXX: if we allow LW components to have a shape, this must be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10104
        return (this.compoundShape == null || isLightweight()) ? getNormalShape() : this.compoundShape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10106
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10107
    Point getLocationOnWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10108
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10109
        Point curLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10110
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10111
        for (Container parent = getContainer();
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10112
                parent != null && !(parent instanceof Window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10113
                parent = parent.getContainer())
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10114
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10115
            curLocation.x += parent.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10116
            curLocation.y += parent.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10118
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10119
        return curLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10121
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10123
     * Returns the full shape of the component located in window coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10125
    final Region getNormalShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10126
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10127
        //XXX: we may take into account a user-specified shape for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10128
        Point compAbsolute = getLocationOnWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10129
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10130
            Region.getInstanceXYWH(
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10131
                    compAbsolute.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10132
                    compAbsolute.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10133
                    getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10134
                    getHeight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10135
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10137
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10138
    /**
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10139
     * Returns the "opaque shape" of the component.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10140
     *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10141
     * The opaque shape of a lightweight components is the actual shape that
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10142
     * needs to be cut off of the heavyweight components in order to mix this
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10143
     * lightweight component correctly with them.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10144
     *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10145
     * The method is overriden in the java.awt.Container to handle non-opaque
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10146
     * containers containing opaque children.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10147
     *
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10148
     * See 6637655 for details.
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10149
     */
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10150
    Region getOpaqueShape() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10151
        checkTreeLock();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10152
        if (mixingCutoutRegion != null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10153
            return mixingCutoutRegion;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10154
        } else {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10155
            return getNormalShape();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10156
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10157
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10158
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10159
    final int getSiblingIndexAbove() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10160
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10161
        Container parent = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10162
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10163
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10165
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10166
        int nextAbove = parent.getComponentZOrder(this) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10167
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10168
        return nextAbove < 0 ? -1 : nextAbove;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10170
2462
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10171
    final ComponentPeer getHWPeerAboveMe() {
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10172
        checkTreeLock();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10173
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10174
        Container cont = getContainer();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10175
        int indexAbove = getSiblingIndexAbove();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10176
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10177
        while (cont != null) {
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10178
            for (int i = indexAbove; i > -1; i--) {
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10179
                Component comp = cont.getComponent(i);
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10180
                if (comp != null && comp.isDisplayable() && !comp.isLightweight()) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
 10181
                    return comp.peer;
2462
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10182
                }
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10183
            }
3727
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
 10184
            // traversing the hierarchy up to the closest HW container;
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
 10185
            // further traversing may return a component that is not actually
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
 10186
            // a native sibling of this component and this kind of z-order
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
 10187
            // request may not be allowed by the underlying system (6852051).
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
 10188
            if (!cont.isLightweight()) {
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
 10189
                break;
43b25dfd1129 6852051: Getting Null Pointer Exception when displaying message for TrayIcon on Opensolaris
dcherepanov
parents: 3237
diff changeset
 10190
            }
2462
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10191
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10192
            indexAbove = cont.getSiblingIndexAbove();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10193
            cont = cont.getContainer();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10194
        }
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10195
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10196
        return null;
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10197
    }
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
 10198
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10199
    final int getSiblingIndexBelow() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10200
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10201
        Container parent = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10202
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10203
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10205
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10206
        int nextBelow = parent.getComponentZOrder(this) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10207
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10208
        return nextBelow >= parent.getComponentCount() ? -1 : nextBelow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10210
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10211
    final boolean isNonOpaqueForMixing() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10212
        return mixingCutoutRegion != null &&
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10213
            mixingCutoutRegion.isEmpty();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10214
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10215
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10216
    private Region calculateCurrentShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10217
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10218
        Region s = getNormalShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10219
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10220
        if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10221
            mixingLog.fine("this = " + this + "; normalShape=" + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10223
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10224
        if (getContainer() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10225
            Component comp = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10226
            Container cont = comp.getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10227
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10228
            while (cont != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10229
                for (int index = comp.getSiblingIndexAbove(); index != -1; --index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10230
                    /* It is assumed that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10231
                     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10232
                     *    getComponent(getContainer().getComponentZOrder(comp)) == comp
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10233
                     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10234
                     * The assumption has been made according to the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10235
                     * implementation of the Container class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10236
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10237
                    Component c = cont.getComponent(index);
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10238
                    if (c.isLightweight() && c.isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10239
                        s = s.getDifference(c.getOpaqueShape());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10240
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10242
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10243
                if (cont.isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10244
                    s = s.getIntersection(cont.getNormalShape());
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10245
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10246
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10248
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10249
                comp = cont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10250
                cont = cont.getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10253
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10254
        if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10255
            mixingLog.fine("currentShape=" + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10257
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10258
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10260
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10261
    void applyCurrentShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10262
        checkTreeLock();
126
b37abdfa7875 6637796: setBounds doesn't enlarge Component
anthony
parents: 123
diff changeset
 10263
        if (!areBoundsValid()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10264
            if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10265
                mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10266
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10267
            return; // Because applyCompoundShape() ignores such components anyway
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10268
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10269
        if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10270
            mixingLog.fine("this = " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10272
        applyCompoundShape(calculateCurrentShape());
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10274
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10275
    final void subtractAndApplyShape(Region s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10276
        checkTreeLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10277
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10278
        if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10279
            mixingLog.fine("this = " + this + "; s=" + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10281
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10282
        applyCompoundShape(getAppliedShape().getDifference(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10284
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47970
diff changeset
 10285
    private void applyCurrentShapeBelowMe() {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10286
        checkTreeLock();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10287
        Container parent = getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10288
        if (parent != null && parent.isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10289
            // First, reapply shapes of my siblings
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10290
            parent.recursiveApplyCurrentShape(getSiblingIndexBelow());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10291
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10292
            // Second, if my container is non-opaque, reapply shapes of siblings of my container
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10293
            Container parent2 = parent.getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10294
            while (!parent.isOpaque() && parent2 != null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10295
                parent2.recursiveApplyCurrentShape(parent.getSiblingIndexBelow());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10296
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10297
                parent = parent2;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10298
                parent2 = parent.getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10299
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10300
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10301
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10302
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10303
    final void subtractAndApplyShapeBelowMe() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10304
        checkTreeLock();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10305
        Container parent = getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10306
        if (parent != null && isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10307
            Region opaqueShape = getOpaqueShape();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10308
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10309
            // First, cut my siblings
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10310
            parent.recursiveSubtractAndApplyShape(opaqueShape, getSiblingIndexBelow());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10311
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10312
            // Second, if my container is non-opaque, cut siblings of my container
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10313
            Container parent2 = parent.getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10314
            while (!parent.isOpaque() && parent2 != null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10315
                parent2.recursiveSubtractAndApplyShape(opaqueShape, parent.getSiblingIndexBelow());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10316
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10317
                parent = parent2;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10318
                parent2 = parent.getContainer();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10319
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10320
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10321
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10322
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10323
    void mixOnShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10324
        synchronized (getTreeLock()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10325
            if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10326
                mixingLog.fine("this = " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10327
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10328
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10329
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10330
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10331
            if (isLightweight()) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10332
                subtractAndApplyShapeBelowMe();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10333
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10334
                applyCurrentShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10338
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10339
    void mixOnHiding(boolean isLightweight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10340
        // We cannot be sure that the peer exists at this point, so we need the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10341
        //    to find out whether the hiding component is (well, actually was) a LW or a HW.
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10342
        synchronized (getTreeLock()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10343
            if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10344
                mixingLog.fine("this = " + this + "; isLightweight = " + isLightweight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10345
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10346
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10347
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10348
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10349
            if (isLightweight) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10350
                applyCurrentShapeBelowMe();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10351
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10354
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10355
    void mixOnReshaping() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10356
        synchronized (getTreeLock()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10357
            if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10358
                mixingLog.fine("this = " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10359
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10360
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10361
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10362
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10363
            if (isLightweight()) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10364
                applyCurrentShapeBelowMe();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10365
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10366
                applyCurrentShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10370
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10371
    void mixOnZOrderChanging(int oldZorder, int newZorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10372
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10373
            boolean becameHigher = newZorder < oldZorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10374
            Container parent = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10375
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10376
            if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10377
                mixingLog.fine("this = " + this +
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10378
                    "; oldZorder=" + oldZorder + "; newZorder=" + newZorder + "; parent=" + parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10379
            }
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10380
            if (!isMixingNeeded()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10381
                return;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10382
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10383
            if (isLightweight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10384
                if (becameHigher) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10385
                    if (parent != null && isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10386
                        parent.recursiveSubtractAndApplyShape(getOpaqueShape(), getSiblingIndexBelow(), oldZorder);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10387
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10388
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10389
                    if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10390
                        parent.recursiveApplyCurrentShape(oldZorder, newZorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10391
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10393
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10394
                if (becameHigher) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10395
                    applyCurrentShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10396
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10397
                    if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10398
                        Region shape = getAppliedShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10399
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10400
                        for (int index = oldZorder; index < newZorder; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10401
                            Component c = parent.getComponent(index);
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10402
                            if (c.isLightweight() && c.isShowing()) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10403
                                shape = shape.getDifference(c.getOpaqueShape());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10404
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10405
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10406
                        applyCompoundShape(shape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10407
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10412
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10413
    void mixOnValidating() {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10414
        // This method gets overriden in the Container. Obviously, a plain
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10415
        // non-container components don't need to handle validation.
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10416
    }
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 1181
diff changeset
 10417
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10418
    final boolean isMixingNeeded() {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10419
        if (SunToolkit.getSunAwtDisableMixing()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10420
            if (mixingLog.isLoggable(PlatformLogger.Level.FINEST)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10421
                mixingLog.finest("this = " + this + "; Mixing disabled via sun.awt.disableMixing");
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10422
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10423
            return false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10424
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10425
        if (!areBoundsValid()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10426
            if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10427
                mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10428
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10429
            return false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10430
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10431
        Window window = getContainingWindow();
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10432
        if (window != null) {
11982
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11270
diff changeset
 10433
            if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants() || window.isDisposing()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10434
                if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10435
                    mixingLog.fine("containing window = " + window +
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10436
                            "; has h/w descendants = " + window.hasHeavyweightDescendants() +
11982
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11270
diff changeset
 10437
                            "; has l/w descendants = " + window.hasLightweightDescendants() +
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11270
diff changeset
 10438
                            "; disposing = " + window.isDisposing());
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10439
                }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10440
                return false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10441
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10442
        } else {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17416
diff changeset
 10443
            if (mixingLog.isLoggable(PlatformLogger.Level.FINE)) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3932
diff changeset
 10444
                mixingLog.fine("this = " + this + "; containing window is null");
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10445
            }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10446
            return false;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10447
        }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10448
        return true;
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10449
    }
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 1964
diff changeset
 10450
41004
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10451
    /**
43724
a272f9475e44 8173409: make setMixingCutoutShape public and remove jdk.desktop
prr
parents: 43722
diff changeset
 10452
     * Sets a 'mixing-cutout' shape for this lightweight component.
a272f9475e44 8173409: make setMixingCutoutShape public and remove jdk.desktop
prr
parents: 43722
diff changeset
 10453
     *
a272f9475e44 8173409: make setMixingCutoutShape public and remove jdk.desktop
prr
parents: 43722
diff changeset
 10454
     * This method is used exclusively for the purposes of the
a272f9475e44 8173409: make setMixingCutoutShape public and remove jdk.desktop
prr
parents: 43722
diff changeset
 10455
     * Heavyweight/Lightweight Components Mixing feature and will
a272f9475e44 8173409: make setMixingCutoutShape public and remove jdk.desktop
prr
parents: 43722
diff changeset
 10456
     * have no effect if applied to a heavyweight component.
41004
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10457
     *
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10458
     * By default a lightweight component is treated as an opaque rectangle for
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10459
     * the purposes of the Heavyweight/Lightweight Components Mixing feature.
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10460
     * This method enables developers to set an arbitrary shape to be cut out
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10461
     * from heavyweight components positioned underneath the lightweight
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10462
     * component in the z-order.
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10463
     * <p>
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10464
     * The {@code shape} argument may have the following values:
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10465
     * <ul>
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10466
     * <li>{@code null} - reverts the default cutout shape (the rectangle equal
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10467
     * to the component's {@code getBounds()})
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10468
     * <li><i>empty-shape</i> - does not cut out anything from heavyweight
43724
a272f9475e44 8173409: make setMixingCutoutShape public and remove jdk.desktop
prr
parents: 43722
diff changeset
 10469
     * components. This makes this lightweight component effectively
41004
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10470
     * transparent. Note that descendants of the lightweight component still
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10471
     * affect the shapes of heavyweight components.  An example of an
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10472
     * <i>empty-shape</i> is {@code new Rectangle()}.
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10473
     * <li><i>non-empty-shape</i> - the given shape will be cut out from
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10474
     * heavyweight components.
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10475
     * </ul>
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10476
     * <p>
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10477
     * The most common example when the 'mixing-cutout' shape is needed is a
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43724
diff changeset
 10478
     * glass pane component. The {@link JRootPane#setGlassPane} method
41004
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10479
     * automatically sets the <i>empty-shape</i> as the 'mixing-cutout' shape
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10480
     * for the given glass pane component.  If a developer needs some other
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10481
     * 'mixing-cutout' shape for the glass pane (which is rare), this must be
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10482
     * changed manually after installing the glass pane to the root pane.
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10483
     *
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10484
     * @param shape the new 'mixing-cutout' shape
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10485
     * @since 9
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10486
     */
43724
a272f9475e44 8173409: make setMixingCutoutShape public and remove jdk.desktop
prr
parents: 43722
diff changeset
 10487
    public void setMixingCutoutShape(Shape shape) {
41004
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10488
        Region region = shape == null ? null : Region.getInstance(shape, null);
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10489
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10490
        synchronized (getTreeLock()) {
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10491
            boolean needShowing = false;
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10492
            boolean needHiding = false;
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10493
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10494
            if (!isNonOpaqueForMixing()) {
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10495
                needHiding = true;
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10496
            }
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10497
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10498
            mixingCutoutRegion = region;
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10499
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10500
            if (!isNonOpaqueForMixing()) {
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10501
                needShowing = true;
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10502
            }
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10503
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10504
            if (isMixingNeeded()) {
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10505
                if (needHiding) {
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10506
                    mixOnHiding(isLightweight());
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10507
                }
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10508
                if (needShowing) {
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10509
                    mixOnShowing();
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10510
                }
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10511
            }
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10512
        }
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10513
    }
01e8aabf5e7c 8164899: Provide package access to setComponentMixingCutoutShape
prr
parents: 40719
diff changeset
 10514
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10515
    // ****************** END OF MIXING CODE ********************************
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1978
diff changeset
 10516
2647
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10517
    // Note that the method is overriden in the Window class,
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10518
    // a window doesn't need to be updated in the Z-order.
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10519
    void updateZOrder() {
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10520
        peer.setZOrder(getHWPeerAboveMe());
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10521
    }
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
 10522
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
 10523
}