001/* MetalScrollPaneUI.java 002 Copyright (C) 2005 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package javax.swing.plaf.metal; 040 041import java.beans.PropertyChangeListener; 042 043import javax.swing.JComponent; 044import javax.swing.JScrollBar; 045import javax.swing.JScrollPane; 046import javax.swing.plaf.ComponentUI; 047import javax.swing.plaf.basic.BasicScrollPaneUI; 048 049/** 050 * A UI delegate for the {@link JScrollPane} component. 051 */ 052public class MetalScrollPaneUI 053 extends BasicScrollPaneUI 054{ 055 /** 056 * Constructs a new instance of <code>MetalScrollPaneUI</code>. 057 */ 058 public MetalScrollPaneUI() 059 { 060 super(); 061 } 062 063 /** 064 * Returns a shared instance of <code>MetalScrollPaneUI</code>. 065 * 066 * @param component the component for which we return an UI instance 067 * 068 * @return A shared instance of <code>MetalScrollPaneUI</code>. 069 */ 070 public static ComponentUI createUI(JComponent component) 071 { 072 return new MetalScrollPaneUI(); 073 } 074 075 /** 076 * Configures the specified component appropriate for the look and feel. 077 * This method is invoked when the ComponentUI instance is being installed 078 * as the UI delegate on the specified component. This method should 079 * completely configure the component for the look and feel, 080 * including the following: 081 * 1. Install any default property values for color, fonts, borders, 082 * icons, opacity, etc. on the component. Whenever possible, property 083 * values initialized by the client program should not be overridden. 084 * 2. Install a LayoutManager on the component if necessary. 085 * 3. Create/add any required sub-components to the component. 086 * 4. Create/install event listeners on the component. 087 * 5. Create/install a PropertyChangeListener on the component in order 088 * to detect and respond to component property changes appropriately. 089 * 6. Install keyboard UI (mnemonics, traversal, etc.) on the component. 090 * 7. Initialize any appropriate instance data. 091 * 092 * @param c - the component to install the ui on 093 */ 094 public void installUI(JComponent c) 095 { 096 super.installUI(c); 097 JScrollBar hsb = scrollpane.getHorizontalScrollBar(); 098 hsb.putClientProperty(MetalScrollBarUI.FREE_STANDING_PROP, Boolean.FALSE); 099 JScrollBar vsb = scrollpane.getVerticalScrollBar(); 100 vsb.putClientProperty(MetalScrollBarUI.FREE_STANDING_PROP, Boolean.FALSE); 101 } 102 103 /** 104 * Reverses configuration which was done on the specified component 105 * during installUI. This method is invoked when this UIComponent 106 * instance is being removed as the UI delegate for the specified 107 * component. This method should undo the configuration performed in 108 * installUI, being careful to leave the JComponent instance in a 109 * clean state (no extraneous listeners, look-and-feel-specific property 110 * objects, etc.). This should include the following: 111 * 1. Remove any UI-set borders from the component. 112 * 2. Remove any UI-set layout managers on the component. 113 * 3. Remove any UI-added sub-components from the component. 114 * 4. Remove any UI-added event/property listeners from the component. 115 * 5. Remove any UI-installed keyboard UI from the component. 116 * 6. Nullify any allocated instance data objects to allow for GC. 117 * 118 * @param c - the component to uninstall the ui on 119 */ 120 public void uninstallUI(JComponent c) 121 { 122 JScrollBar hsb = scrollpane.getHorizontalScrollBar(); 123 hsb.putClientProperty(MetalScrollBarUI.FREE_STANDING_PROP, null); 124 JScrollBar vsb = scrollpane.getVerticalScrollBar(); 125 vsb.putClientProperty(MetalScrollBarUI.FREE_STANDING_PROP, null); 126 super.uninstallUI(c); 127 } 128 129 /** 130 * Installs listeners on scrollPane 131 * 132 * @param scrollPane - the component to install the listeners on 133 */ 134 public void installListeners(JScrollPane scrollPane) 135 { 136 super.installListeners(scrollPane); 137 } 138 139 /** 140 * Uninstalls listeners on scrollPane 141 * 142 * @param scrollPane - the component to uninstall the listeners on 143 */ 144 public void uninstallListeners(JScrollPane scrollPane) 145 { 146 super.uninstallListeners(scrollPane); 147 } 148 149 /** 150 * TODO 151 * 152 * @return TODO 153 */ 154 protected PropertyChangeListener createScrollBarSwapListener() 155 { 156 // FIXME: Anything else to do here? 157 return super.createPropertyChangeListener(); 158 } 159}