Преглед на файлове

Adds the ability to lock the scroll direction of the Escalator (#13334)

Change-Id: I8e20ce971e313495941059a869d4db826bfa903b
tags/7.4.0.beta1
Henrik Paul преди 9 години
родител
ревизия
c464d7fe2c
променени са 2 файла, в които са добавени 104 реда и са изтрити 1 реда
  1. 45
    0
      client/src/com/vaadin/client/ui/grid/Escalator.java
  2. 59
    1
      client/src/com/vaadin/client/ui/grid/ScrollbarBundle.java

+ 45
- 0
client/src/com/vaadin/client/ui/grid/Escalator.java Целия файл

@@ -4623,4 +4623,49 @@ public class Escalator extends Widget {
}
return null;
}

/**
* Sets whether a scroll direction is locked or not.
* <p>
* If a direction is locked, the escalator will refuse to scroll in that
* direction.
*
* @param direction
* the orientation of the scroll to set the lock status
* @param locked
* <code>true</code> to lock, <code>false</code> to unlock
*/
public void setScrollLocked(ScrollbarBundle.Direction direction,
boolean locked) {
switch (direction) {
case HORIZONTAL:
horizontalScrollbar.setLocked(locked);
break;
case VERTICAL:
verticalScrollbar.setLocked(locked);
break;
default:
throw new UnsupportedOperationException("Unexpected value: "
+ direction);
}
}

/**
* Checks whether or not an direction is locked for scrolling.
*
* @param direction
* the direction of the scroll of which to check the lock status
* @return <code>true</code> iff the direction is locked
*/
public boolean isScrollLocked(ScrollbarBundle.Direction direction) {
switch (direction) {
case HORIZONTAL:
return horizontalScrollbar.isLocked();
case VERTICAL:
return verticalScrollbar.isLocked();
default:
throw new UnsupportedOperationException("Unexpected value: "
+ direction);
}
}
}

+ 59
- 1
client/src/com/vaadin/client/ui/grid/ScrollbarBundle.java Целия файл

@@ -39,6 +39,13 @@ import com.google.gwt.user.client.Timer;
*/
abstract class ScrollbarBundle {

/**
* The orientation of the scrollbar.
*/
public enum Direction {
VERTICAL, HORIZONTAL;
}

private class TemporaryResizer extends Object {
private static final int TEMPORARY_RESIZE_DELAY = 1000;

@@ -188,6 +195,11 @@ abstract class ScrollbarBundle {
root.getStyle().clearOverflowY();
}
}

@Override
public Direction getDirection() {
return Direction.VERTICAL;
}
}

/**
@@ -252,6 +264,11 @@ abstract class ScrollbarBundle {
root.getStyle().clearOverflowX();
}
}

@Override
public Direction getDirection() {
return Direction.HORIZONTAL;
}
}

protected final Element root = DOM.createDiv();
@@ -263,6 +280,8 @@ abstract class ScrollbarBundle {

private boolean scrollHandleIsVisible = false;

private boolean isLocked = false;

/** @deprecarted access via {@link #getHandlerManager()} instead. */
@Deprecated
private HandlerManager handlerManager;
@@ -369,6 +388,10 @@ abstract class ScrollbarBundle {
* the new scroll position in pixels
*/
public final void setScrollPos(double px) {
if (isLocked()) {
return;
}

double oldScrollPos = scrollPos;
scrollPos = Math.max(0, Math.min(maxScrollPos, truncate(px)));

@@ -577,7 +600,13 @@ abstract class ScrollbarBundle {
* the DOM.
*/
private final void updateScrollPosFromDom() {
scrollPos = internalGetScrollPos();
int newScrollPos = internalGetScrollPos();
if (!isLocked()) {
scrollPos = newScrollPos;
} else if (scrollPos != newScrollPos) {
// we need to actually undo the setting of the scroll.
internalSetScrollPos(toInt32(scrollPos));
}
}

protected HandlerManager getHandlerManager() {
@@ -636,4 +665,33 @@ abstract class ScrollbarBundle {
private static boolean pixelValuesEqual(final double num1, final double num2) {
return Math.abs(num1 - num2) <= PIXEL_EPSILON;
}

/**
* Locks or unlocks the scrollbar bundle.
* <p>
* A locked scrollbar bundle will refuse to scroll, both programmatically
* and via user-triggered events.
*
* @param isLocked
* <code>true</code> to lock, <code>false</code> to unlock
*/
public void setLocked(boolean isLocked) {
this.isLocked = isLocked;
}

/**
* Checks whether the scrollbar bundle is locked or not.
*
* @return <code>true</code> iff the scrollbar bundle is locked
*/
public boolean isLocked() {
return isLocked;
}

/**
* Returns the scroll direction of this scrollbar bundle.
*
* @return the scroll direction of this scrollbar bundle
*/
public abstract Direction getDirection();
}

Loading…
Отказ
Запис