120 /**
121 * True indicates a middle click will absolutely position the
122 * scrollbar.
123 */
124 private boolean supportsAbsolutePositioning;
125
126 /**
127 * Hint as to what width (when vertical) or height (when horizontal)
128 * should be.
129 *
130 * @since 1.7
131 */
132 protected int scrollBarWidth;
133
134 private Handler handler;
135
136 private boolean thumbActive;
137
138 /**
139 * Determine whether scrollbar layout should use cached value or adjusted
140 * value returned by scrollbar's <code>getValue</code>.
141 */
142 private boolean useCachedValue = false;
143 /**
144 * The scrollbar value is cached to save real value if the view is adjusted.
145 */
146 private int scrollBarValue;
147
148 /**
149 * Distance between the increment button and the track. This may be a negative
150 * number. If negative, then an overlap between the button and track will occur,
151 * which is useful for shaped buttons.
152 *
153 * @since 1.7
154 */
155 protected int incrGap;
156
157 /**
158 * Distance between the decrement button and the track. This may be a negative
159 * number. If negative, then an overlap between the button and track will occur,
160 * which is useful for shaped buttons.
497 * Returns true if the mouse is currently over the thumb.
498 *
499 * @return true if the thumb is currently active
500 * @since 1.5
501 */
502 public boolean isThumbRollover() {
503 return thumbActive;
504 }
505
506 public void paint(Graphics g, JComponent c) {
507 paintTrack(g, c, getTrackBounds());
508 Rectangle thumbBounds = getThumbBounds();
509 if (thumbBounds.intersects(g.getClipBounds())) {
510 paintThumb(g, c, thumbBounds);
511 }
512 }
513
514
515 /**
516 * A vertical scrollbar's preferred width is the maximum of
517 * preferred widths of the (non <code>null</code>)
518 * increment/decrement buttons,
519 * and the minimum width of the thumb. The preferred height is the
520 * sum of the preferred heights of the same parts. The basis for
521 * the preferred size of a horizontal scrollbar is similar.
522 * <p>
523 * The <code>preferredSize</code> is only computed once, subsequent
524 * calls to this method just return a cached size.
525 *
526 * @param c the <code>JScrollBar</code> that's delegating this method to us
527 * @return the preferred size of a Basic JScrollBar
528 * @see #getMaximumSize
529 * @see #getMinimumSize
530 */
531 public Dimension getPreferredSize(JComponent c) {
532 return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
533 ? new Dimension(scrollBarWidth, 48)
534 : new Dimension(48, scrollBarWidth);
535 }
536
537
538 /**
539 * @param c The JScrollBar that's delegating this method to us.
540 * @return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
541 * @see #getMinimumSize
542 * @see #getPreferredSize
543 */
544 public Dimension getMaximumSize(JComponent c) {
545 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
546 }
698 }
699
700
701 /**
702 * Returns the smallest acceptable size for the thumb. If the scrollbar
703 * becomes so small that this size isn't available, the thumb will be
704 * hidden.
705 * <p>
706 * <b>Warning </b>: the value returned by this method should not be
707 * be modified, it's a shared static constant.
708 *
709 * @return The smallest acceptable size for the thumb.
710 * @see #getMaximumThumbSize
711 */
712 protected Dimension getMinimumThumbSize() {
713 return minimumThumbSize;
714 }
715
716 /**
717 * Returns the largest acceptable size for the thumb. To create a fixed
718 * size thumb one make this method and <code>getMinimumThumbSize</code>
719 * return the same value.
720 * <p>
721 * <b>Warning </b>: the value returned by this method should not be
722 * be modified, it's a shared static constant.
723 *
724 * @return The largest acceptable size for the thumb.
725 * @see #getMinimumThumbSize
726 */
727 protected Dimension getMaximumThumbSize() {
728 return maximumThumbSize;
729 }
730
731
732 /*
733 * LayoutManager Implementation
734 */
735
736 public void addLayoutComponent(String name, Component child) {}
737 public void removeLayoutComponent(Component child) {}
738
1506 scrollListener.setDirection(direction);
1507 scrollListener.setScrollByBlock(false);
1508 scrollTimer.start();
1509
1510 handledEvent = true;
1511 if (!scrollbar.hasFocus() && scrollbar.isRequestFocusEnabled()) {
1512 scrollbar.requestFocus();
1513 }
1514 }
1515
1516 public void mouseReleased(MouseEvent e) {
1517 scrollTimer.stop();
1518 handledEvent = false;
1519 scrollbar.setValueIsAdjusting(false);
1520 }
1521 }
1522
1523
1524 /**
1525 * Listener for scrolling events initiated in the
1526 * <code>ScrollPane</code>.
1527 */
1528 protected class ScrollListener implements ActionListener
1529 {
1530 int direction = +1;
1531 boolean useBlockIncrement;
1532
1533 /** Constructs a {@code ScrollListener}. */
1534 public ScrollListener() {
1535 direction = +1;
1536 useBlockIncrement = false;
1537 }
1538
1539 /**
1540 * Constructs a {@code ScrollListener}.
1541 * @param dir direction
1542 * @param block use block increment
1543 */
1544 public ScrollListener(int dir, boolean block) {
1545 direction = dir;
1546 useBlockIncrement = block;
|
120 /**
121 * True indicates a middle click will absolutely position the
122 * scrollbar.
123 */
124 private boolean supportsAbsolutePositioning;
125
126 /**
127 * Hint as to what width (when vertical) or height (when horizontal)
128 * should be.
129 *
130 * @since 1.7
131 */
132 protected int scrollBarWidth;
133
134 private Handler handler;
135
136 private boolean thumbActive;
137
138 /**
139 * Determine whether scrollbar layout should use cached value or adjusted
140 * value returned by scrollbar's {@code getValue}.
141 */
142 private boolean useCachedValue = false;
143 /**
144 * The scrollbar value is cached to save real value if the view is adjusted.
145 */
146 private int scrollBarValue;
147
148 /**
149 * Distance between the increment button and the track. This may be a negative
150 * number. If negative, then an overlap between the button and track will occur,
151 * which is useful for shaped buttons.
152 *
153 * @since 1.7
154 */
155 protected int incrGap;
156
157 /**
158 * Distance between the decrement button and the track. This may be a negative
159 * number. If negative, then an overlap between the button and track will occur,
160 * which is useful for shaped buttons.
497 * Returns true if the mouse is currently over the thumb.
498 *
499 * @return true if the thumb is currently active
500 * @since 1.5
501 */
502 public boolean isThumbRollover() {
503 return thumbActive;
504 }
505
506 public void paint(Graphics g, JComponent c) {
507 paintTrack(g, c, getTrackBounds());
508 Rectangle thumbBounds = getThumbBounds();
509 if (thumbBounds.intersects(g.getClipBounds())) {
510 paintThumb(g, c, thumbBounds);
511 }
512 }
513
514
515 /**
516 * A vertical scrollbar's preferred width is the maximum of
517 * preferred widths of the (non {@code null})
518 * increment/decrement buttons,
519 * and the minimum width of the thumb. The preferred height is the
520 * sum of the preferred heights of the same parts. The basis for
521 * the preferred size of a horizontal scrollbar is similar.
522 * <p>
523 * The {@code preferredSize} is only computed once, subsequent
524 * calls to this method just return a cached size.
525 *
526 * @param c the {@code JScrollBar} that's delegating this method to us
527 * @return the preferred size of a Basic JScrollBar
528 * @see #getMaximumSize
529 * @see #getMinimumSize
530 */
531 public Dimension getPreferredSize(JComponent c) {
532 return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
533 ? new Dimension(scrollBarWidth, 48)
534 : new Dimension(48, scrollBarWidth);
535 }
536
537
538 /**
539 * @param c The JScrollBar that's delegating this method to us.
540 * @return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
541 * @see #getMinimumSize
542 * @see #getPreferredSize
543 */
544 public Dimension getMaximumSize(JComponent c) {
545 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
546 }
698 }
699
700
701 /**
702 * Returns the smallest acceptable size for the thumb. If the scrollbar
703 * becomes so small that this size isn't available, the thumb will be
704 * hidden.
705 * <p>
706 * <b>Warning </b>: the value returned by this method should not be
707 * be modified, it's a shared static constant.
708 *
709 * @return The smallest acceptable size for the thumb.
710 * @see #getMaximumThumbSize
711 */
712 protected Dimension getMinimumThumbSize() {
713 return minimumThumbSize;
714 }
715
716 /**
717 * Returns the largest acceptable size for the thumb. To create a fixed
718 * size thumb one make this method and {@code getMinimumThumbSize}
719 * return the same value.
720 * <p>
721 * <b>Warning </b>: the value returned by this method should not be
722 * be modified, it's a shared static constant.
723 *
724 * @return The largest acceptable size for the thumb.
725 * @see #getMinimumThumbSize
726 */
727 protected Dimension getMaximumThumbSize() {
728 return maximumThumbSize;
729 }
730
731
732 /*
733 * LayoutManager Implementation
734 */
735
736 public void addLayoutComponent(String name, Component child) {}
737 public void removeLayoutComponent(Component child) {}
738
1506 scrollListener.setDirection(direction);
1507 scrollListener.setScrollByBlock(false);
1508 scrollTimer.start();
1509
1510 handledEvent = true;
1511 if (!scrollbar.hasFocus() && scrollbar.isRequestFocusEnabled()) {
1512 scrollbar.requestFocus();
1513 }
1514 }
1515
1516 public void mouseReleased(MouseEvent e) {
1517 scrollTimer.stop();
1518 handledEvent = false;
1519 scrollbar.setValueIsAdjusting(false);
1520 }
1521 }
1522
1523
1524 /**
1525 * Listener for scrolling events initiated in the
1526 * {@code ScrollPane}.
1527 */
1528 protected class ScrollListener implements ActionListener
1529 {
1530 int direction = +1;
1531 boolean useBlockIncrement;
1532
1533 /** Constructs a {@code ScrollListener}. */
1534 public ScrollListener() {
1535 direction = +1;
1536 useBlockIncrement = false;
1537 }
1538
1539 /**
1540 * Constructs a {@code ScrollListener}.
1541 * @param dir direction
1542 * @param block use block increment
1543 */
1544 public ScrollListener(int dir, boolean block) {
1545 direction = dir;
1546 useBlockIncrement = block;
|