src/Tools/jEdit/src/session_dockable.scala
author wenzelm
Mon Jul 04 22:11:32 2011 +0200 (2011-07-04)
changeset 43661 39fdbd814c7f
parent 43606 e1a09c2a6248
child 43721 fad8634cee62
permissions -rw-r--r--
quasi-static Isabelle_System -- reduced tendency towards "functorial style";
     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, ScrollPane, TabbedPane, Component, Swing}
    14 import scala.swing.event.{ButtonClicked, SelectionChanged}
    15 
    16 import java.lang.System
    17 import java.awt.BorderLayout
    18 import javax.swing.border.{BevelBorder, SoftBevelBorder}
    19 
    20 import org.gjt.sp.jedit.View
    21 
    22 
    23 class Session_Dockable(view: View, position: String) extends Dockable(view: View, position: String)
    24 {
    25   /* main tabs */
    26 
    27   private val readme = new HTML_Panel("SansSerif", 14)
    28   readme.render_document(Isabelle_System.try_read(List(Path.explode("$JEDIT_HOME/README.html"))))
    29 
    30   private val syslog = new TextArea(Isabelle.session.syslog())
    31   syslog.editable = false
    32 
    33   private val tabs = new TabbedPane {
    34     pages += new TabbedPane.Page("README", Component.wrap(readme))
    35     pages += new TabbedPane.Page("System log", new ScrollPane(syslog))
    36 
    37     selection.index =
    38     {
    39       val index = Isabelle.Int_Property("session-panel.selection", 0)
    40       if (index >= pages.length) 0 else index
    41     }
    42     listenTo(selection)
    43     reactions += {
    44       case SelectionChanged(_) =>
    45         Isabelle.Int_Property("session-panel.selection") = selection.index
    46     }
    47   }
    48 
    49   set_content(tabs)
    50 
    51 
    52   /* controls */
    53 
    54   val session_phase = new Label(Isabelle.session.phase.toString)
    55   session_phase.border = new SoftBevelBorder(BevelBorder.LOWERED)
    56   session_phase.tooltip = "Prover status"
    57 
    58   private val interrupt = new Button("Interrupt") {
    59     reactions += { case ButtonClicked(_) => Isabelle.session.interrupt }
    60   }
    61   interrupt.tooltip = "Broadcast interrupt to all prover tasks"
    62 
    63   private val logic = Isabelle.logic_selector(Isabelle.Property("logic"))
    64   logic.listenTo(logic.selection)
    65   logic.reactions += {
    66     case SelectionChanged(_) => Isabelle.Property("logic") = logic.selection.item.name
    67   }
    68 
    69   private val controls =
    70     new FlowPanel(FlowPanel.Alignment.Right)(session_phase, interrupt, logic)
    71   add(controls.peer, BorderLayout.NORTH)
    72 
    73 
    74   /* main actor */
    75 
    76   private val main_actor = actor {
    77     loop {
    78       react {
    79         case result: Isabelle_Process.Result =>
    80           if (result.is_syslog)
    81             Swing_Thread.now {
    82               val text = Isabelle.session.syslog()
    83               if (text != syslog.text) {
    84                 syslog.text = text
    85               }
    86             }
    87 
    88         case phase: Session.Phase =>
    89           Swing_Thread.now { session_phase.text = " " + phase.toString + " " }
    90 
    91         case bad => System.err.println("Session_Dockable: ignoring bad message " + bad)
    92       }
    93     }
    94   }
    95 
    96   override def init() {
    97     Isabelle.session.raw_messages += main_actor
    98     Isabelle.session.phase_changed += main_actor
    99   }
   100 
   101   override def exit() {
   102     Isabelle.session.raw_messages -= main_actor
   103     Isabelle.session.phase_changed -= main_actor
   104   }
   105 }