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;
wenzelm@43282
     1
/*  Title:      Tools/jEdit/src/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@39734
    13
import scala.swing.{FlowPanel, Button, TextArea, Label, ScrollPane, TabbedPane, Component, Swing}
wenzelm@39638
    14
import scala.swing.event.{ButtonClicked, SelectionChanged}
wenzelm@39593
    15
wenzelm@43520
    16
import java.lang.System
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@43661
    27
  private val readme = new HTML_Panel("SansSerif", 14)
wenzelm@43661
    28
  readme.render_document(Isabelle_System.try_read(List(Path.explode("$JEDIT_HOME/README.html"))))
wenzelm@39591
    29
wenzelm@39629
    30
  private val syslog = new TextArea(Isabelle.session.syslog())
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@39697
    54
  session_phase.border = new SoftBevelBorder(BevelBorder.LOWERED)
wenzelm@39697
    55
  session_phase.tooltip = "Prover status"
wenzelm@39635
    56
wenzelm@39702
    57
  private val logic = Isabelle.logic_selector(Isabelle.Property("logic"))
wenzelm@39702
    58
  logic.listenTo(logic.selection)
wenzelm@39702
    59
  logic.reactions += {
wenzelm@39702
    60
    case SelectionChanged(_) => Isabelle.Property("logic") = logic.selection.item.name
wenzelm@39702
    61
  }
wenzelm@39702
    62
wenzelm@44335
    63
  private val controls = new FlowPanel(FlowPanel.Alignment.Right)(session_phase, logic)
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@43721
    72
        case input: Isabelle_Process.Input =>
wenzelm@43721
    73
wenzelm@39589
    74
        case result: Isabelle_Process.Result =>
wenzelm@39625
    75
          if (result.is_syslog)
wenzelm@39625
    76
            Swing_Thread.now {
wenzelm@39629
    77
              val text = Isabelle.session.syslog()
wenzelm@39626
    78
              if (text != syslog.text) {
wenzelm@39626
    79
                syslog.text = text
wenzelm@39626
    80
              }
wenzelm@39625
    81
            }
wenzelm@39589
    82
wenzelm@39701
    83
        case phase: Session.Phase =>
wenzelm@39696
    84
          Swing_Thread.now { session_phase.text = " " + phase.toString + " " }
wenzelm@39635
    85
wenzelm@39515
    86
        case bad => System.err.println("Session_Dockable: ignoring bad message " + bad)
wenzelm@39515
    87
      }
wenzelm@39515
    88
    }
wenzelm@39515
    89
  }
wenzelm@39515
    90
wenzelm@39635
    91
  override def init() {
wenzelm@39635
    92
    Isabelle.session.raw_messages += main_actor
wenzelm@39635
    93
    Isabelle.session.phase_changed += main_actor
wenzelm@39635
    94
  }
wenzelm@39635
    95
wenzelm@39635
    96
  override def exit() {
wenzelm@39635
    97
    Isabelle.session.raw_messages -= main_actor
wenzelm@39635
    98
    Isabelle.session.phase_changed -= main_actor
wenzelm@39635
    99
  }
wenzelm@39515
   100
}