jdk/src/share/classes/javax/swing/plaf/ComponentUI.java
author malenkov
Wed, 30 Apr 2014 19:28:05 +0400
changeset 24544 c0133e7c7162
parent 24164 1d505466ea3f
child 26013 83b99f14245f
permissions -rw-r--r--
8041917: unexcepted behavior of LineBorder while using Boolean variable true Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 11268
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: 4394
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: 4394
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: 4394
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.JComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.SwingUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.accessibility.Accessible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The base class for all UI delegate objects in the Swing pluggable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * look and feel architecture.  The UI delegate object for a Swing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * component is responsible for implementing the aspects of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * component that depend on the look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The <code>JComponent</code> class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * invokes methods from this class in order to delegate operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * (painting, layout calculations, etc.) that may vary depending on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * look and feel installed.  <b>Client programs should not invoke methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * on this class directly.</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see javax.swing.JComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see javax.swing.UIManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public abstract class ComponentUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Sole constructor. (For invocation by subclass constructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * typically implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public ComponentUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    63
     * Configures the specified component appropriately for the look and feel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * This method is invoked when the <code>ComponentUI</code> instance is being installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * as the UI delegate on the specified component.  This method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * completely configure the component for the look and feel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * including the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * <ol>
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
    69
     * <li>Install default property values for color, fonts, borders,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *     icons, opacity, etc. on the component.  Whenever possible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *     property values initialized by the client program should <i>not</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *     be overridden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * <li>Install a <code>LayoutManager</code> on the component if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <li>Create/add any required sub-components to the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <li>Create/install event listeners on the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <li>Create/install a <code>PropertyChangeListener</code> on the component in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *     to detect and respond to component property changes appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * <li>Install keyboard UI (mnemonics, traversal, etc.) on the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * <li>Initialize any appropriate instance data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param c the component where this UI delegate is being installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @see #uninstallUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @see javax.swing.JComponent#setUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @see javax.swing.JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Reverses configuration which was done on the specified component during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * <code>installUI</code>.  This method is invoked when this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <code>UIComponent</code> instance is being removed as the UI delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * for the specified component.  This method should undo the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * configuration performed in <code>installUI</code>, being careful to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * leave the <code>JComponent</code> instance in a clean state (no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * extraneous listeners, look-and-feel-specific property objects, etc.).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * This should include the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * <li>Remove any UI-set borders from the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <li>Remove any UI-set layout managers on the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <li>Remove any UI-added sub-components from the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <li>Remove any UI-added event/property listeners from the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <li>Remove any UI-installed keyboard UI from the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * <li>Nullify any allocated instance data objects to allow for GC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param c the component from which this UI delegate is being removed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #installUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @see javax.swing.JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   119
     * Paints the specified component appropriately for the look and feel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * This method is invoked from the <code>ComponentUI.update</code> method when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * the specified component is being painted.  Subclasses should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * this method and use the specified <code>Graphics</code> object to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * render the content of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param g the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param c the component being painted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see #update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   137
     * Notifies this UI delegate that it is time to paint the specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * component.  This method is invoked by <code>JComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * when the specified component is being painted.
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   140
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   141
     * <p>By default this method fills the specified component with
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   142
     * its background color if its {@code opaque} property is {@code true},
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   143
     * and then immediately calls {@code paint}. In general this method need
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   144
     * not be overridden by subclasses; all look-and-feel rendering code should
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2
diff changeset
   145
     * reside in the {@code paint} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param g the <code>Graphics</code> context in which to paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param c the component being painted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see #paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @see javax.swing.JComponent#paintComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (c.isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            g.setColor(c.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            g.fillRect(0, 0, c.getWidth(),c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        paint(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Returns the specified component's preferred size appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * the look and feel.  If <code>null</code> is returned, the preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * size will be calculated by the component's layout manager instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * (this is the preferred approach for any component with a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * layout manager installed).  The default implementation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * method returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param c the component whose preferred size is being queried;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @see javax.swing.JComponent#getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see java.awt.LayoutManager#preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Returns the specified component's minimum size appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * the look and feel.  If <code>null</code> is returned, the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * size will be calculated by the component's layout manager instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * (this is the preferred approach for any component with a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * layout manager installed).  The default implementation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * method invokes <code>getPreferredSize</code> and returns that value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param c the component whose minimum size is being queried;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @return a <code>Dimension</code> object or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see javax.swing.JComponent#getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see java.awt.LayoutManager#minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Returns the specified component's maximum size appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * the look and feel.  If <code>null</code> is returned, the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * size will be calculated by the component's layout manager instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * (this is the preferred approach for any component with a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * layout manager installed).  The default implementation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * method invokes <code>getPreferredSize</code> and returns that value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param c the component whose maximum size is being queried;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @return a <code>Dimension</code> object or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see javax.swing.JComponent#getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @see java.awt.LayoutManager2#maximumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Returns <code>true</code> if the specified <i>x,y</i> location is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * contained within the look and feel's defined shape of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * component. <code>x</code> and <code>y</code> are defined to be relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * to the coordinate system of the specified component.  Although
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * a component's <code>bounds</code> is constrained to a rectangle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * this method provides the means for defining a non-rectangular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * shape within those bounds for the purpose of hit detection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param c the component where the <i>x,y</i> location is being queried;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param x the <i>x</i> coordinate of the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param y the <i>y</i> coordinate of the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see javax.swing.JComponent#contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see java.awt.Component#contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   247
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public boolean contains(JComponent c, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return c.inside(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Returns an instance of the UI delegate for the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Each subclass must provide its own static <code>createUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * method that returns an instance of that UI delegate subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * If the UI delegate subclass is stateless, it may return an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * that is shared by multiple components.  If the UI delegate is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * stateful, then it should return a new instance per component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * The default implementation of this method throws an error, as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * should never be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        throw new Error("ComponentUI.createUI not implemented.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Returns the baseline.  The baseline is measured from the top of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the component.  This method is primarily meant for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <code>LayoutManager</code>s to align components along their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * baseline.  A return value less than 0 indicates this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * does not have a reasonable baseline and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <code>LayoutManager</code>s should not align this component on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * its baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * This method returns -1.  Subclasses that have a meaningful baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * should override appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param c <code>JComponent</code> baseline is being requested for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param width the width to get the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param height the height to get the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @throws NullPointerException if <code>c</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @throws IllegalArgumentException if width or height is &lt; 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @return baseline or a value &lt; 0 indicating there is no reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *                  baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see javax.swing.JComponent#getBaseline(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            throw new NullPointerException("Component must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (width < 0 || height < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    "Width and height must be >= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return -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
    /**
24164
1d505466ea3f 6475394: Spelling mistake in doc for ComponentUI.getBaselineResizeBehaviour
alexsch
parents: 23010
diff changeset
   300
     * Returns an enum indicating how the baseline of the component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * changes as the size changes.  This method is primarily meant for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * layout managers and GUI builders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * This method returns <code>BaselineResizeBehavior.OTHER</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Subclasses that support a baseline should override appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param c <code>JComponent</code> to return baseline resize behavior for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return an enum indicating how the baseline changes as the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *         size changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @throws NullPointerException if <code>c</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            throw new NullPointerException("Component must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return Component.BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * of the children of this object implement <code>Accessible</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * UIs might wish to override this if they present areas on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * screen that can be viewed as components, but actual components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * are not used for presenting those areas.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Note: As of v1.3, it is recommended that developers call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <code>Component.AccessibleAWTComponent.getAccessibleChildrenCount()</code> instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @see #getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @return the number of accessible children in the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public int getAccessibleChildrenCount(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return SwingUtilities.getAccessibleChildrenCount(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Returns the <code>i</code>th <code>Accessible</code> child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * UIs might need to override this if they present areas on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * screen that can be viewed as components, but actual components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * are not used for presenting those areas.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Note: As of v1.3, it is recommended that developers call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * <code>Component.AccessibleAWTComponent.getAccessibleChild()</code> instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @return the <code>i</code>th <code>Accessible</code> child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public Accessible getAccessibleChild(JComponent c, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return SwingUtilities.getAccessibleChild(c, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
}