src/Tools/jEdit/src/info_dockable.scala
author wenzelm
Thu, 08 Dec 2022 22:38:03 +0100
changeset 76610 6e2383488a55
parent 75839 29441f2bfe81
child 81379 cbfc76aace10
permissions -rw-r--r--
clarified signature: proper scopes and types;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/info_dockable.scala
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
     3
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
     4
Dockable window with info text.
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
     5
*/
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
     6
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
     8
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
     9
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    10
import isabelle._
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    11
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    12
import java.awt.BorderLayout
49870
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    13
import java.awt.event.{ComponentEvent, ComponentAdapter, WindowFocusListener, WindowEvent}
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    14
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    15
import org.gjt.sp.jedit.View
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    16
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    17
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    18
object Info_Dockable {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57044
diff changeset
    19
  /* implicit arguments -- owned by GUI thread */
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    20
52972
8fd8e1c14988 tuned signature;
wenzelm
parents: 52907
diff changeset
    21
  private var implicit_snapshot = Document.Snapshot.init
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    22
  private var implicit_results = Command.Results.empty
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    23
  private var implicit_info: XML.Body = Nil
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    24
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
    25
  private def set_implicit(
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    26
    snapshot: Document.Snapshot,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    27
    results: Command.Results,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    28
    info: XML.Body
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    29
  ): Unit = {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57044
diff changeset
    30
    GUI_Thread.require {}
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    31
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    32
    implicit_snapshot = snapshot
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50451
diff changeset
    33
    implicit_results = results
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    34
    implicit_info = info
49870
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    35
  }
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    36
50451
wenzelm
parents: 50207
diff changeset
    37
  private def reset_implicit(): Unit =
52972
8fd8e1c14988 tuned signature;
wenzelm
parents: 52907
diff changeset
    38
    set_implicit(Document.Snapshot.init, Command.Results.empty, Nil)
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    39
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
    40
  def apply(
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    41
    view: View,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    42
    snapshot: Document.Snapshot,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    43
    results: Command.Results,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    44
    info: XML.Body
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    45
  ): Unit = {
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50451
diff changeset
    46
    set_implicit(snapshot, results, info)
49870
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    47
    view.getDockableWindowManager.floatDockableWindow("isabelle-info")
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    48
  }
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    49
}
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    50
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    51
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    52
class Info_Dockable(view: View, position: String) extends Dockable(view, position) {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57044
diff changeset
    53
  /* component state -- owned by GUI thread */
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    54
49870
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    55
  private val snapshot = Info_Dockable.implicit_snapshot
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50451
diff changeset
    56
  private val results = Info_Dockable.implicit_results
49870
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    57
  private val info = Info_Dockable.implicit_info
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    58
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    59
  private val window_focus_listener =
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    60
    new WindowFocusListener {
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
    61
      def windowGainedFocus(e: WindowEvent): Unit =
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
    62
        Info_Dockable.set_implicit(snapshot, results, info)
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
    63
      def windowLostFocus(e: WindowEvent): Unit =
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
    64
        Info_Dockable.reset_implicit()
49870
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    65
    }
2b82358694e6 retain info dockable state via educated guess on window focus;
wenzelm
parents: 49726
diff changeset
    66
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    67
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    68
  /* pretty text area */
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    69
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    70
  private val pretty_text_area = new Pretty_Text_Area(view)
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    71
  set_content(pretty_text_area)
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    72
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50451
diff changeset
    73
  pretty_text_area.update(snapshot, results, info)
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    74
75839
29441f2bfe81 clarified signature: more explicit types;
wenzelm
parents: 75813
diff changeset
    75
  private val zoom = new Font_Info.Zoom { override def changed(): Unit = handle_resize() }
57044
042d6e58cb40 more uniform Font_Info.Zoom_Box;
wenzelm
parents: 57042
diff changeset
    76
75812
d6e8d12494be clarified signature;
wenzelm
parents: 75810
diff changeset
    77
  private def handle_resize(): Unit =
75839
29441f2bfe81 clarified signature: more explicit types;
wenzelm
parents: 75813
diff changeset
    78
    GUI_Thread.require { pretty_text_area.zoom(zoom) }
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    79
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    80
50451
wenzelm
parents: 50207
diff changeset
    81
  /* resize */
wenzelm
parents: 50207
diff changeset
    82
wenzelm
parents: 50207
diff changeset
    83
  private val delay_resize =
76610
6e2383488a55 clarified signature: proper scopes and types;
wenzelm
parents: 75839
diff changeset
    84
    Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() }
50451
wenzelm
parents: 50207
diff changeset
    85
wenzelm
parents: 50207
diff changeset
    86
  addComponentListener(new ComponentAdapter {
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
    87
    override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke()
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 71704
diff changeset
    88
    override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke()
50451
wenzelm
parents: 50207
diff changeset
    89
  })
wenzelm
parents: 50207
diff changeset
    90
66205
e9fa94f43a15 tuned signature;
wenzelm
parents: 64865
diff changeset
    91
  private val controls =
66206
2d2082db735a clarified defaults;
wenzelm
parents: 66205
diff changeset
    92
    Wrap_Panel(List(pretty_text_area.search_label, pretty_text_area.search_field, zoom))
66205
e9fa94f43a15 tuned signature;
wenzelm
parents: 64865
diff changeset
    93
50451
wenzelm
parents: 50207
diff changeset
    94
  add(controls.peer, BorderLayout.NORTH)
wenzelm
parents: 50207
diff changeset
    95
wenzelm
parents: 50207
diff changeset
    96
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
    97
  /* main */
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
    98
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
    99
  private val main =
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   100
    Session.Consumer[Session.Global_Options](getClass.getName) {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57044
diff changeset
   101
      case _: Session.Global_Options => GUI_Thread.later { handle_resize() }
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
   102
    }
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
   103
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   104
  override def init(): Unit = {
75813
wenzelm
parents: 75812
diff changeset
   105
    GUI.parent_window(this).foreach(_.addWindowFocusListener(window_focus_listener))
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   106
    PIDE.session.global_options += main
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
   107
    handle_resize()
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
   108
  }
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
   109
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   110
  override def exit(): Unit = {
75813
wenzelm
parents: 75812
diff changeset
   111
    GUI.parent_window(this).foreach(_.removeWindowFocusListener(window_focus_listener))
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   112
    PIDE.session.global_options -= main
49726
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
   113
    delay_resize.revoke()
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
   114
  }
2074197dc274 detach tooltip as dockable window;
wenzelm
parents:
diff changeset
   115
}