src/Pure/PIDE/markup_tree.scala
changeset 51618 a3577cd80c41
parent 50642 aca12f646772
child 52642 84eb792224a8
equal deleted inserted replaced
51617:4e49bba9772d 51618:a3577cd80c41
     6 Markup trees over nested / non-overlapping text ranges.
     6 Markup trees over nested / non-overlapping text ranges.
     7 */
     7 */
     8 
     8 
     9 package isabelle
     9 package isabelle
    10 
    10 
    11 import java.lang.System
       
    12 import javax.swing.tree.DefaultMutableTreeNode
       
    13 
    11 
    14 import scala.collection.immutable.SortedMap
    12 import scala.collection.immutable.SortedMap
    15 import scala.collection.mutable
    13 import scala.collection.mutable
    16 import scala.annotation.tailrec
    14 import scala.annotation.tailrec
    17 
    15 
   130   def from_XML(body: XML.Body): Markup_Tree =
   128   def from_XML(body: XML.Body): Markup_Tree =
   131     merge_disjoint(((0, Nil: List[Markup_Tree]) /: body)(make_trees)._2)
   129     merge_disjoint(((0, Nil: List[Markup_Tree]) /: body)(make_trees)._2)
   132 }
   130 }
   133 
   131 
   134 
   132 
   135 final class Markup_Tree private(private val branches: Markup_Tree.Branches.T)
   133 final class Markup_Tree private(val branches: Markup_Tree.Branches.T)
   136 {
   134 {
   137   import Markup_Tree._
   135   import Markup_Tree._
   138 
   136 
   139   private def this(branches: Markup_Tree.Branches.T, entry: Markup_Tree.Entry) =
   137   private def this(branches: Markup_Tree.Branches.T, entry: Markup_Tree.Entry) =
   140     this(branches + (entry.range -> entry))
   138     this(branches + (entry.range -> entry))
   278       }
   276       }
   279     }
   277     }
   280     stream(root_range.start,
   278     stream(root_range.start,
   281       List((Text.Info(root_range, root_info), overlapping(root_range).toStream)))
   279       List((Text.Info(root_range, root_info), overlapping(root_range).toStream)))
   282   }
   280   }
   283 
       
   284   def swing_tree(parent: DefaultMutableTreeNode,
       
   285     swing_node: Text.Info[List[XML.Elem]] => DefaultMutableTreeNode)
       
   286   {
       
   287     for ((_, entry) <- branches) {
       
   288       val node = swing_node(Text.Info(entry.range, entry.markup))
       
   289       entry.subtree.swing_tree(node, swing_node)
       
   290       parent.add(node)
       
   291     }
       
   292   }
       
   293 }
   281 }
   294 
   282