You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/12/21 22:29:19 UTC
svn commit: r1818986 - in /pivot/trunk:
wtk-terra/src/org/apache/pivot/wtk/skin/terra/ wtk/src/org/apache/pivot/wtk/
Author: rwhitcomb
Date: Thu Dec 21 22:29:19 2017
New Revision: 1818986
URL: http://svn.apache.org/viewvc?rev=1818986&view=rev
Log:
PIVOT-999: Start to make changes to use lambdas for ApplicationContext.queueCallback()
to (often greatly) simplify the code.
* Three skin classes for relatively complex callbacks.
* TaskAdapter which has very simple callbacks, which used to use a lot of boilerplate
code to work correctly pre-lambda functions.
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMenuPopupSkin.java
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/TaskAdapter.java
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java?rev=1818986&r1=1818985&r2=1818986&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListButtonSkin.java Thu Dec 21 22:29:19 2017
@@ -106,15 +106,12 @@ public class TerraListButtonSkin extends
repaintComponent();
- ApplicationContext.queueCallback(new Runnable() {
- @Override
- public void run() {
- int selectedIndex = listView.getSelectedIndex();
+ ApplicationContext.queueCallback(() -> {
+ int selectedIndex = listView.getSelectedIndex();
- if (selectedIndex >= 0) {
- Bounds itemBounds = listView.getItemBounds(selectedIndex);
- listView.scrollAreaToVisible(itemBounds);
- }
+ if (selectedIndex >= 0) {
+ Bounds itemBounds = listView.getItemBounds(selectedIndex);
+ listView.scrollAreaToVisible(itemBounds);
}
});
}
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMenuPopupSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMenuPopupSkin.java?rev=1818986&r1=1818985&r2=1818986&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMenuPopupSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMenuPopupSkin.java Thu Dec 21 22:29:19 2017
@@ -48,39 +48,36 @@ import org.apache.pivot.wtk.skin.WindowS
*/
public class TerraMenuPopupSkin extends WindowSkin implements MenuPopupListener,
MenuPopupStateListener {
- private class RepositionCallback implements Runnable {
- @Override
- public void run() {
- MenuPopup menuPopup = (MenuPopup) getComponent();
- Display display = menuPopup.getDisplay();
-
- Point location = menuPopup.getLocation();
- Dimensions size = menuPopup.getSize();
-
- int x = location.x;
- int displayWidth = display.getWidth();
- if (size.width > displayWidth) {
- border.setPreferredWidth(displayWidth);
- x = 0;
- } else if (x + size.width > displayWidth) {
- x = Math.max(displayWidth - size.width, 0);
- }
-
- int y = location.y;
- int displayHeight = display.getHeight();
- if (size.height > displayHeight) {
- border.setPreferredHeight(displayHeight);
- y = 0;
- } else if (y + size.height > displayHeight) {
- y = Math.max(displayHeight - size.height, 0);
- }
+ private Panorama panorama;
+ private Border border;
- menuPopup.setLocation(x, y);
+ private Runnable repositionCallback = () -> {
+ MenuPopup menuPopup = (MenuPopup) getComponent();
+ Display display = menuPopup.getDisplay();
+
+ Point location = menuPopup.getLocation();
+ Dimensions size = menuPopup.getSize();
+
+ int x = location.x;
+ int displayWidth = display.getWidth();
+ if (size.width > displayWidth) {
+ border.setPreferredWidth(displayWidth);
+ x = 0;
+ } else if (x + size.width > displayWidth) {
+ x = Math.max(displayWidth - size.width, 0);
+ }
+
+ int y = location.y;
+ int displayHeight = display.getHeight();
+ if (size.height > displayHeight) {
+ border.setPreferredHeight(displayHeight);
+ y = 0;
+ } else if (y + size.height > displayHeight) {
+ y = Math.max(displayHeight - size.height, 0);
}
- }
- private Panorama panorama;
- private Border border;
+ menuPopup.setLocation(x, y);
+ };
private DropShadowDecorator dropShadowDecorator = null;
private Transition closeTransition = null;
@@ -238,7 +235,7 @@ public class TerraMenuPopupSkin extends
panorama.setScrollTop(0);
// Always ensure that the menu popup fits on the display.
- ApplicationContext.queueCallback(new RepositionCallback());
+ ApplicationContext.queueCallback(repositionCallback);
}
@Override
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java?rev=1818986&r1=1818985&r2=1818986&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.java Thu Dec 21 22:29:19 2017
@@ -1683,12 +1683,8 @@ public class TerraTabPaneSkin extends Ta
selectedTab.setVisible(true);
selectedTab.requestFocus();
- ApplicationContext.queueCallback(new Runnable() {
- @Override
- public void run() {
- button.scrollAreaToVisible(0, 0, button.getWidth(), button.getHeight());
- }
- });
+ ApplicationContext.queueCallback(() ->
+ button.scrollAreaToVisible(0, 0, button.getWidth(), button.getHeight()));
}
if (previousSelectedIndex != -1) {
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TaskAdapter.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TaskAdapter.java?rev=1818986&r1=1818985&r2=1818986&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TaskAdapter.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TaskAdapter.java Thu Dec 21 22:29:19 2017
@@ -24,49 +24,13 @@ import org.apache.pivot.util.concurrent.
* Class that forwards task events to the UI thread.
*/
public class TaskAdapter<T> implements TaskListener<T> {
- /**
- * Callback that gets posted to the UI thread when our task has been
- * executed.
- */
- private class TaskExecutedCallback implements Runnable {
- private Task<T> task;
-
- public TaskExecutedCallback(Task<T> task) {
- this.task = task;
- }
-
- @Override
- public void run() {
- taskListener.taskExecuted(task);
- }
- }
-
- /**
- * Callback that gets posted to the UI thread when our task execution has
- * failed.
- */
- private class ExecuteFailedCallback implements Runnable {
- private Task<T> task;
-
- public ExecuteFailedCallback(Task<T> task) {
- this.task = task;
- }
-
- @Override
- public void run() {
- taskListener.executeFailed(task);
- }
- }
-
- // The TaskListener that we're adapting
+ /** The TaskListener that we're adapting. */
private TaskListener<T> taskListener;
/**
- * Creates a new <tt>TaskAdapter</tt> that wraps the specified task
- * listener.
+ * Creates a new <tt>TaskAdapter</tt> that wraps the specified task listener.
*
- * @param taskListener The task listener that will be notified on the UI
- * thread
+ * @param taskListener The task listener that will be notified on the UI thread.
*/
public TaskAdapter(TaskListener<T> taskListener) {
Utils.checkNull(taskListener, "Task listener");
@@ -77,12 +41,12 @@ public class TaskAdapter<T> implements T
// TaskListener methods
@Override
- public void taskExecuted(Task<T> task) {
- ApplicationContext.queueCallback(new TaskExecutedCallback(task));
+ public void taskExecuted(final Task<T> task) {
+ ApplicationContext.queueCallback(() -> taskListener.taskExecuted(task));
}
@Override
- public void executeFailed(Task<T> task) {
- ApplicationContext.queueCallback(new ExecuteFailedCallback(task));
+ public void executeFailed(final Task<T> task) {
+ ApplicationContext.queueCallback(() -> taskListener.executeFailed(task));
}
}