Author: rwhitcomb Date: Wed Dec 6 06:05:38 2017 New Revision: 1817267 URL: http://svn.apache.org/viewvc?rev=1817267&view=rev Log: PIVOT-1011: Move the listener list out of ScrollPane and into ScrollPaneListener. Misc. other reformatting in the skin class, and Utils checks on parameters in ScrollPane itself.
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPane.java pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPaneListener.java pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPane.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPane.java?rev=1817267&r1=1817266&r2=1817267&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPane.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPane.java Wed Dec 6 06:05:38 2017 @@ -18,6 +18,7 @@ package org.apache.pivot.wtk; import org.apache.pivot.collections.Sequence; import org.apache.pivot.util.ListenerList; +import org.apache.pivot.util.Utils; /** * Container that provides a scrollable view of a component, with optional fixed @@ -66,48 +67,6 @@ public class ScrollPane extends Viewport FILL_TO_CAPACITY } - private static class ScrollPaneListenerList extends ListenerList<ScrollPaneListener> - implements ScrollPaneListener { - - @Override - public void horizontalScrollBarPolicyChanged(ScrollPane scrollPane, - ScrollBarPolicy previousHorizontalScrollBarPolicy) { - for (ScrollPaneListener listener : this) { - listener.horizontalScrollBarPolicyChanged(scrollPane, - previousHorizontalScrollBarPolicy); - } - } - - @Override - public void verticalScrollBarPolicyChanged(ScrollPane scrollPane, - ScrollBarPolicy previousVerticalScrollBarPolicy) { - for (ScrollPaneListener listener : this) { - listener.verticalScrollBarPolicyChanged(scrollPane, previousVerticalScrollBarPolicy); - } - } - - @Override - public void rowHeaderChanged(ScrollPane scrollPane, Component previousRowHeader) { - for (ScrollPaneListener listener : this) { - listener.rowHeaderChanged(scrollPane, previousRowHeader); - } - } - - @Override - public void columnHeaderChanged(ScrollPane scrollPane, Component previousColumnHeader) { - for (ScrollPaneListener listener : this) { - listener.columnHeaderChanged(scrollPane, previousColumnHeader); - } - } - - @Override - public void cornerChanged(ScrollPane scrollPane, Component previousCorner) { - for (ScrollPaneListener listener : this) { - listener.cornerChanged(scrollPane, previousCorner); - } - } - } - /** * Component class representing the components that will get placed in the * corners of a <tt>ScrollPane</tt>. Skins will instantiate these components @@ -125,9 +84,7 @@ public class ScrollPane extends Viewport private Placement placement; public Corner(Placement placement) { - if (placement == null) { - throw new IllegalArgumentException("Placement is null."); - } + Utils.checkNull(placement, "placement"); this.placement = placement; @@ -144,7 +101,7 @@ public class ScrollPane extends Viewport private Component rowHeader; private Component columnHeader; private Component corner; - private ScrollPaneListenerList scrollPaneListeners = new ScrollPaneListenerList(); + private ScrollPaneListener.List scrollPaneListeners = new ScrollPaneListener.List(); public ScrollPane() { this(ScrollBarPolicy.AUTO, ScrollBarPolicy.AUTO); @@ -154,13 +111,8 @@ public class ScrollPane extends Viewport ScrollBarPolicy verticalScrollBarPolicy) { super(); - if (horizontalScrollBarPolicy == null) { - throw new IllegalArgumentException("horizontalScrollBarPolicy is null"); - } - - if (verticalScrollBarPolicy == null) { - throw new IllegalArgumentException("verticalScrollBarPolicy is null"); - } + Utils.checkNull(horizontalScrollBarPolicy, "horizontalScrollBarPolicy"); + Utils.checkNull(verticalScrollBarPolicy, "verticalScrollBarPolicy"); this.horizontalScrollBarPolicy = horizontalScrollBarPolicy; this.verticalScrollBarPolicy = verticalScrollBarPolicy; @@ -173,9 +125,7 @@ public class ScrollPane extends Viewport } public void setHorizontalScrollBarPolicy(ScrollBarPolicy horizontalScrollBarPolicy) { - if (horizontalScrollBarPolicy == null) { - throw new IllegalArgumentException("horizontalScrollBarPolicy is null"); - } + Utils.checkNull(horizontalScrollBarPolicy, "horizontalScrollBarPolicy"); ScrollBarPolicy previousHorizontalScrollBarPolicy = this.horizontalScrollBarPolicy; @@ -191,9 +141,7 @@ public class ScrollPane extends Viewport } public void setVerticalScrollBarPolicy(ScrollBarPolicy verticalScrollBarPolicy) { - if (verticalScrollBarPolicy == null) { - throw new IllegalArgumentException("verticalScrollBarPolicy is null"); - } + Utils.checkNull(verticalScrollBarPolicy, "verticalScrollBarPolicy"); ScrollBarPolicy previousVerticalScrollBarPolicy = this.verticalScrollBarPolicy; Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPaneListener.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPaneListener.java?rev=1817267&r1=1817266&r2=1817267&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPaneListener.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ScrollPaneListener.java Wed Dec 6 06:05:38 2017 @@ -16,23 +16,28 @@ */ package org.apache.pivot.wtk; +import org.apache.pivot.util.ListenerList; +import org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy; + + /** * Scroll pane listener interface. */ public interface ScrollPaneListener { /** - * Scroll pane listener adapter. + * Scroll pane listener adapter: default implementation methods + * for this interface. */ public static class Adapter implements ScrollPaneListener { @Override public void horizontalScrollBarPolicyChanged(ScrollPane scrollPane, - ScrollPane.ScrollBarPolicy previousPolicy) { + ScrollBarPolicy previousPolicy) { // empty block } @Override public void verticalScrollBarPolicyChanged(ScrollPane scrollPane, - ScrollPane.ScrollBarPolicy previousPolicy) { + ScrollBarPolicy previousPolicy) { // empty block } @@ -53,13 +58,48 @@ public interface ScrollPaneListener { } /** + * Scroll pane listener list. + */ + public static class List extends ListenerList<ScrollPaneListener> + implements ScrollPaneListener { + + @Override + public void horizontalScrollBarPolicyChanged(ScrollPane scrollPane, + ScrollBarPolicy previousHorizontalScrollBarPolicy) { + forEach(listener -> listener.horizontalScrollBarPolicyChanged(scrollPane, + previousHorizontalScrollBarPolicy)); + } + + @Override + public void verticalScrollBarPolicyChanged(ScrollPane scrollPane, + ScrollBarPolicy previousVerticalScrollBarPolicy) { + forEach(listener -> listener.verticalScrollBarPolicyChanged(scrollPane, previousVerticalScrollBarPolicy)); + } + + @Override + public void rowHeaderChanged(ScrollPane scrollPane, Component previousRowHeader) { + forEach(listener -> listener.rowHeaderChanged(scrollPane, previousRowHeader)); + } + + @Override + public void columnHeaderChanged(ScrollPane scrollPane, Component previousColumnHeader) { + forEach(listener -> listener.columnHeaderChanged(scrollPane, previousColumnHeader)); + } + + @Override + public void cornerChanged(ScrollPane scrollPane, Component previousCorner) { + forEach(listener -> listener.cornerChanged(scrollPane, previousCorner)); + } + } + + /** * Called when the scroll pane's horizontal scroll bar policy changed. * * @param scrollPane The source of the event. * @param previousPolicy The previous horizontal scroll bar policy. */ public void horizontalScrollBarPolicyChanged(ScrollPane scrollPane, - ScrollPane.ScrollBarPolicy previousPolicy); + ScrollBarPolicy previousPolicy); /** * Called when the scroll pane's vertical scroll bar policy changed. @@ -68,7 +108,7 @@ public interface ScrollPaneListener { * @param previousPolicy The previous vertical scroll bar policy. */ public void verticalScrollBarPolicyChanged(ScrollPane scrollPane, - ScrollPane.ScrollBarPolicy previousPolicy); + ScrollBarPolicy previousPolicy); /** * Called when the scroll pane's row header changed. Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java?rev=1817267&r1=1817266&r2=1817267&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java Wed Dec 6 06:05:38 2017 @@ -246,15 +246,11 @@ public class ScrollPaneSkin extends Cont } if (horizontalPolicy == ScrollBarPolicy.FILL) { - // Preferred height is the sum of the constrained preferred - // height - // of the view and the unconstrained preferred height of the - // column - // header + // Preferred height is the sum of the constrained preferred height + // of the view and the unconstrained preferred height of the column header int widthUpdated = width; if (widthUpdated >= 0) { - // Subtract the unconstrained preferred width of the row - // header + // Subtract the unconstrained preferred width of the row header // from the width constraint widthUpdated = Math.max(widthUpdated - preferredRowHeaderWidth, 0); } @@ -663,14 +659,12 @@ public class ScrollPaneSkin extends Cont if (view != null) { if (constrainWidth && constrainHeight) { viewWidth = Math.max(width - rowHeaderWidth - verticalScrollBarWidth, 0); - viewHeight = Math.max(height - columnHeaderHeight - horizontalScrollBarHeight, - 0); + viewHeight = Math.max(height - columnHeaderHeight - horizontalScrollBarHeight, 0); } else if (constrainWidth) { viewWidth = Math.max(width - rowHeaderWidth - verticalScrollBarWidth, 0); viewHeight = view.getPreferredHeight(viewWidth); } else if (constrainHeight) { - viewHeight = Math.max(height - columnHeaderHeight - horizontalScrollBarHeight, - 0); + viewHeight = Math.max(height - columnHeaderHeight - horizontalScrollBarHeight, 0); viewWidth = view.getPreferredWidth(viewHeight); } else { Dimensions viewPreferredSize = view.getPreferredSize();