1 /* 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing.plaf; 27 28 import javax.swing.JComponent; 29 import javax.swing.SwingUtilities; 30 import javax.accessibility.Accessible; 31 32 import java.awt.Component; 33 import java.awt.Container; 34 import java.awt.Dimension; 35 import java.awt.Graphics; 36 import java.awt.Insets; 37 38 39 /** 40 * The base class for all UI delegate objects in the Swing pluggable 41 * look and feel architecture. The UI delegate object for a Swing 42 * component is responsible for implementing the aspects of the 43 * component that depend on the look and feel. 44 * The <code>JComponent</code> class 45 * invokes methods from this class in order to delegate operations 46 * (painting, layout calculations, etc.) that may vary depending on the 47 * look and feel installed. <b>Client programs should not invoke methods 48 * on this class directly.</b> 49 * 50 * @see javax.swing.JComponent 51 * @see javax.swing.UIManager 52 * 53 */ 54 public abstract class ComponentUI { 55 /** 56 * Sole constructor. (For invocation by subclass constructors, 57 * typically implicit.) 58 */ 59 public ComponentUI() { 60 } 61 62 /** 63 * Configures the specified component appropriately for the look and feel. 64 * This method is invoked when the <code>ComponentUI</code> instance is being installed 65 * as the UI delegate on the specified component. This method should 66 * completely configure the component for the look and feel, 67 * including the following: 68 * <ol> 69 * <li>Install default property values for color, fonts, borders, 70 * icons, opacity, etc. on the component. Whenever possible, 71 * property values initialized by the client program should <i>not</i> 72 * be overridden. 73 * <li>Install a <code>LayoutManager</code> on the component if necessary. 74 * <li>Create/add any required sub-components to the component. 75 * <li>Create/install event listeners on the component. 76 * <li>Create/install a <code>PropertyChangeListener</code> on the component in order 77 * to detect and respond to component property changes appropriately. 78 * <li>Install keyboard UI (mnemonics, traversal, etc.) on the component. 79 * <li>Initialize any appropriate instance data. 80 * </ol> 81 * @param c the component where this UI delegate is being installed 82 * 83 * @see #uninstallUI 84 * @see javax.swing.JComponent#setUI 85 * @see javax.swing.JComponent#updateUI 86 */ 87 public void installUI(JComponent c) { 88 } 89 90 /** 91 * Reverses configuration which was done on the specified component during 92 * <code>installUI</code>. This method is invoked when this 93 * <code>UIComponent</code> instance is being removed as the UI delegate 94 * for the specified component. This method should undo the 95 * configuration performed in <code>installUI</code>, being careful to 96 * leave the <code>JComponent</code> instance in a clean state (no 97 * extraneous listeners, look-and-feel-specific property objects, etc.). 98 * This should include the following: 99 * <ol> 100 * <li>Remove any UI-set borders from the component. 101 * <li>Remove any UI-set layout managers on the component. 102 * <li>Remove any UI-added sub-components from the component. 103 * <li>Remove any UI-added event/property listeners from the component. 104 * <li>Remove any UI-installed keyboard UI from the component. 105 * <li>Nullify any allocated instance data objects to allow for GC. 106 * </ol> 107 * @param c the component from which this UI delegate is being removed; 108 * this argument is often ignored, 109 * but might be used if the UI object is stateless 110 * and shared by multiple components 111 * 112 * @see #installUI 113 * @see javax.swing.JComponent#updateUI 114 */ 115 public void uninstallUI(JComponent c) { 116 } 117 118 /** 119 * Paints the specified component appropriately for the look and feel. 120 * This method is invoked from the <code>ComponentUI.update</code> method when 121 * the specified component is being painted. Subclasses should override 122 * this method and use the specified <code>Graphics</code> object to 123 * render the content of the component. 124 * 125 * @param g the <code>Graphics</code> context in which to paint 126 * @param c the component being painted; 127 * this argument is often ignored, 128 * but might be used if the UI object is stateless 129 * and shared by multiple components 130 * 131 * @see #update 132 */ 133 public void paint(Graphics g, JComponent c) { 134 } 135 348 /** 349 * Returns the <code>i</code>th <code>Accessible</code> child of the object. 350 * UIs might need to override this if they present areas on the 351 * screen that can be viewed as components, but actual components 352 * are not used for presenting those areas. 353 * 354 * <p> 355 * 356 * Note: As of v1.3, it is recommended that developers call 357 * <code>Component.AccessibleAWTComponent.getAccessibleChild()</code> instead of 358 * this method. 359 * 360 * @param c a {@code JComponent} for which to get a child object 361 * @param i zero-based index of child 362 * @return the <code>i</code>th <code>Accessible</code> child of the object 363 * @see #getAccessibleChildrenCount 364 */ 365 public Accessible getAccessibleChild(JComponent c, int i) { 366 return SwingUtilities.getAccessibleChild(c, i); 367 } 368 } | 1 /* 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing.plaf; 27 28 import javax.swing.JComponent; 29 import javax.swing.SwingUtilities; 30 import javax.accessibility.Accessible; 31 32 import java.awt.Component; 33 import java.awt.Dimension; 34 import java.awt.Graphics; 35 import javax.swing.UIManager; 36 import sun.swing.SwingUtilities2; 37 38 39 /** 40 * The base class for all UI delegate objects in the Swing pluggable 41 * look and feel architecture. The UI delegate object for a Swing 42 * component is responsible for implementing the aspects of the 43 * component that depend on the look and feel. 44 * The <code>JComponent</code> class 45 * invokes methods from this class in order to delegate operations 46 * (painting, layout calculations, etc.) that may vary depending on the 47 * look and feel installed. <b>Client programs should not invoke methods 48 * on this class directly.</b> 49 * 50 * @see javax.swing.JComponent 51 * @see javax.swing.UIManager 52 * 53 */ 54 public abstract class ComponentUI { 55 56 private TextUIDrawing textUIDrawing; 57 58 /** 59 * Sole constructor. (For invocation by subclass constructors, 60 * typically implicit.) 61 */ 62 public ComponentUI() { 63 } 64 65 /** 66 * Configures the specified component appropriately for the look and feel. 67 * This method is invoked when the <code>ComponentUI</code> instance is being installed 68 * as the UI delegate on the specified component. This method should 69 * completely configure the component for the look and feel, 70 * including the following: 71 * <ol> 72 * <li>Install default property values for color, fonts, borders, 73 * icons, opacity, etc. on the component. Whenever possible, 74 * property values initialized by the client program should <i>not</i> 75 * be overridden. 76 * <li>Install a <code>LayoutManager</code> on the component if necessary. 77 * <li>Create/add any required sub-components to the component. 78 * <li>Create/install event listeners on the component. 79 * <li>Create/install a <code>PropertyChangeListener</code> on the component in order 80 * to detect and respond to component property changes appropriately. 81 * <li>Install keyboard UI (mnemonics, traversal, etc.) on the component. 82 * <li>Initialize any appropriate instance data. 83 * </ol> 84 * @param c the component where this UI delegate is being installed 85 * 86 * @see #uninstallUI 87 * @see javax.swing.JComponent#setUI 88 * @see javax.swing.JComponent#updateUI 89 */ 90 public void installUI(JComponent c) { 91 92 if (textUIDrawing == null || textUIDrawing instanceof UIResource) { 93 textUIDrawing = (TextUIDrawing) UIManager.get("uiDrawing.text"); 94 } 95 96 if (textUIDrawing == null) { 97 textUIDrawing = SwingUtilities2.DEFAULT_UI_TEXT_DRAWING; 98 } 99 } 100 101 /** 102 * Reverses configuration which was done on the specified component during 103 * <code>installUI</code>. This method is invoked when this 104 * <code>UIComponent</code> instance is being removed as the UI delegate 105 * for the specified component. This method should undo the 106 * configuration performed in <code>installUI</code>, being careful to 107 * leave the <code>JComponent</code> instance in a clean state (no 108 * extraneous listeners, look-and-feel-specific property objects, etc.). 109 * This should include the following: 110 * <ol> 111 * <li>Remove any UI-set borders from the component. 112 * <li>Remove any UI-set layout managers on the component. 113 * <li>Remove any UI-added sub-components from the component. 114 * <li>Remove any UI-added event/property listeners from the component. 115 * <li>Remove any UI-installed keyboard UI from the component. 116 * <li>Nullify any allocated instance data objects to allow for GC. 117 * </ol> 118 * @param c the component from which this UI delegate is being removed; 119 * this argument is often ignored, 120 * but might be used if the UI object is stateless 121 * and shared by multiple components 122 * 123 * @see #installUI 124 * @see javax.swing.JComponent#updateUI 125 */ 126 public void uninstallUI(JComponent c) { 127 if (textUIDrawing instanceof UIResource) { 128 textUIDrawing = null; 129 } 130 } 131 132 /** 133 * Paints the specified component appropriately for the look and feel. 134 * This method is invoked from the <code>ComponentUI.update</code> method when 135 * the specified component is being painted. Subclasses should override 136 * this method and use the specified <code>Graphics</code> object to 137 * render the content of the component. 138 * 139 * @param g the <code>Graphics</code> context in which to paint 140 * @param c the component being painted; 141 * this argument is often ignored, 142 * but might be used if the UI object is stateless 143 * and shared by multiple components 144 * 145 * @see #update 146 */ 147 public void paint(Graphics g, JComponent c) { 148 } 149 362 /** 363 * Returns the <code>i</code>th <code>Accessible</code> child of the object. 364 * UIs might need to override this if they present areas on the 365 * screen that can be viewed as components, but actual components 366 * are not used for presenting those areas. 367 * 368 * <p> 369 * 370 * Note: As of v1.3, it is recommended that developers call 371 * <code>Component.AccessibleAWTComponent.getAccessibleChild()</code> instead of 372 * this method. 373 * 374 * @param c a {@code JComponent} for which to get a child object 375 * @param i zero-based index of child 376 * @return the <code>i</code>th <code>Accessible</code> child of the object 377 * @see #getAccessibleChildrenCount 378 */ 379 public Accessible getAccessibleChild(JComponent c, int i) { 380 return SwingUtilities.getAccessibleChild(c, i); 381 } 382 383 /** 384 * Returns the {@code TextUIDrawing} instance responsible for text drawing 385 * and measuring. 386 * 387 * @return {@code TextUIDrawing} instance 388 * 389 * @since 9 390 */ 391 public TextUIDrawing getTextUIDrawing() { 392 return textUIDrawing; 393 } 394 } |