src/Tools/jEdit/src/document_view.scala
author wenzelm
Tue, 21 Feb 2012 15:36:23 +0100
changeset 46571 edcccd7a9eee
parent 46550 0133d31f9ab4
child 46572 3074685ab7ed
permissions -rw-r--r--
overview.delay_repaint: avoid wasting GUI cycles via update_delay; prefer delay_first for prover initiated events -- avoid indefinite delay;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43282
5d294220ca43 moved sources -- eliminated Netbeans artifact of jedit package directory;
wenzelm
parents: 42839
diff changeset
     1
/*  Title:      Tools/jEdit/src/document_view.scala
36760
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     2
    Author:     Fabian Immler, TU Munich
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     3
    Author:     Makarius
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     4
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     5
Document view connected to jEdit text area.
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     6
*/
34408
ad7b6c4813c8 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     7
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
     8
package isabelle.jedit
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
     9
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
    10
36015
6111de7c916a adapted to Scala 2.8.0 Beta 1;
wenzelm
parents: 34871
diff changeset
    11
import isabelle._
6111de7c916a adapted to Scala 2.8.0 Beta 1;
wenzelm
parents: 34871
diff changeset
    12
46549
1bffe63879af more careful painting of overview component: more precise and more efficient;
wenzelm
parents: 46229
diff changeset
    13
import scala.annotation.tailrec
44379
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
    14
import scala.collection.mutable
45460
dcd02d1a25d7 more tooltip content;
wenzelm
parents: 44805
diff changeset
    15
import scala.collection.immutable.SortedMap
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    16
import scala.actors.Actor._
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    17
43520
cec9b95fa35d explicit import java.lang.System to prevent odd scope problems;
wenzelm
parents: 43510
diff changeset
    18
import java.lang.System
45744
0ad063afa3d6 caret_range based on BreakIterator, which handles combined unicode characters as well;
wenzelm
parents: 45665
diff changeset
    19
import java.text.BreakIterator
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
    20
import java.awt.{BorderLayout, Graphics, Color, Dimension, Graphics2D, Point}
39741
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
    21
import java.awt.event.{MouseAdapter, MouseMotionAdapter, MouseEvent,
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
    22
  FocusAdapter, FocusEvent, WindowEvent, WindowAdapter}
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
    23
import javax.swing.{JPanel, ToolTipManager, Popup, PopupFactory, SwingUtilities, BorderFactory}
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    24
import javax.swing.event.{CaretListener, CaretEvent}
34734
wenzelm
parents: 34733
diff changeset
    25
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
    26
import org.gjt.sp.util.Log
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
    27
42839
19df8385f38d basic support for overpainting of text, imitating jEdit internals;
wenzelm
parents: 42838
diff changeset
    28
import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug}
34709
2f0c18f9b6c7 minor tuning;
wenzelm
parents: 34679
diff changeset
    29
import org.gjt.sp.jedit.gui.RolloverButton
39176
b8fdd3ae8815 Document_View: more precise painting of gutter icons, only if line selection area is sufficiently large;
wenzelm
parents: 39175
diff changeset
    30
import org.gjt.sp.jedit.options.GutterOptionPane
44436
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44379
diff changeset
    31
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter,
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44379
diff changeset
    32
  ScrollListener}
43369
4c86b3405010 separate isabelle.jedit.Text_Painter, which actually replaces the original TextAreaPainter$PaintText instance;
wenzelm
parents: 43282
diff changeset
    33
import org.gjt.sp.jedit.syntax.{SyntaxStyle}
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    34
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    35
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    36
object Document_View
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    37
{
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    38
  /* document view of text area */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    39
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    40
  private val key = new Object
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    41
39741
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
    42
  def apply(text_area: JEditTextArea): Option[Document_View] =
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    43
  {
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
    44
    Swing_Thread.require()
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    45
    text_area.getClientProperty(key) match {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    46
      case doc_view: Document_View => Some(doc_view)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    47
      case _ => None
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    48
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    49
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    50
39741
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
    51
  def exit(text_area: JEditTextArea)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    52
  {
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
    53
    Swing_Thread.require()
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34784
diff changeset
    54
    apply(text_area) match {
39636
610dc743932c permissive exit;
wenzelm
parents: 39182
diff changeset
    55
      case None =>
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    56
      case Some(doc_view) =>
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    57
        doc_view.deactivate()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    58
        text_area.putClientProperty(key, null)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    59
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    60
  }
43397
dba359c0ae3b more robust init;
wenzelm
parents: 43393
diff changeset
    61
dba359c0ae3b more robust init;
wenzelm
parents: 43393
diff changeset
    62
  def init(model: Document_Model, text_area: JEditTextArea): Document_View =
dba359c0ae3b more robust init;
wenzelm
parents: 43393
diff changeset
    63
  {
dba359c0ae3b more robust init;
wenzelm
parents: 43393
diff changeset
    64
    exit(text_area)
dba359c0ae3b more robust init;
wenzelm
parents: 43393
diff changeset
    65
    val doc_view = new Document_View(model, text_area)
dba359c0ae3b more robust init;
wenzelm
parents: 43393
diff changeset
    66
    text_area.putClientProperty(key, doc_view)
dba359c0ae3b more robust init;
wenzelm
parents: 43393
diff changeset
    67
    doc_view.activate()
dba359c0ae3b more robust init;
wenzelm
parents: 43393
diff changeset
    68
    doc_view
dba359c0ae3b more robust init;
wenzelm
parents: 43393
diff changeset
    69
  }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    70
}
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
    71
34733
a3ad6d51db1d misc tuning and unification;
wenzelm
parents: 34711
diff changeset
    72
43376
0f6880c1c759 some direct text foreground painting, instead of token marking;
wenzelm
parents: 43369
diff changeset
    73
class Document_View(val model: Document_Model, val text_area: JEditTextArea)
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
    74
{
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    75
  private val session = model.session
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    76
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
    77
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
    78
  /* robust extension body */
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
    79
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
    80
  def robust_body[A](default: A)(body: => A): A =
43417
83be997a11d6 more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents: 43414
diff changeset
    81
  {
83be997a11d6 more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents: 43414
diff changeset
    82
    try {
83be997a11d6 more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents: 43414
diff changeset
    83
      Swing_Thread.require()
83be997a11d6 more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents: 43414
diff changeset
    84
      if (model.buffer == text_area.getBuffer) body
83be997a11d6 more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents: 43414
diff changeset
    85
      else {
43650
f00da558b78e imitate exception ERROR of Isabelle/ML;
wenzelm
parents: 43520
diff changeset
    86
        Log.log(Log.ERROR, this, ERROR("Inconsistent document model"))
43417
83be997a11d6 more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents: 43414
diff changeset
    87
        default
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
    88
      }
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
    89
    }
43417
83be997a11d6 more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents: 43414
diff changeset
    90
    catch { case t: Throwable => Log.log(Log.ERROR, this, t); default }
83be997a11d6 more precise imitation of original TextAreaPainter: no locking;
wenzelm
parents: 43414
diff changeset
    91
  }
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
    92
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
    93
44378
81b4af4cfa5a tuned signature;
wenzelm
parents: 43661
diff changeset
    94
  /* visible text range */
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
    95
38883
0998a635684a refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents: 38881
diff changeset
    96
  // simplify slightly odd result of TextArea.getScreenLineEndOffset etc.
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
    97
  // NB: jEdit already normalizes \r\n and \r to \n
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
    98
  def proper_line_range(start: Text.Offset, end: Text.Offset): Text.Range =
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
    99
  {
38883
0998a635684a refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents: 38881
diff changeset
   100
    val stop = if (start < end) end - 1 else end min model.buffer.getLength
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   101
    Text.Range(start, stop)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   102
  }
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   103
44378
81b4af4cfa5a tuned signature;
wenzelm
parents: 43661
diff changeset
   104
  def visible_range(): Text.Range =
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   105
  {
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   106
    val start = text_area.getScreenLineStartOffset(0)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   107
    val raw_end = text_area.getScreenLineEndOffset(text_area.getVisibleLines - 1 max 0)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   108
    proper_line_range(start, if (raw_end >= 0) raw_end else model.buffer.getLength)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   109
  }
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   110
44378
81b4af4cfa5a tuned signature;
wenzelm
parents: 43661
diff changeset
   111
  def invalidate_range(range: Text.Range)
39132
ba17ca3acdd3 refined treatment of multi-line subexpressions;
wenzelm
parents: 39131
diff changeset
   112
  {
ba17ca3acdd3 refined treatment of multi-line subexpressions;
wenzelm
parents: 39131
diff changeset
   113
    text_area.invalidateLineRange(
ba17ca3acdd3 refined treatment of multi-line subexpressions;
wenzelm
parents: 39131
diff changeset
   114
      model.buffer.getLineOfOffset(range.start),
ba17ca3acdd3 refined treatment of multi-line subexpressions;
wenzelm
parents: 39131
diff changeset
   115
      model.buffer.getLineOfOffset(range.stop))
ba17ca3acdd3 refined treatment of multi-line subexpressions;
wenzelm
parents: 39131
diff changeset
   116
  }
ba17ca3acdd3 refined treatment of multi-line subexpressions;
wenzelm
parents: 39131
diff changeset
   117
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   118
44379
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   119
  /* perspective */
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   120
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   121
  def perspective(): Text.Perspective =
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   122
  {
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   123
    Swing_Thread.require()
44776
47e8c8daccae added "check" button: adhoc change to full buffer perspective;
wenzelm
parents: 44615
diff changeset
   124
    val buffer_range = model.buffer_range()
44473
4f264fdf8d0e slightly more abstract Text.Perspective;
wenzelm
parents: 44437
diff changeset
   125
    Text.Perspective(
44379
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   126
      for {
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   127
        i <- 0 until text_area.getVisibleLines
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   128
        val start = text_area.getScreenLineStartOffset(i)
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   129
        val stop = text_area.getScreenLineEndOffset(i)
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   130
        if start >= 0 && stop >= 0
44583
022509c908fb restrict perspective to actual buffer_range, to avoid spurious edits due to faulty last_exec_offset (NB: jEdit screenlines may be silently extended by trailing newline);
wenzelm
parents: 44473
diff changeset
   131
        val range <- buffer_range.try_restrict(Text.Range(start, stop))
022509c908fb restrict perspective to actual buffer_range, to avoid spurious edits due to faulty last_exec_offset (NB: jEdit screenlines may be silently extended by trailing newline);
wenzelm
parents: 44473
diff changeset
   132
        if !range.is_singularity
44379
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   133
      }
44583
022509c908fb restrict perspective to actual buffer_range, to avoid spurious edits due to faulty last_exec_offset (NB: jEdit screenlines may be silently extended by trailing newline);
wenzelm
parents: 44473
diff changeset
   134
      yield range)
44379
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   135
  }
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   136
44437
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   137
  private def update_perspective = new TextAreaExtension
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   138
  {
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   139
    override def paintScreenLineRange(gfx: Graphics2D,
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   140
      first_line: Int, last_line: Int, physical_lines: Array[Int],
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   141
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   142
    {
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   143
      model.update_perspective()
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   144
    }
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   145
  }
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   146
44379
1079ab6b342b added official Text.Range.Ordering;
wenzelm
parents: 44378
diff changeset
   147
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   148
  /* snapshot */
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   149
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   150
  // owned by Swing thread
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   151
  @volatile private var was_outdated = false
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   152
  @volatile private var was_updated = false
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   153
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   154
  def update_snapshot(): Document.Snapshot =
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   155
  {
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   156
    Swing_Thread.require()
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   157
    val snapshot = model.snapshot()
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   158
    was_updated = was_outdated && !snapshot.is_outdated
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   159
    was_outdated = was_outdated || snapshot.is_outdated
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   160
    snapshot
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   161
  }
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   162
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   163
  def flush_snapshot(): (Boolean, Document.Snapshot) =
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   164
  {
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   165
    Swing_Thread.require()
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   166
    val snapshot = update_snapshot()
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   167
    val updated = was_updated
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   168
    if (updated) { was_outdated = false; was_updated = false }
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   169
    (updated, snapshot)
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   170
  }
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   171
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   172
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   173
  /* HTML popups */
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   174
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   175
  private var html_popup: Option[Popup] = None
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   176
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   177
  private def exit_popup() { html_popup.map(_.hide) }
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   178
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   179
  private val html_panel =
43661
39fdbd814c7f quasi-static Isabelle_System -- reduced tendency towards "functorial style";
wenzelm
parents: 43650
diff changeset
   180
    new HTML_Panel(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
39741
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
   181
  html_panel.setBorder(BorderFactory.createLineBorder(Color.black))
38884
9ec5f6010d6e Document_View: repaint overview for any command change of this node (again);
wenzelm
parents: 38883
diff changeset
   182
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   183
  private def html_panel_resize()
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   184
  {
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   185
    Swing_Thread.now {
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   186
      html_panel.resize(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   187
    }
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   188
  }
38884
9ec5f6010d6e Document_View: repaint overview for any command change of this node (again);
wenzelm
parents: 38883
diff changeset
   189
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   190
  private def init_popup(snapshot: Document.Snapshot, x: Int, y: Int)
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   191
  {
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   192
    exit_popup()
40154
e11da4ec9d74 disable broken popups for now;
wenzelm
parents: 39742
diff changeset
   193
/* FIXME broken
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   194
    val offset = text_area.xyToOffset(x, y)
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   195
    val p = new Point(x, y); SwingUtilities.convertPointToScreen(p, text_area.getPainter)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   196
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   197
    // FIXME snapshot.cumulate
45665
129db1416717 renamed Isabelle_Markup to Isabelle_Rendering to emphasize its meaning and make room for Pure Isabelle_Markup module;
wenzelm
parents: 45467
diff changeset
   198
    snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Rendering.popup) match {
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   199
      case Text.Info(_, Some(msg)) #:: _ =>
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   200
        val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60)
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   201
        html_panel.render_sync(List(msg))
39742
b59e064e32c3 CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents: 39741
diff changeset
   202
        Thread.sleep(10)  // FIXME !?
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   203
        popup.show
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   204
        html_popup = Some(popup)
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   205
      case _ =>
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   206
    }
40154
e11da4ec9d74 disable broken popups for now;
wenzelm
parents: 39742
diff changeset
   207
*/
34678
acaac03ced00 tuned whitespace
immler@in.tum.de
parents: 34654
diff changeset
   208
  }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   209
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   210
39131
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   211
  /* subexpression highlighting */
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   212
46205
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   213
  @volatile private var _highlight_range: Option[Text.Info[Color]] = None
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   214
  def highlight_range(): Option[Text.Info[Color]] = _highlight_range
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   215
40338
e2f03de2b3c7 clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents: 40154
diff changeset
   216
  private var control: Boolean = false
e2f03de2b3c7 clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents: 40154
diff changeset
   217
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   218
  private def exit_control()
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   219
  {
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   220
    exit_popup()
43381
806878ae2219 separate module for text area painting;
wenzelm
parents: 43376
diff changeset
   221
    _highlight_range = None
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   222
  }
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   223
39131
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   224
  private val focus_listener = new FocusAdapter {
39742
b59e064e32c3 CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents: 39741
diff changeset
   225
    override def focusLost(e: FocusEvent) {
43381
806878ae2219 separate module for text area painting;
wenzelm
parents: 43376
diff changeset
   226
      _highlight_range = None // FIXME exit_control !?
39742
b59e064e32c3 CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents: 39741
diff changeset
   227
    }
39131
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   228
  }
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   229
39741
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
   230
  private val window_listener = new WindowAdapter {
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
   231
    override def windowIconified(e: WindowEvent) { exit_control() }
39742
b59e064e32c3 CONTROL-mouse management: handle windowDeactivated as well;
wenzelm
parents: 39741
diff changeset
   232
    override def windowDeactivated(e: WindowEvent) { exit_control() }
39741
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
   233
  }
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
   234
39131
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   235
  private val mouse_motion_listener = new MouseMotionAdapter {
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   236
    override def mouseMoved(e: MouseEvent) {
40338
e2f03de2b3c7 clarified tooltips: message output by default, extra info via control/command;
wenzelm
parents: 40154
diff changeset
   237
      control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   238
      val x = e.getX()
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   239
      val y = e.getY()
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   240
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   241
      if (!model.buffer.isLoaded) exit_control()
39132
ba17ca3acdd3 refined treatment of multi-line subexpressions;
wenzelm
parents: 39131
diff changeset
   242
      else
ba17ca3acdd3 refined treatment of multi-line subexpressions;
wenzelm
parents: 39131
diff changeset
   243
        Isabelle.swing_buffer_lock(model.buffer) {
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   244
          val snapshot = update_snapshot()
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   245
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   246
          if (control) init_popup(snapshot, x, y)
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   247
46205
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   248
          for (Text.Info(range, _) <- _highlight_range) invalidate_range(range)
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   249
          _highlight_range =
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   250
            if (control) {
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   251
              val offset = text_area.xyToOffset(x, y)
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   252
              Isabelle_Rendering.subexp(snapshot, Text.Range(offset, offset + 1))
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   253
            }
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   254
            else None
07e334ad2e2a ignore empty gfx_range;
wenzelm
parents: 46178
diff changeset
   255
          for (Text.Info(range, _) <- _highlight_range) invalidate_range(range)
39132
ba17ca3acdd3 refined treatment of multi-line subexpressions;
wenzelm
parents: 39131
diff changeset
   256
        }
39131
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   257
    }
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   258
  }
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   259
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   260
43381
806878ae2219 separate module for text area painting;
wenzelm
parents: 43376
diff changeset
   261
  /* text area painting */
39044
5c13736e81c7 Document_View: squiggly underline for messages;
wenzelm
parents: 38886
diff changeset
   262
43381
806878ae2219 separate module for text area painting;
wenzelm
parents: 43376
diff changeset
   263
  private val text_area_painter = new Text_Area_Painter(this)
39700
fa55cf2c1ae4 more precise treatment of backgrounds vs. rectangles;
wenzelm
parents: 39690
diff changeset
   264
43381
806878ae2219 separate module for text area painting;
wenzelm
parents: 43376
diff changeset
   265
  private val tooltip_painter = new TextAreaExtension
806878ae2219 separate module for text area painting;
wenzelm
parents: 43376
diff changeset
   266
  {
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   267
    override def getToolTipText(x: Int, y: Int): String =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   268
    {
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   269
      robust_body(null: String) {
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   270
        val snapshot = update_snapshot()
38845
a9e37daf5bd0 added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents: 38843
diff changeset
   271
        val offset = text_area.xyToOffset(x, y)
45460
dcd02d1a25d7 more tooltip content;
wenzelm
parents: 44805
diff changeset
   272
        val range = Text.Range(offset, offset + 1)
46178
1c5c88f6feb5 clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents: 45744
diff changeset
   273
        val tip =
1c5c88f6feb5 clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents: 45744
diff changeset
   274
          if (control) Isabelle_Rendering.tooltip(snapshot, range)
1c5c88f6feb5 clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents: 45744
diff changeset
   275
          else Isabelle_Rendering.tooltip_message(snapshot, range)
1c5c88f6feb5 clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents: 45744
diff changeset
   276
        tip.map(Isabelle.tooltip(_)) getOrElse null
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   277
      }
34734
wenzelm
parents: 34733
diff changeset
   278
    }
34678
acaac03ced00 tuned whitespace
immler@in.tum.de
parents: 34654
diff changeset
   279
  }
34513
411017e76e98 respect current offsets
immler@in.tum.de
parents: 34503
diff changeset
   280
42825
wenzelm
parents: 40338
diff changeset
   281
  private val gutter_painter = new TextAreaExtension
39175
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   282
  {
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   283
    override def paintScreenLineRange(gfx: Graphics2D,
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   284
      first_line: Int, last_line: Int, physical_lines: Array[Int],
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   285
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   286
    {
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   287
      robust_body(()) {
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   288
        val gutter = text_area.getGutter
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   289
        val width = GutterOptionPane.getSelectionAreaWidth
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   290
        val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3)
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   291
        val FOLD_MARKER_SIZE = 12
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   292
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   293
        if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) {
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   294
          Isabelle.swing_buffer_lock(model.buffer) {
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   295
            val snapshot = update_snapshot()
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   296
            for (i <- 0 until physical_lines.length) {
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   297
              if (physical_lines(i) != -1) {
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   298
                val line_range = proper_line_range(start(i), end(i))
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   299
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   300
                // gutter icons
46178
1c5c88f6feb5 clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents: 45744
diff changeset
   301
                Isabelle_Rendering.gutter_message(snapshot, line_range) match {
1c5c88f6feb5 clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents: 45744
diff changeset
   302
                  case Some(icon) =>
46227
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46205
diff changeset
   303
                    val x0 = (FOLD_MARKER_SIZE + width - border_width - icon.getIconWidth) max 10
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46205
diff changeset
   304
                    val y0 = y + i * line_height + (((line_height - icon.getIconHeight) / 2) max 0)
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46205
diff changeset
   305
                    icon.paintIcon(gutter, gfx, x0, y0)
46178
1c5c88f6feb5 clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents: 45744
diff changeset
   306
                  case None =>
43404
c8369f3d88a1 uniform use of Document_View.robust_body;
wenzelm
parents: 43397
diff changeset
   307
                }
39175
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   308
              }
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   309
            }
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   310
          }
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   311
        }
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   312
      }
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   313
    }
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   314
  }
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   315
a08d68e993ea basic support for warning/error gutter icons;
wenzelm
parents: 39174
diff changeset
   316
43448
90aec5043461 more robust caret painting wrt. surrogate characters;
wenzelm
parents: 43419
diff changeset
   317
  /* caret range */
90aec5043461 more robust caret painting wrt. surrogate characters;
wenzelm
parents: 43419
diff changeset
   318
90aec5043461 more robust caret painting wrt. surrogate characters;
wenzelm
parents: 43419
diff changeset
   319
  def caret_range(): Text.Range =
46229
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   320
    Isabelle.buffer_lock(model.buffer) {
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   321
      def text(i: Text.Offset): Char = model.buffer.getText(i, 1).charAt(0)
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   322
      val caret = text_area.getCaretPosition
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   323
      try {
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   324
        val c = text(caret)
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   325
        if (Character.isHighSurrogate(c) && Character.isLowSurrogate(text(caret + 1)))
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   326
          Text.Range(caret, caret + 2)
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   327
        else if (Character.isLowSurrogate(c) && Character.isHighSurrogate(text(caret - 1)))
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   328
          Text.Range(caret - 1, caret + 1)
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   329
        else Text.Range(caret, caret + 1)
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   330
      }
d8286601e7df back to more basic caret_range (reverting 0ad063afa3d6) -- BreakIterator crashes due to non-zero text.offset when deleting the first character of the buffer;
wenzelm
parents: 46227
diff changeset
   331
      catch { case _: ArrayIndexOutOfBoundsException => Text.Range(caret, caret + 1) }
43448
90aec5043461 more robust caret painting wrt. surrogate characters;
wenzelm
parents: 43419
diff changeset
   332
    }
90aec5043461 more robust caret painting wrt. surrogate characters;
wenzelm
parents: 43419
diff changeset
   333
90aec5043461 more robust caret painting wrt. surrogate characters;
wenzelm
parents: 43419
diff changeset
   334
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 36990
diff changeset
   335
  /* caret handling */
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   336
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37685
diff changeset
   337
  def selected_command(): Option[Command] =
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
   338
  {
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
   339
    Swing_Thread.require()
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   340
    update_snapshot().node.proper_command_at(text_area.getCaretPosition)
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
   341
  }
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   342
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37685
diff changeset
   343
  private val caret_listener = new CaretListener {
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37685
diff changeset
   344
    private val delay = Swing_Thread.delay_last(session.input_delay) {
44805
48a5c104d434 clarified terminology;
wenzelm
parents: 44776
diff changeset
   345
      session.caret_focus.event(Session.Caret_Focus)
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   346
    }
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37685
diff changeset
   347
    override def caretUpdate(e: CaretEvent) { delay() }
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   348
  }
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   349
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   350
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   351
  /* overview of command status left of scrollbar */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   352
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   353
  private val overview = new JPanel(new BorderLayout)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   354
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   355
    private val WIDTH = 10
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   356
    private val HEIGHT = 2
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   357
46549
1bffe63879af more careful painting of overview component: more precise and more efficient;
wenzelm
parents: 46229
diff changeset
   358
    private def lines(): Int = model.buffer.getLineCount max text_area.getVisibleLines
46227
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46205
diff changeset
   359
34806
wenzelm
parents: 34794
diff changeset
   360
    setPreferredSize(new Dimension(WIDTH, 0))
wenzelm
parents: 34794
diff changeset
   361
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   362
    setRequestFocusEnabled(false)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   363
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   364
    addMouseListener(new MouseAdapter {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   365
      override def mousePressed(event: MouseEvent) {
46549
1bffe63879af more careful painting of overview component: more precise and more efficient;
wenzelm
parents: 46229
diff changeset
   366
        val line = (event.getY * lines()) / getHeight
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   367
        if (line >= 0 && line < text_area.getLineCount)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   368
          text_area.setCaretPosition(text_area.getLineStartOffset(line))
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   369
      }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   370
    })
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   371
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   372
    override def addNotify() {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   373
      super.addNotify()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   374
      ToolTipManager.sharedInstance.registerComponent(this)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   375
    }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   376
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   377
    override def removeNotify() {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   378
      ToolTipManager.sharedInstance.unregisterComponent(this)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   379
      super.removeNotify
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   380
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   381
46571
edcccd7a9eee overview.delay_repaint: avoid wasting GUI cycles via update_delay;
wenzelm
parents: 46550
diff changeset
   382
    val delay_repaint =
edcccd7a9eee overview.delay_repaint: avoid wasting GUI cycles via update_delay;
wenzelm
parents: 46550
diff changeset
   383
      Swing_Thread.delay_first(Isabelle.session.update_delay) { repaint() }
edcccd7a9eee overview.delay_repaint: avoid wasting GUI cycles via update_delay;
wenzelm
parents: 46550
diff changeset
   384
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   385
    override def paintComponent(gfx: Graphics)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   386
    {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   387
      super.paintComponent(gfx)
38640
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   388
      Swing_Thread.assert()
39737
8c312f064223 more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents: 39700
diff changeset
   389
46550
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   390
      robust_body(()) {
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   391
        val buffer = model.buffer
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   392
        Isabelle.buffer_lock(buffer) {
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   393
          val snapshot = update_snapshot()
39737
8c312f064223 more defensive overview.paintComponent: avoid potential crash due to buffer change while painting;
wenzelm
parents: 39700
diff changeset
   394
46550
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   395
          gfx.setColor(getBackground)
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   396
          gfx.asInstanceOf[Graphics2D].fill(gfx.getClipBounds)
46549
1bffe63879af more careful painting of overview component: more precise and more efficient;
wenzelm
parents: 46229
diff changeset
   397
46550
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   398
          val line_count = buffer.getLineCount
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   399
          val char_count = buffer.getLength
46549
1bffe63879af more careful painting of overview component: more precise and more efficient;
wenzelm
parents: 46229
diff changeset
   400
46550
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   401
          val L = lines()
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   402
          val H = getHeight()
46549
1bffe63879af more careful painting of overview component: more precise and more efficient;
wenzelm
parents: 46229
diff changeset
   403
46550
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   404
          @tailrec def paint_loop(l: Int, h: Int, p: Int, q: Int): Unit =
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   405
          {
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   406
            if (l < line_count && h < H) {
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   407
              val p1 = p + H
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   408
              val q1 = q + HEIGHT * L
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   409
              val (l1, h1) =
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   410
                if (p1 >= q1) (l + 1, h + (p1 - q) / L)
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   411
                else (l + (q1 - p) / H, h + HEIGHT)
46549
1bffe63879af more careful painting of overview component: more precise and more efficient;
wenzelm
parents: 46229
diff changeset
   412
46550
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   413
              val start = buffer.getLineStartOffset(l)
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   414
              val end =
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   415
                if (l1 < line_count) buffer.getLineStartOffset(l1)
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   416
                else char_count
46549
1bffe63879af more careful painting of overview component: more precise and more efficient;
wenzelm
parents: 46229
diff changeset
   417
46550
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   418
              Isabelle_Rendering.overview_color(snapshot, Text.Range(start, end)) match {
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   419
                case None =>
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   420
                case Some(color) =>
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   421
                  gfx.setColor(color)
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   422
                  gfx.fillRect(0, h, getWidth, h1 - h)
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   423
              }
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   424
              paint_loop(l1, h1, p + (l1 - l) * H, q + (h1 - h) * L)
46227
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46205
diff changeset
   425
            }
46549
1bffe63879af more careful painting of overview component: more precise and more efficient;
wenzelm
parents: 46229
diff changeset
   426
          }
46550
0133d31f9ab4 observe HEIGHT of overview ticks;
wenzelm
parents: 46549
diff changeset
   427
          paint_loop(0, 0, 0, 0)
37188
b78ff6b4f4b3 do not highlight ignored command spans;
wenzelm
parents: 37187
diff changeset
   428
        }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   429
      }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   430
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   431
  }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   432
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   433
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   434
  /* main actor */
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   435
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   436
  private val main_actor = actor {
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   437
    loop {
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   438
      react {
44608
76c2e3ddc183 tuned Commands_Changed: cover nodes as well;
wenzelm
parents: 44583
diff changeset
   439
        case changed: Session.Commands_Changed =>
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   440
          val buffer = model.buffer
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   441
          Isabelle.swing_buffer_lock(buffer) {
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   442
            val (updated, snapshot) = flush_snapshot()
44378
81b4af4cfa5a tuned signature;
wenzelm
parents: 43661
diff changeset
   443
            val visible = visible_range()
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   444
44608
76c2e3ddc183 tuned Commands_Changed: cover nodes as well;
wenzelm
parents: 44583
diff changeset
   445
            if (updated ||
44615
a4ff8a787202 more abstract Document.Node.Name;
wenzelm
parents: 44608
diff changeset
   446
                (changed.nodes.contains(model.name) &&
44608
76c2e3ddc183 tuned Commands_Changed: cover nodes as well;
wenzelm
parents: 44583
diff changeset
   447
                 changed.commands.exists(snapshot.node.commands.contains)))
46571
edcccd7a9eee overview.delay_repaint: avoid wasting GUI cycles via update_delay;
wenzelm
parents: 46550
diff changeset
   448
              overview.delay_repaint()
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   449
44378
81b4af4cfa5a tuned signature;
wenzelm
parents: 43661
diff changeset
   450
            if (updated) invalidate_range(visible)
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   451
            else {
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   452
              val visible_cmds =
44378
81b4af4cfa5a tuned signature;
wenzelm
parents: 43661
diff changeset
   453
                snapshot.node.command_range(snapshot.revert(visible)).map(_._1)
44608
76c2e3ddc183 tuned Commands_Changed: cover nodes as well;
wenzelm
parents: 44583
diff changeset
   454
              if (visible_cmds.exists(changed.commands)) {
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   455
                for {
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   456
                  line <- 0 until text_area.getVisibleLines
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   457
                  val start = text_area.getScreenLineStartOffset(line) if start >= 0
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   458
                  val end = text_area.getScreenLineEndOffset(line) if end >= 0
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   459
                  val range = proper_line_range(start, end)
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   460
                  val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1)
44608
76c2e3ddc183 tuned Commands_Changed: cover nodes as well;
wenzelm
parents: 44583
diff changeset
   461
                  if line_cmds.exists(changed.commands)
43419
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   462
                } text_area.invalidateScreenLineRange(line, line)
6ed49c52d463 flush snapshot on falling edge of is_outdated -- recover effect of former buffer.propertiesChanged on text area (cf. f0770743b7ec);
wenzelm
parents: 43417
diff changeset
   463
              }
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   464
            }
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   465
          }
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   466
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   467
        case Session.Global_Settings => html_panel_resize()
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   468
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   469
        case bad => System.err.println("command_change_actor: ignoring bad message " + bad)
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   470
      }
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   471
    }
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   472
  }
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   473
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   474
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   475
  /* activation */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   476
34808
e462572536e9 eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents: 34806
diff changeset
   477
  private def activate()
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   478
  {
42825
wenzelm
parents: 40338
diff changeset
   479
    val painter = text_area.getPainter
44437
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   480
    painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_perspective)
43387
a59ae768249e recovered tooltip Entity content (odd effect of layer change!? cf. 806878ae2219);
wenzelm
parents: 43381
diff changeset
   481
    painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, tooltip_painter)
43381
806878ae2219 separate module for text area painting;
wenzelm
parents: 43376
diff changeset
   482
    text_area_painter.activate()
42825
wenzelm
parents: 40338
diff changeset
   483
    text_area.getGutter.addExtension(gutter_painter)
39131
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   484
    text_area.addFocusListener(focus_listener)
39741
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
   485
    text_area.getView.addWindowListener(window_listener)
42825
wenzelm
parents: 40338
diff changeset
   486
    painter.addMouseMotionListener(mouse_motion_listener)
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   487
    text_area.addCaretListener(caret_listener)
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   488
    text_area.addLeftOfScrollBar(overview)
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   489
    session.commands_changed += main_actor
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   490
    session.global_settings += main_actor
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   491
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   492
34808
e462572536e9 eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents: 34806
diff changeset
   493
  private def deactivate()
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   494
  {
42825
wenzelm
parents: 40338
diff changeset
   495
    val painter = text_area.getPainter
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   496
    session.commands_changed -= main_actor
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   497
    session.global_settings -= main_actor
39131
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   498
    text_area.removeFocusListener(focus_listener)
39741
62b91eb2d39a CONTROL-mouse management: handle windowIconified;
wenzelm
parents: 39740
diff changeset
   499
    text_area.getView.removeWindowListener(window_listener)
42825
wenzelm
parents: 40338
diff changeset
   500
    painter.removeMouseMotionListener(mouse_motion_listener)
39131
947c62440026 basic support for subexpression highlighting (see also gatchan.jedit.hyperlinks.HyperlinkManager/HyperlinkTextAreaPainter);
wenzelm
parents: 39044
diff changeset
   501
    text_area.removeCaretListener(caret_listener)
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   502
    text_area.removeLeftOfScrollBar(overview)
42825
wenzelm
parents: 40338
diff changeset
   503
    text_area.getGutter.removeExtension(gutter_painter)
43381
806878ae2219 separate module for text area painting;
wenzelm
parents: 43376
diff changeset
   504
    text_area_painter.deactivate()
806878ae2219 separate module for text area painting;
wenzelm
parents: 43376
diff changeset
   505
    painter.removeExtension(tooltip_painter)
44437
bebe15799192 more reliable update_perspective handler based on actual text visibility (e.g. on startup or when resizing without scrolling);
wenzelm
parents: 44436
diff changeset
   506
    painter.removeExtension(update_perspective)
39740
0294948ba962 basic support for message popups via HTML_Panel;
wenzelm
parents: 39737
diff changeset
   507
    exit_popup()
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   508
  }
42825
wenzelm
parents: 40338
diff changeset
   509
}