Path: blob/master/src/java.desktop/macosx/classes/sun/lwawt/LWScrollBarPeer.java
41153 views
/*1* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526package sun.lwawt;2728import java.awt.Adjustable;29import java.awt.Scrollbar;30import java.awt.event.AdjustmentEvent;31import java.awt.event.AdjustmentListener;32import java.awt.peer.ScrollbarPeer;3334import javax.swing.JScrollBar;3536/**37* Lightweight implementation of {@link ScrollbarPeer}. Delegates most of the38* work to the {@link JScrollBar}.39*/40final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar>41implements ScrollbarPeer, AdjustmentListener {4243// JScrollBar fires two changes with firePropertyChange (one for old value44// and one for new one.45// We save the last value and don't fire event if not changed.46private int currentValue;4748LWScrollBarPeer(final Scrollbar target,49final PlatformComponent platformComponent) {50super(target, platformComponent);51}5253@Override54JScrollBar createDelegate() {55return new JScrollBar();56}5758@Override59void initializeImpl() {60super.initializeImpl();61final Scrollbar target = getTarget();62setLineIncrement(target.getUnitIncrement());63setPageIncrement(target.getBlockIncrement());64setValues(target.getValue(), target.getVisibleAmount(),65target.getMinimum(), target.getMaximum());6667final int orientation = target.getOrientation();68final JScrollBar delegate = getDelegate();69synchronized (getDelegateLock()) {70delegate.setOrientation(orientation == Scrollbar.HORIZONTAL71? Adjustable.HORIZONTAL72: Adjustable.VERTICAL);73delegate.addAdjustmentListener(this);74}75}7677@Override78public void setValues(final int value, final int visible, final int minimum,79final int maximum) {80synchronized (getDelegateLock()) {81currentValue = value;82getDelegate().setValues(value, visible, minimum, maximum);83}84}8586@Override87public void setLineIncrement(final int l) {88synchronized (getDelegateLock()) {89getDelegate().setUnitIncrement(l);90}91}9293@Override94public void setPageIncrement(final int l) {95synchronized (getDelegateLock()) {96getDelegate().setBlockIncrement(l);97}98}99100// Peer also registered as a listener for ComponentDelegate component101@Override102public void adjustmentValueChanged(final AdjustmentEvent e) {103final int value = e.getValue();104synchronized (getDelegateLock()) {105if (currentValue == value) {106return;107}108currentValue = value;109}110getTarget().setValueIsAdjusting(e.getValueIsAdjusting());111getTarget().setValue(value);112postEvent(new AdjustmentEvent(getTarget(), e.getID(),113e.getAdjustmentType(), value,114e.getValueIsAdjusting()));115}116}117118119