PMD code sweep, #6 don't add MyWindow twice to MyApplication
[nikiroo-utils.git] / src / jexer / backend / MultiBackend.java
index 9166e1c19bec44817a21297d87d949cb27b1a1f2..4e82d4ee694e13cbe12275ca1e16f67b42391251 100644 (file)
@@ -38,6 +38,10 @@ import jexer.event.TInputEvent;
  */
 public class MultiBackend implements Backend {
 
+    // ------------------------------------------------------------------------
+    // Variables --------------------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * The screen to use.
      */
@@ -48,6 +52,10 @@ public class MultiBackend implements Backend {
      */
     private List<Backend> backends = new LinkedList<Backend>();
 
+    // ------------------------------------------------------------------------
+    // Constructors -----------------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * Public constructor requires one backend.  Note that this backend's
      * screen will be replaced with a MultiScreen.
@@ -63,35 +71,9 @@ public class MultiBackend implements Backend {
         }
     }
 
-    /**
-     * Add a backend to the list.
-     *
-     * @param backend the backend to add
-     */
-    public void addBackend(final Backend backend) {
-        backends.add(backend);
-        if (backend instanceof TWindowBackend) {
-            multiScreen.addScreen(((TWindowBackend) backend).getOtherScreen());
-        } else {
-            multiScreen.addScreen(backend.getScreen());
-        }
-    }
-
-    /**
-     * Remove a backend from the list.
-     *
-     * @param backend the backend to remove
-     */
-    public void removeBackend(final Backend backend) {
-        if (backends.size() > 1) {
-            if (backend instanceof TWindowBackend) {
-                multiScreen.removeScreen(((TWindowBackend) backend).getOtherScreen());
-            } else {
-                multiScreen.removeScreen(backend.getScreen());
-            }
-            backends.remove(backend);
-        }
-    }
+    // ------------------------------------------------------------------------
+    // Backend ----------------------------------------------------------------
+    // ------------------------------------------------------------------------
 
     /**
      * Getter for sessionInfo.
@@ -121,6 +103,20 @@ public class MultiBackend implements Backend {
         }
     }
 
+    /**
+     * Check if there are events in the queue.
+     *
+     * @return if true, getEvents() has something to return to the application
+     */
+    public boolean hasEvents() {
+        for (Backend backend: backends) {
+            if (backend.hasEvents()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     /**
      * Subclasses must provide an implementation to get keyboard, mouse, and
      * screen resize events.
@@ -166,4 +162,38 @@ public class MultiBackend implements Backend {
         }
     }
 
+    // ------------------------------------------------------------------------
+    // MultiBackend -----------------------------------------------------------
+    // ------------------------------------------------------------------------
+
+    /**
+     * Add a backend to the list.
+     *
+     * @param backend the backend to add
+     */
+    public void addBackend(final Backend backend) {
+        backends.add(backend);
+        if (backend instanceof TWindowBackend) {
+            multiScreen.addScreen(((TWindowBackend) backend).getOtherScreen());
+        } else {
+            multiScreen.addScreen(backend.getScreen());
+        }
+    }
+
+    /**
+     * Remove a backend from the list.
+     *
+     * @param backend the backend to remove
+     */
+    public void removeBackend(final Backend backend) {
+        if (backends.size() > 1) {
+            if (backend instanceof TWindowBackend) {
+                multiScreen.removeScreen(((TWindowBackend) backend).getOtherScreen());
+            } else {
+                multiScreen.removeScreen(backend.getScreen());
+            }
+            backends.remove(backend);
+        }
+    }
+
 }