01: package com.jidesoft.dialog;
02:
03: import javax.swing.*;
04: import java.awt.*;
05:
06: /**
07: * A <code>ButtonPanel</code> that implements the <code>Scrollable</code> so that it can
08: * be added to a JScrollPane.
09: */
10: public class ScrollableButtonPanel extends ButtonPanel implements
11: Scrollable {
12:
13: public ScrollableButtonPanel() {
14: }
15:
16: public ScrollableButtonPanel(int alignment) {
17: super (alignment);
18: }
19:
20: public ScrollableButtonPanel(int alignment, int sizeContraint) {
21: super (alignment, sizeContraint);
22: }
23:
24: public Dimension getPreferredScrollableViewportSize() {
25: return getPreferredSize();
26: }
27:
28: public int getScrollableUnitIncrement(Rectangle visibleRect,
29: int orientation, int direction) {
30: if (getComponentCount() > 0) {
31: Component c = getComponent(0);
32: if (orientation == SwingConstants.HORIZONTAL)
33: return c.getWidth();
34: else
35: return c.getHeight();
36: }
37: return 50;
38: }
39:
40: public int getScrollableBlockIncrement(Rectangle visibleRect,
41: int orientation, int direction) {
42: if (orientation == SwingConstants.HORIZONTAL)
43: return visibleRect.width;
44: else
45: return visibleRect.width;
46: }
47:
48: /**
49: * Override this method to make sure the button panel expand all the way if the view port is small.
50: *
51: * @return true if parent is null or parent width is greater than preferred width
52: */
53: public boolean getScrollableTracksViewportWidth() {
54: if (getParent() == null) {
55: return true;
56: }
57:
58: return getParent().getSize().width > getPreferredSize().width;
59: }
60:
61: public boolean getScrollableTracksViewportHeight() {
62: return false;
63: }
64: }
|