src/Tools/jEdit/src/theories_dockable.scala
author wenzelm
Tue, 29 May 2018 20:00:10 +0200
changeset 68321 daca5f2a0c90
parent 68299 0b5a23477911
child 68758 a110e7e24e55
permissions -rw-r--r--
tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50250
diff changeset
     1
/*  Title:      Tools/jEdit/src/theories_dockable.scala
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
     3
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50250
diff changeset
     4
Dockable window for theories managed by prover.
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
     5
*/
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
     6
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
     8
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
     9
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
    10
import isabelle._
66591
6efa351190d0 more robust: provide docking framework via base plugin;
wenzelm
parents: 66460
diff changeset
    11
import isabelle.jedit_base.Dockable
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
    12
53711
8ce7795256e1 improved FlowLayout for wrapping of components over multiple lines;
wenzelm
parents: 53178
diff changeset
    13
import scala.swing.{Button, TextArea, Label, ListView, Alignment,
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
    14
  ScrollPane, Component, CheckBox, BorderPanel}
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64854
diff changeset
    15
import scala.swing.event.{ButtonClicked, MouseClicked, MouseMoved}
39593
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39591
diff changeset
    16
53178
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
    17
import java.awt.{BorderLayout, Graphics2D, Color, Point, Dimension}
56389
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
    18
import javax.swing.{JList, BorderFactory, UIManager}
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
    19
import javax.swing.border.{BevelBorder, SoftBevelBorder}
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
    20
44865
679f0d57e831 some keyboard shortcuts for important actions;
wenzelm
parents: 44864
diff changeset
    21
import org.gjt.sp.jedit.{View, jEdit}
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
    22
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
    23
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50250
diff changeset
    24
class Theories_Dockable(view: View, position: String) extends Dockable(view, position)
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
    25
{
48021
d899be1cfe6d separate syslog dockable -- discontinued tendency of sub-window management via tabs;
wenzelm
parents: 48018
diff changeset
    26
  /* status */
39591
a43a723753e6 more content for Session_Dockable;
wenzelm
parents: 39589
diff changeset
    27
48021
d899be1cfe6d separate syslog dockable -- discontinued tendency of sub-window management via tabs;
wenzelm
parents: 48018
diff changeset
    28
  private val status = new ListView(Nil: List[Document.Node.Name]) {
56389
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
    29
    background =
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
    30
    {
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
    31
      // enforce default value
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
    32
      val c = UIManager.getDefaults.getColor("Panel.background")
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
    33
      new Color(c.getRed, c.getGreen, c.getBlue, c.getAlpha)
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
    34
    }
44991
d88f7fc62a40 double clicks switch to document node buffer;
wenzelm
parents: 44990
diff changeset
    35
    listenTo(mouse.clicks)
52817
408fb2e563df added home-made tooltips;
wenzelm
parents: 52816
diff changeset
    36
    listenTo(mouse.moves)
44991
d88f7fc62a40 double clicks switch to document node buffer;
wenzelm
parents: 44990
diff changeset
    37
    reactions += {
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
    38
      case MouseClicked(_, point, _, clicks, _) =>
44991
d88f7fc62a40 double clicks switch to document node buffer;
wenzelm
parents: 44990
diff changeset
    39
        val index = peer.locationToIndex(point)
52817
408fb2e563df added home-made tooltips;
wenzelm
parents: 52816
diff changeset
    40
        if (index >= 0) {
408fb2e563df added home-made tooltips;
wenzelm
parents: 52816
diff changeset
    41
          if (in_checkbox(peer.indexToLocation(index), point)) {
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
    42
            if (clicks == 1) Document_Model.node_required(listData(index), toggle = true)
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
    43
          }
66082
2d12a730a380 clarified modules;
wenzelm
parents: 66032
diff changeset
    44
          else if (clicks == 2) PIDE.editor.goto_file(true, view, listData(index).node)
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
    45
        }
52817
408fb2e563df added home-made tooltips;
wenzelm
parents: 52816
diff changeset
    46
      case MouseMoved(_, point, _) =>
408fb2e563df added home-made tooltips;
wenzelm
parents: 52816
diff changeset
    47
        val index = peer.locationToIndex(point)
66032
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
    48
        val index_location = peer.indexToLocation(index)
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
    49
        if (index >= 0 && in_checkbox(index_location, point))
52817
408fb2e563df added home-made tooltips;
wenzelm
parents: 52816
diff changeset
    50
          tooltip = "Mark as required for continuous checking"
66418
410b10ea405c tuned GUI;
wenzelm
parents: 66417
diff changeset
    51
        else if (index >= 0 && in_label(index_location, point)) {
410b10ea405c tuned GUI;
wenzelm
parents: 66417
diff changeset
    52
          val name = listData(index)
410b10ea405c tuned GUI;
wenzelm
parents: 66417
diff changeset
    53
          val st = overall_node_status(name)
410b10ea405c tuned GUI;
wenzelm
parents: 66417
diff changeset
    54
          tooltip =
410b10ea405c tuned GUI;
wenzelm
parents: 66417
diff changeset
    55
            "theory " + quote(name.theory) +
410b10ea405c tuned GUI;
wenzelm
parents: 66417
diff changeset
    56
              (if (st == Overall_Node_Status.ok) "" else " (" + st + ")")
410b10ea405c tuned GUI;
wenzelm
parents: 66417
diff changeset
    57
        }
410b10ea405c tuned GUI;
wenzelm
parents: 66417
diff changeset
    58
        else tooltip = null
44991
d88f7fc62a40 double clicks switch to document node buffer;
wenzelm
parents: 44990
diff changeset
    59
    }
d88f7fc62a40 double clicks switch to document node buffer;
wenzelm
parents: 44990
diff changeset
    60
  }
50250
267bd685a69f smarter list layout;
wenzelm
parents: 50209
diff changeset
    61
  status.peer.setLayoutOrientation(JList.HORIZONTAL_WRAP)
267bd685a69f smarter list layout;
wenzelm
parents: 50209
diff changeset
    62
  status.peer.setVisibleRowCount(0)
44609
6ec4a5eb2fc0 some support for theory status overview;
wenzelm
parents: 44335
diff changeset
    63
  status.selection.intervalMode = ListView.IntervalMode.Single
6ec4a5eb2fc0 some support for theory status overview;
wenzelm
parents: 44335
diff changeset
    64
49038
2f0530b81c45 recovered ScrollPane from d899be1cfe6d;
wenzelm
parents: 48870
diff changeset
    65
  set_content(new ScrollPane(status))
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
    66
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
    67
39593
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39591
diff changeset
    68
  /* controls */
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39591
diff changeset
    69
65206
ff8c3c29a924 clarified Session.Phase;
wenzelm
parents: 64867
diff changeset
    70
  def phase_text(phase: Session.Phase): String = "Prover: " + phase.print
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50250
diff changeset
    71
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50250
diff changeset
    72
  private val session_phase = new Label(phase_text(PIDE.session.phase))
39697
d54242927fb1 tuned border;
wenzelm
parents: 39696
diff changeset
    73
  session_phase.border = new SoftBevelBorder(BevelBorder.LOWERED)
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50250
diff changeset
    74
  session_phase.tooltip = "Status of prover session"
39635
5cd8545a070b added Session_Dockable.session_phase label;
wenzelm
parents: 39629
diff changeset
    75
48018
b941dd7df92a make double sure that GUI components are up-to-date after init;
wenzelm
parents: 48014
diff changeset
    76
  private def handle_phase(phase: Session.Phase)
b941dd7df92a make double sure that GUI components are up-to-date after init;
wenzelm
parents: 48014
diff changeset
    77
  {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 56715
diff changeset
    78
    GUI_Thread.require {}
53177
dcac8d837b9c more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents: 53176
diff changeset
    79
    session_phase.text = " " + phase_text(phase) + " "
48018
b941dd7df92a make double sure that GUI components are up-to-date after init;
wenzelm
parents: 48014
diff changeset
    80
  }
b941dd7df92a make double sure that GUI components are up-to-date after init;
wenzelm
parents: 48014
diff changeset
    81
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64854
diff changeset
    82
  private val purge = new Button("Purge") {
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64854
diff changeset
    83
    tooltip = "Restrict document model to theories required for open editor buffers"
66082
2d12a730a380 clarified modules;
wenzelm
parents: 66032
diff changeset
    84
    reactions += { case ButtonClicked(_) => PIDE.editor.purge() }
64867
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64854
diff changeset
    85
  }
e7220f4de11f support "purge" operation on document model;
wenzelm
parents: 64854
diff changeset
    86
53715
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53711
diff changeset
    87
  private val continuous_checking = new Isabelle.Continuous_Checking
54652
07ee041537a5 non-focusable button, to avoid second interpretation of SPACE in C+e SPACE (isabelle.set-node-required);
wenzelm
parents: 53715
diff changeset
    88
  continuous_checking.focusable = false
44776
47e8c8daccae added "check" button: adhoc change to full buffer perspective;
wenzelm
parents: 44775
diff changeset
    89
66460
f7b0d6fb417a proper update of options (amending c3d6dd17d626);
wenzelm
parents: 66418
diff changeset
    90
  private val logic = JEdit_Sessions.logic_selector(PIDE.options, true)
39702
d7c256cb2797 Session_Dockable: more startup controls;
wenzelm
parents: 39701
diff changeset
    91
44775
27930cf6f0f7 added "cancel" button based on cancel_execution, not interrupt (cf. 156be0e43336);
wenzelm
parents: 44734
diff changeset
    92
  private val controls =
66206
2d2082db735a clarified defaults;
wenzelm
parents: 66205
diff changeset
    93
    Wrap_Panel(List(purge, continuous_checking, session_phase, logic))
66205
e9fa94f43a15 tuned signature;
wenzelm
parents: 66191
diff changeset
    94
39593
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39591
diff changeset
    95
  add(controls.peer, BorderLayout.NORTH)
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39591
diff changeset
    96
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39591
diff changeset
    97
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 56715
diff changeset
    98
  /* component state -- owned by GUI thread */
44609
6ec4a5eb2fc0 some support for theory status overview;
wenzelm
parents: 44335
diff changeset
    99
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
   100
  private var nodes_status: Map[Document.Node.Name, Protocol.Node_Status] = Map.empty
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   101
  private var nodes_required: Set[Document.Node.Name] = Document_Model.required_nodes()
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   102
66411
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   103
  private object Overall_Node_Status extends Enumeration
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   104
  {
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   105
    val ok, failed, pending = Value
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   106
  }
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   107
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   108
  private def overall_node_status(name: Document.Node.Name): Overall_Node_Status.Value =
66410
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   109
    nodes_status.get(name) match {
66411
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   110
      case Some(st) if st.consolidated =>
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   111
        if (st.ok) Overall_Node_Status.ok else Overall_Node_Status.failed
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   112
      case _ => Overall_Node_Status.pending
66410
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   113
    }
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   114
66032
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   115
  private def in(geometry: Option[(Point, Dimension)], loc0: Point, p: Point): Boolean =
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   116
    geometry match {
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   117
      case Some((loc, size)) =>
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   118
        loc0.x + loc.x <= p.x && p.x < loc0.x + size.width &&
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   119
        loc0.y + loc.y <= p.y && p.y < loc0.y + size.height
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   120
      case None => false
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   121
    }
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   122
52817
408fb2e563df added home-made tooltips;
wenzelm
parents: 52816
diff changeset
   123
  private def in_checkbox(loc0: Point, p: Point): Boolean =
66032
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   124
    Node_Renderer_Component != null && in(Node_Renderer_Component.checkbox_geometry, loc0, p)
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   125
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   126
  private def in_label(loc0: Point, p: Point): Boolean =
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   127
    Node_Renderer_Component != null && in(Node_Renderer_Component.label_geometry, loc0, p)
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   128
52817
408fb2e563df added home-made tooltips;
wenzelm
parents: 52816
diff changeset
   129
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   130
  private object Node_Renderer_Component extends BorderPanel
44866
0eb8284a64bd some color scheme for theory status;
wenzelm
parents: 44865
diff changeset
   131
  {
56389
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
   132
    opaque = true
53176
f88635e1c52e clarified border (again, see also 7ce3ebc268a1);
wenzelm
parents: 52980
diff changeset
   133
    border = BorderFactory.createEmptyBorder(2, 2, 2, 2)
44957
098dd95349e7 more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents: 44867
diff changeset
   134
098dd95349e7 more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents: 44867
diff changeset
   135
    var node_name = Document.Node.Name.empty
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   136
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   137
    var checkbox_geometry: Option[(Point, Dimension)] = None
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   138
    val checkbox = new CheckBox {
52819
7ce3ebc268a1 proper border (again) -- avoid NPE on Windows;
wenzelm
parents: 52817
diff changeset
   139
      opaque = false
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   140
      override def paintComponent(gfx: Graphics2D)
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   141
      {
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   142
        super.paintComponent(gfx)
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   143
        if (location != null && size != null)
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   144
          checkbox_geometry = Some((location, size))
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   145
      }
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   146
    }
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   147
66032
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   148
    var label_geometry: Option[(Point, Dimension)] = None
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   149
    val label = new Label {
56389
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
   150
      background = view.getTextArea.getPainter.getBackground
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
   151
      foreground = view.getTextArea.getPainter.getForeground
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   152
      opaque = false
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   153
      xAlignment = Alignment.Leading
52809
e750169a5884 paint unassigned/unchanged nodes as unprocessed -- relevant for editor_continuous_checking = false;
wenzelm
parents: 52807
diff changeset
   154
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   155
      override def paintComponent(gfx: Graphics2D)
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   156
      {
53178
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   157
        def paint_segment(x: Int, w: Int, color: Color)
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   158
        {
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   159
          gfx.setColor(color)
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   160
          gfx.fillRect(x, 0, w, size.height)
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   161
        }
50900
6d80709ab862 separate color ranges by 1px to improve discernment of overall theory status;
wenzelm
parents: 50895
diff changeset
   162
56389
e49561ae3b65 tuned rendering for 5 different look-and-feels;
wenzelm
parents: 56372
diff changeset
   163
        paint_segment(0, size.width, background)
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   164
        nodes_status.get(node_name) match {
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   165
          case Some(st) if st.total > 0 =>
53178
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   166
            val segments =
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   167
              List(
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   168
                (st.unprocessed, PIDE.options.color_value("unprocessed1_color")),
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   169
                (st.running, PIDE.options.color_value("running_color")),
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   170
                (st.warned, PIDE.options.color_value("warning_color")),
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   171
                (st.failed, PIDE.options.color_value("error_color"))
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   172
              ).filter(_._1 > 0)
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   173
66417
1f46b6693b56 tuned GUI;
wenzelm
parents: 66416
diff changeset
   174
            ((size.width - 2) /: segments)({ case (last, (n, color)) =>
1f46b6693b56 tuned GUI;
wenzelm
parents: 66416
diff changeset
   175
              val w = (n * ((size.width - 4) - segments.length) / st.total) max 4
53178
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   176
              paint_segment(last - w, w, color)
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   177
              last - w - 1
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   178
            })
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   179
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   180
          case _ =>
53178
0a3a5f606b2a more precise painting;
wenzelm
parents: 53177
diff changeset
   181
            paint_segment(0, size.width, PIDE.options.color_value("unprocessed1_color"))
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   182
        }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   183
        super.paintComponent(gfx)
66032
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   184
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   185
        if (location != null && size != null)
fd8a65b026f1 more tooltips;
wenzelm
parents: 65897
diff changeset
   186
          label_geometry = Some((location, size))
44866
0eb8284a64bd some color scheme for theory status;
wenzelm
parents: 44865
diff changeset
   187
      }
0eb8284a64bd some color scheme for theory status;
wenzelm
parents: 44865
diff changeset
   188
    }
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   189
66410
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   190
    def label_border(name: Document.Node.Name)
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   191
    {
66411
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   192
      val status = overall_node_status(name)
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   193
      val color =
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   194
        if (status == Overall_Node_Status.failed) PIDE.options.color_value("error_color")
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   195
        else label.foreground
66417
1f46b6693b56 tuned GUI;
wenzelm
parents: 66416
diff changeset
   196
      val thickness1 = if (status == Overall_Node_Status.pending) 1 else 2
1f46b6693b56 tuned GUI;
wenzelm
parents: 66416
diff changeset
   197
      val thickness2 = 3 - thickness1
66411
72de7d59e2f7 more explicit failure;
wenzelm
parents: 66410
diff changeset
   198
66410
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   199
      label.border =
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   200
        BorderFactory.createCompoundBorder(
66412
a8556be5be0b tuned GUI;
wenzelm
parents: 66411
diff changeset
   201
          BorderFactory.createLineBorder(color, thickness1),
a8556be5be0b tuned GUI;
wenzelm
parents: 66411
diff changeset
   202
          BorderFactory.createEmptyBorder(thickness2, thickness2, thickness2, thickness2))
66410
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   203
    }
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   204
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   205
    layout(checkbox) = BorderPanel.Position.West
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 52809
diff changeset
   206
    layout(label) = BorderPanel.Position.Center
44866
0eb8284a64bd some color scheme for theory status;
wenzelm
parents: 44865
diff changeset
   207
  }
0eb8284a64bd some color scheme for theory status;
wenzelm
parents: 44865
diff changeset
   208
44990
wenzelm
parents: 44989
diff changeset
   209
  private class Node_Renderer extends ListView.Renderer[Document.Node.Name]
44957
098dd95349e7 more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents: 44867
diff changeset
   210
  {
66191
d91108ba9474 back to scala-2.12.2, after a41435469559;
wenzelm
parents: 66082
diff changeset
   211
    def componentFor(list: ListView[_ <: isabelle.Document.Node.Name], isSelected: Boolean,
64442
85adb337e32f updated to scala-2.12.0;
wenzelm
parents: 62973
diff changeset
   212
      focused: Boolean, name: Document.Node.Name, index: Int): Component =
44957
098dd95349e7 more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents: 44867
diff changeset
   213
    {
44990
wenzelm
parents: 44989
diff changeset
   214
      val component = Node_Renderer_Component
44957
098dd95349e7 more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents: 44867
diff changeset
   215
      component.node_name = name
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   216
      component.checkbox.selected = nodes_required.contains(name)
66410
72a7e29104f1 explicit indication of consolidated nodes;
wenzelm
parents: 66206
diff changeset
   217
      component.label_border(name)
65493
4729318d3fc3 tuned GUI;
wenzelm
parents: 65361
diff changeset
   218
      component.label.text = name.theory_base_name
44990
wenzelm
parents: 44989
diff changeset
   219
      component
44957
098dd95349e7 more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents: 44867
diff changeset
   220
    }
098dd95349e7 more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents: 44867
diff changeset
   221
  }
098dd95349e7 more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents: 44867
diff changeset
   222
  status.renderer = new Node_Renderer
44609
6ec4a5eb2fc0 some support for theory status overview;
wenzelm
parents: 44335
diff changeset
   223
45011
436ea69d5d37 more careful treatment of initial update, similar to output panel;
wenzelm
parents: 44991
diff changeset
   224
  private def handle_update(restriction: Option[Set[Document.Node.Name]] = None)
44609
6ec4a5eb2fc0 some support for theory status overview;
wenzelm
parents: 44335
diff changeset
   225
  {
62052
8bcbf1c93119 node_status update is back on GUI thread (reverting 3ad2b2055ffc) -- avoid potential deadlock of GUI_Thread.now during shutdown, when GUI thread is already terminated;
wenzelm
parents: 61716
diff changeset
   226
    GUI_Thread.require {}
53177
dcac8d837b9c more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents: 53176
diff changeset
   227
62052
8bcbf1c93119 node_status update is back on GUI thread (reverting 3ad2b2055ffc) -- avoid potential deadlock of GUI_Thread.now during shutdown, when GUI thread is already terminated;
wenzelm
parents: 61716
diff changeset
   228
    val snapshot = PIDE.session.snapshot()
57619
dcd69422b953 clarified display;
wenzelm
parents: 57617
diff changeset
   229
    val nodes = snapshot.version.nodes
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44609
diff changeset
   230
53177
dcac8d837b9c more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents: 53176
diff changeset
   231
    val nodes_status1 =
68321
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   232
      (nodes_status /: (restriction.getOrElse(nodes.domain).iterator))(
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   233
        { case (status, name) =>
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   234
            if (PIDE.resources.is_hidden(name) ||
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   235
                PIDE.resources.session_base.loaded_theory(name) ||
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   236
                nodes(name).is_empty) status
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   237
            else {
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   238
              val st = Protocol.node_status(snapshot.state, snapshot.version, name)
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   239
              status + (name -> st)
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   240
            }
daca5f2a0c90 tuned signature;
wenzelm
parents: 68299
diff changeset
   241
        })
44672
07dad1433cd7 some support to prune_history;
wenzelm
parents: 44641
diff changeset
   242
57619
dcd69422b953 clarified display;
wenzelm
parents: 57617
diff changeset
   243
    val nodes_status2 =
68299
0b5a23477911 clarified signature -- avoid confusion with Resources.is_hidden;
wenzelm
parents: 67287
diff changeset
   244
      nodes_status1 -- nodes_status1.keysIterator.filter(nodes.is_suppressed(_))
57619
dcd69422b953 clarified display;
wenzelm
parents: 57617
diff changeset
   245
62052
8bcbf1c93119 node_status update is back on GUI thread (reverting 3ad2b2055ffc) -- avoid potential deadlock of GUI_Thread.now during shutdown, when GUI thread is already terminated;
wenzelm
parents: 61716
diff changeset
   246
    if (nodes_status != nodes_status2) {
8bcbf1c93119 node_status update is back on GUI thread (reverting 3ad2b2055ffc) -- avoid potential deadlock of GUI_Thread.now during shutdown, when GUI thread is already terminated;
wenzelm
parents: 61716
diff changeset
   247
      nodes_status = nodes_status2
8bcbf1c93119 node_status update is back on GUI thread (reverting 3ad2b2055ffc) -- avoid potential deadlock of GUI_Thread.now during shutdown, when GUI thread is already terminated;
wenzelm
parents: 61716
diff changeset
   248
      status.listData = nodes.topological_order.filter(nodes_status.isDefinedAt(_))
8bcbf1c93119 node_status update is back on GUI thread (reverting 3ad2b2055ffc) -- avoid potential deadlock of GUI_Thread.now during shutdown, when GUI thread is already terminated;
wenzelm
parents: 61716
diff changeset
   249
    }
44609
6ec4a5eb2fc0 some support for theory status overview;
wenzelm
parents: 44335
diff changeset
   250
  }
6ec4a5eb2fc0 some support for theory status overview;
wenzelm
parents: 44335
diff changeset
   251
6ec4a5eb2fc0 some support for theory status overview;
wenzelm
parents: 44335
diff changeset
   252
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   253
  /* main */
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
   254
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   255
  private val main =
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   256
    Session.Consumer[Any](getClass.getName) {
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   257
      case phase: Session.Phase =>
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 56715
diff changeset
   258
        GUI_Thread.later { handle_phase(phase) }
39635
5cd8545a070b added Session_Dockable.session_phase label;
wenzelm
parents: 39629
diff changeset
   259
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   260
      case _: Session.Global_Options =>
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 56715
diff changeset
   261
        GUI_Thread.later {
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   262
          continuous_checking.load()
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   263
          logic.load ()
64817
0bb6b582bb4f separate Buffer_Model vs. File_Model;
wenzelm
parents: 64813
diff changeset
   264
          nodes_required = Document_Model.required_nodes()
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   265
          status.repaint()
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   266
        }
49247
ffd9ad9dc35b more detailed option tooltip;
wenzelm
parents: 49246
diff changeset
   267
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   268
      case changed: Session.Commands_Changed =>
62052
8bcbf1c93119 node_status update is back on GUI thread (reverting 3ad2b2055ffc) -- avoid potential deadlock of GUI_Thread.now during shutdown, when GUI thread is already terminated;
wenzelm
parents: 61716
diff changeset
   269
        GUI_Thread.later { handle_update(Some(changed.nodes)) }
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
   270
    }
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
   271
48018
b941dd7df92a make double sure that GUI components are up-to-date after init;
wenzelm
parents: 48014
diff changeset
   272
  override def init()
b941dd7df92a make double sure that GUI components are up-to-date after init;
wenzelm
parents: 48014
diff changeset
   273
  {
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   274
    PIDE.session.phase_changed += main
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   275
    PIDE.session.global_options += main
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   276
    PIDE.session.commands_changed += main
53177
dcac8d837b9c more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents: 53176
diff changeset
   277
dcac8d837b9c more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents: 53176
diff changeset
   278
    handle_phase(PIDE.session.phase)
dcac8d837b9c more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents: 53176
diff changeset
   279
    handle_update()
39635
5cd8545a070b added Session_Dockable.session_phase label;
wenzelm
parents: 39629
diff changeset
   280
  }
5cd8545a070b added Session_Dockable.session_phase label;
wenzelm
parents: 39629
diff changeset
   281
48018
b941dd7df92a make double sure that GUI components are up-to-date after init;
wenzelm
parents: 48014
diff changeset
   282
  override def exit()
b941dd7df92a make double sure that GUI components are up-to-date after init;
wenzelm
parents: 48014
diff changeset
   283
  {
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   284
    PIDE.session.phase_changed -= main
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   285
    PIDE.session.global_options -= main
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   286
    PIDE.session.commands_changed -= main
39635
5cd8545a070b added Session_Dockable.session_phase label;
wenzelm
parents: 39629
diff changeset
   287
  }
39515
57ceabb0bb8e basic setup for prover session panel;
wenzelm
parents:
diff changeset
   288
}