src/Tools/jEdit/src/session_dockable.scala
author wenzelm
Wed Aug 31 17:36:10 2011 +0200 (2011-08-31)
changeset 44609 6ec4a5eb2fc0
parent 44335 156be0e43336
child 44613 a3255c85327b
permissions -rw-r--r--
some support for theory status overview;
     1 /*  Title:      Tools/jEdit/src/session_dockable.scala
     2     Author:     Makarius
     3 
     4 Dockable window for prover session management.
     5 */
     6 
     7 package isabelle.jedit
     8 
     9 
    10 import isabelle._
    11 
    12 import scala.actors.Actor._
    13 import scala.swing.{FlowPanel, Button, TextArea, Label, ListView,
    14   ScrollPane, TabbedPane, Component, Swing}
    15 import scala.swing.event.{ButtonClicked, SelectionChanged}
    16 
    17 import java.lang.System
    18 import java.awt.BorderLayout
    19 import javax.swing.JList
    20 import javax.swing.border.{BevelBorder, SoftBevelBorder}
    21 
    22 import org.gjt.sp.jedit.View
    23 
    24 
    25 class Session_Dockable(view: View, position: String) extends Dockable(view: View, position: String)
    26 {
    27   /* main tabs */
    28 
    29   private val readme = new HTML_Panel("SansSerif", 14)
    30   readme.render_document(Isabelle_System.try_read(List(Path.explode("$JEDIT_HOME/README.html"))))
    31 
    32   val status = new ListView(Nil: List[String])
    33   status.peer.setLayoutOrientation(JList.VERTICAL_WRAP)
    34   status.selection.intervalMode = ListView.IntervalMode.Single
    35 
    36   private val syslog = new TextArea(Isabelle.session.syslog())
    37 
    38   private val tabs = new TabbedPane {
    39     pages += new TabbedPane.Page("README", Component.wrap(readme))
    40     pages += new TabbedPane.Page("Theory Status", new ScrollPane(status))
    41     pages += new TabbedPane.Page("System Log", new ScrollPane(syslog))
    42 
    43     selection.index =
    44     {
    45       val index = Isabelle.Int_Property("session-panel.selection", 0)
    46       if (index >= pages.length) 0 else index
    47     }
    48     listenTo(selection)
    49     reactions += {
    50       case SelectionChanged(_) =>
    51         Isabelle.Int_Property("session-panel.selection") = selection.index
    52     }
    53   }
    54 
    55   set_content(tabs)
    56 
    57 
    58   /* controls */
    59 
    60   val session_phase = new Label(Isabelle.session.phase.toString)
    61   session_phase.border = new SoftBevelBorder(BevelBorder.LOWERED)
    62   session_phase.tooltip = "Prover status"
    63 
    64   private val logic = Isabelle.logic_selector(Isabelle.Property("logic"))
    65   logic.listenTo(logic.selection)
    66   logic.reactions += {
    67     case SelectionChanged(_) => Isabelle.Property("logic") = logic.selection.item.name
    68   }
    69 
    70   private val controls = new FlowPanel(FlowPanel.Alignment.Right)(session_phase, logic)
    71   add(controls.peer, BorderLayout.NORTH)
    72 
    73 
    74   /* component state -- owned by Swing thread */
    75 
    76   private var nodes: Set[String] = Set.empty
    77 
    78   private def handle_changed(changed_nodes: Set[String])
    79   {
    80     Swing_Thread.now {
    81       val nodes1 = nodes ++ changed_nodes
    82       if (nodes1 != nodes) {
    83         nodes = nodes1
    84         status.listData = Library.sort_strings(nodes.toList)
    85       }
    86     }
    87   }
    88 
    89 
    90   /* main actor */
    91 
    92   private val main_actor = actor {
    93     loop {
    94       react {
    95         case input: Isabelle_Process.Input =>
    96 
    97         case result: Isabelle_Process.Result =>
    98           if (result.is_syslog)
    99             Swing_Thread.now {
   100               val text = Isabelle.session.syslog()
   101               if (text != syslog.text) {
   102                 syslog.text = text
   103               }
   104             }
   105 
   106         case phase: Session.Phase =>
   107           Swing_Thread.now { session_phase.text = " " + phase.toString + " " }
   108 
   109         case changed: Session.Commands_Changed => handle_changed(changed.nodes)
   110 
   111         case bad => System.err.println("Session_Dockable: ignoring bad message " + bad)
   112       }
   113     }
   114   }
   115 
   116   override def init() {
   117     Isabelle.session.raw_messages += main_actor
   118     Isabelle.session.phase_changed += main_actor
   119     Isabelle.session.commands_changed += main_actor
   120   }
   121 
   122   override def exit() {
   123     Isabelle.session.raw_messages -= main_actor
   124     Isabelle.session.phase_changed -= main_actor
   125     Isabelle.session.commands_changed -= main_actor
   126   }
   127 }