src/Tools/jEdit/src/jedit/session_dockable.scala
author wenzelm
Fri Sep 24 14:47:01 2010 +0200 (2010-09-24)
changeset 39638 4293ce5b07fb
parent 39635 5cd8545a070b
child 39696 f4da0428dc78
permissions -rw-r--r--
persistent session-panel.selection;
wenzelm@39515
     1
/*  Title:      Tools/jEdit/src/jedit/session_dockable.scala
wenzelm@39515
     2
    Author:     Makarius
wenzelm@39515
     3
wenzelm@39515
     4
Dockable window for prover session management.
wenzelm@39515
     5
*/
wenzelm@39515
     6
wenzelm@39515
     7
package isabelle.jedit
wenzelm@39515
     8
wenzelm@39515
     9
wenzelm@39515
    10
import isabelle._
wenzelm@39515
    11
wenzelm@39515
    12
import scala.actors.Actor._
wenzelm@39635
    13
import scala.swing.{FlowPanel, Button, TextArea, Label, ScrollPane, TabbedPane,
wenzelm@39635
    14
  Component, Swing}
wenzelm@39638
    15
import scala.swing.event.{ButtonClicked, SelectionChanged}
wenzelm@39593
    16
wenzelm@39593
    17
import java.awt.BorderLayout
wenzelm@39515
    18
wenzelm@39515
    19
import org.gjt.sp.jedit.View
wenzelm@39515
    20
wenzelm@39515
    21
wenzelm@39515
    22
class Session_Dockable(view: View, position: String) extends Dockable(view: View, position: String)
wenzelm@39515
    23
{
wenzelm@39591
    24
  /* main tabs */
wenzelm@39591
    25
wenzelm@39591
    26
  private val readme = new HTML_Panel(Isabelle.system, "SansSerif", 12)
wenzelm@39591
    27
  readme.render_document(Isabelle.system.try_read(List("$JEDIT_HOME/README.html")))
wenzelm@39591
    28
wenzelm@39629
    29
  private val syslog = new TextArea(Isabelle.session.syslog())
wenzelm@39591
    30
  syslog.editable = false
wenzelm@39591
    31
wenzelm@39591
    32
  private val tabs = new TabbedPane {
wenzelm@39591
    33
    pages += new TabbedPane.Page("README", Component.wrap(readme))
wenzelm@39591
    34
    pages += new TabbedPane.Page("System log", new ScrollPane(syslog))
wenzelm@39638
    35
wenzelm@39638
    36
    selection.index =
wenzelm@39638
    37
    {
wenzelm@39638
    38
      val index = Isabelle.Int_Property("session-panel.selection", 0)
wenzelm@39638
    39
      if (index >= pages.length) 0 else index
wenzelm@39638
    40
    }
wenzelm@39638
    41
    listenTo(selection)
wenzelm@39638
    42
    reactions += {
wenzelm@39638
    43
      case SelectionChanged(_) =>
wenzelm@39638
    44
        Isabelle.Int_Property("session-panel.selection") = selection.index
wenzelm@39638
    45
    }
wenzelm@39591
    46
  }
wenzelm@39591
    47
wenzelm@39591
    48
  set_content(tabs)
wenzelm@39515
    49
wenzelm@39515
    50
wenzelm@39593
    51
  /* controls */
wenzelm@39593
    52
wenzelm@39635
    53
  val session_phase = new Label(Isabelle.session.phase.toString)
wenzelm@39635
    54
  session_phase.border = Swing.EtchedBorder(Swing.Lowered)
wenzelm@39635
    55
  session_phase.tooltip = "Prover process status"
wenzelm@39635
    56
wenzelm@39593
    57
  private val interrupt = new Button("Interrupt") {
wenzelm@39593
    58
    reactions += { case ButtonClicked(_) => Isabelle.session.interrupt }
wenzelm@39593
    59
  }
wenzelm@39593
    60
  interrupt.tooltip = "Broadcast interrupt to all prover tasks"
wenzelm@39593
    61
wenzelm@39635
    62
  private val controls =
wenzelm@39635
    63
    new FlowPanel(FlowPanel.Alignment.Right)(session_phase, interrupt)
wenzelm@39593
    64
  add(controls.peer, BorderLayout.NORTH)
wenzelm@39593
    65
wenzelm@39593
    66
wenzelm@39515
    67
  /* main actor */
wenzelm@39515
    68
wenzelm@39515
    69
  private val main_actor = actor {
wenzelm@39515
    70
    loop {
wenzelm@39515
    71
      react {
wenzelm@39589
    72
        case result: Isabelle_Process.Result =>
wenzelm@39625
    73
          if (result.is_syslog)
wenzelm@39625
    74
            Swing_Thread.now {
wenzelm@39629
    75
              val text = Isabelle.session.syslog()
wenzelm@39626
    76
              if (text != syslog.text) {
wenzelm@39626
    77
                syslog.text = text
wenzelm@39626
    78
              }
wenzelm@39625
    79
            }
wenzelm@39589
    80
wenzelm@39635
    81
        case (_, phase: Session.Phase) =>
wenzelm@39635
    82
          Swing_Thread.now { session_phase.text = phase.toString }
wenzelm@39635
    83
wenzelm@39515
    84
        case bad => System.err.println("Session_Dockable: ignoring bad message " + bad)
wenzelm@39515
    85
      }
wenzelm@39515
    86
    }
wenzelm@39515
    87
  }
wenzelm@39515
    88
wenzelm@39635
    89
  override def init() {
wenzelm@39635
    90
    Isabelle.session.raw_messages += main_actor
wenzelm@39635
    91
    Isabelle.session.phase_changed += main_actor
wenzelm@39635
    92
  }
wenzelm@39635
    93
wenzelm@39635
    94
  override def exit() {
wenzelm@39635
    95
    Isabelle.session.raw_messages -= main_actor
wenzelm@39635
    96
    Isabelle.session.phase_changed -= main_actor
wenzelm@39635
    97
  }
wenzelm@39515
    98
}