Browse Source

Checkstyle fixes for SplitPanel widgets. (#12378)

- Added and updated JavaDocs.
- Added default cases to Switch statements.
- Deprecated unused fields.
- Switched to use non-deprecated calls where possible.
tags/8.14.0.beta1
Anna Koskinen 2 years ago
parent
commit
4f6f3ae3e2
No account linked to committer's email address

+ 167
- 26
client/src/main/java/com/vaadin/client/ui/VAbstractSplitPanel.java View File

import com.vaadin.client.WidgetUtil; import com.vaadin.client.WidgetUtil;
import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler; import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler;
import com.vaadin.client.ui.VAbstractSplitPanel.SplitterMoveHandler.SplitterMoveEvent; import com.vaadin.client.ui.VAbstractSplitPanel.SplitterMoveHandler.SplitterMoveEvent;
import com.vaadin.client.widgets.Overlay;
import com.vaadin.shared.ui.Orientation; import com.vaadin.shared.ui.Orientation;


/**
* Base class for the SplitPanel widgets.
*
* @author Vaadin Ltd
*
*/
public abstract class VAbstractSplitPanel extends ComplexPanel { public abstract class VAbstractSplitPanel extends ComplexPanel {


private boolean enabled = false; private boolean enabled = false;


/** Default classname for this widget. */
public static final String CLASSNAME = "v-splitpanel"; public static final String CLASSNAME = "v-splitpanel";


private static final int MIN_SIZE = 30; private static final int MIN_SIZE = 30;


private TouchScrollHandler touchScrollHandler; private TouchScrollHandler touchScrollHandler;


/**
* @deprecated this element is no longer used or updated by the framework
*/
@Deprecated
protected Element scrolledContainer; protected Element scrolledContainer;


/**
* @deprecated this value is no longer used or updated by the framework
*/
@Deprecated
protected int origScrollTop; protected int origScrollTop;


/**
* Constructs a base widget for a SplitPanel component. Uses horizontal
* orientation.
*/
public VAbstractSplitPanel() { public VAbstractSplitPanel() {
this(Orientation.HORIZONTAL); this(Orientation.HORIZONTAL);
} }


/**
* Constructs a base widget for a SplitPanel component with the given
* orientation.
*
* @param orientation
* the orientation to use
*/
@SuppressWarnings("deprecation")
public VAbstractSplitPanel(Orientation orientation) { public VAbstractSplitPanel(Orientation orientation) {
setElement(DOM.createDiv()); setElement(DOM.createDiv());
switch (orientation) { switch (orientation) {


} }


/**
* Constructs the DOM structure for this widget.
*/
protected void constructDom() { protected void constructDom() {
DOM.appendChild(splitter, DOM.createDiv()); // for styling DOM.appendChild(splitter, DOM.createDiv()); // for styling
DOM.appendChild(getElement(), wrapper); DOM.appendChild(getElement(), wrapper);
return removed; return removed;
} }


/** For internal use only. May be removed or replaced in the future. */
/**
* For internal use only. May be removed or replaced in the future.
*
* @param newValue
* {@code true} if split position should be locked, {@code false}
* otherwise
*/
public void setLocked(boolean newValue) { public void setLocked(boolean newValue) {
if (locked != newValue) { if (locked != newValue) {
locked = newValue; locked = newValue;
} }
} }


/** For internal use only. May be removed or replaced in the future. */
/**
* For internal use only. May be removed or replaced in the future.
*
* @param reversed
* {@code true} if split position should be measured from the
* second region, {@code false} (default) if from the the first
* region
*/
public void setPositionReversed(boolean reversed) { public void setPositionReversed(boolean reversed) {
if (positionReversed != reversed) { if (positionReversed != reversed) {
if (orientation == Orientation.HORIZONTAL) { if (orientation == Orientation.HORIZONTAL) {
return pos; return pos;
} }


/**
* Sets the position of the splitter element.
*
* @param pos
* the required position as either percentage or pixels
*/
public void setSplitPosition(String pos) { public void setSplitPosition(String pos) {
setSplitPosition(pos, true); setSplitPosition(pos, true);
} }
case VERTICAL: case VERTICAL:
verticalOrientationUpdateSizes(); verticalOrientationUpdateSizes();
break; break;
default:
throw new IllegalStateException(
"New orientation option has been added "
+ "without configuring handling for it.");
} }
} }


private void verticalOrientationUpdateSizes() { private void verticalOrientationUpdateSizes() {
int wholeSize = DOM.getElementPropertyInt(wrapper, "clientHeight");
int pixelPosition = DOM.getElementPropertyInt(splitter, "offsetTop");
int wholeSize = wrapper.getPropertyInt("clientHeight");
int pixelPosition = splitter.getPropertyInt("offsetTop");


// reposition splitter in case it is out of box // reposition splitter in case it is out of box
if (pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize if (pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize
} }


private void horizontalOrientationUpdateSizes() { private void horizontalOrientationUpdateSizes() {
int wholeSize = DOM.getElementPropertyInt(wrapper, "clientWidth");
int pixelPosition = DOM.getElementPropertyInt(splitter, "offsetLeft");
int wholeSize = wrapper.getPropertyInt("clientWidth");
int pixelPosition = splitter.getPropertyInt("offsetLeft");


// reposition splitter in case it is out of box // reposition splitter in case it is out of box
if (pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize if (pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize
} }
} }


/** For internal use only. May be removed or replaced in the future. */
/**
* For internal use only. May be removed or replaced in the future.
*
* @param w
* the widget to set to the first region or {@code null} to
* remove previously set widget
*/
public void setFirstWidget(Widget w) { public void setFirstWidget(Widget w) {
if (firstChild == w) { if (firstChild == w) {
return; return;
firstChild = w; firstChild = w;
} }


/**
* Returns the widget in the first region, if any.
*
* @return the widget in the first region, or {@code null} if not set
*/
public Widget getFirstWidget() { public Widget getFirstWidget() {
return firstChild; return firstChild;
} }


/** For internal use only. May be removed or replaced in the future. */
/**
* For internal use only. May be removed or replaced in the future.
*
* @param w
* the widget to set to the second region or {@code null} to
* remove previously set widget
*/
public void setSecondWidget(Widget w) { public void setSecondWidget(Widget w) {
if (secondChild == w) { if (secondChild == w) {
return; return;
secondChild = w; secondChild = w;
} }


/**
* Returns the widget in the second region, if any.
*
* @return the widget in the second region, or {@code null} if not set
*/
public Widget getSecondWidget() { public Widget getSecondWidget() {
return secondChild; return secondChild;
} }
stopResize(); stopResize();
resizing = false; resizing = false;
break; break;
default:
// NOP
break;
} }
// Only fire click event listeners if the splitter isn't moved // Only fire click event listeners if the splitter isn't moved
if (WidgetUtil.isTouchEvent(event) || !resized) { if (WidgetUtil.isTouchEvent(event) || !resized) {
} }
} }


/**
* Handle initiating content resize and moving of the split position when
* clicking the splitter with a mouse. If the click targets any other
* element, the split position is locked, or this split panel is not
* enabled, nothing is done.
*
* @param event
* the browser event
*/
public void onMouseDown(Event event) { public void onMouseDown(Event event) {
if (locked || !isEnabled()) { if (locked || !isEnabled()) {
return; return;
startResize(); startResize();
resizing = true; resizing = true;
DOM.setCapture(getElement()); DOM.setCapture(getElement());
origX = DOM.getElementPropertyInt(splitter, "offsetLeft");
origY = DOM.getElementPropertyInt(splitter, "offsetTop");
origX = splitter.getPropertyInt("offsetLeft");
origY = splitter.getPropertyInt("offsetTop");
origMouseX = WidgetUtil.getTouchOrMouseClientX(event); origMouseX = WidgetUtil.getTouchOrMouseClientX(event);
origMouseY = WidgetUtil.getTouchOrMouseClientY(event); origMouseY = WidgetUtil.getTouchOrMouseClientY(event);
event.stopPropagation(); event.stopPropagation();
} }


/** /**
* Called when starting drag resize.
* Called when starting splitter drag resize of contents.
* *
* @since 7.5.1 * @since 7.5.1
*/ */
protected abstract void startResize(); protected abstract void startResize();


/** /**
* Called when stopping drag resize.
* Called when stopping splitter drag resize of contents.
* *
* @since 7.5.1 * @since 7.5.1
*/ */
protected abstract void stopResize(); protected abstract void stopResize();


/** /**
* Gets the first container.
* Gets the first region's container element.
* *
* @since 7.5.1 * @since 7.5.1
* @return the firstContainer
* @return the container element
*/ */
protected Element getFirstContainer() { protected Element getFirstContainer() {
return firstContainer; return firstContainer;
} }


/** /**
* Gets the second container.
* Gets the second region's container element.
* *
* @since 7.5.1 * @since 7.5.1
* @return the secondContainer
* @return the container element
*/ */
protected Element getSecondContainer() { protected Element getSecondContainer() {
return secondContainer; return secondContainer;
} }


/**
* Handle updating the splitter position when dragging the splitter with a
* mouse. This should only be called if content resizing has been
* successfully initialized via a mouse down event.
*
* @param event
* the browser event
*/
public void onMouseMove(Event event) { public void onMouseMove(Event event) {
switch (orientation) { switch (orientation) {
case HORIZONTAL: case HORIZONTAL:
setSplitPosition(newY + "px"); setSplitPosition(newY + "px");
} }


/**
* Handle concluding the content resize when dragging the splitter with a
* mouse. This should only be called if resizing has been successfully
* initialized via a mouse down event.
*
* @param event
* the browser event
*/
public void onMouseUp(Event event) { public void onMouseUp(Event event) {
DOM.releaseCapture(getElement()); DOM.releaseCapture(getElement());
hideDraggingCurtain(); hideDraggingCurtain();
fireEvent(new SplitterMoveEvent(this)); fireEvent(new SplitterMoveEvent(this));
} }


/**
* Event handler interface for moving the splitter element.
*
* @author Vaadin Ltd
*/
public interface SplitterMoveHandler extends EventHandler { public interface SplitterMoveHandler extends EventHandler {
/**
* Handle moving of the splitter element.
*
* @param event
* the splitter move event
*/
public void splitterMoved(SplitterMoveEvent event); public void splitterMoved(SplitterMoveEvent event);


/**
* Event class for splitter element move.
*
* @author Vaadin Ltd
*/
public static class SplitterMoveEvent public static class SplitterMoveEvent
extends GwtEvent<SplitterMoveHandler> { extends GwtEvent<SplitterMoveHandler> {


/**
* Handler type.
*/
public static final Type<SplitterMoveHandler> TYPE = new Type<>(); public static final Type<SplitterMoveHandler> TYPE = new Type<>();


private Widget splitPanel;

/**
* Constructs a move event for the splitter element.
*
* @param splitPanel
* the split panel whose splitter is moved
*/
public SplitterMoveEvent(Widget splitPanel) { public SplitterMoveEvent(Widget splitPanel) {
this.splitPanel = splitPanel;
// no default use for the given splitPanel
} }


@Override @Override
} }
} }


/** For internal use only. May be removed or replaced in the future. */
/**
* For internal use only. May be removed or replaced in the future.
*
* @return the current position of the split handle in either percentages or
* pixels
*/
public String getSplitterPosition() { public String getSplitterPosition() {
return position; return position;
} }
draggingCurtain.getStyle().setLeft(0, Unit.PX); draggingCurtain.getStyle().setLeft(0, Unit.PX);
draggingCurtain.getStyle().setWidth(100, Unit.PCT); draggingCurtain.getStyle().setWidth(100, Unit.PCT);
draggingCurtain.getStyle().setHeight(100, Unit.PCT); draggingCurtain.getStyle().setHeight(100, Unit.PCT);
draggingCurtain.getStyle().setZIndex(VOverlay.Z_INDEX);
draggingCurtain.getStyle().setZIndex(Overlay.Z_INDEX);


DOM.appendChild(wrapper, draggingCurtain); DOM.appendChild(wrapper, draggingCurtain);
} }
*/ */
private void hideDraggingCurtain() { private void hideDraggingCurtain() {
if (draggingCurtain != null) { if (draggingCurtain != null) {
DOM.removeChild(wrapper, draggingCurtain);
wrapper.removeChild(draggingCurtain);
draggingCurtain = null; draggingCurtain = null;
} }
} }
if (isAttached()) { if (isAttached()) {
switch (orientation) { switch (orientation) {
case HORIZONTAL: case HORIZONTAL:
splitterSize = DOM.getElementPropertyInt(splitter,
"offsetWidth");
splitterSize = splitter.getPropertyInt("offsetWidth");
break; break;


default: default:
splitterSize = DOM.getElementPropertyInt(splitter,
"offsetHeight");
splitterSize = splitter.getPropertyInt("offsetHeight");
break; break;
} }
} }
} }
} }


/**
* Sets this split panel enabled.
*
* @param enabled
* {@code true} if enabled, {@code false} if disabled
*/
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
this.enabled = enabled; this.enabled = enabled;
} }


/**
* Returns whether this split panel is enabled or not.
*
* @return {@code true} if enabled, {@code false} if disabled
*/
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;
} }

+ 9
- 0
client/src/main/java/com/vaadin/client/ui/VSplitPanelHorizontal.java View File

import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import com.vaadin.shared.ui.Orientation; import com.vaadin.shared.ui.Orientation;


/**
* Widget class for the HorizontalSplitPanel component.
*
* @author Vaadin Ltd
*
*/
public class VSplitPanelHorizontal extends VAbstractSplitPanel { public class VSplitPanelHorizontal extends VAbstractSplitPanel {


/**
* Constructs a widget for the HorizontalSplitPanel component.
*/
public VSplitPanelHorizontal() { public VSplitPanelHorizontal() {
super(Orientation.HORIZONTAL); super(Orientation.HORIZONTAL);
} }

+ 9
- 0
client/src/main/java/com/vaadin/client/ui/VSplitPanelVertical.java View File

import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import com.vaadin.shared.ui.Orientation; import com.vaadin.shared.ui.Orientation;


/**
* Widget class for the VerticalSplitPanel component.
*
* @author Vaadin Ltd
*
*/
public class VSplitPanelVertical extends VAbstractSplitPanel { public class VSplitPanelVertical extends VAbstractSplitPanel {


/**
* Constructs a widget for the VerticalSplitPanel component.
*/
public VSplitPanelVertical() { public VSplitPanelVertical() {
super(Orientation.VERTICAL); super(Orientation.VERTICAL);
} }

+ 10
- 1
shared/src/main/java/com/vaadin/shared/ui/Orientation.java View File

*/ */
package com.vaadin.shared.ui; package com.vaadin.shared.ui;


/**
* Defines orientation for widgets that can be configured either horizontally or
* vertically. By default used by SplitPanels.
*
* @author Vaadin Ltd
*/
public enum Orientation { public enum Orientation {
HORIZONTAL, VERTICAL;
/** Horizontal orientation required. */
HORIZONTAL,
/** Vertical orientation required. */
VERTICAL;
} }

Loading…
Cancel
Save