src/Tools/jEdit/src/session_dockable.scala
author wenzelm
Tue Aug 23 12:20:12 2011 +0200 (2011-08-23)
changeset 44385 e7fdb008aa7d
parent 44335 156be0e43336
child 44609 6ec4a5eb2fc0
permissions -rw-r--r--
propagate editor perspective through document model;
     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 
    32   private val tabs = new TabbedPane {
    33     pages += new TabbedPane.Page("README", Component.wrap(readme))
    34     pages += new TabbedPane.Page("System log", new ScrollPane(syslog))
    35 
    36     selection.index =
    37     {
    38       val index = Isabelle.Int_Property("session-panel.selection", 0)
    39       if (index >= pages.length) 0 else index
    40     }
    41     listenTo(selection)
    42     reactions += {
    43       case SelectionChanged(_) =>
    44         Isabelle.Int_Property("session-panel.selection") = selection.index
    45     }
    46   }
    47 
    48   set_content(tabs)
    49 
    50 
    51   /* controls */
    52 
    53   val session_phase = new Label(Isabelle.session.phase.toString)
    54   session_phase.border = new SoftBevelBorder(BevelBorder.LOWERED)
    55   session_phase.tooltip = "Prover status"
    56 
    57   private val logic = Isabelle.logic_selector(Isabelle.Property("logic"))
    58   logic.listenTo(logic.selection)
    59   logic.reactions += {
    60     case SelectionChanged(_) => Isabelle.Property("logic") = logic.selection.item.name
    61   }
    62 
    63   private val controls = new FlowPanel(FlowPanel.Alignment.Right)(session_phase, logic)
    64   add(controls.peer, BorderLayout.NORTH)
    65 
    66 
    67   /* main actor */
    68 
    69   private val main_actor = actor {
    70     loop {
    71       react {
    72         case input: Isabelle_Process.Input =>
    73 
    74         case result: Isabelle_Process.Result =>
    75           if (result.is_syslog)
    76             Swing_Thread.now {
    77               val text = Isabelle.session.syslog()
    78               if (text != syslog.text) {
    79                 syslog.text = text
    80               }
    81             }
    82 
    83         case phase: Session.Phase =>
    84           Swing_Thread.now { session_phase.text = " " + phase.toString + " " }
    85 
    86         case bad => System.err.println("Session_Dockable: ignoring bad message " + bad)
    87       }
    88     }
    89   }
    90 
    91   override def init() {
    92     Isabelle.session.raw_messages += main_actor
    93     Isabelle.session.phase_changed += main_actor
    94   }
    95 
    96   override def exit() {
    97     Isabelle.session.raw_messages -= main_actor
    98     Isabelle.session.phase_changed -= main_actor
    99   }
   100 }