Author: rwhitcomb
Date: Thu Jan 11 21:13:38 2018
New Revision: 1820933

URL: http://svn.apache.org/viewvc?rev=1820933&view=rev
Log:
Cleanup some duplicated code in Frame.java around building a linked list
of ancestor components.

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Frame.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Frame.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Frame.java?rev=1820933&r1=1820932&r2=1820933&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Frame.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Frame.java Thu Jan 11 21:13:38 2018
@@ -85,18 +85,22 @@ public class Frame extends Window {
         requestActive();
     }
 
+    private LinkedList<Component> getAncestorPath(Component component) {
+        LinkedList<Component> path = new LinkedList<>();
+
+        for (Component ancestor = component;
+             !(ancestor instanceof Display);
+             ancestor = ancestor.getParent()) {
+            path.insert(ancestor, 0);
+        }
+
+        return path;
+    }
+
     @Override
     protected void descendantGainedFocus(Component descendant, Component 
previousFocusedComponent) {
         if (menuBar != null) {
-            LinkedList<Component> path = new LinkedList<>();
-
-            Component ancestor = descendant;
-            while (!(ancestor instanceof Display)) {
-                path.insert(ancestor, 0);
-                ancestor = ancestor.getParent();
-            }
-
-            for (Component component : path) {
+            for (Component component : getAncestorPath(descendant)) {
                 MenuHandler menuHandler = component.getMenuHandler();
 
                 if (menuHandler != null) {
@@ -111,15 +115,7 @@ public class Frame extends Window {
     @Override
     protected void descendantLostFocus(Component descendant) {
         if (menuBar != null) {
-            LinkedList<Component> path = new LinkedList<>();
-
-            Component ancestor = descendant;
-            while (!(ancestor instanceof Display)) {
-                path.insert(ancestor, 0);
-                ancestor = ancestor.getParent();
-            }
-
-            for (Component component : path) {
+            for (Component component : getAncestorPath(descendant)) {
                 MenuHandler menuHandler = component.getMenuHandler();
 
                 if (menuHandler != null) {


Reply via email to