jdk/src/java.desktop/share/classes/javax/swing/plaf/ComponentUI.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26013 jdk/src/share/classes/javax/swing/plaf/ComponentUI.java@83b99f14245f
parent 25859 jdk/src/share/classes/javax/swing/plaf/ComponentUI.java@3317bb8137f4
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 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
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   176
     * @return a {@code Dimension} object containing given component's preferred
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   177
     *         size appropriate for the look and feel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see javax.swing.JComponent#getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see java.awt.LayoutManager#preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Returns the specified component's minimum size appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * the look and feel.  If <code>null</code> is returned, the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * size will be calculated by the component's layout manager instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * (this is the preferred approach for any component with a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * layout manager installed).  The default implementation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * method invokes <code>getPreferredSize</code> and returns that value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param c the component whose minimum size is being queried;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return a <code>Dimension</code> object or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see javax.swing.JComponent#getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see java.awt.LayoutManager#minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @see #getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Returns the specified component's maximum size appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * the look and feel.  If <code>null</code> is returned, the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * size will be calculated by the component's layout manager instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * (this is the preferred approach for any component with a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * layout manager installed).  The default implementation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * method invokes <code>getPreferredSize</code> and returns that value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param c the component whose maximum size is being queried;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return a <code>Dimension</code> object or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @see javax.swing.JComponent#getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see java.awt.LayoutManager2#maximumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Returns <code>true</code> if the specified <i>x,y</i> location is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * contained within the look and feel's defined shape of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * component. <code>x</code> and <code>y</code> are defined to be relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * to the coordinate system of the specified component.  Although
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * a component's <code>bounds</code> is constrained to a rectangle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * this method provides the means for defining a non-rectangular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * shape within those bounds for the purpose of hit detection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param c the component where the <i>x,y</i> location is being queried;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *          this argument is often ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *          but might be used if the UI object is stateless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *          and shared by multiple components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param x the <i>x</i> coordinate of the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param y the <i>y</i> coordinate of the point
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   244
     * @return {@code true} if the specified {@code x,y} location is contained
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   245
     *         within the look and feel's defined shape for the given component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @see javax.swing.JComponent#contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see java.awt.Component#contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   249
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public boolean contains(JComponent c, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return c.inside(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Returns an instance of the UI delegate for the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Each subclass must provide its own static <code>createUI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * method that returns an instance of that UI delegate subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * If the UI delegate subclass is stateless, it may return an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * that is shared by multiple components.  If the UI delegate is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * stateful, then it should return a new instance per component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * The default implementation of this method throws an error, as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * should never be invoked.
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   263
     *
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   264
     * @param c a {@code JComponent} for which to create a UI delegate
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   265
     * @return a {@code ComponentUI} object for {@code c}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        throw new Error("ComponentUI.createUI not implemented.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Returns the baseline.  The baseline is measured from the top of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * the component.  This method is primarily meant for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <code>LayoutManager</code>s to align components along their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * baseline.  A return value less than 0 indicates this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * does not have a reasonable baseline and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * <code>LayoutManager</code>s should not align this component on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * its baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * This method returns -1.  Subclasses that have a meaningful baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * should override appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param c <code>JComponent</code> baseline is being requested for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param width the width to get the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @param height the height to get the baseline for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @throws NullPointerException if <code>c</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @throws IllegalArgumentException if width or height is &lt; 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @return baseline or a value &lt; 0 indicating there is no reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *                  baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @see javax.swing.JComponent#getBaseline(int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            throw new NullPointerException("Component must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        if (width < 0 || height < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    "Width and height must be >= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
24164
1d505466ea3f 6475394: Spelling mistake in doc for ComponentUI.getBaselineResizeBehaviour
alexsch
parents: 23010
diff changeset
   305
     * Returns an enum indicating how the baseline of the component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * changes as the size changes.  This method is primarily meant for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * layout managers and GUI builders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * This method returns <code>BaselineResizeBehavior.OTHER</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Subclasses that support a baseline should override appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @param c <code>JComponent</code> to return baseline resize behavior for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @return an enum indicating how the baseline changes as the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *         size changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @throws NullPointerException if <code>c</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            throw new NullPointerException("Component must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return Component.BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * of the children of this object implement <code>Accessible</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * UIs might wish to override this if they present areas on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * screen that can be viewed as components, but actual components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * are not used for presenting those areas.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Note: As of v1.3, it is recommended that developers call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <code>Component.AccessibleAWTComponent.getAccessibleChildrenCount()</code> instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   340
     * @param c {@code JComponent} for which to get count of accessible children
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   341
     * @return the number of accessible children in the object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see #getAccessibleChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public int getAccessibleChildrenCount(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return SwingUtilities.getAccessibleChildrenCount(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Returns the <code>i</code>th <code>Accessible</code> child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * UIs might need to override this if they present areas on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * screen that can be viewed as components, but actual components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * are not used for presenting those areas.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Note: As of v1.3, it is recommended that developers call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <code>Component.AccessibleAWTComponent.getAccessibleChild()</code> instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   360
     * @param c a {@code JComponent} for which to get a child object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @return the <code>i</code>th <code>Accessible</code> child of the object
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 24164
diff changeset
   363
     * @see #getAccessibleChildrenCount
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public Accessible getAccessibleChild(JComponent c, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return SwingUtilities.getAccessibleChild(c, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
}