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