KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > TrackingAdjustmentListener


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.log4j.lf5.viewer;
17
18 import java.awt.*;
19 import java.awt.event.AdjustmentEvent JavaDoc;
20 import java.awt.event.AdjustmentListener JavaDoc;
21
22 /**
23  * An AdjustmentListener which ensures that an Adjustable (e.g. a Scrollbar)
24  * will "track" when the Adjustable expands.
25  * For example, when a vertical scroll bar is at its bottom anchor,
26  * the scrollbar will remain at the bottom. When the vertical scroll bar
27  * is at any other location, then no tracking will happen.
28  * An instance of this class should only listen to one Adjustable as
29  * it retains state information about the Adjustable it listens to.
30  *
31  * @author Richard Wan
32  */

33
34 // Contributed by ThoughtWorks Inc.
35

36 public class TrackingAdjustmentListener implements AdjustmentListener JavaDoc {
37   //--------------------------------------------------------------------------
38
// Constants:
39
//--------------------------------------------------------------------------
40

41   //--------------------------------------------------------------------------
42
// Protected Variables:
43
//--------------------------------------------------------------------------
44

45   protected int _lastMaximum = -1;
46
47   //--------------------------------------------------------------------------
48
// Private Variables:
49
//--------------------------------------------------------------------------
50

51   //--------------------------------------------------------------------------
52
// Constructors:
53
//--------------------------------------------------------------------------
54

55   //--------------------------------------------------------------------------
56
// Public Methods:
57
//--------------------------------------------------------------------------
58

59   public void adjustmentValueChanged(AdjustmentEvent JavaDoc e) {
60     Adjustable bar = e.getAdjustable();
61     int currentMaximum = bar.getMaximum();
62     if (bar.getMaximum() == _lastMaximum) {
63       return; // nothing to do, the adjustable has not expanded
64
}
65     int bottom = bar.getValue() + bar.getVisibleAmount();
66
67     if (bottom + bar.getUnitIncrement() >= _lastMaximum) {
68       bar.setValue(bar.getMaximum()); // use the most recent maximum
69
}
70     _lastMaximum = currentMaximum;
71   }
72
73   //--------------------------------------------------------------------------
74
// Protected Methods:
75
//--------------------------------------------------------------------------
76

77   //--------------------------------------------------------------------------
78
// Private Methods:
79
//--------------------------------------------------------------------------
80

81   //--------------------------------------------------------------------------
82
// Nested Top-Level Classes or Interfaces
83
//--------------------------------------------------------------------------
84
}
85
86
Popular Tags