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