ComponentUI.java revision 2362
2362N/A * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The base class for all UI delegate objects in the Swing pluggable 0N/A * look and feel architecture. The UI delegate object for a Swing 0N/A * component is responsible for implementing the aspects of the 0N/A * component that depend on the look and feel. 0N/A * The <code>JComponent</code> class 0N/A * invokes methods from this class in order to delegate operations 0N/A * (painting, layout calculations, etc.) that may vary depending on the 0N/A * look and feel installed. <b>Client programs should not invoke methods 0N/A * on this class directly.</b> 0N/A * @see javax.swing.JComponent 0N/A * @see javax.swing.UIManager 0N/A * Sole constructor. (For invocation by subclass constructors, 0N/A * typically implicit.) 1999N/A * Configures the specified component appropriately for the look and feel. 0N/A * This method is invoked when the <code>ComponentUI</code> instance is being installed 0N/A * as the UI delegate on the specified component. This method should 0N/A * completely configure the component for the look and feel, 0N/A * including the following: 1999N/A * <li>Install default property values for color, fonts, borders, 0N/A * icons, opacity, etc. on the component. Whenever possible, 0N/A * property values initialized by the client program should <i>not</i> 0N/A * <li>Install a <code>LayoutManager</code> on the component if necessary. 0N/A * <li>Create/add any required sub-components to the component. 0N/A * <li>Create/install a <code>PropertyChangeListener</code> on the component in order 0N/A * to detect and respond to component property changes appropriately. 0N/A * <li>Install keyboard UI (mnemonics, traversal, etc.) on the component. 0N/A * <li>Initialize any appropriate instance data. 0N/A * @param c the component where this UI delegate is being installed 0N/A * @see javax.swing.JComponent#setUI 0N/A * @see javax.swing.JComponent#updateUI 0N/A * Reverses configuration which was done on the specified component during 0N/A * <code>installUI</code>. This method is invoked when this 0N/A * <code>UIComponent</code> instance is being removed as the UI delegate 0N/A * for the specified component. This method should undo the 0N/A * configuration performed in <code>installUI</code>, being careful to 0N/A * leave the <code>JComponent</code> instance in a clean state (no 0N/A * extraneous listeners, look-and-feel-specific property objects, etc.). 0N/A * This should include the following: 0N/A * <li>Remove any UI-set borders from the component. 0N/A * <li>Remove any UI-set layout managers on the component. 0N/A * <li>Remove any UI-added sub-components from the component. 0N/A * <li>Remove any UI-installed keyboard UI from the component. 0N/A * <li>Nullify any allocated instance data objects to allow for GC. 0N/A * @param c the component from which this UI delegate is being removed; 0N/A * this argument is often ignored, 0N/A * but might be used if the UI object is stateless 0N/A * and shared by multiple components 0N/A * @see javax.swing.JComponent#updateUI 1999N/A * Paints the specified component appropriately for the look and feel. 0N/A * This method is invoked from the <code>ComponentUI.update</code> method when 0N/A * the specified component is being painted. Subclasses should override 0N/A * this method and use the specified <code>Graphics</code> object to 0N/A * render the content of the component. 0N/A * @param g the <code>Graphics</code> context in which to paint 0N/A * @param c the component being painted; 0N/A * this argument is often ignored, 0N/A * but might be used if the UI object is stateless 0N/A * and shared by multiple components 1999N/A * Notifies this UI delegate that it is time to paint the specified 0N/A * component. This method is invoked by <code>JComponent</code> 0N/A * when the specified component is being painted. 1999N/A * <p>By default this method fills the specified component with 1999N/A * its background color if its {@code opaque} property is {@code true}, 1999N/A * and then immediately calls {@code paint}. In general this method need 1999N/A * not be overridden by subclasses; all look-and-feel rendering code should 1999N/A * reside in the {@code paint} method. 0N/A * @param g the <code>Graphics</code> context in which to paint 0N/A * @param c the component being painted; 0N/A * this argument is often ignored, 0N/A * but might be used if the UI object is stateless 0N/A * and shared by multiple components 0N/A * @see javax.swing.JComponent#paintComponent 0N/A * Returns the specified component's preferred size appropriate for 0N/A * the look and feel. If <code>null</code> is returned, the preferred 0N/A * size will be calculated by the component's layout manager instead 0N/A * (this is the preferred approach for any component with a specific 0N/A * layout manager installed). The default implementation of this 0N/A * method returns <code>null</code>. 0N/A * @param c the component whose preferred size is being queried; 0N/A * this argument is often ignored, 0N/A * but might be used if the UI object is stateless 0N/A * and shared by multiple components 0N/A * @see javax.swing.JComponent#getPreferredSize 0N/A * @see java.awt.LayoutManager#preferredLayoutSize 0N/A * Returns the specified component's minimum size appropriate for 0N/A * the look and feel. If <code>null</code> is returned, the minimum 0N/A * size will be calculated by the component's layout manager instead 0N/A * (this is the preferred approach for any component with a specific 0N/A * layout manager installed). The default implementation of this 0N/A * method invokes <code>getPreferredSize</code> and returns that value. 0N/A * @param c the component whose minimum size is being queried; 0N/A * this argument is often ignored, 0N/A * but might be used if the UI object is stateless 0N/A * and shared by multiple components 0N/A * @return a <code>Dimension</code> object or <code>null</code> 0N/A * @see javax.swing.JComponent#getMinimumSize 0N/A * @see java.awt.LayoutManager#minimumLayoutSize 0N/A * @see #getPreferredSize 0N/A * Returns the specified component's maximum size appropriate for 0N/A * the look and feel. If <code>null</code> is returned, the maximum 0N/A * size will be calculated by the component's layout manager instead 0N/A * (this is the preferred approach for any component with a specific 0N/A * layout manager installed). The default implementation of this 0N/A * method invokes <code>getPreferredSize</code> and returns that value. 0N/A * @param c the component whose maximum size is being queried; 0N/A * this argument is often ignored, 0N/A * but might be used if the UI object is stateless 0N/A * and shared by multiple components 0N/A * @return a <code>Dimension</code> object or <code>null</code> 0N/A * @see javax.swing.JComponent#getMaximumSize 0N/A * @see java.awt.LayoutManager2#maximumLayoutSize 0N/A * Returns <code>true</code> if the specified <i>x,y</i> location is 0N/A * contained within the look and feel's defined shape of the specified 0N/A * component. <code>x</code> and <code>y</code> are defined to be relative 0N/A * to the coordinate system of the specified component. Although 0N/A * a component's <code>bounds</code> is constrained to a rectangle, 0N/A * this method provides the means for defining a non-rectangular 0N/A * shape within those bounds for the purpose of hit detection. 0N/A * @param c the component where the <i>x,y</i> location is being queried; 0N/A * this argument is often ignored, 0N/A * but might be used if the UI object is stateless 0N/A * and shared by multiple components 0N/A * @param x the <i>x</i> coordinate of the point 0N/A * @param y the <i>y</i> coordinate of the point 0N/A * @see javax.swing.JComponent#contains 0N/A * @see java.awt.Component#contains 0N/A * Returns an instance of the UI delegate for the specified component. 0N/A * Each subclass must provide its own static <code>createUI</code> 0N/A * method that returns an instance of that UI delegate subclass. 0N/A * If the UI delegate subclass is stateless, it may return an instance 0N/A * that is shared by multiple components. If the UI delegate is 0N/A * stateful, then it should return a new instance per component. 0N/A * The default implementation of this method throws an error, as it 0N/A * should never be invoked. 0N/A throw new Error(
"ComponentUI.createUI not implemented.");
0N/A * Returns the baseline. The baseline is measured from the top of 0N/A * the component. This method is primarily meant for 0N/A * <code>LayoutManager</code>s to align components along their 0N/A * baseline. A return value less than 0 indicates this component 0N/A * does not have a reasonable baseline and that 0N/A * <code>LayoutManager</code>s should not align this component on 0N/A * This method returns -1. Subclasses that have a meaningful baseline 0N/A * should override appropriately. 0N/A * @param c <code>JComponent</code> baseline is being requested for 0N/A * @param width the width to get the baseline for 0N/A * @param height the height to get the baseline for 0N/A * @throws NullPointerException if <code>c</code> is <code>null</code> 0N/A * @throws IllegalArgumentException if width or height is < 0 0N/A * @return baseline or a value < 0 indicating there is no reasonable 0N/A * @see javax.swing.JComponent#getBaseline(int,int) 0N/A "Width and height must be >= 0");
0N/A * Returns an enum indicating how the baseline of he component 0N/A * changes as the size changes. This method is primarily meant for 0N/A * layout managers and GUI builders. 0N/A * This method returns <code>BaselineResizeBehavior.OTHER</code>. 0N/A * Subclasses that support a baseline should override appropriately. 0N/A * @param c <code>JComponent</code> to return baseline resize behavior for 0N/A * @return an enum indicating how the baseline changes as the component 0N/A * @throws NullPointerException if <code>c</code> is <code>null</code> 0N/A * @see javax.swing.JComponent#getBaseline(int, int) 0N/A * Returns the number of accessible children in the object. If all 0N/A * of the children of this object implement <code>Accessible</code>, 0N/A * method should return the number of children of this object. 0N/A * UIs might wish to override this if they present areas on the 0N/A * screen that can be viewed as components, but actual components 0N/A * are not used for presenting those areas. 0N/A * Note: As of v1.3, it is recommended that developers call 0N/A * <code>Component.AccessibleAWTComponent.getAccessibleChildrenCount()</code> instead 0N/A * @see #getAccessibleChild 0N/A * @return the number of accessible children in the object 0N/A * Returns the <code>i</code>th <code>Accessible</code> child of the object. 0N/A * UIs might need to override this if they present areas on the 0N/A * screen that can be viewed as components, but actual components 0N/A * are not used for presenting those areas. 0N/A * Note: As of v1.3, it is recommended that developers call 0N/A * <code>Component.AccessibleAWTComponent.getAccessibleChild()</code> instead of 0N/A * @see #getAccessibleChildrenCount 0N/A * @param i zero-based index of child 0N/A * @return the <code>i</code>th <code>Accessible</code> child of the object