28 import java.awt.ScrollPane; |
28 import java.awt.ScrollPane; |
29 import java.awt.Insets; |
29 import java.awt.Insets; |
30 import java.awt.Adjustable; |
30 import java.awt.Adjustable; |
31 import java.awt.event.MouseWheelEvent; |
31 import java.awt.event.MouseWheelEvent; |
32 |
32 |
33 import java.util.logging.*; |
33 import sun.util.logging.PlatformLogger; |
34 |
34 |
35 /* |
35 /* |
36 * ScrollPaneWheelScroller is a helper class for implmenenting mouse wheel |
36 * ScrollPaneWheelScroller is a helper class for implmenenting mouse wheel |
37 * scrolling on a java.awt.ScrollPane. It contains only static methods. |
37 * scrolling on a java.awt.ScrollPane. It contains only static methods. |
38 * No objects of this class may be instantiated, thus it is declared abstract. |
38 * No objects of this class may be instantiated, thus it is declared abstract. |
39 */ |
39 */ |
40 public abstract class ScrollPaneWheelScroller { |
40 public abstract class ScrollPaneWheelScroller { |
41 |
41 |
42 private static final Logger log = Logger.getLogger("sun.awt.ScrollPaneWheelScroller"); |
42 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.ScrollPaneWheelScroller"); |
43 |
43 |
44 private ScrollPaneWheelScroller() {} |
44 private ScrollPaneWheelScroller() {} |
45 |
45 |
46 /* |
46 /* |
47 * Called from ScrollPane.processMouseWheelEvent() |
47 * Called from ScrollPane.processMouseWheelEvent() |
48 */ |
48 */ |
49 public static void handleWheelScrolling(ScrollPane sp, MouseWheelEvent e) { |
49 public static void handleWheelScrolling(ScrollPane sp, MouseWheelEvent e) { |
50 if (log.isLoggable(Level.FINER)) { |
50 if (log.isLoggable(PlatformLogger.FINER)) { |
51 log.log(Level.FINER, "x = " + e.getX() + ", y = " + e.getY() + ", src is " + e.getSource()); |
51 log.finer("x = " + e.getX() + ", y = " + e.getY() + ", src is " + e.getSource()); |
52 } |
52 } |
53 int increment = 0; |
53 int increment = 0; |
54 |
54 |
55 if (sp != null && e.getScrollAmount() != 0) { |
55 if (sp != null && e.getScrollAmount() != 0) { |
56 Adjustable adj = getAdjustableToScroll(sp); |
56 Adjustable adj = getAdjustableToScroll(sp); |
57 if (adj != null) { |
57 if (adj != null) { |
58 increment = getIncrementFromAdjustable(adj, e); |
58 increment = getIncrementFromAdjustable(adj, e); |
59 if (log.isLoggable(Level.FINER)) { |
59 if (log.isLoggable(PlatformLogger.FINER)) { |
60 log.log(Level.FINER, "increment from adjustable(" + adj.getClass() + ") : " + increment); |
60 log.finer("increment from adjustable(" + adj.getClass() + ") : " + increment); |
61 } |
61 } |
62 scrollAdjustable(adj, increment); |
62 scrollAdjustable(adj, increment); |
63 } |
63 } |
64 } |
64 } |
65 } |
65 } |
72 int policy = sp.getScrollbarDisplayPolicy(); |
72 int policy = sp.getScrollbarDisplayPolicy(); |
73 |
73 |
74 // if policy is display always or never, use vert |
74 // if policy is display always or never, use vert |
75 if (policy == ScrollPane.SCROLLBARS_ALWAYS || |
75 if (policy == ScrollPane.SCROLLBARS_ALWAYS || |
76 policy == ScrollPane.SCROLLBARS_NEVER) { |
76 policy == ScrollPane.SCROLLBARS_NEVER) { |
77 if (log.isLoggable(Level.FINER)) { |
77 if (log.isLoggable(PlatformLogger.FINER)) { |
78 log.log(Level.FINER, "using vertical scrolling due to scrollbar policy"); |
78 log.finer("using vertical scrolling due to scrollbar policy"); |
79 } |
79 } |
80 return sp.getVAdjustable(); |
80 return sp.getVAdjustable(); |
81 |
81 |
82 } |
82 } |
83 else { |
83 else { |
84 |
84 |
85 Insets ins = sp.getInsets(); |
85 Insets ins = sp.getInsets(); |
86 int vertScrollWidth = sp.getVScrollbarWidth(); |
86 int vertScrollWidth = sp.getVScrollbarWidth(); |
87 |
87 |
88 if (log.isLoggable(Level.FINER)) { |
88 if (log.isLoggable(PlatformLogger.FINER)) { |
89 log.log(Level.FINER, "insets: l = " + ins.left + ", r = " + ins.right + |
89 log.finer("insets: l = " + ins.left + ", r = " + ins.right + |
90 ", t = " + ins.top + ", b = " + ins.bottom); |
90 ", t = " + ins.top + ", b = " + ins.bottom); |
91 log.log(Level.FINER, "vertScrollWidth = " + vertScrollWidth); |
91 log.finer("vertScrollWidth = " + vertScrollWidth); |
92 } |
92 } |
93 |
93 |
94 // Check if scrollbar is showing by examining insets of the |
94 // Check if scrollbar is showing by examining insets of the |
95 // ScrollPane |
95 // ScrollPane |
96 if (ins.right >= vertScrollWidth) { |
96 if (ins.right >= vertScrollWidth) { |
97 if (log.isLoggable(Level.FINER)) { |
97 if (log.isLoggable(PlatformLogger.FINER)) { |
98 log.log(Level.FINER, "using vertical scrolling because scrollbar is present"); |
98 log.finer("using vertical scrolling because scrollbar is present"); |
99 } |
99 } |
100 return sp.getVAdjustable(); |
100 return sp.getVAdjustable(); |
101 } |
101 } |
102 else { |
102 else { |
103 int horizScrollHeight = sp.getHScrollbarHeight(); |
103 int horizScrollHeight = sp.getHScrollbarHeight(); |
104 if (ins.bottom >= horizScrollHeight) { |
104 if (ins.bottom >= horizScrollHeight) { |
105 if (log.isLoggable(Level.FINER)) { |
105 if (log.isLoggable(PlatformLogger.FINER)) { |
106 log.log(Level.FINER, "using horiz scrolling because scrollbar is present"); |
106 log.finer("using horiz scrolling because scrollbar is present"); |
107 } |
107 } |
108 return sp.getHAdjustable(); |
108 return sp.getHAdjustable(); |
109 } |
109 } |
110 else { |
110 else { |
111 if (log.isLoggable(Level.FINER)) { |
111 if (log.isLoggable(PlatformLogger.FINER)) { |
112 log.log(Level.FINER, "using NO scrollbar becsause neither is present"); |
112 log.finer("using NO scrollbar becsause neither is present"); |
113 } |
113 } |
114 return null; |
114 return null; |
115 } |
115 } |
116 } |
116 } |
117 } |
117 } |
144 /* |
144 /* |
145 * Scroll the given Adjustable by the given amount. Checks the Adjustable's |
145 * Scroll the given Adjustable by the given amount. Checks the Adjustable's |
146 * bounds and sets the new value to the Adjustable. |
146 * bounds and sets the new value to the Adjustable. |
147 */ |
147 */ |
148 public static void scrollAdjustable(Adjustable adj, int amount) { |
148 public static void scrollAdjustable(Adjustable adj, int amount) { |
149 if (log.isLoggable(Level.FINE)) { |
149 if (log.isLoggable(PlatformLogger.FINE)) { |
150 if (adj == null) { |
150 if (adj == null) { |
151 log.log(Level.FINE, "Assertion (adj != null) failed"); |
151 log.fine("Assertion (adj != null) failed"); |
152 } |
152 } |
153 if (amount == 0) { |
153 if (amount == 0) { |
154 log.log(Level.FINE, "Assertion (amount != 0) failed"); |
154 log.fine("Assertion (amount != 0) failed"); |
155 } |
155 } |
156 } |
156 } |
157 |
157 |
158 int current = adj.getValue(); |
158 int current = adj.getValue(); |
159 int upperLimit = adj.getMaximum() - adj.getVisibleAmount(); |
159 int upperLimit = adj.getMaximum() - adj.getVisibleAmount(); |
160 if (log.isLoggable(Level.FINER)) { |
160 if (log.isLoggable(PlatformLogger.FINER)) { |
161 log.log(Level.FINER, "doScrolling by " + amount); |
161 log.finer("doScrolling by " + amount); |
162 } |
162 } |
163 |
163 |
164 if (amount > 0 && current < upperLimit) { // still some room to scroll |
164 if (amount > 0 && current < upperLimit) { // still some room to scroll |
165 // down |
165 // down |
166 if (current + amount < upperLimit) { |
166 if (current + amount < upperLimit) { |