import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.MouseWheelListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
public class CustomScrollBar {
- static final int SCROLL_SHIFT_LENGTH = 10;
+ static final int SCROLL_INCREMENT_AMOUNT = 10;
private Logger logger = SkinLogger.getSkinLogger(
CustomScrollBar.class).getLogger();
CustomScrolledComposite compositeScroll;
private int heightScrollBar;
- private int maxShift;
+ private int amountIncrement;
private Image[] imagesArrowUp;
private Image[] imagesArrowDown;
composite.setLayout(rowLayout);
this.heightScrollBar = heightScrollBar;
- this.maxShift = SCROLL_SHIFT_LENGTH;
+ this.amountIncrement = SCROLL_INCREMENT_AMOUNT;
this.imagesArrowUp = imagesArrowUp;
this.imagesArrowDown = imagesArrowDown;
}
}
+ private void scrollUp(int amount) {
+ int amountRemaining = getSelection();
+
+ if (amountRemaining > 0) {
+ setSelection(getSelection() - Math.min(amount, amountRemaining));
+ compositeScroll.vScroll();
+ }
+ }
+
+ private void scrollDown(int amount) {
+ int minHeightContents =
+ ((CustomScrolledComposite) parent.getParent()).getMinHeight();
+
+ int amountRemaining = (minHeightContents - heightScrollBar) - getSelection();
+
+ if (amountRemaining > 0) {
+ setSelection(getSelection() + Math.min(amount, amountRemaining));
+ compositeScroll.vScroll();
+ }
+ }
+
protected void addScrollBarListener() {
buttonArrowUp.addMouseListener(new MouseListener() {
@Override
public void mouseDown(MouseEvent e) {
- int shift = getSelection();
-
- if (shift > 0) {
- setSelection(getSelection() - Math.min(maxShift, shift));
- ((CustomScrolledComposite) parent.getParent()).vScroll();
- }
+ scrollUp(amountIncrement);
}
@Override
buttonArrowDown.addMouseListener(new MouseListener() {
@Override
public void mouseDown(MouseEvent e) {
- int minHeightContents =
- ((CustomScrolledComposite) parent.getParent()).getMinHeight();
-
- int shift = (minHeightContents - heightScrollBar) - getSelection();
-
- if (shift > 0) {
- setSelection(getSelection() + Math.min(maxShift, shift));
- ((CustomScrolledComposite) parent.getParent()).vScroll();
- }
+ scrollDown(amountIncrement);
}
@Override
public void mouseUp(MouseEvent e) {
- timerScroller.cancel();
- timerScroller = new Timer();
+ //timerScroller.cancel();
+ //timerScroller = new Timer();
}
@Override
// timerScroller.schedule(new ScrollerTask(), 1, 100);
// }
// });
+
+ compositeScroll.addMouseWheelListener(new MouseWheelListener() {
+ @Override
+ public void mouseScrolled(MouseEvent e) {
+ if (e.count > 0) {
+ scrollUp(amountIncrement);
+ } else {
+ scrollDown(amountIncrement);
+ }
+ }
+ });
}
public int getSelection() {