src/Tools/jEdit/src/simplifier_trace_window.scala
author wenzelm
Thu, 07 Nov 2024 13:22:59 +0100
changeset 81387 c677755779f5
parent 81386 bcd880130390
child 81391 365b9aac4363
permissions -rw-r--r--
more uniform pretty_text_area.zoom via its zoom_component;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/simplifier_trace_window.scala
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
     2
    Author:     Lars Hupel
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
     3
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
     4
Trace window with tree-style view of the simplifier trace.
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
     5
*/
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
     6
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
     7
package isabelle.jedit
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
     8
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
     9
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    10
import isabelle._
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    11
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    12
import scala.annotation.tailrec
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    13
import scala.collection.immutable.SortedMap
75852
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
    14
import scala.swing.{BorderPanel, Component, Dimension, Frame, Label, TextField}
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    15
import scala.swing.event.{Key, KeyPressed}
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    16
import scala.util.matching.Regex
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    17
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    18
import java.awt.BorderLayout
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    19
import java.awt.event.{ComponentEvent, ComponentAdapter}
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    20
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    21
import javax.swing.SwingUtilities
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    22
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    23
import org.gjt.sp.jedit.View
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    24
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55316
diff changeset
    25
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
    26
private object Simplifier_Trace_Window {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
    27
  sealed trait Trace_Tree {
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    28
    // FIXME replace with immutable tree builder
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    29
    var children: SortedMap[Long, Either[Simplifier_Trace.Item.Data, Elem_Tree]] = SortedMap.empty
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    30
    val serial: Long
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    31
    val parent: Option[Trace_Tree]
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    32
    val markup: String
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    33
    def interesting: Boolean
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    34
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    35
    def tree_children: List[Elem_Tree] = children.values.toList.collect {
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    36
      case Right(tree) => tree
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    37
    }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    38
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    39
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
    40
  final class Root_Tree(val serial: Long) extends Trace_Tree {
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    41
    val parent = None
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    42
    val interesting = true
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    43
    val markup = ""
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    44
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    45
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55316
diff changeset
    46
  final class Elem_Tree(data: Simplifier_Trace.Item.Data, val parent: Option[Trace_Tree])
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
    47
  extends Trace_Tree {
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    48
    val serial = data.serial
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    49
    val markup = data.markup
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    50
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    51
    lazy val interesting: Boolean =
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    52
      data.markup == Markup.SIMP_TRACE_STEP ||
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    53
      data.markup == Markup.SIMP_TRACE_LOG ||
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    54
      tree_children.exists(_.interesting)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    55
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    56
    private def body_contains(regex: Regex, body: XML.Body): Boolean =
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    57
      body.exists(tree => regex.findFirstIn(XML.content(tree)).isDefined)
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    58
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
    59
    def format: Option[XML.Tree] = {
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55316
diff changeset
    60
      def format_hint(data: Simplifier_Trace.Item.Data): XML.Tree =
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    61
        Pretty.block(Pretty.separate(XML.Text(data.text) :: data.content))
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    62
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    63
      lazy val bodies: XML.Body =
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    64
        children.values.toList.collect {
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    65
          case Left(data) => Some(format_hint(data))
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    66
          case Right(tree) if tree.interesting => tree.format
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    67
        }.flatten.map(item =>
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    68
          XML.Elem(Markup(Markup.ITEM, Nil), List(item))
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    69
        )
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    70
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    71
      val all = XML.Text(data.text) :: data.content ::: bodies
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    72
      val res = XML.Elem(Markup(Markup.TEXT_FOLD, Nil), List(Pretty.block(Pretty.separate(all))))
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    73
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    74
      if (bodies != Nil)
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    75
        Some(res)
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    76
      else
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    77
        None
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    78
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    79
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    80
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    81
  @tailrec
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55316
diff changeset
    82
  def walk_trace(rest: List[Simplifier_Trace.Item.Data], lookup: Map[Long, Trace_Tree]): Unit =
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    83
    rest match {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    84
      case Nil =>
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    85
        ()
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    86
      case head :: tail =>
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    87
        lookup.get(head.parent) match {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    88
          case Some(parent) =>
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
    89
            if (head.markup == Markup.SIMP_TRACE_HINT) {
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    90
              head.props match {
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    91
                case Simplifier_Trace.Success(x)
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    92
                  if x ||
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    93
                     parent.markup == Markup.SIMP_TRACE_LOG ||
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    94
                     parent.markup == Markup.SIMP_TRACE_STEP =>
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    95
                  parent.children += ((head.serial, Left(head)))
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    96
                case _ =>
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    97
                  // ignore
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
    98
              }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
    99
              walk_trace(tail, lookup)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   100
            }
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
   101
            else if (head.markup == Markup.SIMP_TRACE_IGNORE) {
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   102
              parent.parent match {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   103
                case None =>
57043
0f44d6dbd2a4 added zoom box, like for outer output windows;
wenzelm
parents: 57042
diff changeset
   104
                  Output.error_message(
0f44d6dbd2a4 added zoom box, like for outer output windows;
wenzelm
parents: 57042
diff changeset
   105
                    "Simplifier_Trace_Window: malformed ignore message with parent " + head.parent)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   106
                case Some(tree) =>
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   107
                  tree.children -= head.parent
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
   108
                  walk_trace(tail, lookup)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   109
              }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   110
            }
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
   111
            else {
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   112
              val entry = new Elem_Tree(head, Some(parent))
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
   113
              parent.children += ((head.serial, Right(entry)))
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   114
              walk_trace(tail, lookup + (head.serial -> entry))
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   115
            }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   116
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   117
          case None =>
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56770
diff changeset
   118
            Output.error_message("Simplifier_Trace_Window: unknown parent " + head.parent)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   119
        }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   120
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   121
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   122
}
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   123
55556
60ba93d8f9e5 tuned imports;
wenzelm
parents: 55553
diff changeset
   124
60ba93d8f9e5 tuned imports;
wenzelm
parents: 55553
diff changeset
   125
class Simplifier_Trace_Window(
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
   126
  view: View,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
   127
  snapshot: Document.Snapshot,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
   128
  trace: Simplifier_Trace.Trace
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
   129
) extends Frame {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57044
diff changeset
   130
  GUI_Thread.require {}
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   131
57044
042d6e58cb40 more uniform Font_Info.Zoom_Box;
wenzelm
parents: 57043
diff changeset
   132
  private val pretty_text_area = new Pretty_Text_Area(view)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   133
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   134
  size = new Dimension(500, 500)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   135
  contents = new BorderPanel {
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
   136
    layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   137
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   138
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   139
  private val tree = trace.entries.headOption match {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   140
    case Some(first) =>
55556
60ba93d8f9e5 tuned imports;
wenzelm
parents: 55553
diff changeset
   141
      val tree = new Simplifier_Trace_Window.Root_Tree(first.parent)
60ba93d8f9e5 tuned imports;
wenzelm
parents: 55553
diff changeset
   142
      Simplifier_Trace_Window.walk_trace(trace.entries, Map(first.parent -> tree))
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   143
      tree
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   144
    case None =>
55556
60ba93d8f9e5 tuned imports;
wenzelm
parents: 55553
diff changeset
   145
      new Simplifier_Trace_Window.Root_Tree(0)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   146
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   147
81385
072ce947ee50 tuned signature: more standard names;
wenzelm
parents: 81379
diff changeset
   148
  handle_update()
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   149
  open()
81385
072ce947ee50 tuned signature: more standard names;
wenzelm
parents: 81379
diff changeset
   150
  handle_resize()
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   151
81385
072ce947ee50 tuned signature: more standard names;
wenzelm
parents: 81379
diff changeset
   152
  def handle_update(): Unit = {
81386
bcd880130390 tuned signature;
wenzelm
parents: 81385
diff changeset
   153
    val xml = Pretty.separate(tree.tree_children.flatMap(_.format))
57004
c8288ce9676a trace windows uses search feature of Pretty_Text_Area;
Lars Hupel <lars.hupel@mytum.de>
parents: 56782
diff changeset
   154
    pretty_text_area.update(snapshot, Command.Results.empty, xml)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   155
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   156
81387
c677755779f5 more uniform pretty_text_area.zoom via its zoom_component;
wenzelm
parents: 81386
diff changeset
   157
  def handle_resize(): Unit = pretty_text_area.zoom()
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   158
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   159
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   160
  /* resize */
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   161
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   162
  private val delay_resize =
76610
6e2383488a55 clarified signature: proper scopes and types;
wenzelm
parents: 75852
diff changeset
   163
    Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   164
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   165
  peer.addComponentListener(new ComponentAdapter {
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
   166
    override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke()
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
   167
    override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke()
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   168
  })
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   169
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   170
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   171
  /* controls */
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   172
81387
c677755779f5 more uniform pretty_text_area.zoom via its zoom_component;
wenzelm
parents: 81386
diff changeset
   173
  private val controls = Wrap_Panel(pretty_text_area.search_zoom_components)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   174
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   175
  peer.add(controls.peer, BorderLayout.NORTH)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents:
diff changeset
   176
}