1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17package org.apache.log4j.lf5.viewer;
1819import java.awt.Adjustable;
20import java.awt.event.AdjustmentEvent;
21import java.awt.event.AdjustmentListener;
2223/**24 * An AdjustmentListener which ensures that an Adjustable (e.g. a Scrollbar)25 * will "track" when the Adjustable expands.26 * For example, when a vertical scroll bar is at its bottom anchor,27 * the scrollbar will remain at the bottom. When the vertical scroll bar28 * is at any other location, then no tracking will happen.29 * An instance of this class should only listen to one Adjustable as30 * it retains state information about the Adjustable it listens to.31 *32 * @author Richard Wan33 */3435// Contributed by ThoughtWorks Inc.3637publicclassTrackingAdjustmentListener implements AdjustmentListener {
38//--------------------------------------------------------------------------39// Constants:40//--------------------------------------------------------------------------4142//--------------------------------------------------------------------------43// Protected Variables:44//--------------------------------------------------------------------------4546protectedint _lastMaximum = -1;
4748//--------------------------------------------------------------------------49// Private Variables:50//--------------------------------------------------------------------------5152//--------------------------------------------------------------------------53// Constructors:54//--------------------------------------------------------------------------5556//--------------------------------------------------------------------------57// Public Methods:58//--------------------------------------------------------------------------5960publicvoid adjustmentValueChanged(AdjustmentEvent e) {
61 Adjustable bar = e.getAdjustable();
62int currentMaximum = bar.getMaximum();
63if (bar.getMaximum() == _lastMaximum) {
64return; // nothing to do, the adjustable has not expanded65 }
66int bottom = bar.getValue() + bar.getVisibleAmount();
6768if (bottom + bar.getUnitIncrement() >= _lastMaximum) {
69 bar.setValue(bar.getMaximum()); // use the most recent maximum70 }
71 _lastMaximum = currentMaximum;
72 }
7374//--------------------------------------------------------------------------75// Protected Methods:76//--------------------------------------------------------------------------7778//--------------------------------------------------------------------------79// Private Methods:80//--------------------------------------------------------------------------8182//--------------------------------------------------------------------------83// Nested Top-Level Classes or Interfaces84//--------------------------------------------------------------------------85 }
86