jdk/src/java.desktop/share/classes/javax/swing/JComponent.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26001 jdk/src/share/classes/javax/swing/JComponent.java@991e1be0b235
parent 25859 jdk/src/share/classes/javax/swing/JComponent.java@3317bb8137f4
child 27055 57d7b3b1463b
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
     2
 * Copyright (c) 1997, 2014, 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: 4261
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: 4261
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: 4261
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4261
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4261
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Dictionary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.image.VolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.dnd.DropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.font.FontRenderContext;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    46
import java.beans.PropertyChangeListener;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    47
import java.beans.VetoableChangeListener;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    48
import java.beans.VetoableChangeSupport;
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    49
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.io.ObjectInputValidation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import static javax.swing.ClientPropertyKey.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
25104
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24537
diff changeset
    66
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import sun.swing.UIClientPropertyKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * The base class for all Swing components except top-level containers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * To use a component that inherits from <code>JComponent</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * you must place the component in a containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * whose root is a top-level Swing container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Top-level Swing containers --
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * such as <code>JFrame</code>, <code>JDialog</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * and <code>JApplet</code> --
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * are specialized components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * that provide a place for other Swing components to paint themselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * For an explanation of containment hierarchies, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    82
 href="http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html">Swing Components and the Containment Hierarchy</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * The <code>JComponent</code> class provides:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <li>The base class for both standard and custom components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *     that use the Swing architecture.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 15506
diff changeset
    90
 * <li>A "pluggable look and feel" (L&amp;F) that can be specified by the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *     programmer or (optionally) selected by the user at runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *     The look and feel for each component is provided by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *     <em>UI delegate</em> -- an object that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *     {@link javax.swing.plaf.ComponentUI}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *     See <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    96
 * href="http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html">How
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *     to Set the Look and Feel</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *     in <em>The Java Tutorial</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *     for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <li>Comprehensive keystroke handling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *     See the document <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
   102
 * href="http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html">How to Use Key Bindings</a>,
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
   103
 *     an article in <em>The Java Tutorial</em>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *     for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <li>Support for tool tips --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *     short descriptions that pop up when the cursor lingers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *     over a component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *     See <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
   109
 * href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *     to Use Tool Tips</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *     in <em>The Java Tutorial</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *     for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * <li>Support for accessibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *     <code>JComponent</code> contains all of the methods in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *     <code>Accessible</code> interface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *     but it doesn't actually implement the interface.  That is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *     responsibility of the individual classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *     that extend <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <li>Support for component-specific properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *     With the {@link #putClientProperty}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *     and {@link #getClientProperty} methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *     you can associate name-object pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *     with any object that descends from <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <li>An infrastructure for painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *     that includes double buffering and support for borders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *     For more information see <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
   127
 * href="http://www.oracle.com/technetwork/java/painting-140037.html#swing">Painting</a> and
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
   128
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/border.htmll">How
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *     to Use Borders</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *     both of which are sections in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * For more information on these subjects, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * <a href="package-summary.html#package_description">Swing package description</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * and <em>The Java Tutorial</em> section
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
   135
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/jcomponent.html">The JComponent Class</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * <code>JComponent</code> and its subclasses document default values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * for certain properties.  For example, <code>JTable</code> documents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * default row height as 16.  Each <code>JComponent</code> subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * that has a <code>ComponentUI</code> will create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <code>ComponentUI</code> as part of its constructor.  In order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * to provide a particular look and feel each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <code>ComponentUI</code> may set properties back on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * <code>JComponent</code> that created it.  For example, a custom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * look and feel may require <code>JTable</code>s to have a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * height of 24. The documented defaults are the value of a property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * BEFORE the <code>ComponentUI</code> has been installed.  If you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * need a specific value for a particular property you should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * explicitly set it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * In release 1.4, the focus subsystem was rearchitected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * For more information, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
   153
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   167
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * @see KeyStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * @see #setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * @see #registerKeyboardAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * @see JOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * @see #setDebugGraphicsOptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * @see #setToolTipText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * @see #setAutoscrolls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * @author Arnaud Weber
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 25109
diff changeset
   182
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
   184
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
public abstract class JComponent extends Container implements Serializable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                              TransferHandler.HasGetTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see #writeObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private static final String uiClassID = "ComponentUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   197
    private static final Hashtable<ObjectInputStream, ReadObjectCallback> readObjectCallbacks =
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   198
            new Hashtable<ObjectInputStream, ReadObjectCallback>(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Keys to use for forward focus traversal when the JComponent is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * managing focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    private static Set<KeyStroke> managingFocusForwardTraversalKeys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Keys to use for backward focus traversal when the JComponent is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * managing focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    private static Set<KeyStroke> managingFocusBackwardTraversalKeys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    // Following are the possible return values from getObscuredState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private static final int NOT_OBSCURED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    private static final int PARTIALLY_OBSCURED = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    private static final int COMPLETELY_OBSCURED = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Set to true when DebugGraphics has been loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    static boolean DEBUG_GRAPHICS_LOADED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Key used to look up a value from the AppContext to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * JComponent the InputVerifier is running for. That is, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * AppContext.get(INPUT_VERIFIER_SOURCE_KEY) returns non-null, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * indicates the EDT is calling into the InputVerifier from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * returned component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    private static final Object INPUT_VERIFIER_SOURCE_KEY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            new StringBuilder("InputVerifierSourceKey");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /* The following fields support set methods for the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * java.awt.Component properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private boolean isAlignmentXSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private float alignmentX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private boolean isAlignmentYSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private float alignmentY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Backing store for JComponent properties and listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /** The look and feel delegate for this component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    protected transient ComponentUI ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /** A list of event listeners for this component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    protected EventListenerList listenerList = new EventListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    private transient ArrayTable clientProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    private VetoableChangeSupport vetoableChangeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Whether or not autoscroll has been enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private boolean autoscrolls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    private Border border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    private int flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /* Input verifier for this component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    private InputVerifier inputVerifier = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private boolean verifyInputWhenFocusTarget = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Set in <code>_paintImmediately</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Will indicate the child that initiated the painting operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * If <code>paintingChild</code> is opaque, no need to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * any child components after <code>paintingChild</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Test used in <code>paintChildren</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    transient Component         paintingChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Constant used for <code>registerKeyboardAction</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * means that the command should be invoked when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * the component has the focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public static final int WHEN_FOCUSED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Constant used for <code>registerKeyboardAction</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * means that the command should be invoked when the receiving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * component is an ancestor of the focused component or is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * itself the focused component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Constant used for <code>registerKeyboardAction</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * means that the command should be invoked when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * the receiving component is in the window that has the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * or is itself the focused component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public static final int WHEN_IN_FOCUSED_WINDOW = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Constant used by some of the APIs to mean that no condition is defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public static final int UNDEFINED_CONDITION = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * The key used by <code>JComponent</code> to access keyboard bindings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    private static final String KEYBOARD_BINDINGS_KEY = "_KeyboardBindings";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * An array of <code>KeyStroke</code>s used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <code>WHEN_IN_FOCUSED_WINDOW</code> are stashed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * in the client properties under this string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    private static final String WHEN_IN_FOCUSED_WINDOW_BINDINGS = "_WhenInFocusedWindow";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * The comment to display when the cursor is over the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * also known as a "value tip", "flyover help", or "flyover label".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public static final String TOOL_TIP_TEXT_KEY = "ToolTipText";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    private static final String NEXT_FOCUS = "nextFocus";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <code>JPopupMenu</code> assigned to this component
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   322
     * and all of its children
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    private JPopupMenu popupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /** Private flags **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    private static final int IS_DOUBLE_BUFFERED                       =  0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    private static final int ANCESTOR_USING_BUFFER                    =  1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    private static final int IS_PAINTING_TILE                         =  2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    private static final int IS_OPAQUE                                =  3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    private static final int KEY_EVENTS_ENABLED                       =  4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    private static final int FOCUS_INPUTMAP_CREATED                   =  5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    private static final int ANCESTOR_INPUTMAP_CREATED                =  6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    private static final int WIF_INPUTMAP_CREATED                     =  7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    private static final int ACTIONMAP_CREATED                        =  8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    private static final int CREATED_DOUBLE_BUFFER                    =  9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    // bit 10 is free
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    private static final int IS_PRINTING                              = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    private static final int IS_PRINTING_ALL                          = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    private static final int IS_REPAINTING                            = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /** Bits 14-21 are used to handle nested writeObject calls. **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    private static final int WRITE_OBJ_COUNTER_FIRST                  = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private static final int RESERVED_1                               = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    private static final int RESERVED_2                               = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private static final int RESERVED_3                               = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    private static final int RESERVED_4                               = 18;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    private static final int RESERVED_5                               = 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    private static final int RESERVED_6                               = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    private static final int WRITE_OBJ_COUNTER_LAST                   = 21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    private static final int REQUEST_FOCUS_DISABLED                   = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    private static final int INHERITS_POPUP_MENU                      = 23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    private static final int OPAQUE_SET                               = 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    private static final int AUTOSCROLLS_SET                          = 25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    private static final int FOCUS_TRAVERSAL_KEYS_FORWARD_SET         = 26;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    private static final int FOCUS_TRAVERSAL_KEYS_BACKWARD_SET        = 27;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    private static final int REVALIDATE_RUNNABLE_SCHEDULED            = 28;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Temporary rectangles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   362
    private static java.util.List<Rectangle> tempRectangles = new java.util.ArrayList<Rectangle>(11);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /** Used for <code>WHEN_FOCUSED</code> bindings. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    private InputMap focusInputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /** Used for <code>WHEN_ANCESTOR_OF_FOCUSED_COMPONENT</code> bindings. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    private InputMap ancestorInputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /** Used for <code>WHEN_IN_FOCUSED_KEY</code> bindings. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    private ComponentInputMap windowInputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /** ActionMap. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    private ActionMap actionMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /** Key used to store the default locale in an AppContext **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    private static final String defaultLocale = "JComponent.defaultLocale";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    private static Component componentObtainingGraphicsFrom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    private static Object componentObtainingGraphicsFromLock = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            StringBuilder("componentObtainingGraphicsFrom");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * AA text hints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    transient private Object aaTextInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    static Graphics safelyGetGraphics(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return safelyGetGraphics(c, SwingUtilities.getRoot(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    static Graphics safelyGetGraphics(Component c, Component root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        synchronized(componentObtainingGraphicsFromLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            componentObtainingGraphicsFrom = root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            Graphics g = c.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            componentObtainingGraphicsFrom = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            return g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    static void getGraphicsInvoked(Component root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (!JComponent.isComponentObtainingGraphicsFrom(root)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            JRootPane rootPane = ((RootPaneContainer)root).getRootPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            if (rootPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                rootPane.disableTrueDoubleBuffering();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Returns true if {@code c} is the component the graphics is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * requested of. This is intended for use when getGraphics is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    private static boolean isComponentObtainingGraphicsFrom(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        synchronized(componentObtainingGraphicsFromLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return (componentObtainingGraphicsFrom == c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Returns the Set of <code>KeyStroke</code>s to use if the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * is managing focus for forward focus traversal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    static Set<KeyStroke> getManagingFocusForwardTraversalKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        synchronized(JComponent.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            if (managingFocusForwardTraversalKeys == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                managingFocusForwardTraversalKeys = new HashSet<KeyStroke>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                managingFocusForwardTraversalKeys.add(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                           InputEvent.CTRL_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return managingFocusForwardTraversalKeys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Returns the Set of <code>KeyStroke</code>s to use if the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * is managing focus for backward focus traversal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    static Set<KeyStroke> getManagingFocusBackwardTraversalKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        synchronized(JComponent.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            if (managingFocusBackwardTraversalKeys == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                managingFocusBackwardTraversalKeys = new HashSet<KeyStroke>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                managingFocusBackwardTraversalKeys.add(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                                           InputEvent.SHIFT_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                                           InputEvent.CTRL_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return managingFocusBackwardTraversalKeys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    private static Rectangle fetchRectangle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        synchronized(tempRectangles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            Rectangle rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            int size = tempRectangles.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (size > 0) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   457
                rect = tempRectangles.remove(size - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                rect = new Rectangle(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    private static void recycleRectangle(Rectangle rect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        synchronized(tempRectangles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            tempRectangles.add(rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Sets whether or not <code>getComponentPopupMenu</code> should delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * to the parent if this component does not have a <code>JPopupMenu</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * assigned to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * The default value for this is false, but some <code>JComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * subclasses that are implemented as a number of <code>JComponent</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * may set this to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param value whether or not the JPopupMenu is inherited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @see #setComponentPopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *  description: Whether or not the JPopupMenu is inherited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public void setInheritsPopupMenu(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        boolean oldValue = getFlag(INHERITS_POPUP_MENU);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        setFlag(INHERITS_POPUP_MENU, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        firePropertyChange("inheritsPopupMenu", oldValue, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * Returns true if the JPopupMenu should be inherited from the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
   499
     * @return true if the JPopupMenu should be inherited from the parent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @see #setComponentPopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    public boolean getInheritsPopupMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        return getFlag(INHERITS_POPUP_MENU);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Sets the <code>JPopupMenu</code> for this <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * The UI is responsible for registering bindings and adding the necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * listeners such that the <code>JPopupMenu</code> will be shown at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * the appropriate time. When the <code>JPopupMenu</code> is shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * depends upon the look and feel: some may show it on a mouse event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * some may enable a key binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * If <code>popup</code> is null, and <code>getInheritsPopupMenu</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * returns true, then <code>getComponentPopupMenu</code> will be delegated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * to the parent. This provides for a way to make all child components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * inherit the popupmenu of the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @param popup - the popup that will be assigned to this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     *                may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @see #getComponentPopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *  description: Popup to show
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public void setComponentPopupMenu(JPopupMenu popup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if(popup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            enableEvents(AWTEvent.MOUSE_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        JPopupMenu oldPopup = this.popupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        this.popupMenu = popup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        firePropertyChange("componentPopupMenu", oldPopup, popup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * Returns <code>JPopupMenu</code> that assigned for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * If this component does not have a <code>JPopupMenu</code> assigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * to it and <code>getInheritsPopupMenu</code> is true, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * will return <code>getParent().getComponentPopupMenu()</code> (assuming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * the parent is valid.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @return <code>JPopupMenu</code> assigned for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *         or <code>null</code> if no popup assigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @see #setComponentPopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    public JPopupMenu getComponentPopupMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        if(!getInheritsPopupMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            return popupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if(popupMenu == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            // Search parents for its popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            Container parent = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            while (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                if(parent instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                    return ((JComponent)parent).getComponentPopupMenu();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                if(parent instanceof Window ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                   parent instanceof Applet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    // Reached toplevel, break and return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        return popupMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Default <code>JComponent</code> constructor.  This constructor does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * very little initialization beyond calling the <code>Container</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * constructor.  For example, the initial layout manager is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * <code>null</code>. It does, however, set the component's locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * property to the value returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * <code>JComponent.getDefaultLocale</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @see #getDefaultLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public JComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        // We enable key events on all JComponents so that accessibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        // bindings will work everywhere. This is a partial fix to BugID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        // 4282211.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        enableEvents(AWTEvent.KEY_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        if (isManagingFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            LookAndFeel.installProperty(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                        "focusTraversalKeysForward",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                  getManagingFocusForwardTraversalKeys());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            LookAndFeel.installProperty(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                                        "focusTraversalKeysBackward",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                                  getManagingFocusBackwardTraversalKeys());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        super.setLocale( JComponent.getDefaultLocale() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * <code>JComponent</code> subclasses must override this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *   public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *      setUI((SliderUI)UIManager.getUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @see #setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @see UIManager#getLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @see UIManager#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public void updateUI() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Sets the look and feel delegate for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <code>JComponent</code> subclasses generally override this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * to narrow the argument type. For example, in <code>JSlider</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * public void setUI(SliderUI newUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *     super.setUI(newUI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * Additionally <code>JComponent</code> subclasses must provide a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * <code>getUI</code> method that returns the correct type.  For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * public SliderUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *     return (SliderUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @param newUI the new UI delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @see #updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @see UIManager#getLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @see UIManager#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *  description: The component's look and feel delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    protected void setUI(ComponentUI newUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        /* We do not check that the UI instance is different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
         * before allowing the switch in order to enable the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
         * same UI instance *with different default settings*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
         * to be installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        uninstallUIAndProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        // aaText shouldn't persist between look and feels, reset it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        aaTextInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            UIManager.getDefaults().get(SwingUtilities2.AA_TEXT_PROPERTY_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        ComponentUI oldUI = ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        ui = newUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        firePropertyChange("UI", oldUI, newUI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * Uninstalls the UI, if any, and any client properties designated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * as being specific to the installed UI - instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * {@code UIClientPropertyKey}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    private void uninstallUIAndProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            ui.uninstallUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            //clean UIClientPropertyKeys from client properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            if (clientProperties != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                synchronized(clientProperties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    Object[] clientPropertyKeys =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                        clientProperties.getKeys(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    if (clientPropertyKeys != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        for (Object key : clientPropertyKeys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                            if (key instanceof UIClientPropertyKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                putClientProperty(key, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * Returns the <code>UIDefaults</code> key used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * look up the name of the <code>swing.plaf.ComponentUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * class that defines the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * for this component.  Most applications will never need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * call this method.  Subclasses of <code>JComponent</code> that support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * pluggable look and feel should override this method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * return a <code>UIDefaults</code> key that maps to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * <code>ComponentUI</code> subclass that defines their look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @return the <code>UIDefaults</code> key for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *          <code>ComponentUI</code> subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * description: UIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Returns the graphics object used to paint this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * If <code>DebugGraphics</code> is turned on we create a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * <code>DebugGraphics</code> object if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Otherwise we just configure the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * specified graphics object's foreground and font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * @param g the original <code>Graphics</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @return a <code>Graphics</code> object configured for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    protected Graphics getComponentGraphics(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        Graphics componentGraphics = g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        if (ui != null && DEBUG_GRAPHICS_LOADED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            if ((DebugGraphics.debugComponentCount() != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    (shouldDebugGraphics() != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                    !(g instanceof DebugGraphics)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                componentGraphics = new DebugGraphics(g,this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        componentGraphics.setColor(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        componentGraphics.setFont(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        return componentGraphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * Calls the UI delegate's paint method, if the UI delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * is non-<code>null</code>.  We pass the delegate a copy of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * <code>Graphics</code> object to protect the rest of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * paint code from irrevocable changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * (for example, <code>Graphics.translate</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * If you override this in a subclass you should not make permanent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * changes to the passed in <code>Graphics</code>. For example, you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * should not alter the clip <code>Rectangle</code> or modify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * transform. If you need to do these operations you may find it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * easier to create a new <code>Graphics</code> from the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * <code>Graphics</code> and manipulate it. Further, if you do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * invoker super's implementation you must honor the opaque property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * if this component is opaque, you must completely fill in the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * in a non-opaque color. If you do not honor the opaque property you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * will likely see visual artifacts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * The passed in <code>Graphics</code> object might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * have a transform other than the identify transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * installed on it.  In this case, you might get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * unexpected results if you cumulatively apply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * another transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @param g the <code>Graphics</code> object to protect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * @see ComponentUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    protected void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            Graphics scratchGraphics = (g == null) ? null : g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                ui.update(scratchGraphics, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                scratchGraphics.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Paints this component's children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * If <code>shouldUseBuffer</code> is true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * no component ancestor has a buffer and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * the component children can use a buffer if they have one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * Otherwise, one ancestor has a buffer currently in use and children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * should not use a buffer to paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @param g  the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @see java.awt.Container#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    protected void paintChildren(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        Graphics sg = g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            int i = getComponentCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            if (i < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            // If we are only to paint to a specific child, determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            // its index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            if (paintingChild != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                (paintingChild instanceof JComponent) &&
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   812
                paintingChild.isOpaque()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                for (; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    if (getComponent(i) == paintingChild){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            Rectangle tmpRect = fetchRectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            boolean checkSiblings = (!isOptimizedDrawingEnabled() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                                     checkIfChildObscuredBySibling());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            Rectangle clipBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            if (checkSiblings) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                clipBounds = sg.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                if (clipBounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    clipBounds = new Rectangle(0, 0, getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                                               getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            boolean printing = getFlag(IS_PRINTING);
4258
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   831
            final Window window = SwingUtilities.getWindowAncestor(this);
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   832
            final boolean isWindowOpaque = window == null || window.isOpaque();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            for (; i >= 0 ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                Component comp = getComponent(i);
4258
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   835
                if (comp == null) {
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   836
                    continue;
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   837
                }
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   838
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   839
                final boolean isJComponent = comp instanceof JComponent;
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   840
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   841
                // Enable painting of heavyweights in non-opaque windows.
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   842
                // See 6884960
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   843
                if ((!isWindowOpaque || isJComponent ||
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   844
                            isLightweightComponent(comp)) && comp.isVisible())
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   845
                {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    Rectangle cr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                    cr = comp.getBounds(tmpRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                    boolean hitClip = g.hitClip(cr.x, cr.y, cr.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                                                cr.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    if (hitClip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                        if (checkSiblings && i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                            int x = cr.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                            int y = cr.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                            int width = cr.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                            int height = cr.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                            SwingUtilities.computeIntersection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                                (clipBounds.x, clipBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                                 clipBounds.width, clipBounds.height, cr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                            if(getObscuredState(i, cr.x, cr.y, cr.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                                          cr.height) == COMPLETELY_OBSCURED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                            cr.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                            cr.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                            cr.width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                            cr.height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                        Graphics cg = sg.create(cr.x, cr.y, cr.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                                                cr.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                        cg.setColor(comp.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                        cg.setFont(comp.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                        boolean shouldSetFlagBack = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                            if(isJComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                                if(getFlag(ANCESTOR_USING_BUFFER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                                    ((JComponent)comp).setFlag(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                                                 ANCESTOR_USING_BUFFER,true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                                    shouldSetFlagBack = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                                if(getFlag(IS_PAINTING_TILE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                                    ((JComponent)comp).setFlag(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                                 IS_PAINTING_TILE,true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                                    shouldSetFlagBack = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                                if(!printing) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
   890
                                    comp.paint(cg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                                    if (!getFlag(IS_PRINTING_ALL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                                        comp.print(cg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                                        comp.printAll(cg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                            } else {
4258
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   901
                                // The component is either lightweight, or
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 2808
diff changeset
   902
                                // heavyweight in a non-opaque window
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                                if (!printing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                                    comp.paint(cg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                                    if (!getFlag(IS_PRINTING_ALL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                                        comp.print(cg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                                        comp.printAll(cg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                            cg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                            if(shouldSetFlagBack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                                ((JComponent)comp).setFlag(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                                             ANCESTOR_USING_BUFFER,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                                ((JComponent)comp).setFlag(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                                             IS_PAINTING_TILE,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            recycleRectangle(tmpRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * Paints the component's border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * If you override this in a subclass you should not make permanent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * changes to the passed in <code>Graphics</code>. For example, you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * should not alter the clip <code>Rectangle</code> or modify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * transform. If you need to do these operations you may find it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * easier to create a new <code>Graphics</code> from the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * <code>Graphics</code> and manipulate it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @param g  the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * @see #setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    protected void paintBorder(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        Border border = getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            border.paintBorder(this, g, 0, 0, getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * Calls <code>paint</code>.  Doesn't clear the background but see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * <code>ComponentUI.update</code>, which is called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * <code>paintComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @param g the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * @see #paintComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @see javax.swing.plaf.ComponentUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    public void update(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * Invoked by Swing to draw components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * Applications should not invoke <code>paint</code> directly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * but should instead use the <code>repaint</code> method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * schedule the component for redrawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * This method actually delegates the work of painting to three
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * protected methods: <code>paintComponent</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * <code>paintBorder</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * and <code>paintChildren</code>.  They're called in the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * listed to ensure that children appear on top of component itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * Generally speaking, the component and its children should not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * paint in the insets area allocated to the border. Subclasses can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * just override this method, as always.  A subclass that just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * wants to specialize the UI (look and feel) delegate's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * <code>paint</code> method should just override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * <code>paintComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * @param g  the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * @see #paintComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @see #paintBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * @see #paintChildren
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * @see #getComponentGraphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @see #repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        boolean shouldClearPaintFlags = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        if ((getWidth() <= 0) || (getHeight() <= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        Graphics componentGraphics = getComponentGraphics(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        Graphics co = componentGraphics.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            RepaintManager repaintManager = RepaintManager.currentManager(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            Rectangle clipRect = co.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            int clipX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            int clipY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            int clipW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            int clipH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            if (clipRect == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                clipX = clipY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                clipW = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                clipH = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                clipX = clipRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                clipY = clipRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                clipW = clipRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                clipH = clipRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            if(clipW > getWidth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                clipW = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            if(clipH > getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                clipH = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            if(getParent() != null && !(getParent() instanceof JComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                adjustPaintFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                shouldClearPaintFlags = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            int bw,bh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            boolean printing = getFlag(IS_PRINTING);
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2473
diff changeset
  1037
            if (!printing && repaintManager.isDoubleBufferingEnabled() &&
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2473
diff changeset
  1038
                !getFlag(ANCESTOR_USING_BUFFER) && isDoubleBuffered() &&
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2473
diff changeset
  1039
                (getFlag(IS_REPAINTING) || repaintManager.isPainting()))
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2473
diff changeset
  1040
            {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                repaintManager.beginPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                    repaintManager.paint(this, this, co, clipX, clipY, clipW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                                         clipH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                    repaintManager.endPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                // Will ocassionaly happen in 1.2, especially when printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                if (clipRect == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                    co.setClip(clipX, clipY, clipW, clipH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                if (!rectangleIsObscured(clipX,clipY,clipW,clipH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                    if (!printing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                        paintComponent(co);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                        paintBorder(co);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                        printComponent(co);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                        printBorder(co);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                if (!printing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                    paintChildren(co);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                    printChildren(co);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            co.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            if(shouldClearPaintFlags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                setFlag(ANCESTOR_USING_BUFFER,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                setFlag(IS_PAINTING_TILE,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                setFlag(IS_PRINTING,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                setFlag(IS_PRINTING_ALL,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    // paint forcing use of the double buffer.  This is used for historical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    // reasons: JViewport, when scrolling, previously directly invoked paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    // while turning off double buffering at the RepaintManager level, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    // codes simulates that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    void paintForceDoubleBuffered(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        RepaintManager rm = RepaintManager.currentManager(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        Rectangle clip = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        rm.beginPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        setFlag(IS_REPAINTING, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            rm.paint(this, this, g, clip.x, clip.y, clip.width, clip.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            rm.endPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            setFlag(IS_REPAINTING, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * Returns true if this component, or any of its ancestors, are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * the processing of painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    boolean isPainting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        Container component = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        while (component != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            if (component instanceof JComponent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                   ((JComponent)component).getFlag(ANCESTOR_USING_BUFFER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            component = component.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    private void adjustPaintFlags() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  1117
        JComponent jparent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        Container parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        for(parent = getParent() ; parent != null ; parent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            parent.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            if(parent instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                jparent = (JComponent) parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                if(jparent.getFlag(ANCESTOR_USING_BUFFER))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                  setFlag(ANCESTOR_USING_BUFFER, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                if(jparent.getFlag(IS_PAINTING_TILE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                  setFlag(IS_PAINTING_TILE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                if(jparent.getFlag(IS_PRINTING))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                  setFlag(IS_PRINTING, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                if(jparent.getFlag(IS_PRINTING_ALL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                  setFlag(IS_PRINTING_ALL, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * Invoke this method to print the component. This method invokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * <code>print</code> on the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @param g the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * @see #print
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * @see #printComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * @see #printBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @see #printChildren
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    public void printAll(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        setFlag(IS_PRINTING_ALL, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            setFlag(IS_PRINTING_ALL, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * Invoke this method to print the component to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * <code>Graphics</code>. This method will result in invocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * of <code>printComponent</code>, <code>printBorder</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * <code>printChildren</code>. It is recommended that you override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * one of the previously mentioned methods rather than this one if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * your intention is to customize the way printing looks. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * it can be useful to override this method should you want to prepare
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * state before invoking the superclass behavior. As an example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * if you wanted to change the component's background color before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * printing, you could do the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *     public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     *         Color orig = getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     *         setBackground(Color.WHITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     *         // wrap in try/finally so that we always restore the state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     *             super.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     *         } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *             setBackground(orig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * Alternatively, or for components that delegate painting to other objects,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * you can query during painting whether or not the component is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * midst of a print operation. The <code>isPaintingForPrint</code> method provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * this ability and its return value will be changed by this method: to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * <code>true</code> immediately before rendering and to <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * immediately after. With each change a property change event is fired on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * this component with the name <code>"paintingForPrint"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * This method sets the component's state such that the double buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * will not be used: painting will be done directly on the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * <code>Graphics</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @param g the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * @see #printComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * @see #printBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * @see #printChildren
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * @see #isPaintingForPrint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        setFlag(IS_PRINTING, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        firePropertyChange("paintingForPrint", false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            setFlag(IS_PRINTING, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            firePropertyChange("paintingForPrint", true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        }
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
     * This is invoked during a printing operation. This is implemented to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * invoke <code>paintComponent</code> on the component. Override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * if you wish to add special painting behavior when printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * @param g the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * @see #print
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    protected void printComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * Prints this component's children. This is implemented to invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * <code>paintChildren</code> on the component. Override this if you
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * wish to print the children differently than painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * @param g the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * @see #print
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    protected void printChildren(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        paintChildren(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * Prints the component's border. This is implemented to invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * <code>paintBorder</code> on the component. Override this if you
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * wish to print the border differently that it is painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @param g the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * @see #print
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    protected void printBorder(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     *  Returns true if the component is currently painting a tile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     *  If this method returns true, paint will be called again for another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     *  tile. This method returns false if you are not painting a tile or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     *  if the last tile is painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     *  Use this method to keep some state you might need between tiles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     *  @return  true if the component is currently painting a tile,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     *          false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    public boolean isPaintingTile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        return getFlag(IS_PAINTING_TILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * Returns <code>true</code> if the current painting operation on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * component is part of a <code>print</code> operation. This method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * useful when you want to customize what you print versus what you show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * You can detect changes in the value of this property by listening for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * property change events on this component with name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * <code>"paintingForPrint"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * Note: This method provides complimentary functionality to that provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * by other high level Swing printing APIs. However, it deals strictly with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * painting and should not be confused as providing information on higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * level print processes. For example, a {@link javax.swing.JTable#print()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * operation doesn't necessarily result in a continuous rendering of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * full component, and the return value of this method can change multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * times during that operation. It is even possible for the component to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * painted to the screen while the printing process is ongoing. In such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * case, the return value of this method is <code>true</code> when, and only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * when, the table is being painted as part of the printing process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * @return true if the current painting operation on this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     *         is part of a print operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * @see #print
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    public final boolean isPaintingForPrint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        return getFlag(IS_PRINTING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * In release 1.4, the focus subsystem was rearchitected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * For more information, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  1297
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * Changes this <code>JComponent</code>'s focus traversal keys to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * CTRL+TAB and CTRL+SHIFT+TAB. Also prevents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * <code>SortingFocusTraversalPolicy</code> from considering descendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * of this JComponent when computing a focus traversal cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  1306
     * @return false
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * @see java.awt.Component#setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * @see SortingFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * @deprecated As of 1.4, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     *   <code>Component.setFocusTraversalKeys(int, Set)</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     *   <code>Container.setFocusCycleRoot(boolean)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    public boolean isManagingFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    private void registerNextFocusableComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        registerNextFocusableComponent(getNextFocusableComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    private void registerNextFocusableComponent(Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                                                nextFocusableComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        if (nextFocusableComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        Container nearestRoot =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        if (!(policy instanceof LegacyGlueFocusTraversalPolicy)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            policy = new LegacyGlueFocusTraversalPolicy(policy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            nearestRoot.setFocusTraversalPolicy(policy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        ((LegacyGlueFocusTraversalPolicy)policy).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            setNextFocusableComponent(this, nextFocusableComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    private void deregisterNextFocusableComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        Component nextFocusableComponent = getNextFocusableComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        if (nextFocusableComponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        Container nearestRoot =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        if (nearestRoot == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        if (policy instanceof LegacyGlueFocusTraversalPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            ((LegacyGlueFocusTraversalPolicy)policy).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                unsetNextFocusableComponent(this, nextFocusableComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * In release 1.4, the focus subsystem was rearchitected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * For more information, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  1360
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * Overrides the default <code>FocusTraversalPolicy</code> for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * <code>JComponent</code>'s focus traversal cycle by unconditionally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     * setting the specified <code>Component</code> as the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * <code>Component</code> in the cycle, and this <code>JComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * as the specified <code>Component</code>'s previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * <code>Component</code> in the cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * @param aComponent the <code>Component</code> that should follow this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     *        <code>JComponent</code> in the focus traversal cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * @see #getNextFocusableComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * @see java.awt.FocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * @deprecated As of 1.4, replaced by <code>FocusTraversalPolicy</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    public void setNextFocusableComponent(Component aComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        boolean displayable = isDisplayable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        if (displayable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            deregisterNextFocusableComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        putClientProperty(NEXT_FOCUS, aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        if (displayable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            registerNextFocusableComponent(aComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * In release 1.4, the focus subsystem was rearchitected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * For more information, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  1393
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * Returns the <code>Component</code> set by a prior call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * <code>setNextFocusableComponent(Component)</code> on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * @return the <code>Component</code> that will follow this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     *        <code>JComponent</code> in the focus traversal cycle, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     *        <code>null</code> if none has been explicitly specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * @see #setNextFocusableComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * @deprecated As of 1.4, replaced by <code>FocusTraversalPolicy</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    public Component getNextFocusableComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        return (Component)getClientProperty(NEXT_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * Provides a hint as to whether or not this <code>JComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * should get focus. This is only a hint, and it is up to consumers that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * are requesting focus to honor this property. This is typically honored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * for mouse operations, but not keyboard operations. For example, look
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * and feels could verify this property is true before requesting focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * during a mouse operation. This would often times be used if you did
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * not want a mouse press on a <code>JComponent</code> to steal focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * but did want the <code>JComponent</code> to be traversable via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * keyboard. If you do not want this <code>JComponent</code> focusable at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * all, use the <code>setFocusable</code> method instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * Please see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  1426
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * a section in <em>The Java Tutorial</em>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * @param requestFocusEnabled indicates whether you want this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     *        <code>JComponent</code> to be focusable or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * @see java.awt.Component#setFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    public void setRequestFocusEnabled(boolean requestFocusEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        setFlag(REQUEST_FOCUS_DISABLED, !requestFocusEnabled);
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
     * Returns <code>true</code> if this <code>JComponent</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * get focus; otherwise returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * Please see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  1445
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * a section in <em>The Java Tutorial</em>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * @return <code>true</code> if this component should get focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     *     otherwise returns <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * @see #setRequestFocusEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     *      Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * @see java.awt.Component#isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    public boolean isRequestFocusEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        return !getFlag(REQUEST_FOCUS_DISABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * Requests that this <code>Component</code> gets the input focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * Refer to {@link java.awt.Component#requestFocus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     * Component.requestFocus()} for a complete description of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     * Note that the use of this method is discouraged because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * its behavior is platform dependent. Instead we recommend the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * use of {@link #requestFocusInWindow() requestFocusInWindow()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * If you would like more information on focus, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  1471
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * @see java.awt.Component#requestFocusInWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * @see java.awt.Component#requestFocusInWindow(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    public void requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        super.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * Requests that this <code>Component</code> gets the input focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * Refer to {@link java.awt.Component#requestFocus(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * Component.requestFocus(boolean)} for a complete description of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     * Note that the use of this method is discouraged because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     * its behavior is platform dependent. Instead we recommend the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     * use of {@link #requestFocusInWindow(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     * requestFocusInWindow(boolean)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     * If you would like more information on focus, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  1494
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
     * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     * @param temporary boolean indicating if the focus change is temporary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * @return <code>false</code> if the focus change request is guaranteed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     *         fail; <code>true</code> if it is likely to succeed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * @see java.awt.Component#requestFocusInWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * @see java.awt.Component#requestFocusInWindow(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    public boolean requestFocus(boolean temporary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        return super.requestFocus(temporary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * Requests that this <code>Component</code> gets the input focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * Refer to {@link java.awt.Component#requestFocusInWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * Component.requestFocusInWindow()} for a complete description of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     * If you would like more information on focus, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  1516
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * @return <code>false</code> if the focus change request is guaranteed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     *         fail; <code>true</code> if it is likely to succeed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     * @see java.awt.Component#requestFocusInWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     * @see java.awt.Component#requestFocusInWindow(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    public boolean requestFocusInWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        return super.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * Requests that this <code>Component</code> gets the input focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * Refer to {@link java.awt.Component#requestFocusInWindow(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * Component.requestFocusInWindow(boolean)} for a complete description of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * If you would like more information on focus, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  1537
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     * @param temporary boolean indicating if the focus change is temporary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     * @return <code>false</code> if the focus change request is guaranteed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     *         fail; <code>true</code> if it is likely to succeed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * @see java.awt.Component#requestFocusInWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     * @see java.awt.Component#requestFocusInWindow(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    protected boolean requestFocusInWindow(boolean temporary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        return super.requestFocusInWindow(temporary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     * Requests that this Component get the input focus, and that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     * Component's top-level ancestor become the focused Window. This component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     * must be displayable, visible, and focusable for the request to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     * granted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     * This method is intended for use by focus implementations. Client code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     * should not use this method; instead, it should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     * <code>requestFocusInWindow()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     * @see #requestFocusInWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    public void grabFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     * Sets the value to indicate whether input verifier for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     * current focus owner will be called before this component requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     * focus. The default is true. Set to false on components such as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * Cancel button or a scrollbar, which should activate even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * input in the current focus owner is not "passed" by the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * verifier for that component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     * @param verifyInputWhenFocusTarget value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     *        <code>verifyInputWhenFocusTarget</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * @see InputVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * @see #setInputVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * @see #getInputVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * @see #getVerifyInputWhenFocusTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * description: Whether the Component verifies input before accepting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     *              focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    public void setVerifyInputWhenFocusTarget(boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                                              verifyInputWhenFocusTarget) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        boolean oldVerifyInputWhenFocusTarget =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
            this.verifyInputWhenFocusTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        this.verifyInputWhenFocusTarget = verifyInputWhenFocusTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        firePropertyChange("verifyInputWhenFocusTarget",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                           oldVerifyInputWhenFocusTarget,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                           verifyInputWhenFocusTarget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * Returns the value that indicates whether the input verifier for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * current focus owner will be called before this component requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * @return value of the <code>verifyInputWhenFocusTarget</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * @see InputVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     * @see #setInputVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * @see #getInputVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     * @see #setVerifyInputWhenFocusTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    public boolean getVerifyInputWhenFocusTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        return verifyInputWhenFocusTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     * Gets the <code>FontMetrics</code> for the specified <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     * @param font the font for which font metrics is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     *          obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * @return the font metrics for <code>font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     * @throws NullPointerException if <code>font</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    public FontMetrics getFontMetrics(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        return SwingUtilities2.getFontMetrics(this, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * Sets the preferred size of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     * If <code>preferredSize</code> is <code>null</code>, the UI will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     * be asked for the preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
     * description: The preferred size of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    public void setPreferredSize(Dimension preferredSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        super.setPreferredSize(preferredSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
     * If the <code>preferredSize</code> has been set to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
     * non-<code>null</code> value just returns it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     * If the UI delegate's <code>getPreferredSize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * method returns a non <code>null</code> value then return that;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     * otherwise defer to the component's layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
     * @return the value of the <code>preferredSize</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     * @see #setPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     * @see ComponentUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
  1657
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        if (isPreferredSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
            return super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        Dimension size = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            size = ui.getPreferredSize(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        return (size != null) ? size : super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     * Sets the maximum size of this component to a constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     * value.  Subsequent calls to <code>getMaximumSize</code> will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     * return this value; the component's UI will not be asked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     * to compute it.  Setting the maximum size to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * restores the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     * @param maximumSize a <code>Dimension</code> containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     *          desired maximum allowable size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     * @see #getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
     * description: The maximum size of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
    public void setMaximumSize(Dimension maximumSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        super.setMaximumSize(maximumSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
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 the maximum size has been set to a non-<code>null</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     * just returns it.  If the UI delegate's <code>getMaximumSize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     * method returns a non-<code>null</code> value then return that;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * otherwise defer to the component's layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * @return the value of the <code>maximumSize</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * @see #setMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * @see ComponentUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
  1699
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        if (isMaximumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            return super.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        Dimension size = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            size = ui.getMaximumSize(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        return (size != null) ? size : super.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * Sets the minimum size of this component to a constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * value.  Subsequent calls to <code>getMinimumSize</code> will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * return this value; the component's UI will not be asked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * to compute it.  Setting the minimum size to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * restores the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * @param minimumSize the new minimum size of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * description: The minimum size of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    public void setMinimumSize(Dimension minimumSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        super.setMinimumSize(minimumSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     * If the minimum size has been set to a non-<code>null</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * just returns it.  If the UI delegate's <code>getMinimumSize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     * method returns a non-<code>null</code> value then return that; otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * defer to the component's layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * @return the value of the <code>minimumSize</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * @see #setMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * @see ComponentUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
  1739
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        if (isMinimumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
            return super.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        Dimension size = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            size = ui.getMinimumSize(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
        return (size != null) ? size : super.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * Gives the UI delegate an opportunity to define the precise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * shape of this component for the sake of mouse processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     * @return true if this component logically contains x,y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
     * @see java.awt.Component#contains(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
     * @see ComponentUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
    public boolean contains(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        return (ui != null) ? ui.contains(this, x, y) : super.contains(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * Sets the border of this component.  The <code>Border</code> object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * responsible for defining the insets for the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * (overriding any insets set directly on the component) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * for optionally rendering any border decorations within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     * bounds of those insets.  Borders should be used (rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * than insets) for creating both decorative and non-decorative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     * (such as margins and padding) regions for a swing component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * Compound borders can be used to nest multiple borders within a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     * single component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     * Although technically you can set the border on any object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * that inherits from <code>JComponent</code>, the look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * feel implementation of many standard Swing components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * doesn't work well with user-set borders.  In general,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     * when you want to set a border on a standard Swing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * component other than <code>JPanel</code> or <code>JLabel</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     * we recommend that you put the component in a <code>JPanel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * and set the border on the <code>JPanel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     * @param border the border to be rendered for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     * @see Border
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * @see CompoundBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     *  description: The component's border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
    public void setBorder(Border border) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        Border         oldBorder = this.border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        this.border = border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        firePropertyChange("border", oldBorder, border);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
        if (border != oldBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
            if (border == null || oldBorder == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                !(border.getBorderInsets(this).equals(oldBorder.getBorderInsets(this)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * Returns the border of this component or <code>null</code> if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * border is currently set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * @return the border object for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * @see #setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
    public Border getBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        return border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * If a border has been set on this component, returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * border's insets; otherwise calls <code>super.getInsets</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     * @return the value of the insets property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * @see #setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            return border.getBorderInsets(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
        return super.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     * Returns an <code>Insets</code> object containing this component's inset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * values.  The passed-in <code>Insets</code> object will be reused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     * if possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     * Calling methods cannot assume that the same object will be returned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     * however.  All existing values within this object are overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     * If <code>insets</code> is null, this will allocate a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * @param insets the <code>Insets</code> object, which can be reused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     * @return the <code>Insets</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * @see #getInsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     *   expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
    public Insets getInsets(Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        if (insets == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            insets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            if (border instanceof AbstractBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                return ((AbstractBorder)border).getBorderInsets(this, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                // Can't reuse border insets because the Border interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                // can't be enhanced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                return border.getBorderInsets(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
            // super.getInsets() always returns an Insets object with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            // all of its value zeroed.  No need for a new object here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            insets.left = insets.top = insets.right = insets.bottom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * Overrides <code>Container.getAlignmentY</code> to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     * the horizontal alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @return the value of the <code>alignmentY</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     * @see #setAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     * @see java.awt.Component#getAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    public float getAlignmentY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
        if (isAlignmentYSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            return alignmentY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        return super.getAlignmentY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     * Sets the the horizontal alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
     * @param alignmentY  the new horizontal alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     * @see #getAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     *   description: The preferred vertical alignment of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
    public void setAlignmentY(float alignmentY) {
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1891
        this.alignmentY = validateAlignment(alignmentY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        isAlignmentYSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * Overrides <code>Container.getAlignmentX</code> to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * the vertical alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     * @return the value of the <code>alignmentX</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * @see #setAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     * @see java.awt.Component#getAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
    public float getAlignmentX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        if (isAlignmentXSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
            return alignmentX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        return super.getAlignmentX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     * Sets the the vertical alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     * @param alignmentX  the new vertical alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     * @see #getAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
     *   description: The preferred horizontal alignment of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
    public void setAlignmentX(float alignmentX) {
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1920
        this.alignmentX = validateAlignment(alignmentX);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        isAlignmentXSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1924
    private float validateAlignment(float alignment) {
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1925
        return alignment > 1.0f ? 1.0f : alignment < 0.0f ? 0.0f : alignment;
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1926
    }
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  1927
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * Sets the input verifier for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     * @param inputVerifier the new input verifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     * @see InputVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * description: The component's input verifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    public void setInputVerifier(InputVerifier inputVerifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        InputVerifier oldInputVerifier = (InputVerifier)getClientProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                                         JComponent_INPUT_VERIFIER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
        putClientProperty(JComponent_INPUT_VERIFIER, inputVerifier);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
        firePropertyChange("inputVerifier", oldInputVerifier, inputVerifier);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     * Returns the input verifier for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * @return the <code>inputVerifier</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * @see InputVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
    public InputVerifier getInputVerifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        return (InputVerifier)getClientProperty(JComponent_INPUT_VERIFIER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * Returns this component's graphics context, which lets you draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     * on a component. Use this method to get a <code>Graphics</code> object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * then invoke operations on that object to draw on the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     * @return this components graphics context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        if (DEBUG_GRAPHICS_LOADED && shouldDebugGraphics() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            DebugGraphics graphics = new DebugGraphics(super.getGraphics(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                                                       this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            return graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        return super.getGraphics();
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
    /** Enables or disables diagnostic information about every graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
      * operation performed within the component or one of its children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
      * @param debugOptions  determines how the component should display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
      *         the information;  one of the following options:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
      * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
      * <li>DebugGraphics.LOG_OPTION - causes a text message to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
      * <li>DebugGraphics.FLASH_OPTION - causes the drawing to flash several
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
      * times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
      * <li>DebugGraphics.BUFFERED_OPTION - creates an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
      *         <code>ExternalWindow</code> that displays the operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
      *         performed on the View's offscreen buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
      * <li>DebugGraphics.NONE_OPTION disables debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
      * <li>A value of 0 causes no changes to the debugging options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
      * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
      * <code>debugOptions</code> is bitwise OR'd into the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
      * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
      *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
      *        enum: NONE_OPTION DebugGraphics.NONE_OPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
      *              LOG_OPTION DebugGraphics.LOG_OPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
      *              FLASH_OPTION DebugGraphics.FLASH_OPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
      *              BUFFERED_OPTION DebugGraphics.BUFFERED_OPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
      * description: Diagnostic options for graphics operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
    public void setDebugGraphicsOptions(int debugOptions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
        DebugGraphics.setDebugOptions(this, debugOptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
    /** Returns the state of graphics debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
      * @return a bitwise OR'd flag of zero or more of the following options:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
      * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
      * <li>DebugGraphics.LOG_OPTION - causes a text message to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
      * <li>DebugGraphics.FLASH_OPTION - causes the drawing to flash several
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
      * times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
      * <li>DebugGraphics.BUFFERED_OPTION - creates an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
      *         <code>ExternalWindow</code> that displays the operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
      *         performed on the View's offscreen buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
      * <li>DebugGraphics.NONE_OPTION disables debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
      * <li>A value of 0 causes no changes to the debugging options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
      * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
      * @see #setDebugGraphicsOptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
    public int getDebugGraphicsOptions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        return DebugGraphics.getDebugOptions(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
     * Returns true if debug information is enabled for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
     * <code>JComponent</code> or one of its parents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
    int shouldDebugGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
        return DebugGraphics.shouldComponentDebug(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     * This method is now obsolete, please use a combination of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     * <code>getActionMap()</code> and <code>getInputMap()</code> for
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
  2032
     * similar behavior. For example, to bind the <code>KeyStroke</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     * <code>aKeyStroke</code> to the <code>Action</code> <code>anAction</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     * now use:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     *   component.getInputMap().put(aKeyStroke, aCommand);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     *   component.getActionMap().put(aCommmand, anAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * The above assumes you want the binding to be applicable for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * <code>WHEN_FOCUSED</code>. To register bindings for other focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * states use the <code>getInputMap</code> method that takes an integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * Register a new keyboard action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * <code>anAction</code> will be invoked if a key event matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * <code>aKeyStroke</code> occurs and <code>aCondition</code> is verified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * The <code>KeyStroke</code> object defines a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     * particular combination of a keyboard key and one or more modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * (alt, shift, ctrl, meta).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * The <code>aCommand</code> will be set in the delivered event if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * The <code>aCondition</code> can be one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * <DL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * <DT>WHEN_FOCUSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * <DD>The action will be invoked only when the keystroke occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     *     while the component has the focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     * <DT>WHEN_IN_FOCUSED_WINDOW
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * <DD>The action will be invoked when the keystroke occurs while
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     *     the component has the focus or if the component is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     *     window that has the focus. Note that the component need not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     *     be an immediate descendent of the window -- it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     *     anywhere in the window's containment hierarchy. In other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     *     words, whenever <em>any</em> component in the window has the focus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     *     the action registered with this component is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     * <DT>WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     * <DD>The action will be invoked when the keystroke occurs while the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     *     component has the focus or if the component is an ancestor of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     *     the component that has the focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     * </DL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
     * The combination of keystrokes and conditions lets you define high
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
     * level (semantic) action events for a specified keystroke+modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
     * combination (using the KeyStroke class) and direct to a parent or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
     * child of a component that has the focus, or to the component itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     * In other words, in any hierarchical structure of components, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     * arbitrary key-combination can be immediately directed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     * appropriate component in the hierarchy, and cause a specific method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
     * to be invoked (usually by way of adapter objects).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
     * If an action has already been registered for the receiving
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
     * container, with the same charCode and the same modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
     * <code>anAction</code> will replace the action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
     * @param anAction  the <code>Action</code> to be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
     * @param aCommand  the command to be set in the delivered event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
     * @param aKeyStroke the <code>KeyStroke</code> to bind to the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
     * @param aCondition the condition that needs to be met, see above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
     * @see KeyStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
    public void registerKeyboardAction(ActionListener anAction,String aCommand,KeyStroke aKeyStroke,int aCondition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
        InputMap inputMap = getInputMap(aCondition, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        if (inputMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            ActionMap actionMap = getActionMap(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
            ActionStandin action = new ActionStandin(anAction, aCommand);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            inputMap.put(aKeyStroke, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
            if (actionMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                actionMap.put(action, action);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     * Registers any bound <code>WHEN_IN_FOCUSED_WINDOW</code> actions with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     * the <code>KeyboardManager</code>. If <code>onlyIfNew</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     * is true only actions that haven't been registered are pushed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * to the <code>KeyboardManager</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     * otherwise all actions are pushed to the <code>KeyboardManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     * @param onlyIfNew  if true, only actions that haven't been registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     *          are pushed to the <code>KeyboardManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
    private void registerWithKeyboardManager(boolean onlyIfNew) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
        InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
        KeyStroke[] strokes;
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  2120
        @SuppressWarnings("unchecked")
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9035
diff changeset
  2121
        Hashtable<KeyStroke, KeyStroke> registered =
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9035
diff changeset
  2122
                (Hashtable<KeyStroke, KeyStroke>)getClientProperty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                                (WHEN_IN_FOCUSED_WINDOW_BINDINGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
        if (inputMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
            // Push any new KeyStrokes to the KeyboardManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
            strokes = inputMap.allKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
            if (strokes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
                for (int counter = strokes.length - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                     counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                    if (!onlyIfNew || registered == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                        registered.get(strokes[counter]) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                        registerWithKeyboardManager(strokes[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                    if (registered != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                        registered.remove(strokes[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
            strokes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
        // Remove any old ones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
        if (registered != null && registered.size() > 0) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  2146
            Enumeration<KeyStroke> keys = registered.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
            while (keys.hasMoreElements()) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  2149
                KeyStroke ks = keys.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
                unregisterWithKeyboardManager(ks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
            registered.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        // Updated the registered Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        if (strokes != null && strokes.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            if (registered == null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  2157
                registered = new Hashtable<KeyStroke, KeyStroke>(strokes.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
                putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, registered);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
            for (int counter = strokes.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
                registered.put(strokes[counter], strokes[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
     * Unregisters all the previously registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
     * <code>WHEN_IN_FOCUSED_WINDOW</code> <code>KeyStroke</code> bindings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
    private void unregisterWithKeyboardManager() {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  2174
        @SuppressWarnings("unchecked")
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9035
diff changeset
  2175
        Hashtable<KeyStroke, KeyStroke> registered =
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9035
diff changeset
  2176
                (Hashtable<KeyStroke, KeyStroke>)getClientProperty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
                                (WHEN_IN_FOCUSED_WINDOW_BINDINGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        if (registered != null && registered.size() > 0) {
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9035
diff changeset
  2180
            Enumeration<KeyStroke> keys = registered.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
            while (keys.hasMoreElements()) {
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9035
diff changeset
  2183
                KeyStroke ks = keys.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
                unregisterWithKeyboardManager(ks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * Invoked from <code>ComponentInputMap</code> when its bindings change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * If <code>inputMap</code> is the current <code>windowInputMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * (or a parent of the window <code>InputMap</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * the <code>KeyboardManager</code> is notified of the new bindings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     * @param inputMap the map containing the new bindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
    void componentInputMapChanged(ComponentInputMap inputMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        InputMap km = getInputMap(WHEN_IN_FOCUSED_WINDOW, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        while (km != inputMap && km != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  2202
            km = km.getParent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
        if (km != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
            registerWithKeyboardManager(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
    private void registerWithKeyboardManager(KeyStroke aKeyStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
        KeyboardManager.getCurrentManager().registerKeyStroke(aKeyStroke,this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
    private void unregisterWithKeyboardManager(KeyStroke aKeyStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        KeyboardManager.getCurrentManager().unregisterKeyStroke(aKeyStroke,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                                                                this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     * This method is now obsolete, please use a combination of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * <code>getActionMap()</code> and <code>getInputMap()</code> for
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
  2221
     * similar behavior.
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2222
     *
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2223
     * @param anAction  action to be registered to given keystroke and condition
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2224
     * @param aKeyStroke  a {@code KeyStroke}
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2225
     * @param aCondition  the condition to be associated with given keystroke
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2226
     *                    and action
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2227
     * @see #getActionMap
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2228
     * @see #getInputMap(int)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
    public void registerKeyboardAction(ActionListener anAction,KeyStroke aKeyStroke,int aCondition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
        registerKeyboardAction(anAction,null,aKeyStroke,aCondition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
     * This method is now obsolete. To unregister an existing binding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
     * you can either remove the binding from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
     * <code>ActionMap/InputMap</code>, or place a dummy binding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     * <code>InputMap</code>. Removing the binding from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     * <code>InputMap</code> allows bindings in parent <code>InputMap</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     * to be active, whereas putting a dummy binding in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
     * <code>InputMap</code> effectively disables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     * the binding from ever happening.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
     * Unregisters a keyboard action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     * This will remove the binding from the <code>ActionMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
     * (if it exists) as well as the <code>InputMap</code>s.
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2247
     *
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2248
     * @param aKeyStroke  the keystroke for which to unregister its
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2249
     *                    keyboard action
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
    public void unregisterKeyboardAction(KeyStroke aKeyStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
        ActionMap am = getActionMap(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
        for (int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
            InputMap km = getInputMap(counter, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
            if (km != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
                Object actionID = km.get(aKeyStroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
                if (am != null && actionID != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
                    am.remove(actionID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                km.remove(aKeyStroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
     * Returns the <code>KeyStrokes</code> that will initiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
     * registered actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
     * @return an array of <code>KeyStroke</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
     * @see #registerKeyboardAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
    public KeyStroke[] getRegisteredKeyStrokes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
        int[] counts = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
        KeyStroke[][] strokes = new KeyStroke[3][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
        for (int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
            InputMap km = getInputMap(counter, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
            strokes[counter] = (km != null) ? km.allKeys() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
            counts[counter] = (strokes[counter] != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
                               strokes[counter].length : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
        KeyStroke[] retValue = new KeyStroke[counts[0] + counts[1] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                                            counts[2]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
        for (int counter = 0, last = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
            if (counts[counter] > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
                System.arraycopy(strokes[counter], 0, retValue, last,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
                                 counts[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
                last += counts[counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
     * Returns the condition that determines whether a registered action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     * occurs in response to the specified keystroke.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
     * For Java 2 platform v1.3, a <code>KeyStroke</code> can be associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
     * with more than one condition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
     * For example, 'a' could be bound for the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
     * conditions <code>WHEN_FOCUSED</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
     * <code>WHEN_IN_FOCUSED_WINDOW</code> condition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2305
     * @param aKeyStroke  the keystroke for which to request an
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2306
     *                    action-keystroke condition
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
     * @return the action-keystroke condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
    public int getConditionForKeyStroke(KeyStroke aKeyStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
        for (int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
            InputMap inputMap = getInputMap(counter, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
            if (inputMap != null && inputMap.get(aKeyStroke) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
                return counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
        return UNDEFINED_CONDITION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     * Returns the object that will perform the action registered for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     * given keystroke.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2323
     * @param aKeyStroke  the keystroke for which to return a listener
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * @return the <code>ActionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     *          object invoked when the keystroke occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
    public ActionListener getActionForKeyStroke(KeyStroke aKeyStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
        ActionMap am = getActionMap(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
        if (am == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        for (int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            InputMap inputMap = getInputMap(counter, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
            if (inputMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
                Object actionBinding = inputMap.get(aKeyStroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
                if (actionBinding != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
                    Action action = am.get(actionBinding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
                    if (action instanceof ActionStandin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
                        return ((ActionStandin)action).actionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
                    return action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     * Unregisters all the bindings in the first tier <code>InputMaps</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     * and <code>ActionMap</code>. This has the effect of removing any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
     * local bindings, and allowing the bindings defined in parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
     * <code>InputMap/ActionMaps</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
     * (the UI is usually defined in the second tier) to persist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
    public void resetKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
        // Keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
        for (int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
            InputMap inputMap = getInputMap(counter, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            if (inputMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                inputMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
        // Actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
        ActionMap am = getActionMap(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        if (am != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
            am.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
     * Sets the <code>InputMap</code> to use under the condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
     * <code>condition</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
     * <code>map</code>. A <code>null</code> value implies you
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
     * do not want any bindings to be used, even from the UI. This will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
     * not reinstall the UI <code>InputMap</code> (if there was one).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
     * <code>condition</code> has one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     * <li><code>WHEN_IN_FOCUSED_WINDOW</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     * <li><code>WHEN_FOCUSED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
     * <li><code>WHEN_ANCESTOR_OF_FOCUSED_COMPONENT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
     * If <code>condition</code> is <code>WHEN_IN_FOCUSED_WINDOW</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
     * and <code>map</code> is not a <code>ComponentInputMap</code>, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
     * <code>IllegalArgumentException</code> will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
     * Similarly, if <code>condition</code> is not one of the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
     * listed, an <code>IllegalArgumentException</code> will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
     * @param condition one of the values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
     * @param map  the <code>InputMap</code> to use for the given condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
     * @exception IllegalArgumentException if <code>condition</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
     *          <code>WHEN_IN_FOCUSED_WINDOW</code> and <code>map</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
     *          is not an instance of <code>ComponentInputMap</code>; or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
     *          if <code>condition</code> is not one of the legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
     *          specified above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
    public final void setInputMap(int condition, InputMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
        switch (condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
        case WHEN_IN_FOCUSED_WINDOW:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
            if (map != null && !(map instanceof ComponentInputMap)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                throw new IllegalArgumentException("WHEN_IN_FOCUSED_WINDOW InputMaps must be of type ComponentInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
            windowInputMap = (ComponentInputMap)map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
            setFlag(WIF_INPUTMAP_CREATED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
            registerWithKeyboardManager(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
        case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
            ancestorInputMap = map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
            setFlag(ANCESTOR_INPUTMAP_CREATED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
        case WHEN_FOCUSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
            focusInputMap = map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
            setFlag(FOCUS_INPUTMAP_CREATED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
            throw new IllegalArgumentException("condition must be one of JComponent.WHEN_IN_FOCUSED_WINDOW, JComponent.WHEN_FOCUSED or JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     * Returns the <code>InputMap</code> that is used during
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
     * <code>condition</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
     * @param condition one of WHEN_IN_FOCUSED_WINDOW, WHEN_FOCUSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
     *        WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
     * @return the <code>InputMap</code> for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
     *          <code>condition</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
    public final InputMap getInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        return getInputMap(condition, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
     * Returns the <code>InputMap</code> that is used when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
     * component has focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
     * This is convenience method for <code>getInputMap(WHEN_FOCUSED)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
     * @return the <code>InputMap</code> used when the component has focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
    public final InputMap getInputMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        return getInputMap(WHEN_FOCUSED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
     * Sets the <code>ActionMap</code> to <code>am</code>. This does not set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
     * the parent of the <code>am</code> to be the <code>ActionMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
     * from the UI (if there was one), it is up to the caller to have done this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
     * @param am  the new <code>ActionMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
    public final void setActionMap(ActionMap am) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
        actionMap = am;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
        setFlag(ACTIONMAP_CREATED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
     * Returns the <code>ActionMap</code> used to determine what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
     * <code>Action</code> to fire for particular <code>KeyStroke</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
     * binding. The returned <code>ActionMap</code>, unless otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
     * set, will have the <code>ActionMap</code> from the UI set as the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
     * @return the <code>ActionMap</code> containing the key/action bindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
    public final ActionMap getActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
        return getActionMap(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
     * Returns the <code>InputMap</code> to use for condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * <code>condition</code>.  If the <code>InputMap</code> hasn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     * been created, and <code>create</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     * true, it will be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
     * @param condition one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
     * <li>JComponent.FOCUS_INPUTMAP_CREATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
     * <li>JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * <li>JComponent.WHEN_IN_FOCUSED_WINDOW
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * @param create if true, create the <code>InputMap</code> if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     *          is not already created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * @return the <code>InputMap</code> for the given <code>condition</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
     *          if <code>create</code> is false and the <code>InputMap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
     *          hasn't been created, returns <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
     * @exception IllegalArgumentException if <code>condition</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
     *          is not one of the legal values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
    final InputMap getInputMap(int condition, boolean create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
        switch (condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        case WHEN_FOCUSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
            if (getFlag(FOCUS_INPUTMAP_CREATED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
                return focusInputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
            // Hasn't been created yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
            if (create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                InputMap km = new InputMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                setInputMap(condition, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                return km;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
        case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
            if (getFlag(ANCESTOR_INPUTMAP_CREATED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
                return ancestorInputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
            // Hasn't been created yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
            if (create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
                InputMap km = new InputMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
                setInputMap(condition, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
                return km;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
        case WHEN_IN_FOCUSED_WINDOW:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
            if (getFlag(WIF_INPUTMAP_CREATED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
                return windowInputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
            // Hasn't been created yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
            if (create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
                ComponentInputMap km = new ComponentInputMap(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
                setInputMap(condition, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
                return km;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
            throw new IllegalArgumentException("condition must be one of JComponent.WHEN_IN_FOCUSED_WINDOW, JComponent.WHEN_FOCUSED or JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
     * Finds and returns the appropriate <code>ActionMap</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
     * @param create if true, create the <code>ActionMap</code> if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
     *          is not already created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
     * @return the <code>ActionMap</code> for this component; if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
     *          <code>create</code> flag is false and there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
     *          current <code>ActionMap</code>, returns <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
    final ActionMap getActionMap(boolean create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
        if (getFlag(ACTIONMAP_CREATED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
            return actionMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
        // Hasn't been created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
        if (create) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            ActionMap am = new ActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
            setActionMap(am);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
            return am;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
     * Returns the baseline.  The baseline is measured from the top of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
     * the component.  This method is primarily meant for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
     * <code>LayoutManager</code>s to align components along their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
     * baseline.  A return value less than 0 indicates this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
     * does not have a reasonable baseline and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
     * <code>LayoutManager</code>s should not align this component on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
     * its baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     * This method calls into the <code>ComponentUI</code> method of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     * same name.  If this component does not have a <code>ComponentUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     * -1 will be returned.  If a value &gt;= 0 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
     * returned, then the component has a valid baseline for any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * size &gt;= the minimum size and <code>getBaselineResizeBehavior</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * can be used to determine how the baseline changes with size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * @see #getBaselineResizeBehavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     * @see java.awt.FontMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
    public int getBaseline(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
        // check size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
        super.getBaseline(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
            return ui.getBaseline(this, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
     * changes as the size changes.  This method is primarily meant for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
     * layout managers and GUI builders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
     * This method calls into the <code>ComponentUI</code> method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
     * the same name.  If this component does not have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
     * <code>ComponentUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
     * <code>BaselineResizeBehavior.OTHER</code> will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
     * returned.  Subclasses should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
     * never return <code>null</code>; if the baseline can not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
     * calculated return <code>BaselineResizeBehavior.OTHER</code>.  Callers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
     * should first ask for the baseline using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
     * <code>getBaseline</code> and if a value &gt;= 0 is returned use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
     * this method.  It is acceptable for this method to return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
     * value other than <code>BaselineResizeBehavior.OTHER</code> even if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
     * <code>getBaseline</code> returns a value less than 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
     * @see #getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
    public BaselineResizeBehavior getBaselineResizeBehavior() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
            return ui.getBaselineResizeBehavior(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
        return BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
     * In release 1.4, the focus subsystem was rearchitected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
     * For more information, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  2621
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
     * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
     * Requests focus on this <code>JComponent</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
     * <code>FocusTraversalPolicy</code>'s default <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
     * If this <code>JComponent</code> is a focus cycle root, then its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
     * <code>FocusTraversalPolicy</code> is used. Otherwise, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
     * <code>FocusTraversalPolicy</code> of this <code>JComponent</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
     * focus-cycle-root ancestor is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2632
     * @return true if this component can request to get the input focus,
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2633
     *              false if it can not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
     * @see java.awt.FocusTraversalPolicy#getDefaultComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     * @deprecated As of 1.4, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     * <code>FocusTraversalPolicy.getDefaultComponent(Container).requestFocus()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
    public boolean requestDefaultFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
        Container nearestRoot =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
            (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
        if (nearestRoot == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
        Component comp = nearestRoot.getFocusTraversalPolicy().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
            getDefaultComponent(nearestRoot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
        if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
            comp.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
     * Makes the component visible or invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
     * Overrides <code>Component.setVisible</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
     * @param aFlag  true to make the component visible; false to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
     *          make it invisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
    public void setVisible(boolean aFlag) {
12530
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  2666
        if (aFlag != isVisible()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
            super.setVisible(aFlag);
12530
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  2668
            if (aFlag) {
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  2669
                Container parent = getParent();
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  2670
                if (parent != null) {
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  2671
                    Rectangle r = getBounds();
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  2672
                    parent.repaint(r.x, r.y, r.width, r.height);
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  2673
                }
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  2674
                revalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
            }
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
     * Sets whether or not this component is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
     * A component that is enabled may respond to user input,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
     * while a component that is not enabled cannot respond to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
     * user input.  Some components may alter their visual
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
     * representation when they are disabled in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
     * provide feedback to the user that they cannot take input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
     * <p>Note: Disabling a component does not disable its children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
     * <p>Note: Disabling a lightweight component does not prevent it from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
     * receiving MouseEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
     * @param enabled true if this component should be enabled, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
     * @see java.awt.Component#isEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
     * @see java.awt.Component#isLightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
     *  description: The enabled state of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
    public void setEnabled(boolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
        boolean oldEnabled = isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
        super.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
        firePropertyChange("enabled", oldEnabled, enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
        if (enabled != oldEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
     * Sets the foreground color of this component.  It is up to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
     * look and feel to honor this property, some may choose to ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
     * it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
     * @param fg  the desired foreground <code>Color</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     * @see java.awt.Component#getForeground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
     *  description: The foreground color of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
    public void setForeground(Color fg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
        Color oldFg = getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
        super.setForeground(fg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
        if ((oldFg != null) ? !oldFg.equals(fg) : ((fg != null) && !fg.equals(oldFg))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
            // foreground already bound in AWT1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
     * Sets the background color of this component.  The background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
     * color is used only if the component is opaque, and only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
     * by subclasses of <code>JComponent</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
     * <code>ComponentUI</code> implementations.  Direct subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
     * <code>JComponent</code> must override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     * <code>paintComponent</code> to honor this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     * It is up to the look and feel to honor this property, some may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     * choose to ignore it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
     * @param bg the desired background <code>Color</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
     * @see java.awt.Component#getBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
     * @see #setOpaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
     *  description: The background color of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
    public void setBackground(Color bg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        Color oldBg = getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
        super.setBackground(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
        if ((oldBg != null) ? !oldBg.equals(bg) : ((bg != null) && !bg.equals(oldBg))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
            // background already bound in AWT1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
     * Sets the font for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
     * @param font the desired <code>Font</code> for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
     * @see java.awt.Component#getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
     *    preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
     *  description: The font for the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
    public void setFont(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
        Font oldFont = getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
        super.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
        // font already bound in AWT1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
        if (font != oldFont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
     * Returns the default locale used to initialize each JComponent's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
     * locale property upon creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
     * The default locale has "AppContext" scope so that applets (and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
     * potentially multiple lightweight applications running in a single VM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
     * can have their own setting. An applet can safely alter its default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
     * locale because it will have no affect on other applets (or the browser).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
     * @return the default <code>Locale</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
     * @see #setDefaultLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
     * @see java.awt.Component#getLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
     * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
    static public Locale getDefaultLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
        Locale l = (Locale) SwingUtilities.appContextGet(defaultLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
        if( l == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
            //REMIND(bcb) choosing the default value is more complicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            //than this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            l = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
            JComponent.setDefaultLocale( l );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
        return l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
     * Sets the default locale used to initialize each JComponent's locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
     * property upon creation.  The initial value is the VM's default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
     * The default locale has "AppContext" scope so that applets (and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
     * potentially multiple lightweight applications running in a single VM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
     * can have their own setting. An applet can safely alter its default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
     * locale because it will have no affect on other applets (or the browser).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
     * @param l the desired default <code>Locale</code> for new components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
     * @see #getDefaultLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
     * @see java.awt.Component#getLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
     * @see #setLocale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
    static public void setDefaultLocale( Locale l ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
        SwingUtilities.appContextPut(defaultLocale, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
     * Processes any key events that the component itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
     * recognizes.  This is called after the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     * manager and any interested listeners have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     * given a chance to steal away the event.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
     * method is called only if the event has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
     * yet been consumed.  This method is called prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
     * to the keyboard UI logic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
     * This method is implemented to do nothing.  Subclasses would
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
     * normally override this method if they process some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
     * key events themselves.  If the event is processed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
     * it should be consumed.
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2845
     *
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  2846
     * @param e the event to be processed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
    protected void processComponentKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
    /** Overrides <code>processKeyEvent</code> to process events. **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
    protected void processKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
      boolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
      boolean shouldProcessKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
      // This gives the key event listeners a crack at the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
      super.processKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
      // give the component itself a crack at the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
      if (! e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
          processComponentKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
      shouldProcessKey = KeyboardState.shouldProcess(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
      if(e.isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
      if (shouldProcessKey && processKeyBindings(e, e.getID() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
                                                 KeyEvent.KEY_PRESSED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
          e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
     * Invoked to process the key bindings for <code>ks</code> as the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
     * of the <code>KeyEvent</code> <code>e</code>. This obtains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
     * the appropriate <code>InputMap</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
     * gets the binding, gets the action from the <code>ActionMap</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
     * and then (if the action is found and the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
     * is enabled) invokes <code>notifyAction</code> to notify the action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
     * @param ks  the <code>KeyStroke</code> queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
     * @param e the <code>KeyEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
     * @param condition one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
     * <li>JComponent.WHEN_FOCUSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
     * <li>JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
     * <li>JComponent.WHEN_IN_FOCUSED_WINDOW
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
     * @param pressed true if the key is pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
     * @return true if there was a binding to an action, and the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
     *         was enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
                                        int condition, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
        InputMap map = getInputMap(condition, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
        ActionMap am = getActionMap(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
        if(map != null && am != null && isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
            Object binding = map.get(ks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
            Action action = (binding == null) ? null : am.get(binding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
            if (action != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
                return SwingUtilities.notifyAction(action, ks, e, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
                                                   e.getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
     * This is invoked as the result of a <code>KeyEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
     * that was not consumed by the <code>FocusManager</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
     * <code>KeyListeners</code>, or the component. It will first try
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
     * <code>WHEN_FOCUSED</code> bindings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
     * then <code>WHEN_ANCESTOR_OF_FOCUSED_COMPONENT</code> bindings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
     * and finally <code>WHEN_IN_FOCUSED_WINDOW</code> bindings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
     * @param e the unconsumed <code>KeyEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
     * @param pressed true if the key is pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
     * @return true if there is a key binding for <code>e</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
    boolean processKeyBindings(KeyEvent e, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
      if (!SwingUtilities.isValidKeyEventForKeyBindings(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
          return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
      // Get the KeyStroke
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2931
      // There may be two keystrokes associated with a low-level key event;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2932
      // in this case a keystroke made of an extended key code has a priority.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
      KeyStroke ks;
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2934
      KeyStroke ksE = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
      if (e.getID() == KeyEvent.KEY_TYPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
          ks = KeyStroke.getKeyStroke(e.getKeyChar());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
      else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
          ks = KeyStroke.getKeyStroke(e.getKeyCode(),e.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
                                    (pressed ? false:true));
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2942
          if (e.getKeyCode() != e.getExtendedKeyCode()) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2943
              ksE = KeyStroke.getKeyStroke(e.getExtendedKeyCode(),e.getModifiers(),
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2944
                                    (pressed ? false:true));
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2945
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2948
      // Do we have a key binding for e?
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2949
      // If we have a binding by an extended code, use it.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2950
      // If not, check for regular code binding.
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2951
      if(ksE != null && processKeyBinding(ksE, e, WHEN_FOCUSED, pressed)) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2952
          return true;
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2953
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
      if(processKeyBinding(ks, e, WHEN_FOCUSED, pressed))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
          return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
      /* We have no key binding. Let's try the path from our parent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
       * window excluded. We store the path components so we can avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
       * asking the same component twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
      Container parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
      while (parent != null && !(parent instanceof Window) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
             !(parent instanceof Applet)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
          if(parent instanceof JComponent) {
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2965
              if(ksE != null && ((JComponent)parent).processKeyBinding(ksE, e,
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2966
                               WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, pressed))
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 1301
diff changeset
  2967
                  return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
              if(((JComponent)parent).processKeyBinding(ks, e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
                               WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, pressed))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
          // This is done so that the children of a JInternalFrame are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
          // given precedence for WHEN_IN_FOCUSED_WINDOW bindings before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
          // other components WHEN_IN_FOCUSED_WINDOW bindings. This also gives
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
          // more precedence to the WHEN_IN_FOCUSED_WINDOW bindings of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
          // JInternalFrame's children vs the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
          // WHEN_ANCESTOR_OF_FOCUSED_COMPONENT bindings of the parents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
          // maybe generalize from JInternalFrame (like isFocusCycleRoot).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
          if ((parent instanceof JInternalFrame) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
              JComponent.processKeyBindingsForAllComponents(e,parent,pressed)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
          parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
      /* No components between the focused component and the window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
       * actually interested by the key event. Let's try the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
       * JComponent in this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
      if(parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
        return JComponent.processKeyBindingsForAllComponents(e,parent,pressed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
      return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
    static boolean processKeyBindingsForAllComponents(KeyEvent e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
                                      Container container, boolean pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
            if (KeyboardManager.getCurrentManager().fireKeyboardAction(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
                                e, pressed, container)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
            if (container instanceof Popup.HeavyWeightWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
                container = ((Window)container).getOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
     * Registers the text to display in a tool tip.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
     * The text displays when the cursor lingers over the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
     * <p>
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  3016
     * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
     * in <em>The Java Tutorial</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
     * for further documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
     * @param text  the string to display; if the text is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
     *              the tool tip is turned off for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
     * @see #TOOL_TIP_TEXT_KEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
     * description: The text to display in a tool tip.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
    public void setToolTipText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
        String oldText = getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
        putClientProperty(TOOL_TIP_TEXT_KEY, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
        ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
        if (text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
            if (oldText == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
                toolTipManager.registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
            toolTipManager.unregisterComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
     * Returns the tooltip string that has been set with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
     * <code>setToolTipText</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
     * @return the text of the tool tip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
     * @see #TOOL_TIP_TEXT_KEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
    public String getToolTipText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
        return (String)getClientProperty(TOOL_TIP_TEXT_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
     * Returns the string to be used as the tooltip for <i>event</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
     * By default this returns any string set using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
     * <code>setToolTipText</code>.  If a component provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
     * more extensive API to support differing tooltips at different locations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
     * this method should be overridden.
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  3058
     *
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  3059
     * @param event the {@code MouseEvent} that initiated the
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  3060
     *              {@code ToolTip} display
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  3061
     * @return a string containing the  tooltip
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
    public String getToolTipText(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
        return getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
     * Returns the tooltip location in this component's coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
     * If <code>null</code> is returned, Swing will choose a location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
     * The default implementation returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
     * @param event  the <code>MouseEvent</code> that caused the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
     *          <code>ToolTipManager</code> to show the tooltip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
     * @return always returns <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
    public Point getToolTipLocation(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
     * Returns the preferred location to display the popup menu in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
     * component's coordinate system. It is up to the look and feel to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
     * honor this property, some may choose to ignore it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
     * If {@code null}, the look and feel will choose a suitable location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
     * @param event the {@code MouseEvent} that triggered the popup to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
     *        shown, or {@code null} if the popup is not being shown as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
     *        result of a mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
     * @return location to display the {@code JPopupMenu}, or {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
    public Point getPopupLocation(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
     * Returns the instance of <code>JToolTip</code> that should be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
     * to display the tooltip.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
     * Components typically would not override this method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
     * but it can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
     * cause different tooltips to be displayed differently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
     * @return the <code>JToolTip</code> used to display this toolTip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
    public JToolTip createToolTip() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
        JToolTip tip = new JToolTip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
        tip.setComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
        return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
     * Forwards the <code>scrollRectToVisible()</code> message to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
     * <code>JComponent</code>'s parent. Components that can service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
     * the request, such as <code>JViewport</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
     * override this method and perform the scrolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
     * @param aRect the visible <code>Rectangle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
     * @see JViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
    public void scrollRectToVisible(Rectangle aRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
        Container parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
        int dx = getX(), dy = getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
        for (parent = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
                 !(parent == null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
                 !(parent instanceof JComponent) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
                 !(parent instanceof CellRendererPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
             parent = parent.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
             Rectangle bounds = parent.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
             dx += bounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
             dy += bounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
        if (!(parent == null) && !(parent instanceof CellRendererPane)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
            aRect.x += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
            aRect.y += dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
            ((JComponent)parent).scrollRectToVisible(aRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
            aRect.x -= dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
            aRect.y -= dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
     * Sets the <code>autoscrolls</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
     * If <code>true</code> mouse dragged events will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
     * synthetically generated when the mouse is dragged
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
     * outside of the component's bounds and mouse motion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
     * has paused (while the button continues to be held
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
     * down). The synthetic events make it appear that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
     * drag gesture has resumed in the direction established when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
     * the component's boundary was crossed.  Components that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
     * support autoscrolling must handle <code>mouseDragged</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
     * events by calling <code>scrollRectToVisible</code> with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
     * rectangle that contains the mouse event's location.  All of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
     * the Swing components that support item selection and are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
     * typically displayed in a <code>JScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
     * (<code>JTable</code>, <code>JList</code>, <code>JTree</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
     * <code>JTextArea</code>, and <code>JEditorPane</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
     * already handle mouse dragged events in this way.  To enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
     * autoscrolling in any other component, add a mouse motion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
     * listener that calls <code>scrollRectToVisible</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
     * For example, given a <code>JPanel</code>, <code>myPanel</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
     * MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
     *     public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
     *        Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
     *        ((JPanel)e.getSource()).scrollRectToVisible(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
     * };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
     * myPanel.addMouseMotionListener(doScrollRectToVisible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
     * The default value of the <code>autoScrolls</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
     * property is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
     * @param autoscrolls if true, synthetic mouse dragged events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
     *   are generated when the mouse is dragged outside of a component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
     *   bounds and the mouse button continues to be held down; otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
     *   false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
     * @see #getAutoscrolls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
     * @see JViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
     * @see JScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
     * description: Determines if this component automatically scrolls its contents when dragged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
    public void setAutoscrolls(boolean autoscrolls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
        setFlag(AUTOSCROLLS_SET, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
        if (this.autoscrolls != autoscrolls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
            this.autoscrolls = autoscrolls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
            if (autoscrolls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
                enableEvents(AWTEvent.MOUSE_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
                enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
                Autoscroller.stop(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
     * Gets the <code>autoscrolls</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
     * @return the value of the <code>autoscrolls</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
     * @see JViewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
     * @see #setAutoscrolls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
    public boolean getAutoscrolls() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
        return autoscrolls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
     * Sets the {@code TransferHandler}, which provides support for transfer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
     * of data into and out of this component via cut/copy/paste and drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
     * and drop. This may be {@code null} if the component does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
     * data transfer operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
     * If the new {@code TransferHandler} is not {@code null}, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
     * also installs a <b>new</b> {@code DropTarget} on the component to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
     * activate drop handling through the {@code TransferHandler} and activate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
     * any built-in support (such as calculating and displaying potential drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
     * locations). If you do not wish for this component to respond in any way
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
     * to drops, you can disable drop support entirely either by removing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
     * drop target ({@code setDropTarget(null)}) or by de-activating it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
     * ({@code getDropTaget().setActive(false)}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
     * If the new {@code TransferHandler} is {@code null}, this method removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
     * the drop target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
     * Under two circumstances, this method does not modify the drop target:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
     * First, if the existing drop target on this component was explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
     * set by the developer to a {@code non-null} value. Second, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
     * system property {@code suppressSwingDropSupport} is {@code true}. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
     * default value for the system property is {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
     * Please see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
  3240
     * <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
     * How to Use Drag and Drop and Data Transfer</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
     * a section in <em>The Java Tutorial</em>, for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
     * @param newHandler the new {@code TransferHandler}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
     * @see #getTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
     *  description: Mechanism for transfer of data to and from the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
    public void setTransferHandler(TransferHandler newHandler) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
        TransferHandler oldHandler = (TransferHandler)getClientProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
                                      JComponent_TRANSFER_HANDLER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
        putClientProperty(JComponent_TRANSFER_HANDLER, newHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
        SwingUtilities.installSwingDropTargetAsNecessary(this, newHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
        firePropertyChange("transferHandler", oldHandler, newHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
     * Gets the <code>transferHandler</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
     * @return  the value of the <code>transferHandler</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
    public TransferHandler getTransferHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
        return (TransferHandler)getClientProperty(JComponent_TRANSFER_HANDLER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
     * Calculates a custom drop location for this type of component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
     * representing where a drop at the given point should insert data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
     * <code>null</code> is returned if this component doesn't calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
     * custom drop locations. In this case, <code>TransferHandler</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
     * will provide a default <code>DropLocation</code> containing just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
     * the point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
     * @param p the point to calculate a drop location for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
     * @return the drop location, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
    TransferHandler.DropLocation dropLocationForPoint(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
     * Called to set or clear the drop location during a DnD operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
     * In some cases, the component may need to use its internal selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
     * temporarily to indicate the drop location. To help facilitate this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
     * this method returns and accepts as a parameter a state object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
     * This state object can be used to store, and later restore, the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
     * state. Whatever this method returns will be passed back to it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
     * future calls, as the state parameter. If it wants the DnD system to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
     * continue storing the same state, it must pass it back every time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
     * Here's how this is used:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
     * Let's say that on the first call to this method the component decides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
     * to save some state (because it is about to use the selection to show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
     * a drop index). It can return a state object to the caller encapsulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
     * any saved selection state. On a second call, let's say the drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
     * is being changed to something else. The component doesn't need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
     * restore anything yet, so it simply passes back the same state object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
     * to have the DnD system continue storing it. Finally, let's say this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
     * method is messaged with <code>null</code>. This means DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
     * is finished with this component for now, meaning it should restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
     * state. At this point, it can use the state parameter to restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
     * said state, and of course return <code>null</code> since there's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
     * no longer anything to store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
     * @param location the drop location (as calculated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
     *        <code>dropLocationForPoint</code>) or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
     *        if there's no longer a valid drop location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
     * @param state the state object saved earlier for this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
     *        or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
     * @param forDrop whether or not the method is being called because an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
     *        actual drop occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
     * @return any saved state for this component, or <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
    Object setDropLocation(TransferHandler.DropLocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
                           Object state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
                           boolean forDrop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
     * Called to indicate to this component that DnD is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
     * Needed by <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
    void dndDone() {
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
     * Processes mouse events occurring on this component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
     * <code>MouseListener</code> objects, refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
     * {@link java.awt.Component#processMouseEvent(MouseEvent)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
     * for a complete description of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
     * @param       e the mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
     * @see         java.awt.Component#processMouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
     * @since       1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
    protected void processMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
        if (autoscrolls && e.getID() == MouseEvent.MOUSE_RELEASED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
            Autoscroller.stop(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
        super.processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
     * Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
     * @param e the <code>MouseEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
     * @see MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
    protected void processMouseMotionEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
        boolean dispatch = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
        if (autoscrolls && e.getID() == MouseEvent.MOUSE_DRAGGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
            // We don't want to do the drags when the mouse moves if we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
            // autoscrolling.  It makes it feel spastic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
            dispatch = !Autoscroller.isRunning(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
            Autoscroller.processMouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
        if (dispatch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
            super.processMouseMotionEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
    // Inner classes can't get at this method from a super class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
    void superProcessMouseMotionEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
        super.processMouseMotionEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
     * This is invoked by the <code>RepaintManager</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
     * <code>createImage</code> is called on the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
     * @param newValue true if the double buffer image was created from this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
    void setCreatedDoubleBuffer(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
        setFlag(CREATED_DOUBLE_BUFFER, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
     * Returns true if the <code>RepaintManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
     * created the double buffer image from the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
     * @return true if this component had a double buffer image, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
    boolean getCreatedDoubleBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
        return getFlag(CREATED_DOUBLE_BUFFER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
     * <code>ActionStandin</code> is used as a standin for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
     * <code>ActionListeners</code> that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
     * added via <code>registerKeyboardAction</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
    final class ActionStandin implements Action {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
        private final ActionListener actionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
        private final String command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
        // This will be non-null if actionListener is an Action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
        private final Action action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
        ActionStandin(ActionListener actionListener, String command) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
            this.actionListener = actionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
            if (actionListener instanceof Action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                this.action = (Action)actionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
                this.action = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
            this.command = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
        public Object getValue(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
            if (key != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
                if (key.equals(Action.ACTION_COMMAND_KEY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
                    return command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
                if (action != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
                    return action.getValue(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
                if (key.equals(NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
                    return "ActionStandin";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
        public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
            if (actionListener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
                // This keeps the old semantics where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
                // registerKeyboardAction(null) would essentialy remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
                // the binding. We don't remove the binding from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
                // InputMap as that would still allow parent InputMaps
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
                // bindings to be accessed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
            if (action == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
            return action.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
        public void actionPerformed(ActionEvent ae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
            if (actionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
                actionListener.actionPerformed(ae);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
        // We don't allow any values to be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
        public void putValue(String key, Object value) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
        // Does nothing, our enabledness is determiend from our asociated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
        // action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
        public void setEnabled(boolean b) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
        public void addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
                    (PropertyChangeListener listener) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
        public void removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
                          (PropertyChangeListener listener) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
    // This class is used by the KeyboardState class to provide a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
    // instance that can be stored in the AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
    static final class IntVector {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
        int array[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
        int capacity = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
        int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
            return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
        int elementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
            return array[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
        void addElement(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
            if (count == capacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
                capacity = (capacity + 2) * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
                int[] newarray = new int[capacity];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
                if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
                    System.arraycopy(array, 0, newarray, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
                array = newarray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
            array[count++] = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
        void setElementAt(int value, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
            array[index] = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9035
diff changeset
  3504
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
    static class KeyboardState implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
        private static final Object keyCodesKey =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
            JComponent.KeyboardState.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
        // Get the array of key codes from the AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
        static IntVector getKeyCodeArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
            IntVector iv =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
                (IntVector)SwingUtilities.appContextGet(keyCodesKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
            if (iv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
                iv = new IntVector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
                SwingUtilities.appContextPut(keyCodesKey, iv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
            return iv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
        static void registerKeyPressed(int keyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
            IntVector kca = getKeyCodeArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
            int count = kca.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
            for(i=0;i<count;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
                if(kca.elementAt(i) == -1){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
                    kca.setElementAt(keyCode, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
            kca.addElement(keyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
        static void registerKeyReleased(int keyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
            IntVector kca = getKeyCodeArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
            int count = kca.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
            for(i=0;i<count;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
                if(kca.elementAt(i) == keyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
                    kca.setElementAt(-1, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
        static boolean keyIsPressed(int keyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
            IntVector kca = getKeyCodeArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
            int count = kca.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
            for(i=0;i<count;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
                if(kca.elementAt(i) == keyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
         * Updates internal state of the KeyboardState and returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
         * if the event should be processed further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
        static boolean shouldProcess(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
            switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
            case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
                if (!keyIsPressed(e.getKeyCode())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
                    registerKeyPressed(e.getKeyCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
            case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
                // We are forced to process VK_PRINTSCREEN separately because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
                // the Windows doesn't generate the key pressed event for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
                // printscreen and it block the processing of key release
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
                // event for printscreen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
                if (keyIsPressed(e.getKeyCode()) || e.getKeyCode()==KeyEvent.VK_PRINTSCREEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
                    registerKeyReleased(e.getKeyCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
            case KeyEvent.KEY_TYPED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
                // Not a known KeyEvent type, bail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
    static final sun.awt.RequestFocusController focusController =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
        new sun.awt.RequestFocusController() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
            public boolean acceptRequestFocus(Component from, Component to,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
                                              boolean temporary, boolean focusedWindowChangeAllowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
                                              sun.awt.CausedFocusEvent.Cause cause)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
                if ((to == null) || !(to instanceof JComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
                if ((from == null) || !(from instanceof JComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
                JComponent target = (JComponent) to;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
                if (!target.getVerifyInputWhenFocusTarget()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
                JComponent jFocusOwner = (JComponent)from;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
                InputVerifier iv = jFocusOwner.getInputVerifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
                if (iv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
                    Object currentSource = SwingUtilities.appContextGet(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
                            INPUT_VERIFIER_SOURCE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
                    if (currentSource == jFocusOwner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
                        // We're currently calling into the InputVerifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
                        // for this component, so allow the focus change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
                    SwingUtilities.appContextPut(INPUT_VERIFIER_SOURCE_KEY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
                                                 jFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
                        return iv.shouldYieldFocus(jFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
                        if (currentSource != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
                            // We're already in the InputVerifier for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
                            // currentSource. By resetting the currentSource
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
                            // we ensure that if the InputVerifier for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
                            // currentSource does a requestFocus, we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
                            // try and run the InputVerifier again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
                            SwingUtilities.appContextPut(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
                                INPUT_VERIFIER_SOURCE_KEY, currentSource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
                            SwingUtilities.appContextRemove(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
                                INPUT_VERIFIER_SOURCE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
     * --- Accessibility Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
     * replaced by <code>java.awt.Component.setEnabled(boolean)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
    public void enable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
        if (isEnabled() != true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
            super.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3655
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
                    null, AccessibleState.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
     * replaced by <code>java.awt.Component.setEnabled(boolean)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
    public void disable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
        if (isEnabled() != false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
            super.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
            if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
                    AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
                    AccessibleState.ENABLED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
     * Inner class of JComponent used to provide default support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
     * accessibility.  This class is not meant to be used directly by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
     * application developers, but is instead meant only to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
     * subclassed by component developers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
  3688
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21982
diff changeset
  3692
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
    public abstract class AccessibleJComponent extends AccessibleAWTContainer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
       implements AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
         * Though the class is abstract, this should be called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
         * all sub-classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
        protected AccessibleJComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3704
        /**
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3705
         * Number of PropertyChangeListener objects registered. It's used
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3706
         * to add/remove ContainerListener and FocusListener to track
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3707
         * target JComponent's state
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3708
         */
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3709
        private volatile transient int propertyListenersCount = 0;
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3710
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3711
        /**
25109
61e7baccc995 8009883: REGRESSION: test/closed/javax/swing/AbstractButton/4246045/bug4246045.java fails
serb
parents: 25104
diff changeset
  3712
         * This field duplicates the function of the accessibleAWTFocusHandler field
61e7baccc995 8009883: REGRESSION: test/closed/javax/swing/AbstractButton/4246045/bug4246045.java fails
serb
parents: 25104
diff changeset
  3713
         * in java.awt.Component.AccessibleAWTComponent, so it has been deprecated.
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3714
         */
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3715
        @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
        protected FocusListener accessibleFocusHandler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
         * Fire PropertyChange listener, if one is registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
         * when children added/removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
        protected class AccessibleContainerHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
            implements ContainerListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
            public void componentAdded(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
                Component c = e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
                if (c != null && c instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
                    AccessibleJComponent.this.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  3729
                        null, c.getAccessibleContext());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
            public void componentRemoved(ContainerEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
                Component c = e.getChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
                if (c != null && c instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
                    AccessibleJComponent.this.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
                        AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  3737
                        c.getAccessibleContext(), null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
         * Fire PropertyChange listener, if one is registered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
         * when focus events happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
        protected class AccessibleFocusHandler implements FocusListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
           public void focusGained(FocusEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
               if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
                        null, AccessibleState.FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
            public void focusLost(FocusEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
                if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
                    accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
                        AccessibleState.FOCUSED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
        } // inner class AccessibleFocusHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
         * Adds a PropertyChangeListener to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
         * @param listener  the PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
        public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
            if (accessibleContainerHandler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
                accessibleContainerHandler = new AccessibleContainerHandler();
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3773
            }
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3774
            if (propertyListenersCount++ == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
                JComponent.this.addContainerListener(accessibleContainerHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
            super.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
         * Removes a PropertyChangeListener from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
         * This removes a PropertyChangeListener that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
         * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
         * @param listener  the PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
        public void removePropertyChangeListener(PropertyChangeListener listener) {
15506
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3788
            if (--propertyListenersCount == 0) {
b947efcfde08 7179482: Component.accessibleContext and JComponent.accessibleContext refactoring
ptbrunet
parents: 12665
diff changeset
  3789
                JComponent.this.removeContainerListener(accessibleContainerHandler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
            super.removePropertyChangeListener(listener);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
         * Recursively search through the border hierarchy (if it exists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
         * for a TitledBorder with a non-null title.  This does a depth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
         * first search on first the inside borders then the outside borders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
         * The assumption is that titles make really pretty inside borders
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
         * but not very pretty outside borders in compound border situations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
         * It's rather arbitrary, but hopefully decent UI programmers will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
         * not create multiple titled borders for the same component.
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  3804
         *
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  3805
         * @param b  the {@code Border} for which to retrieve its title
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  3806
         * @return the border's title as a {@code String}, null if it has
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  3807
         *         no title
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
        protected String getBorderTitle(Border b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
            String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
            if (b instanceof TitledBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
                return ((TitledBorder) b).getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
            } else if (b instanceof CompoundBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
                s = getBorderTitle(((CompoundBorder) b).getInsideBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
                if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
                    s = getBorderTitle(((CompoundBorder) b).getOutsideBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
                return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
        // AccessibleContext methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
         * Gets the accessible name of this object.  This should almost never
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
         * return java.awt.Component.getName(), as that generally isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
         * a localized name, and doesn't have meaning for the user.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
         * object is fundamentally a text object (such as a menu item), the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
         * accessible name should be the text of the object (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
         * "save").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
         * If the object has a tooltip, the tooltip text may also be an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
         * appropriate String to return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
         * @return the localized name of the object -- can be null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
         *         object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
         * @see AccessibleContext#setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
        public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
            String name = accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
            // fallback to the client name property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
                name = (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
            // fallback to the titled border if it exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
                name = getBorderTitle(getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
            // fallback to the label labeling us if it exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
                Object o = getClientProperty(JLabel.LABELED_BY_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
                if (o instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
                    AccessibleContext ac = ((Accessible) o).getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
                    if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
                        name = ac.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
         * Gets the accessible description of this object.  This should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
         * a concise, localized description of what this object is - what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
         * is its meaning to the user.  If the object has a tooltip, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
         * tooltip text may be an appropriate string to return, assuming
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
         * it contains a concise description of the object (instead of just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
         * the name of the object - for example a "Save" icon on a toolbar that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
         * had "save" as the tooltip text shouldn't return the tooltip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
         * text as the description, but something like "Saves the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
         * text document" instead).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
         * @return the localized description of the object -- can be null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
         * this object does not have a description
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
         * @see AccessibleContext#setAccessibleDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
        public String getAccessibleDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
            String description = accessibleDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
            // fallback to the client description property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
            if (description == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
                description = (String)getClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
            // fallback to the tool tip text if it exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
            if (description == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
                    description = getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
                    // Just in case the subclass overrode the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
                    // getToolTipText method and actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
                    // requires a MouseEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
                    // [[[FIXME:  WDW - we probably should require this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
                    // method to take a MouseEvent and just pass it on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
                    // to getToolTipText.  The swing-feedback traffic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
                    // leads me to believe getToolTipText might change,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
                    // though, so I was hesitant to make this change at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
                    // this time.]]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
            // fallback to the label labeling us if it exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
            if (description == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
                Object o = getClientProperty(JLabel.LABELED_BY_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
                if (o instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
                    AccessibleContext ac = ((Accessible) o).getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
                    if (ac != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
                        description = ac.getAccessibleDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
            return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
            return AccessibleRole.SWING_COMPONENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
         * Gets the state of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
         * @return an instance of AccessibleStateSet containing the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
         * state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
            if (JComponent.this.isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
                states.add(AccessibleState.OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
         * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
         * of the children of this object implement Accessible, than this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
         * method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
         * @return the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
            return super.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
         * Returns the nth Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
         * @return the nth Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
            return super.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
        // ----- AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
         * Returns the AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
         * @return the AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
        AccessibleExtendedComponent getAccessibleExtendedComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
         * Returns the tool tip text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
         * @return the tool tip text, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
        public String getToolTipText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
            return JComponent.this.getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
         * Returns the titled border text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
         * @return the titled border text, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
        public String getTitledBorderText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
            Border border = JComponent.this.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
            if (border instanceof TitledBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
                return ((TitledBorder)border).getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
         * Returns key bindings associated with this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
         * @return the key bindings, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
         * @see AccessibleKeyBinding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
         */
24537
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4019
        public AccessibleKeyBinding getAccessibleKeyBinding(){
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4020
            // Try to get the linked label's mnemonic if it exists
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4021
            Object o = getClientProperty(JLabel.LABELED_BY_PROPERTY);
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4022
            if (o instanceof Accessible){
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4023
                AccessibleContext ac = ((Accessible) o).getAccessibleContext();
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4024
                if (ac != null){
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4025
                    AccessibleComponent comp = ac.getAccessibleComponent();
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4026
                    if (! (comp instanceof AccessibleExtendedComponent))
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4027
                        return null;
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4028
                    return ((AccessibleExtendedComponent)comp).getAccessibleKeyBinding();
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4029
                }
ecad2d59bc19 8036819: JAB: mneumonics not read for textboxes
asaha
parents: 22574
diff changeset
  4030
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
    } // inner class AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
     * Returns an <code>ArrayTable</code> used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
     * key/value "client properties" for this component. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
     * <code>clientProperties</code> table doesn't exist, an empty one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
     * will be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
     * @return an ArrayTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
     * @see #putClientProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
     * @see #getClientProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
    private ArrayTable getClientProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
        if (clientProperties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
            clientProperties = new ArrayTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
        return clientProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
     * Returns the value of the property with the specified key.  Only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
     * properties added with <code>putClientProperty</code> will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
     * a non-<code>null</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
     * @param key the being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
     * @return the value of this property or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
     * @see #putClientProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
    public final Object getClientProperty(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
        if (key == SwingUtilities2.AA_TEXT_PROPERTY_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
            return aaTextInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
        } else if (key == SwingUtilities2.COMPONENT_UI_PROPERTY_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
            return ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
         if(clientProperties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
            synchronized(clientProperties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
                return clientProperties.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
     * Adds an arbitrary key/value "client property" to this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
     * The <code>get/putClientProperty</code> methods provide access to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
     * a small per-instance hashtable. Callers can use get/putClientProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
     * to annotate components that were created by another module.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
     * For example, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
     * layout manager might store per child constraints this way. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
     * componentA.putClientProperty("to the left of", componentB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
     * If value is <code>null</code> this method will remove the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
     * Changes to client properties are reported with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
     * <code>PropertyChange</code> events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
     * The name of the property (for the sake of PropertyChange
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
     * events) is <code>key.toString()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
     * The <code>clientProperty</code> dictionary is not intended to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
     * support large
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
     * scale extensions to JComponent nor should be it considered an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
     * alternative to subclassing when designing a new component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
     * @param key the new client property key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
     * @param value the new client property value; if <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
     *          this method will remove the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
     * @see #getClientProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
     * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
    public final void putClientProperty(Object key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
        if (key == SwingUtilities2.AA_TEXT_PROPERTY_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
            aaTextInfo = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
        if (value == null && clientProperties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
            // Both the value and ArrayTable are null, implying we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
            // have to do anything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
        ArrayTable clientProperties = getClientProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
        Object oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
        synchronized(clientProperties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
            oldValue = clientProperties.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
                clientProperties.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
            } else if (oldValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
                clientProperties.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
                // old == new == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
        clientPropertyChanged(key, oldValue, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
        firePropertyChange(key.toString(), oldValue, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
    // Invoked from putClientProperty.  This is provided for subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
    // in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
    void clientPropertyChanged(Object key, Object oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
                               Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
     * Sets the property with the specified name to the specified value if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
     * the property has not already been set by the client program.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
     * This method is used primarily to set UI defaults for properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
     * with primitive types, where the values cannot be marked with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
     * UIResource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
     * @see LookAndFeel#installProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
     * @param propertyName String containing the name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
     * @param value Object containing the property value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
        if (propertyName == "opaque") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
            if (!getFlag(OPAQUE_SET)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
                setOpaque(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
                setFlag(OPAQUE_SET, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
        } else if (propertyName == "autoscrolls") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
            if (!getFlag(AUTOSCROLLS_SET)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
                setAutoscrolls(((Boolean)value).booleanValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
                setFlag(AUTOSCROLLS_SET, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
        } else if (propertyName == "focusTraversalKeysForward") {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  4162
            @SuppressWarnings("unchecked")
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  4163
            Set<AWTKeyStroke> strokeSet = (Set<AWTKeyStroke>) value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
            if (!getFlag(FOCUS_TRAVERSAL_KEYS_FORWARD_SET)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
                super.setFocusTraversalKeys(KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
                                            FORWARD_TRAVERSAL_KEYS,
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  4167
                                            strokeSet);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
        } else if (propertyName == "focusTraversalKeysBackward") {
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  4170
            @SuppressWarnings("unchecked")
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  4171
            Set<AWTKeyStroke> strokeSet = (Set<AWTKeyStroke>) value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
            if (!getFlag(FOCUS_TRAVERSAL_KEYS_BACKWARD_SET)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
                super.setFocusTraversalKeys(KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
                                            BACKWARD_TRAVERSAL_KEYS,
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  4175
                                            strokeSet);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
            throw new IllegalArgumentException("property \""+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
                                               propertyName+ "\" cannot be set using this method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
     * Sets the focus traversal keys for a given traversal operation for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
     * Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
     * Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
     * {@link java.awt.Component#setFocusTraversalKeys}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
     * for a complete description of this method.
12643
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12530
diff changeset
  4190
     * <p>
5d709010bb1d 7146237: closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html failed since 1.8.0b19
bagiras
parents: 12530
diff changeset
  4191
     * 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: 12530
diff changeset
  4192
     * in {@code keystrokes} is not an {@code AWTKeyStroke}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
     *        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
     *        KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
     * @param keystrokes the Set of AWTKeyStroke for the specified operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
     * @see java.awt.KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4199
     * @see java.awt.KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
     * @see java.awt.KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
     *         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: 12530
diff changeset
  4205
     *         contains null, or if any keystroke represents a KEY_TYPED event,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
     *         or if any keystroke already maps to another focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
     *         operation for this Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
    public void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
        setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
        if (id == KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
            setFlag(FOCUS_TRAVERSAL_KEYS_FORWARD_SET,true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
        } else if (id == KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
            setFlag(FOCUS_TRAVERSAL_KEYS_BACKWARD_SET,true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
        super.setFocusTraversalKeys(id,keystrokes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
    /* --- Transitional java.awt.Component Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
     * The methods and fields in this section will migrate to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
     * java.awt.Component in the next JDK release.
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
     * Returns true if this component is lightweight, that is, if it doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
     * have a native window system peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25568
diff changeset
  4232
     * @param c  the {@code Component} to be checked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
     * @return true if this component is lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 9035
diff changeset
  4235
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
    public static boolean isLightweightComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
        return c.getPeer() instanceof LightweightPeer;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
     * @deprecated As of JDK 5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
     * replaced by <code>Component.setBounds(int, int, int, int)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
     * Moves and resizes this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
     * @param x  the new horizontal location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
     * @param y  the new vertical location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
     * @param w  the new width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
     * @param h  the new height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
     * @see java.awt.Component#setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
    public void reshape(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
        super.reshape(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
     * Stores the bounds of this component into "return value"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
     * <code>rv</code> and returns <code>rv</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
     * If <code>rv</code> is <code>null</code> a new <code>Rectangle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
     * is allocated.  This version of <code>getBounds</code> is useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
     * if the caller wants to avoid allocating a new <code>Rectangle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
     * object on the heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
     * @param rv the return value, modified to the component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
     * @return <code>rv</code>; if <code>rv</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
     *          return a newly created <code>Rectangle</code> with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
     *          component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
    public Rectangle getBounds(Rectangle rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
            return new Rectangle(getX(), getY(), getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
            rv.setBounds(getX(), getY(), getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
     * Stores the width/height of this component into "return value"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
     * <code>rv</code> and returns <code>rv</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
     * If <code>rv</code> is <code>null</code> a new <code>Dimension</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
     * object is allocated.  This version of <code>getSize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
     * is useful if the caller wants to avoid allocating a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
     * <code>Dimension</code> object on the heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
     * @param rv the return value, modified to the component's size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
     * @return <code>rv</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
    public Dimension getSize(Dimension rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
            return new Dimension(getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
            rv.setSize(getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
    }
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
     * Stores the x,y origin of this component into "return value"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
     * <code>rv</code> and returns <code>rv</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
     * If <code>rv</code> is <code>null</code> a new <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
     * is allocated.  This version of <code>getLocation</code> is useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
     * if the caller wants to avoid allocating a new <code>Point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
     * object on the heap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
     * @param rv the return value, modified to the component's location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
     * @return <code>rv</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
    public Point getLocation(Point rv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
        if (rv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
            return new Point(getX(), getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
            rv.setLocation(getX(), getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
     * Returns the current x coordinate of the component's origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
     * This method is preferable to writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
     * <code>component.getBounds().x</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
     * <code>component.getLocation().x</code> because it doesn't cause any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
     * heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
     * @return the current x coordinate of the component's origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
    public int getX() { return super.getX(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
     * Returns the current y coordinate of the component's origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
     * This method is preferable to writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
     * <code>component.getBounds().y</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
     * <code>component.getLocation().y</code> because it doesn't cause any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
     * heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
     * @return the current y coordinate of the component's origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
    public int getY() { return super.getY(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
     * Returns the current width of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
     * This method is preferable to writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
     * <code>component.getBounds().width</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
     * <code>component.getSize().width</code> because it doesn't cause any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
     * heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
     * @return the current width of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
    public int getWidth() { return super.getWidth(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
     * Returns the current height of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
     * This method is preferable to writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
     * <code>component.getBounds().height</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
     * <code>component.getSize().height</code> because it doesn't cause any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
     * heap allocations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
     * @return the current height of this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
    public int getHeight() { return super.getHeight(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
     * Returns true if this component is completely opaque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
     * An opaque component paints every pixel within its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
     * rectangular bounds. A non-opaque component paints only a subset of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
     * its pixels or none at all, allowing the pixels underneath it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
     * "show through".  Therefore, a component that does not fully paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
     * its pixels provides a degree of transparency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
     * Subclasses that guarantee to always completely paint their contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
     * should override this method and return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
     * @return true if this component is completely opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
     * @see #setOpaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
    public boolean isOpaque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
        return getFlag(IS_OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
     * If true the component paints every pixel within its bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
     * Otherwise, the component may not paint some or all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
     * pixels, allowing the underlying pixels to show through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
     * The default value of this property is false for <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
     * However, the default value for this property on most standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
     * <code>JComponent</code> subclasses (such as <code>JButton</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
     * <code>JTree</code>) is look-and-feel dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
     * @param isOpaque  true if this component should be opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
     * @see #isOpaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
     *  description: The component's opacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
    public void setOpaque(boolean isOpaque) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
        boolean oldValue = getFlag(IS_OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
        setFlag(IS_OPAQUE, isOpaque);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
        setFlag(OPAQUE_SET, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
        firePropertyChange("opaque", oldValue, isOpaque);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
     * If the specified rectangle is completely obscured by any of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
     * component's opaque children then returns true.  Only direct children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
     * are considered, more distant descendants are ignored.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
     * <code>JComponent</code> is opaque if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
     * <code>JComponent.isOpaque()</code> returns true, other lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
     * components are always considered transparent, and heavyweight components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
     * are always considered opaque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
     * @param x  x value of specified rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
     * @param y  y value of specified rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
     * @param width  width of specified rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
     * @param height height of specified rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
     * @return true if the specified rectangle is obscured by an opaque child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
    boolean rectangleIsObscured(int x,int y,int width,int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
        int numChildren = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
        for(int i = 0; i < numChildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
            Component child = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
            int cx, cy, cw, ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
            cx = child.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
            cy = child.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
            cw = child.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
            ch = child.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
            if (x >= cx && (x + width) <= (cx + cw) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
                y >= cy && (y + height) <= (cy + ch) && child.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
                if(child instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
//                  System.out.println("A) checking opaque: " + ((JComponent)child).isOpaque() + "  " + child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
//                  System.out.print("B) ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
//                  Thread.dumpStack();
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  4453
                    return child.isOpaque();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
                    /** Sometimes a heavy weight can have a bound larger than its peer size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
                     *  so we should always draw under heavy weights
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
     * Returns the <code>Component</code>'s "visible rect rectangle" -  the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
     * intersection of the visible rectangles for the component <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
     * and all of its ancestors.  The return value is stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
     * <code>visibleRect</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
     * @param c  the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
     * @param visibleRect  a <code>Rectangle</code> computed as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
     *          intersection of all visible rectangles for the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
     *          <code>c</code> and all of its ancestors -- this is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
     *          return value for this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
     * @see #getVisibleRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
    static final void computeVisibleRect(Component c, Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
        Container p = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
        Rectangle bounds = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
        if (p == null || p instanceof Window || p instanceof Applet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
            visibleRect.setBounds(0, 0, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
            computeVisibleRect(p, visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
            visibleRect.x -= bounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
            visibleRect.y -= bounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
            SwingUtilities.computeIntersection(0,0,bounds.width,bounds.height,visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
        }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
     * Returns the <code>Component</code>'s "visible rect rectangle" -  the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
     * intersection of the visible rectangles for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
     * and all of its ancestors.  The return value is stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
     * <code>visibleRect</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
     * @param visibleRect a <code>Rectangle</code> computed as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
     *          intersection of all visible rectangles for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
     *          component and all of its ancestors -- this is the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
     *          value for this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
     * @see #getVisibleRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
    public void computeVisibleRect(Rectangle visibleRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
        computeVisibleRect(this, visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
     * Returns the <code>Component</code>'s "visible rectangle" -  the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
     * intersection of this component's visible rectangle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
     * <code>new Rectangle(0, 0, getWidth(), getHeight())</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
     * and all of its ancestors' visible rectangles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
     * @return the visible rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
    public Rectangle getVisibleRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
        Rectangle visibleRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
        computeVisibleRect(visibleRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
        return visibleRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
     * Support for reporting bound property changes for boolean properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
     * This method can be called when a bound property has changed and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
     * send the appropriate PropertyChangeEvent to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
     * PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
     * @param propertyName the property whose value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
    public void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
                                   boolean oldValue, boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
        super.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
     * Support for reporting bound property changes for integer properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
     * This method can be called when a bound property has changed and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
     * send the appropriate PropertyChangeEvent to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
     * PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
     * @param propertyName the property whose value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
    public void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
                                      int oldValue, int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
        super.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
    // XXX This method is implemented as a workaround to a JLS issue with ambiguous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
    // methods. This should be removed once 4758654 is resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
    public void firePropertyChange(String propertyName, char oldValue, char newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
        super.firePropertyChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
     * Supports reporting constrained property changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
     * This method can be called when a constrained property has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
     * and it will send the appropriate <code>PropertyChangeEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
     * to any registered <code>VetoableChangeListeners</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
     * @param propertyName  the name of the property that was listened on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
     * @param oldValue  the old value of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
     * @param newValue  the new value of the property
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 15506
diff changeset
  4573
     * @exception java.beans.PropertyVetoException when the attempt to set the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
     *          property is vetoed by the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
    protected void fireVetoableChange(String propertyName, Object oldValue, Object newValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
        throws java.beans.PropertyVetoException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
        if (vetoableChangeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
        vetoableChangeSupport.fireVetoableChange(propertyName, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
     * Adds a <code>VetoableChangeListener</code> to the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
     * The listener is registered for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
     * @param listener  the <code>VetoableChangeListener</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
    public synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
        if (vetoableChangeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
            vetoableChangeSupport = new java.beans.VetoableChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
        vetoableChangeSupport.addVetoableChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
     * Removes a <code>VetoableChangeListener</code> from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
     * This removes a <code>VetoableChangeListener</code> that was registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
     * for all properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
     * @param listener  the <code>VetoableChangeListener</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
    public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
        if (vetoableChangeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
        vetoableChangeSupport.removeVetoableChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
     * Returns an array of all the vetoable change listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
     * @return all of the component's <code>VetoableChangeListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
     *         or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
     *         array if no vetoable change listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
     * @see #addVetoableChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
     * @see #removeVetoableChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
    public synchronized VetoableChangeListener[] getVetoableChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
        if (vetoableChangeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
            return new VetoableChangeListener[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
        return vetoableChangeSupport.getVetoableChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
     * Returns the top-level ancestor of this component (either the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
     * containing <code>Window</code> or <code>Applet</code>),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
     * or <code>null</code> if this component has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
     * been added to any container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
     * @return the top-level <code>Container</code> that this component is in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
     *          or <code>null</code> if not in any container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
    public Container getTopLevelAncestor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
        for(Container p = this; p != null; p = p.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
            if(p instanceof Window || p instanceof Applet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
                return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
    private AncestorNotifier getAncestorNotifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
        return (AncestorNotifier)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
            getClientProperty(JComponent_ANCESTOR_NOTIFIER);
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
     * Registers <code>listener</code> so that it will receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
     * <code>AncestorEvents</code> when it or any of its ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
     * move or are made visible or invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
     * Events are also sent when the component or its ancestors are added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
     * or removed from the containment hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
     * @param listener  the <code>AncestorListener</code> to register
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
     * @see AncestorEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
    public void addAncestorListener(AncestorListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
        AncestorNotifier ancestorNotifier = getAncestorNotifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
        if (ancestorNotifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
            ancestorNotifier = new AncestorNotifier(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
            putClientProperty(JComponent_ANCESTOR_NOTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
                              ancestorNotifier);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
        ancestorNotifier.addAncestorListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
     * Unregisters <code>listener</code> so that it will no longer receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
     * <code>AncestorEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
     * @param listener  the <code>AncestorListener</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
     * @see #addAncestorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
    public void removeAncestorListener(AncestorListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
        AncestorNotifier ancestorNotifier = getAncestorNotifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
        if (ancestorNotifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
        ancestorNotifier.removeAncestorListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
        if (ancestorNotifier.listenerList.getListenerList().length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
            ancestorNotifier.removeAllListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
            putClientProperty(JComponent_ANCESTOR_NOTIFIER, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
     * Returns an array of all the ancestor listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
     * @return all of the component's <code>AncestorListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
     *         or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
     *         array if no ancestor listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
     * @see #addAncestorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
     * @see #removeAncestorListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
    public AncestorListener[] getAncestorListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
        AncestorNotifier ancestorNotifier = getAncestorNotifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
        if (ancestorNotifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
            return new AncestorListener[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
        return ancestorNotifier.getAncestorListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
     * upon this <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
     * with a class literal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
     * such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
     * <code>JComponent</code> <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
     * for its mouse listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
     * <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
     *          <code><em>Foo</em>Listener</code>s on this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
     *          or an empty array if no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
     *          listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
     * @see #getVetoableChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
     * @see #getAncestorListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
     */
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 25201
diff changeset
  4754
    @SuppressWarnings("unchecked") // Casts to (T[])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
        T[] result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
        if (listenerType == AncestorListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
            // AncestorListeners are handled by the AncestorNotifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
            result = (T[])getAncestorListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
        else if (listenerType == VetoableChangeListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
            // VetoableChangeListeners are handled by VetoableChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4763
            result = (T[])getVetoableChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
        else if (listenerType == PropertyChangeListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
            // PropertyChangeListeners are handled by PropertyChangeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
            result = (T[])getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
        else {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  4770
            result = listenerList.getListeners(listenerType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
        if (result.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
     * Notifies this component that it now has a parent component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
     * When this method is invoked, the chain of parent components is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
     * set up with <code>KeyboardAction</code> event listeners.
7159
6223064e4a43 6899877: JComponent.add/removeNotify() should mention that they are not supposed to be called directly
rupashka
parents: 7005
diff changeset
  4783
     * This method is called by the toolkit internally and should
6223064e4a43 6899877: JComponent.add/removeNotify() should mention that they are not supposed to be called directly
rupashka
parents: 7005
diff changeset
  4784
     * not be called directly by programs.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
     * @see #registerKeyboardAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4789
        super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
        firePropertyChange("ancestor", null, getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4792
        registerWithKeyboardManager(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
        registerNextFocusableComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
     * Notifies this component that it no longer has a parent component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
     * When this method is invoked, any <code>KeyboardAction</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
     * set up in the the chain of parent components are removed.
7159
6223064e4a43 6899877: JComponent.add/removeNotify() should mention that they are not supposed to be called directly
rupashka
parents: 7005
diff changeset
  4801
     * This method is called by the toolkit internally and should
6223064e4a43 6899877: JComponent.add/removeNotify() should mention that they are not supposed to be called directly
rupashka
parents: 7005
diff changeset
  4802
     * not be called directly by programs.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
     * @see #registerKeyboardAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4807
        super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
        // This isn't strictly correct.  The event shouldn't be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4809
        // fired until *after* the parent is set to null.  But
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
        // we only get notified before that happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
        firePropertyChange("ancestor", getParent(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
        unregisterWithKeyboardManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
        deregisterNextFocusableComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
        if (getCreatedDoubleBuffer()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
            RepaintManager.currentManager(this).resetDoubleBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
            setCreatedDoubleBuffer(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
        if (autoscrolls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
            Autoscroller.stop(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
     * Adds the specified region to the dirty region list if the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
     * is showing.  The component will be repainted after all of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
     * currently pending events have been dispatched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
     * @param tm  this parameter is not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
     * @param x  the x value of the dirty region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
     * @param y  the y value of the dirty region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
     * @param width  the width of the dirty region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
     * @param height  the height of the dirty region
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents: 6647
diff changeset
  4836
     * @see #isPaintingOrigin()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
     * @see java.awt.Component#isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
     * @see RepaintManager#addDirtyRegion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
    public void repaint(long tm, int x, int y, int width, int height) {
25104
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24537
diff changeset
  4841
        RepaintManager.currentManager(SunToolkit.targetToAppContext(this))
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24537
diff changeset
  4842
                      .addDirtyRegion(this, x, y, width, height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
     * Adds the specified region to the dirty region list if the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
     * is showing.  The component will be repainted after all of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
     * currently pending events have been dispatched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
     * @param  r a <code>Rectangle</code> containing the dirty region
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents: 6647
diff changeset
  4852
     * @see #isPaintingOrigin()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
     * @see java.awt.Component#isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
     * @see RepaintManager#addDirtyRegion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
    public void repaint(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
        repaint(0,r.x,r.y,r.width,r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4861
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
     * Supports deferred automatic layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
     * Calls <code>invalidate</code> and then adds this component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
     * <code>validateRoot</code> to a list of components that need to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4866
     * validated.  Validation will occur after all currently pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4867
     * events have been dispatched.  In other words after this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4868
     * is called,  the first validateRoot (if any) found when walking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4869
     * up the containment hierarchy of this component will be validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4870
     * By default, <code>JRootPane</code>, <code>JScrollPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4871
     * and <code>JTextField</code> return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4872
     * from <code>isValidateRoot</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4873
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4874
     * This method will automatically be called on this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4875
     * when a property value changes such that size, location, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4876
     * internal layout of this component has been affected.  This automatic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4877
     * updating differs from the AWT because programs generally no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4878
     * longer need to invoke <code>validate</code> to get the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4879
     * GUI to update.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4880
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4881
     * @see java.awt.Component#invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4882
     * @see java.awt.Container#validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4883
     * @see #isValidateRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4884
     * @see RepaintManager#addInvalidComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4885
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4886
    public void revalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4887
        if (getParent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4888
            // Note: We don't bother invalidating here as once added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4889
            // to a valid parent invalidate will be invoked (addImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4890
            // invokes addNotify which will invoke invalidate on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4891
            // new Component). Also, if we do add a check to isValid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4892
            // here it can potentially be called before the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4893
            // which was causing some people grief.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4894
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4895
        }
25104
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24537
diff changeset
  4896
        if (SunToolkit.isDispatchThreadForAppContext(this)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4897
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4898
            RepaintManager.currentManager(this).addInvalidComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4900
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4901
            // To avoid a flood of Runnables when constructing GUIs off
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4902
            // the EDT, a flag is maintained as to whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4903
            // a Runnable has been scheduled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4904
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4905
                if (getFlag(REVALIDATE_RUNNABLE_SCHEDULED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4906
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4907
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4908
                setFlag(REVALIDATE_RUNNABLE_SCHEDULED, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4909
            }
25104
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24537
diff changeset
  4910
            SunToolkit.executeOnEventHandlerThread(this, () -> {
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24537
diff changeset
  4911
                synchronized(JComponent.this) {
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24537
diff changeset
  4912
                    setFlag(REVALIDATE_RUNNABLE_SCHEDULED, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4913
                }
25104
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24537
diff changeset
  4914
                revalidate();
9a002d75bd42 8043610: Sorting columns in JFileChooser fails with AppContext NPE
pchelko
parents: 24537
diff changeset
  4915
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4916
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4920
     * If this method returns true, <code>revalidate</code> calls by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
     * descendants of this component will cause the entire tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4922
     * beginning with this root to be validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4923
     * Returns false by default.  <code>JScrollPane</code> overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4924
     * this method and returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4925
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4926
     * @return always returns false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4927
     * @see #revalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4928
     * @see java.awt.Component#invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4929
     * @see java.awt.Container#validate
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4258
diff changeset
  4930
     * @see java.awt.Container#isValidateRoot
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4258
diff changeset
  4931
     */
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 4258
diff changeset
  4932
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4933
    public boolean isValidateRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4934
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4938
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4939
     * Returns true if this component tiles its children -- that is, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4940
     * it can guarantee that the children will not overlap.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4941
     * repainting system is substantially more efficient in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4942
     * common case.  <code>JComponent</code> subclasses that can't make this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4943
     * guarantee, such as <code>JLayeredPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4944
     * should override this method to return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4945
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4946
     * @return always returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4947
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4948
    public boolean isOptimizedDrawingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4949
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4952
    /**
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents: 6647
diff changeset
  4953
     * Returns {@code true} if a paint triggered on a child component should cause
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4954
     * painting to originate from this Component, or one of its ancestors.
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
  4955
     * <p>
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4956
     * Calling {@link #repaint} or {@link #paintImmediately(int, int, int, int)}
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4957
     * on a Swing component will result in calling
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4958
     * the {@link JComponent#paintImmediately(int, int, int, int)} method of
8382
lana
parents: 8156 8372
diff changeset
  4959
     * the first ancestor which {@code isPaintingOrigin()} returns {@code true}, if there are any.
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
  4960
     * <p>
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4961
     * {@code JComponent} subclasses that need to be painted when any of their
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents: 6647
diff changeset
  4962
     * children are repainted should override this method to return {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
     *
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents: 6647
diff changeset
  4964
     * @return always returns {@code false}
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4965
     *
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4966
     * @see #paintImmediately(int, int, int, int)
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents: 6647
diff changeset
  4967
     */
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents: 6647
diff changeset
  4968
    protected boolean isPaintingOrigin() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4969
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4970
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
     * Paints the specified region in this component and all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
     * descendants that overlap the region, immediately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
     * It's rarely necessary to call this method.  In most cases it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
     * more efficient to call repaint, which defers the actual painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4978
     * and can collapse redundant requests into a single paint call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4979
     * This method is useful if one needs to update the display while
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4980
     * the current event is being dispatched.
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4981
     * <p>
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4982
     * This method is to be overridden when the dirty region needs to be changed
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4983
     * for components that are painting origins.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4984
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4985
     * @param x  the x value of the region to be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
     * @param y  the y value of the region to be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
     * @param w  the width of the region to be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
     * @param h  the height of the region to be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
     * @see #repaint
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4990
     * @see #isPaintingOrigin()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4991
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4992
    public void paintImmediately(int x,int y,int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4993
        Component c = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
        Component parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
        if(!isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
        }
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  4999
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  5000
        JComponent paintingOigin = SwingUtilities.getPaintingOrigin(this);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  5001
        if (paintingOigin != null) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  5002
            Rectangle rectangle = SwingUtilities.convertRectangle(
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  5003
                    c, new Rectangle(x, y, w, h), paintingOigin);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  5004
            paintingOigin.paintImmediately(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  5005
            return;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  5006
        }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
  5007
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  5008
        while(!c.isOpaque()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
            parent = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
            if(parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5011
                x += c.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5012
                y += c.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5013
                c = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5018
            if(!(c instanceof JComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5019
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5022
        if(c instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5023
            ((JComponent)c)._paintImmediately(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5024
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
            c.repaint(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5026
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
     * Paints the specified region now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5032
     * @param r a <code>Rectangle</code> containing the region to be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
    public void paintImmediately(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
        paintImmediately(r.x,r.y,r.width,r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
     * Returns whether this component should be guaranteed to be on top.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
     * For example, it would make no sense for <code>Menu</code>s to pop up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
     * under another component, so they would always return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
     * Most components will want to return false, hence that is the default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
     * @return always returns false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
    // package private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
    boolean alwaysOnTop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
    void setPaintingChild(Component paintingChild) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
        this.paintingChild = paintingChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
    void _paintImmediately(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
        Graphics g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
        Container c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
        Rectangle b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
        int tmpX, tmpY, tmpWidth, tmpHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
        int offsetX=0,offsetY=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5063
        boolean hasBuffer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
        JComponent bufferedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5066
        JComponent paintingComponent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5068
        RepaintManager repaintManager = RepaintManager.currentManager(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
        // parent Container's up to Window or Applet. First container is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
        // the direct parent. Note that in testing it was faster to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
        // alloc a new Vector vs keeping a stack of them around, and gc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
        // seemed to have a minimal effect on this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
        java.util.List<Component> path = new java.util.ArrayList<Component>(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
        int pIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
        int pCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5077
        tmpX = tmpY = tmpWidth = tmpHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5079
        Rectangle paintImmediatelyClip = fetchRectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5080
        paintImmediatelyClip.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5081
        paintImmediatelyClip.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5082
        paintImmediatelyClip.width = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
        paintImmediatelyClip.height = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
        // System.out.println("1) ************* in _paintImmediately for " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
        boolean ontop = alwaysOnTop() && isOpaque();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
        if (ontop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
            SwingUtilities.computeIntersection(0, 0, getWidth(), getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
                                               paintImmediatelyClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
            if (paintImmediatelyClip.width == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
                recycleRectangle(paintImmediatelyClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
        Component child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5098
        for (c = this, child = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5099
             c != null && !(c instanceof Window) && !(c instanceof Applet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
             child = c, c = c.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
                JComponent jc = (c instanceof JComponent) ? (JComponent)c :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
                                null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
                path.add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
                if(!ontop && jc != null && !jc.isOptimizedDrawingEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
                    boolean resetPC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5107
                    // Children of c may overlap, three possible cases for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5108
                    // painting region:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5109
                    // . Completely obscured by an opaque sibling, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
                    //   case there is no need to paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
                    // . Partially obscured by a sibling: need to start
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
                    //   painting from c.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
                    // . Otherwise we aren't obscured and thus don't need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
                    //   start painting from parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5115
                    if (c != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5116
                        if (jc.isPaintingOrigin()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
                            resetPC = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5118
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5119
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5120
                            Component[] children = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5121
                            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5122
                            for (; i<children.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
                                if (children[i] == child) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
                            switch (jc.getObscuredState(i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
                                            paintImmediatelyClip.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
                                            paintImmediatelyClip.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
                                            paintImmediatelyClip.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
                                            paintImmediatelyClip.height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5130
                            case NOT_OBSCURED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5131
                                resetPC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
                            case COMPLETELY_OBSCURED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5134
                                recycleRectangle(paintImmediatelyClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5135
                                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5136
                            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
                                resetPC = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
                        resetPC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
                    if (resetPC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
                        // Get rid of any buffer since we draw from here and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
                        // we might draw something larger
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
                        paintingComponent = jc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5150
                        pIndex = pCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5151
                        offsetX = offsetY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
                        hasBuffer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5154
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5155
                pCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5157
                // look to see if the parent (and therefor this component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
                // is double buffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5159
                if(repaintManager.isDoubleBufferingEnabled() && jc != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5160
                                  jc.isDoubleBuffered()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5161
                    hasBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5162
                    bufferedComponent = jc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5163
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5165
                // if we aren't on top, include the parent's clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5166
                if (!ontop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
                    int bx = c.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
                    int by = c.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
                    tmpWidth = c.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
                    tmpHeight = c.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
                    SwingUtilities.computeIntersection(tmpX,tmpY,tmpWidth,tmpHeight,paintImmediatelyClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
                    paintImmediatelyClip.x += bx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
                    paintImmediatelyClip.y += by;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
                    offsetX += bx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
                    offsetY += by;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5179
        // If the clip width or height is negative, don't bother painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5180
        if(c == null || c.getPeer() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
                        paintImmediatelyClip.width <= 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
                        paintImmediatelyClip.height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
            recycleRectangle(paintImmediatelyClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
        paintingComponent.setFlag(IS_REPAINTING, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
        paintImmediatelyClip.x -= offsetX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
        paintImmediatelyClip.y -= offsetY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
        // Notify the Components that are going to be painted of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
        // child component to paint to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
        if(paintingComponent != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
            Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
            int i = pIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
            for(; i > 0 ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
                comp = path.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
                if(comp instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
                    ((JComponent)comp).setPaintingChild(path.get(i-1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5201
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
        try {
8531
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5205
            if ((g = safelyGetGraphics(paintingComponent, c)) != null) {
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5206
                try {
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5207
                    if (hasBuffer) {
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5208
                        RepaintManager rm = RepaintManager.currentManager(
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5209
                                bufferedComponent);
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5210
                        rm.beginPaint();
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5211
                        try {
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5212
                            rm.paint(paintingComponent, bufferedComponent, g,
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5213
                                    paintImmediatelyClip.x,
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5214
                                    paintImmediatelyClip.y,
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5215
                                    paintImmediatelyClip.width,
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5216
                                    paintImmediatelyClip.height);
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5217
                        } finally {
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5218
                            rm.endPaint();
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5219
                        }
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5220
                    } else {
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5221
                        g.setClip(paintImmediatelyClip.x, paintImmediatelyClip.y,
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5222
                                paintImmediatelyClip.width, paintImmediatelyClip.height);
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5223
                        paintingComponent.paint(g);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
                    }
8531
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5225
                } finally {
4b9696d3b493 6653511: JComponent.safelyGetGraphics() may sometimes return null
alexp
parents: 8372
diff changeset
  5226
                    g.dispose();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
            // Reset the painting child for the parent components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
            if(paintingComponent != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
                Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
                int i = pIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
                for(; i > 0 ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
                    comp = path.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
                    if(comp instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
                        ((JComponent)comp).setPaintingChild(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
            paintingComponent.setFlag(IS_REPAINTING, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
        recycleRectangle(paintImmediatelyClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5248
     * Paints to the specified graphics.  This does not set the clip and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5249
     * does not adjust the Graphics in anyway, callers must do that first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5250
     * This method is package-private for RepaintManager.PaintManager and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5251
     * its subclasses to call, it is NOT intended for general use outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5252
     * of that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5254
    void paintToOffscreen(Graphics g, int x, int y, int w, int h, int maxX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5255
                          int maxY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5256
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5257
            setFlag(ANCESTOR_USING_BUFFER, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5258
            if ((y + h) < maxY || (x + w) < maxX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5259
                setFlag(IS_PAINTING_TILE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5261
            if (getFlag(IS_REPAINTING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5262
                // Called from paintImmediately (RepaintManager) to fill
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5263
                // repaint request
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5264
                paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5265
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5266
                // Called from paint() (AWT) to repair damage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5267
                if(!rectangleIsObscured(x, y, w, h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5268
                    paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5269
                    paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5271
                paintChildren(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5273
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5274
            setFlag(ANCESTOR_USING_BUFFER, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5275
            setFlag(IS_PAINTING_TILE, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5280
     * Returns whether or not the region of the specified component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5281
     * obscured by a sibling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5283
     * @return NOT_OBSCURED if non of the siblings above the Component obscure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5284
     *         it, COMPLETELY_OBSCURED if one of the siblings completely
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
  5285
     *         obscures the Component or PARTIALLY_OBSCURED if the Component is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5286
     *         only partially obscured.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5288
    private int getObscuredState(int compIndex, int x, int y, int width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5289
                                 int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5290
        int retValue = NOT_OBSCURED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5291
        Rectangle tmpRect = fetchRectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5293
        for (int i = compIndex - 1 ; i >= 0 ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5294
            Component sibling = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5295
            if (!sibling.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5296
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5298
            Rectangle siblingRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5299
            boolean opaque;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5300
            if (sibling instanceof JComponent) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  5301
                opaque = sibling.isOpaque();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5302
                if (!opaque) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5303
                    if (retValue == PARTIALLY_OBSCURED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5304
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5305
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5306
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5308
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5309
                opaque = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5311
            siblingRect = sibling.getBounds(tmpRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5312
            if (opaque && x >= siblingRect.x && (x + width) <=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5313
                     (siblingRect.x + siblingRect.width) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5314
                     y >= siblingRect.y && (y + height) <=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5315
                     (siblingRect.y + siblingRect.height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5316
                recycleRectangle(tmpRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5317
                return COMPLETELY_OBSCURED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5319
            else if (retValue == NOT_OBSCURED &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5320
                     !((x + width <= siblingRect.x) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5321
                       (y + height <= siblingRect.y) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5322
                       (x >= siblingRect.x + siblingRect.width) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5323
                       (y >= siblingRect.y + siblingRect.height))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5324
                retValue = PARTIALLY_OBSCURED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5327
        recycleRectangle(tmpRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5328
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5332
     * Returns true, which implies that before checking if a child should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5333
     * be painted it is first check that the child is not obscured by another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5334
     * sibling. This is only checked if <code>isOptimizedDrawingEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5335
     * returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5337
     * @return always returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5339
    boolean checkIfChildObscuredBySibling() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5340
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5344
    private void setFlag(int aFlag, boolean aValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5345
        if(aValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5346
            flags |= (1 << aFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5347
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5348
            flags &= ~(1 << aFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5351
    private boolean getFlag(int aFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5352
        int mask = (1 << aFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5353
        return ((flags & mask) == mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5355
    // These functions must be static so that they can be called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5356
    // subclasses inside the package, but whose inheritance hierarhcy includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5357
    // classes outside of the package below JComponent (e.g., JTextArea).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5358
    static void setWriteObjCounter(JComponent comp, byte count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5359
        comp.flags = (comp.flags & ~(0xFF << WRITE_OBJ_COUNTER_FIRST)) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5360
                     (count << WRITE_OBJ_COUNTER_FIRST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5362
    static byte getWriteObjCounter(JComponent comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5363
        return (byte)((comp.flags >> WRITE_OBJ_COUNTER_FIRST) & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5366
    /** Buffering **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5369
     *  Sets whether this component should use a buffer to paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5370
     *  If set to true, all the drawing from this component will be done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5371
     *  in an offscreen painting buffer. The offscreen painting buffer will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5372
     *  the be copied onto the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5373
     *  If a <code>Component</code> is buffered and one of its ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5374
     *  is also buffered, the ancestor buffer will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5376
     *  @param aFlag if true, set this component to be double buffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5378
    public void setDoubleBuffered(boolean aFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5379
        setFlag(IS_DOUBLE_BUFFERED,aFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5383
     * Returns whether this component should use a buffer to paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5385
     * @return true if this component is double buffered, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5387
    public boolean isDoubleBuffered() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5388
        return getFlag(IS_DOUBLE_BUFFERED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5392
     * Returns the <code>JRootPane</code> ancestor for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5394
     * @return the <code>JRootPane</code> that contains this component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5395
     *          or <code>null</code> if no <code>JRootPane</code> is found
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5397
    public JRootPane getRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5398
        return SwingUtilities.getRootPane(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5402
    /** Serialization **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5405
     * This is called from Component by way of reflection. Do NOT change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5406
     * the name unless you change the code in Component as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5408
    void compWriteObjectNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5409
        byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5410
        JComponent.setWriteObjCounter(this, (byte)(count + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5411
        if (count != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5412
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5415
        uninstallUIAndProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5417
        /* JTableHeader is in a separate package, which prevents it from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5418
         * being able to override this package-private method the way the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5419
         * other components can.  We don't want to make this method protected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5420
         * because it would introduce public-api for a less-than-desirable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5421
         * serialization scheme, so we compromise with this 'instanceof' hack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5422
         * for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5423
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5424
        if (getToolTipText() != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5425
            this instanceof javax.swing.table.JTableHeader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5426
            ToolTipManager.sharedInstance().unregisterComponent(JComponent.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5431
     * This object is the <code>ObjectInputStream</code> callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5432
     * that's called after a complete graph of objects (including at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5433
     * one <code>JComponent</code>) has been read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5434
     *  It sets the UI property of each Swing component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5435
     * that was read to the current default with <code>updateUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5436
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5437
     * As each  component is read in we keep track of the current set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5438
     * root components here, in the roots vector.  Note that there's only one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5439
     * <code>ReadObjectCallback</code> per <code>ObjectInputStream</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5440
     * they're stored in the static <code>readObjectCallbacks</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5441
     * hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5443
     * @see java.io.ObjectInputStream#registerValidation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5444
     * @see SwingUtilities#updateComponentTreeUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5446
    private class ReadObjectCallback implements ObjectInputValidation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5447
    {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  5448
        private final Vector<JComponent> roots = new Vector<JComponent>(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5449
        private final ObjectInputStream inputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5451
        ReadObjectCallback(ObjectInputStream s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5452
            inputStream = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5453
            s.registerValidation(this, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5456
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5457
         * This is the method that's called after the entire graph
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5458
         * of objects has been read in.  It initializes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5459
         * the UI property of all of the copmonents with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5460
         * <code>SwingUtilities.updateComponentTreeUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5461
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5462
        public void validateObject() throws InvalidObjectException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5463
            try {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  5464
                for (JComponent root : roots) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5465
                    SwingUtilities.updateComponentTreeUI(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5466
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5468
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5469
                readObjectCallbacks.remove(inputStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5473
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5474
         * If <code>c</code> isn't a descendant of a component we've already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5475
         * seen, then add it to the roots <code>Vector</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5476
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5477
         * @param c the <code>JComponent</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5478
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5479
        private void registerComponent(JComponent c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5480
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5481
            /* If the Component c is a descendant of one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5482
             * existing roots (or it IS an existing root), we're done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5483
             */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  5484
            for (JComponent root : roots) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5485
                for(Component p = c; p != null; p = p.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5486
                    if (p == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5487
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5488
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5489
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5492
            /* Otherwise: if Component c is an ancestor of any of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5493
             * existing roots then remove them and add c (the "new root")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5494
             * to the roots vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5495
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5496
            for(int i = 0; i < roots.size(); i++) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  5497
                JComponent root = roots.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5498
                for(Component p = root.getParent(); p != null; p = p.getParent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5499
                    if (p == c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5500
                        roots.removeElementAt(i--); // !!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5501
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5502
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5503
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5506
            roots.addElement(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5512
     * We use the <code>ObjectInputStream</code> "registerValidation"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5513
     * callback to update the UI for the entire tree of components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5514
     * after they've all been read in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5516
     * @param s  the <code>ObjectInputStream</code> from which to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5518
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5519
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5520
    {
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5521
        ObjectInputStream.GetField f = s.readFields();
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5522
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5523
        isAlignmentXSet = f.get("isAlignmentXSet", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5524
        alignmentX = validateAlignment(f.get("alignmentX", 0f));
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5525
        isAlignmentYSet = f.get("isAlignmentYSet", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5526
        alignmentY = validateAlignment(f.get("alignmentY", 0f));
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5527
        listenerList = (EventListenerList) f.get("listenerList", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5528
        vetoableChangeSupport = (VetoableChangeSupport) f.get("vetoableChangeSupport", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5529
        autoscrolls = f.get("autoscrolls", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5530
        border = (Border) f.get("border", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5531
        flags = f.get("flags", 0);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5532
        inputVerifier = (InputVerifier) f.get("inputVerifier", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5533
        verifyInputWhenFocusTarget = f.get("verifyInputWhenFocusTarget", false);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5534
        popupMenu = (JPopupMenu) f.get("popupMenu", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5535
        focusInputMap = (InputMap) f.get("focusInputMap", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5536
        ancestorInputMap = (InputMap) f.get("ancestorInputMap", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5537
        windowInputMap = (ComponentInputMap) f.get("windowInputMap", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25760
diff changeset
  5538
        actionMap = (ActionMap) f.get("actionMap", null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5540
        /* If there's no ReadObjectCallback for this stream yet, that is, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5541
         * this is the first call to JComponent.readObject() for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5542
         * graph of objects, then create a callback and stash it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5543
         * in the readObjectCallbacks table.  Note that the ReadObjectCallback
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5544
         * constructor takes care of calling s.registerValidation().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5545
         */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 466
diff changeset
  5546
        ReadObjectCallback cb = readObjectCallbacks.get(s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5547
        if (cb == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5548
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5549
                readObjectCallbacks.put(s, cb = new ReadObjectCallback(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5551
            catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5552
                throw new IOException(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5555
        cb.registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5557
        // Read back the client properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5558
        int cpCount = s.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5559
        if (cpCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5560
            clientProperties = new ArrayTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5561
            for (int counter = 0; counter < cpCount; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5562
                clientProperties.put(s.readObject(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5563
                                     s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5566
        if (getToolTipText() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5567
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5569
        setWriteObjCounter(this, (byte)0);
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
     * Before writing a <code>JComponent</code> to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5575
     * <code>ObjectOutputStream</code> we temporarily uninstall its UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5576
     * This is tricky to do because we want to uninstall
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5577
     * the UI before any of the <code>JComponent</code>'s children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5578
     * (or its <code>LayoutManager</code> etc.) are written,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5579
     * and we don't want to restore the UI until the most derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5580
     * <code>JComponent</code> subclass has been been stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5581
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5582
     * @param s the <code>ObjectOutputStream</code> in which to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5584
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5585
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5586
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5587
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5588
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5589
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5590
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5591
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5593
        ArrayTable.writeArrayTable(s, clientProperties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5597
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5598
     * Returns a string representation of this <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5599
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5600
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5601
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5602
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5603
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5605
     * @return  a string representation of this <code>JComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5607
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5608
        String preferredSizeString = (isPreferredSizeSet() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5609
                                      getPreferredSize().toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5610
        String minimumSizeString = (isMinimumSizeSet() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5611
                                    getMinimumSize().toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5612
        String maximumSizeString = (isMaximumSizeSet() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5613
                                    getMaximumSize().toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5614
        String borderString = (border == null ? ""
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5615
                               : (border == this ? "this" : border.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5617
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5618
        ",alignmentX=" + alignmentX +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5619
        ",alignmentY=" + alignmentY +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5620
        ",border=" + borderString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5621
        ",flags=" + flags +             // should beef this up a bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5622
        ",maximumSize=" + maximumSizeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5623
        ",minimumSize=" + minimumSizeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5624
        ",preferredSize=" + preferredSizeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5626
12530
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5627
    /**
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5628
     * {@inheritDoc}
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5629
     */
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5630
    @Override
12665
7ca53adedb31 7168144: No appropriate CCC request for changes introduced by 7154030
rupashka
parents: 12643
diff changeset
  5631
    @Deprecated
12530
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5632
    public void hide() {
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5633
        boolean showing = isShowing();
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5634
        super.hide();
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5635
        if (showing) {
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5636
            Container parent = getParent();
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5637
            if (parent != null) {
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5638
                Rectangle r = getBounds();
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5639
                parent.repaint(r.x, r.y, r.width, r.height);
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5640
            }
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5641
            revalidate();
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5642
        }
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5643
    }
07f0154e90ea 7154030: java.awt.Component.hide() does not repaint parent component
luchsh
parents: 11268
diff changeset
  5644
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5645
}