src/Pure/System/gui.scala
changeset 53712 ea51046be71b
parent 53452 8181bc357dc4
child 53714 89fb20ae9b73
--- a/src/Pure/System/gui.scala	Wed Sep 18 15:09:15 2013 +0200
+++ b/src/Pure/System/gui.scala	Wed Sep 18 15:50:59 2013 +0200
@@ -1,13 +1,13 @@
 /*  Title:      Pure/System/gui.scala
     Author:     Makarius
 
-Elementary GUI tools.
+Basic GUI tools (for AWT/Swing).
 */
 
 package isabelle
 
 
-import java.awt.{Image, Component, Toolkit}
+import java.awt.{Image, Component, Container, Toolkit, Window}
 import javax.swing.{ImageIcon, JOptionPane, UIManager}
 
 import scala.swing.{ComboBox, TextArea, ScrollPane}
@@ -117,5 +117,29 @@
     new ImageIcon(getClass.getClassLoader.getResource("isabelle/isabelle.gif"))
 
   def isabelle_image(): Image = isabelle_icon().getImage
+
+
+  /* component hierachy */
+
+  def get_parent(component: Component): Option[Container] =
+    component.getParent match {
+      case null => None
+      case parent => Some(parent)
+    }
+
+  def ancestors(component: Component): Iterator[Container] = new Iterator[Container] {
+    private var next_elem = get_parent(component)
+    def hasNext(): Boolean = next_elem.isDefined
+    def next(): Container =
+      next_elem match {
+        case Some(parent) =>
+          next_elem = get_parent(parent)
+          parent
+        case None => Iterator.empty.next()
+      }
+  }
+
+  def parent_window(component: Component): Option[Window] =
+    ancestors(component).collectFirst({ case x: Window => x })
 }