0N/A/*
3261N/A * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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.
0N/A *
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
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing.plaf.metal;
0N/A
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.border.*;
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.swing.plaf.basic.*;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.beans.*;
0N/Aimport java.awt.event.*;
0N/A
0N/A
0N/A/**
0N/A * A Metal L&F implementation of ScrollPaneUI.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @author Steve Wilson
0N/A */
0N/Apublic class MetalScrollPaneUI extends BasicScrollPaneUI
0N/A{
0N/A
0N/A private PropertyChangeListener scrollBarSwapListener;
0N/A
0N/A public static ComponentUI createUI(JComponent x) {
0N/A return new MetalScrollPaneUI();
0N/A }
0N/A
0N/A public void installUI(JComponent c) {
0N/A
0N/A super.installUI(c);
0N/A
0N/A JScrollPane sp = (JScrollPane)c;
0N/A updateScrollbarsFreeStanding();
0N/A }
0N/A
0N/A public void uninstallUI(JComponent c) {
0N/A super.uninstallUI(c);
0N/A
0N/A JScrollPane sp = (JScrollPane)c;
0N/A JScrollBar hsb = sp.getHorizontalScrollBar();
0N/A JScrollBar vsb = sp.getVerticalScrollBar();
0N/A if (hsb != null) {
0N/A hsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null);
0N/A }
0N/A if (vsb != null) {
0N/A vsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null);
0N/A }
0N/A }
0N/A
0N/A public void installListeners(JScrollPane scrollPane) {
0N/A super.installListeners(scrollPane);
0N/A scrollBarSwapListener = createScrollBarSwapListener();
0N/A scrollPane.addPropertyChangeListener(scrollBarSwapListener);
0N/A }
0N/A
3093N/A /**
3093N/A * {@inheritDoc}
3093N/A */
3093N/A protected void uninstallListeners(JComponent c) {
3093N/A super.uninstallListeners(c);
3093N/A c.removePropertyChangeListener(scrollBarSwapListener);
3093N/A }
0N/A
3093N/A /**
3093N/A * @deprecated - Replaced by {@link #uninstallListeners(JComponent)}
3093N/A */
3093N/A @Deprecated
0N/A public void uninstallListeners(JScrollPane scrollPane) {
0N/A super.uninstallListeners(scrollPane);
0N/A scrollPane.removePropertyChangeListener(scrollBarSwapListener);
0N/A }
0N/A
0N/A /**
0N/A * If the border of the scrollpane is an instance of
0N/A * <code>MetalBorders.ScrollPaneBorder</code>, the client property
0N/A * <code>FREE_STANDING_PROP</code> of the scrollbars
0N/A * is set to false, otherwise it is set to true.
0N/A */
0N/A private void updateScrollbarsFreeStanding() {
0N/A if (scrollpane == null) {
0N/A return;
0N/A }
0N/A Border border = scrollpane.getBorder();
0N/A Object value;
0N/A
0N/A if (border instanceof MetalBorders.ScrollPaneBorder) {
0N/A value = Boolean.FALSE;
0N/A }
0N/A else {
0N/A value = Boolean.TRUE;
0N/A }
0N/A JScrollBar sb = scrollpane.getHorizontalScrollBar();
0N/A if (sb != null) {
0N/A sb.putClientProperty
0N/A (MetalScrollBarUI.FREE_STANDING_PROP, value);
0N/A }
0N/A sb = scrollpane.getVerticalScrollBar();
0N/A if (sb != null) {
0N/A sb.putClientProperty
0N/A (MetalScrollBarUI.FREE_STANDING_PROP, value);
0N/A }
0N/A }
0N/A
0N/A protected PropertyChangeListener createScrollBarSwapListener() {
0N/A return new PropertyChangeListener() {
0N/A public void propertyChange(PropertyChangeEvent e) {
0N/A String propertyName = e.getPropertyName();
0N/A if (propertyName.equals("verticalScrollBar") ||
0N/A propertyName.equals("horizontalScrollBar")) {
0N/A JScrollBar oldSB = (JScrollBar)e.getOldValue();
0N/A if (oldSB != null) {
0N/A oldSB.putClientProperty(
0N/A MetalScrollBarUI.FREE_STANDING_PROP, null);
0N/A }
0N/A JScrollBar newSB = (JScrollBar)e.getNewValue();
0N/A if (newSB != null) {
0N/A newSB.putClientProperty(
0N/A MetalScrollBarUI.FREE_STANDING_PROP,
0N/A Boolean.FALSE);
0N/A }
0N/A }
0N/A else if ("border".equals(propertyName)) {
0N/A updateScrollbarsFreeStanding();
0N/A }
0N/A }};
0N/A }
0N/A
0N/A}