src/Tools/jEdit/src/jedit/session_dockable.scala
author wenzelm
Sat Sep 25 17:28:41 2010 +0200 (2010-09-25)
changeset 39702 d7c256cb2797
parent 39701 7c351c1c0624
child 39734 47f5a8c92666
permissions -rw-r--r--
Session_Dockable: more startup controls;
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@39702
    14
  Component, Swing, CheckBox}
wenzelm@39638
    15
import scala.swing.event.{ButtonClicked, SelectionChanged}
wenzelm@39593
    16
wenzelm@39593
    17
import java.awt.BorderLayout
wenzelm@39697
    18
import javax.swing.border.{BevelBorder, SoftBevelBorder}
wenzelm@39515
    19
wenzelm@39515
    20
import org.gjt.sp.jedit.View
wenzelm@39515
    21
wenzelm@39515
    22
wenzelm@39515
    23
class Session_Dockable(view: View, position: String) extends Dockable(view: View, position: String)
wenzelm@39515
    24
{
wenzelm@39591
    25
  /* main tabs */
wenzelm@39591
    26
wenzelm@39591
    27
  private val readme = new HTML_Panel(Isabelle.system, "SansSerif", 12)
wenzelm@39591
    28
  readme.render_document(Isabelle.system.try_read(List("$JEDIT_HOME/README.html")))
wenzelm@39591
    29
wenzelm@39629
    30
  private val syslog = new TextArea(Isabelle.session.syslog())
wenzelm@39591
    31
  syslog.editable = false
wenzelm@39591
    32
wenzelm@39591
    33
  private val tabs = new TabbedPane {
wenzelm@39591
    34
    pages += new TabbedPane.Page("README", Component.wrap(readme))
wenzelm@39591
    35
    pages += new TabbedPane.Page("System log", new ScrollPane(syslog))
wenzelm@39638
    36
wenzelm@39638
    37
    selection.index =
wenzelm@39638
    38
    {
wenzelm@39638
    39
      val index = Isabelle.Int_Property("session-panel.selection", 0)
wenzelm@39638
    40
      if (index >= pages.length) 0 else index
wenzelm@39638
    41
    }
wenzelm@39638
    42
    listenTo(selection)
wenzelm@39638
    43
    reactions += {
wenzelm@39638
    44
      case SelectionChanged(_) =>
wenzelm@39638
    45
        Isabelle.Int_Property("session-panel.selection") = selection.index
wenzelm@39638
    46
    }
wenzelm@39591
    47
  }
wenzelm@39591
    48
wenzelm@39591
    49
  set_content(tabs)
wenzelm@39515
    50
wenzelm@39515
    51
wenzelm@39593
    52
  /* controls */
wenzelm@39593
    53
wenzelm@39635
    54
  val session_phase = new Label(Isabelle.session.phase.toString)
wenzelm@39697
    55
  session_phase.border = new SoftBevelBorder(BevelBorder.LOWERED)
wenzelm@39697
    56
  session_phase.tooltip = "Prover status"
wenzelm@39635
    57
wenzelm@39702
    58
  private val auto_start = new CheckBox("Auto start") {
wenzelm@39702
    59
    selected = Isabelle.Boolean_Property("auto-start")
wenzelm@39702
    60
    reactions += {
wenzelm@39702
    61
      case ButtonClicked(_) =>
wenzelm@39702
    62
        Isabelle.Boolean_Property("auto-start") = selected
wenzelm@39702
    63
        if (selected) Isabelle.start_session()
wenzelm@39702
    64
    }
wenzelm@39702
    65
  }
wenzelm@39702
    66
wenzelm@39702
    67
  private val logic = Isabelle.logic_selector(Isabelle.Property("logic"))
wenzelm@39702
    68
  logic.listenTo(logic.selection)
wenzelm@39702
    69
  logic.reactions += {
wenzelm@39702
    70
    case SelectionChanged(_) => Isabelle.Property("logic") = logic.selection.item.name
wenzelm@39702
    71
  }
wenzelm@39702
    72
wenzelm@39593
    73
  private val interrupt = new Button("Interrupt") {
wenzelm@39593
    74
    reactions += { case ButtonClicked(_) => Isabelle.session.interrupt }
wenzelm@39593
    75
  }
wenzelm@39593
    76
  interrupt.tooltip = "Broadcast interrupt to all prover tasks"
wenzelm@39593
    77
wenzelm@39635
    78
  private val controls =
wenzelm@39702
    79
    new FlowPanel(FlowPanel.Alignment.Right)(session_phase, auto_start, logic, interrupt)
wenzelm@39593
    80
  add(controls.peer, BorderLayout.NORTH)
wenzelm@39593
    81
wenzelm@39593
    82
wenzelm@39515
    83
  /* main actor */
wenzelm@39515
    84
wenzelm@39515
    85
  private val main_actor = actor {
wenzelm@39515
    86
    loop {
wenzelm@39515
    87
      react {
wenzelm@39589
    88
        case result: Isabelle_Process.Result =>
wenzelm@39625
    89
          if (result.is_syslog)
wenzelm@39625
    90
            Swing_Thread.now {
wenzelm@39629
    91
              val text = Isabelle.session.syslog()
wenzelm@39626
    92
              if (text != syslog.text) {
wenzelm@39626
    93
                syslog.text = text
wenzelm@39626
    94
              }
wenzelm@39625
    95
            }
wenzelm@39589
    96
wenzelm@39701
    97
        case phase: Session.Phase =>
wenzelm@39696
    98
          Swing_Thread.now { session_phase.text = " " + phase.toString + " " }
wenzelm@39635
    99
wenzelm@39515
   100
        case bad => System.err.println("Session_Dockable: ignoring bad message " + bad)
wenzelm@39515
   101
      }
wenzelm@39515
   102
    }
wenzelm@39515
   103
  }
wenzelm@39515
   104
wenzelm@39635
   105
  override def init() {
wenzelm@39635
   106
    Isabelle.session.raw_messages += main_actor
wenzelm@39635
   107
    Isabelle.session.phase_changed += main_actor
wenzelm@39635
   108
  }
wenzelm@39635
   109
wenzelm@39635
   110
  override def exit() {
wenzelm@39635
   111
    Isabelle.session.raw_messages -= main_actor
wenzelm@39635
   112
    Isabelle.session.phase_changed -= main_actor
wenzelm@39635
   113
  }
wenzelm@39515
   114
}