src/Tools/jEdit/src/jedit/document_view.scala
author wenzelm
Tue, 31 Aug 2010 17:49:45 +0200
changeset 38884 9ec5f6010d6e
parent 38883 0998a635684a
child 38886 9210cf2b4869
permissions -rw-r--r--
Document_View: repaint overview for any command change of this node (again);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36760
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     1
/*  Title:      Tools/jEdit/src/jedit/document_view.scala
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
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    13
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
    14
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    15
import java.awt.event.{MouseAdapter, MouseEvent}
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    16
import java.awt.{BorderLayout, Graphics, Dimension, Color, Graphics2D}
34734
wenzelm
parents: 34733
diff changeset
    17
import javax.swing.{JPanel, ToolTipManager}
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    18
import javax.swing.event.{CaretListener, CaretEvent}
34734
wenzelm
parents: 34733
diff changeset
    19
34709
2f0c18f9b6c7 minor tuning;
wenzelm
parents: 34679
diff changeset
    20
import org.gjt.sp.jedit.gui.RolloverButton
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    21
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter}
37241
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    22
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
    23
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    24
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    25
object Document_View
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    26
{
38227
6bbb42843b6e concentrate structural document notions in document.scala;
wenzelm
parents: 38223
diff changeset
    27
  def choose_color(snapshot: Document.Snapshot, command: Command): Color =
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    28
  {
38356
443fb83a21e8 consider command state as part of Snapshot, not Document;
wenzelm
parents: 38227
diff changeset
    29
    val state = snapshot.state(command)
38151
2837c952ca31 explicit Change.Snapshot and Document.Node;
wenzelm
parents: 38150
diff changeset
    30
    if (snapshot.is_outdated) new Color(240, 240, 240)
37186
349e9223c685 explicit markup for forked goals, as indicated by Goal.fork;
wenzelm
parents: 37132
diff changeset
    31
    else
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38429
diff changeset
    32
      Isar_Document.command_status(state.status) match {
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38429
diff changeset
    33
        case Isar_Document.Forked(i) if i > 0 => new Color(255, 228, 225)
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38429
diff changeset
    34
        case Isar_Document.Finished => new Color(234, 248, 255)
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38429
diff changeset
    35
        case Isar_Document.Failed => new Color(255, 193, 193)
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38429
diff changeset
    36
        case Isar_Document.Unprocessed => new Color(255, 228, 225)
38429
9951852fae91 simplified command status: interpret stacked markup on demand;
wenzelm
parents: 38426
diff changeset
    37
        case _ => Color.red
37186
349e9223c685 explicit markup for forked goals, as indicated by Goal.fork;
wenzelm
parents: 37132
diff changeset
    38
      }
34784
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
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    41
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    42
  /* 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
    43
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    44
  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
    45
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    46
  def init(model: Document_Model, text_area: TextArea): Document_View =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    47
  {
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
    48
    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
    49
    val doc_view = new Document_View(model, text_area)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    50
    text_area.putClientProperty(key, doc_view)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    51
    doc_view.activate()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    52
    doc_view
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    53
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    54
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34784
diff changeset
    55
  def apply(text_area: TextArea): 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
    56
  {
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
    57
    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
    58
    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
    59
      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
    60
      case _ => None
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    61
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    62
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    63
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    64
  def exit(text_area: TextArea)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    65
  {
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
    66
    Swing_Thread.require()
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34784
diff changeset
    67
    apply(text_area) match {
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    68
      case None => error("No document view for text area: " + text_area)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    69
      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
    70
        doc_view.deactivate()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    71
        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
    72
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    73
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    74
}
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
    75
34733
a3ad6d51db1d misc tuning and unification;
wenzelm
parents: 34711
diff changeset
    76
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 36990
diff changeset
    77
class Document_View(val model: Document_Model, text_area: TextArea)
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
    78
{
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    79
  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
    80
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
    81
37241
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    82
  /* extended token styles */
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    83
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    84
  private var styles: Array[SyntaxStyle] = null  // owned by Swing thread
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    85
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    86
  def extend_styles()
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    87
  {
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
    88
    Swing_Thread.require()
38158
8aaa21db41f3 Document_Model: include token marker here;
wenzelm
parents: 38153
diff changeset
    89
    styles = Document_Model.Token_Markup.extend_styles(text_area.getPainter.getStyles)
37241
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    90
  }
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    91
  extend_styles()
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    92
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    93
  def set_styles()
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    94
  {
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
    95
    Swing_Thread.require()
37241
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    96
    text_area.getPainter.setStyles(styles)
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    97
  }
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    98
04d2521e79b0 basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents: 37201
diff changeset
    99
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   100
  /* visible line ranges */
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   101
38883
0998a635684a refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents: 38881
diff changeset
   102
  // 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
   103
  // 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
   104
  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
   105
  {
38883
0998a635684a refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents: 38881
diff changeset
   106
    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
   107
    Text.Range(start, stop)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   108
  }
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
  def screen_lines_range(): Text.Range =
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   111
  {
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   112
    val start = text_area.getScreenLineStartOffset(0)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   113
    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
   114
    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
   115
  }
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   116
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   117
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 36990
diff changeset
   118
  /* commands_changed_actor */
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   119
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 36990
diff changeset
   120
  private val commands_changed_actor = actor {
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   121
    loop {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   122
      react {
38360
53224a4d2f0e specific Session.Commands_Changed;
wenzelm
parents: 38356
diff changeset
   123
        case Session.Commands_Changed(changed) =>
38843
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   124
          val buffer = model.buffer
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   125
          Isabelle.swing_buffer_lock(buffer) {
38151
2837c952ca31 explicit Change.Snapshot and Document.Node;
wenzelm
parents: 38150
diff changeset
   126
            val snapshot = model.snapshot()
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   127
38884
9ec5f6010d6e Document_View: repaint overview for any command change of this node (again);
wenzelm
parents: 38883
diff changeset
   128
            if (changed.exists(snapshot.node.commands.contains))
9ec5f6010d6e Document_View: repaint overview for any command change of this node (again);
wenzelm
parents: 38883
diff changeset
   129
              overview.repaint()
9ec5f6010d6e Document_View: repaint overview for any command change of this node (again);
wenzelm
parents: 38883
diff changeset
   130
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   131
            val visible_range = screen_lines_range()
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   132
            val visible_cmds = snapshot.node.command_range(snapshot.revert(visible_range)).map(_._1)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   133
            if (visible_cmds.exists(changed)) {
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   134
              for {
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   135
                line <- 0 until text_area.getVisibleLines
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   136
                val start = text_area.getScreenLineStartOffset(line) if start >= 0
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   137
                val end = text_area.getScreenLineEndOffset(line) if end >= 0
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   138
                val range = proper_line_range(start, end)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   139
                val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   140
                if line_cmds.exists(changed)
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   141
              } text_area.invalidateScreenLineRange(line, line)
38884
9ec5f6010d6e Document_View: repaint overview for any command change of this node (again);
wenzelm
parents: 38883
diff changeset
   142
38843
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   143
              // FIXME danger of deadlock!?
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   144
              // FIXME potentially slow!?
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   145
              model.buffer.propertiesChanged()
38640
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   146
            }
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   147
          }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   148
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   149
        case bad => System.err.println("command_change_actor: ignoring bad message " + bad)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   150
      }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   151
    }
34678
acaac03ced00 tuned whitespace
immler@in.tum.de
parents: 34654
diff changeset
   152
  }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   153
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   154
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   155
  /* text_area_extension */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   156
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   157
  private val text_area_extension = new TextAreaExtension
34678
acaac03ced00 tuned whitespace
immler@in.tum.de
parents: 34654
diff changeset
   158
  {
37685
305c326db33b more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents: 37555
diff changeset
   159
    override def paintScreenLineRange(gfx: Graphics2D,
305c326db33b more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents: 37555
diff changeset
   160
      first_line: Int, last_line: Int, physical_lines: Array[Int],
305c326db33b more efficient document model/view -- avoid repeated iteration over commands from start, prefer bulk operations;
wenzelm
parents: 37555
diff changeset
   161
      start: Array[Int], end: Array[Int], y0: Int, line_height: Int)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   162
    {
38843
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   163
      Isabelle.swing_buffer_lock(model.buffer) {
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   164
        val snapshot = model.snapshot()
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   165
        val saved_color = gfx.getColor
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   166
        try {
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   167
          var y = y0
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   168
          for (i <- 0 until physical_lines.length) {
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   169
            if (physical_lines(i) != -1) {
38881
c8123e77acc5 tuned commands_changed_actor: more precise/efficient handling of visible screen lines;
wenzelm
parents: 38880
diff changeset
   170
              val line_range = proper_line_range(start(i), end(i))
38880
5b4efe90c120 simplified/clarified Document_View.text_area_extension;
wenzelm
parents: 38855
diff changeset
   171
              val cmds = snapshot.node.command_range(snapshot.revert(line_range))
38843
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   172
              for ((command, command_start) <- cmds if !command.is_ignored) {
38880
5b4efe90c120 simplified/clarified Document_View.text_area_extension;
wenzelm
parents: 38855
diff changeset
   173
                val range = line_range.restrict(snapshot.convert(command.range + command_start))
5b4efe90c120 simplified/clarified Document_View.text_area_extension;
wenzelm
parents: 38855
diff changeset
   174
                val p = text_area.offsetToXY(range.start)
5b4efe90c120 simplified/clarified Document_View.text_area_extension;
wenzelm
parents: 38855
diff changeset
   175
                val q = text_area.offsetToXY(range.stop)
38883
0998a635684a refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents: 38881
diff changeset
   176
                if (p != null && q != null) {
0998a635684a refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents: 38881
diff changeset
   177
                  gfx.setColor(Document_View.choose_color(snapshot, command))
0998a635684a refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents: 38881
diff changeset
   178
                  gfx.fillRect(p.x, y, q.x - p.x, line_height)
0998a635684a refined proper_line_range (again), to make text_area_extension work with soft wwrap;
wenzelm
parents: 38881
diff changeset
   179
                }
38843
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   180
              }
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   181
            }
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   182
            y += line_height
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
   183
          }
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
   184
        }
38843
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   185
        finally { gfx.setColor(saved_color) }
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
   186
      }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   187
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   188
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   189
    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
   190
    {
38845
a9e37daf5bd0 added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents: 38843
diff changeset
   191
      Isabelle.swing_buffer_lock(model.buffer) {
a9e37daf5bd0 added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents: 38843
diff changeset
   192
        val snapshot = model.snapshot()
a9e37daf5bd0 added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents: 38843
diff changeset
   193
        val offset = text_area.xyToOffset(x, y)
a9e37daf5bd0 added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents: 38843
diff changeset
   194
        val markup =
a9e37daf5bd0 added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents: 38843
diff changeset
   195
          snapshot.select_markup(Text.Range(offset, offset + 1)) {
38580
881c362d48e4 proper range for hyperlinks and tooltips, using original markup information;
wenzelm
parents: 38577
diff changeset
   196
            case Text.Info(range, XML.Elem(Markup(Markup.ML_TYPING, _), body)) =>
38845
a9e37daf5bd0 added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents: 38843
diff changeset
   197
              Isabelle.tooltip(Pretty.string_of(List(Pretty.block(body)), margin = 40))
a9e37daf5bd0 added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents: 38843
diff changeset
   198
          } { null }
a9e37daf5bd0 added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents: 38843
diff changeset
   199
        if (markup.hasNext) markup.next.info else null
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   200
      }
34734
wenzelm
parents: 34733
diff changeset
   201
    }
34678
acaac03ced00 tuned whitespace
immler@in.tum.de
parents: 34654
diff changeset
   202
  }
34513
411017e76e98 respect current offsets
immler@in.tum.de
parents: 34503
diff changeset
   203
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   204
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 36990
diff changeset
   205
  /* caret handling */
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   206
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37685
diff changeset
   207
  def selected_command(): Option[Command] =
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
   208
  {
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
   209
    Swing_Thread.require()
38151
2837c952ca31 explicit Change.Snapshot and Document.Node;
wenzelm
parents: 38150
diff changeset
   210
    model.snapshot().node.proper_command_at(text_area.getCaretPosition)
38223
2a368e8e0a80 more explicit treatment of Swing thread context;
wenzelm
parents: 38158
diff changeset
   211
  }
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   212
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37685
diff changeset
   213
  private val caret_listener = new CaretListener {
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37685
diff changeset
   214
    private val delay = Swing_Thread.delay_last(session.input_delay) {
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37685
diff changeset
   215
      session.perspective.event(Session.Perspective)
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   216
    }
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37685
diff changeset
   217
    override def caretUpdate(e: CaretEvent) { delay() }
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   218
  }
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   219
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   220
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   221
  /* 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
   222
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   223
  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
   224
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   225
    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
   226
    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
   227
34806
wenzelm
parents: 34794
diff changeset
   228
    setPreferredSize(new Dimension(WIDTH, 0))
wenzelm
parents: 34794
diff changeset
   229
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   230
    setRequestFocusEnabled(false)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   231
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   232
    addMouseListener(new MouseAdapter {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   233
      override def mousePressed(event: MouseEvent) {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   234
        val line = y_to_line(event.getY)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   235
        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
   236
          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
   237
      }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   238
    })
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   239
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   240
    override def addNotify() {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   241
      super.addNotify()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   242
      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
   243
    }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   244
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   245
    override def removeNotify() {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   246
      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
   247
      super.removeNotify
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   248
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   249
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   250
    override def getToolTipText(event: MouseEvent): String =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   251
    {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   252
      val line = y_to_line(event.getY())
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   253
      if (line >= 0 && line < text_area.getLineCount) "<html><b>TODO:</b><br>Tooltip</html>"
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   254
      else ""
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   255
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   256
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   257
    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
   258
    {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   259
      super.paintComponent(gfx)
38640
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   260
      Swing_Thread.assert()
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   261
      val buffer = model.buffer
38843
d95522496593 more careful locking of jEdit buffer;
wenzelm
parents: 38710
diff changeset
   262
      Isabelle.buffer_lock(buffer) {
38640
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   263
        val snapshot = model.snapshot()
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   264
        val saved_color = gfx.getColor  // FIXME needed!?
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   265
        try {
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   266
          for ((command, start) <- snapshot.node.command_starts if !command.is_ignored) {
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   267
            val line1 = buffer.getLineOfOffset(snapshot.convert(start))
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   268
            val line2 = buffer.getLineOfOffset(snapshot.convert(start + command.length)) + 1
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   269
            val y = line_to_y(line1)
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   270
            val height = HEIGHT * (line2 - line1)
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   271
            gfx.setColor(Document_View.choose_color(snapshot, command))
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   272
            gfx.fillRect(0, y, getWidth - 1, height)
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   273
          }
37188
b78ff6b4f4b3 do not highlight ignored command spans;
wenzelm
parents: 37187
diff changeset
   274
        }
38640
105d1f112da5 sporadic locking of jEdit buffer;
wenzelm
parents: 38582
diff changeset
   275
        finally { gfx.setColor(saved_color) }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   276
      }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   277
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   278
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   279
    private def line_to_y(line: Int): Int =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   280
      (line * getHeight) / (text_area.getBuffer.getLineCount max text_area.getVisibleLines)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   281
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   282
    private def y_to_line(y: Int): Int =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   283
      (y * (text_area.getBuffer.getLineCount max text_area.getVisibleLines)) / getHeight
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   284
  }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   285
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   286
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   287
  /* activation */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   288
34808
e462572536e9 eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents: 34806
diff changeset
   289
  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
   290
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   291
    text_area.getPainter.
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   292
      addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, text_area_extension)
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   293
    text_area.addCaretListener(caret_listener)
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   294
    text_area.addLeftOfScrollBar(overview)
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 36990
diff changeset
   295
    session.commands_changed += commands_changed_actor
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   296
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   297
34808
e462572536e9 eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents: 34806
diff changeset
   298
  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
   299
  {
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 36990
diff changeset
   300
    session.commands_changed -= commands_changed_actor
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   301
    text_area.removeLeftOfScrollBar(overview)
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   302
    text_area.removeCaretListener(caret_listener)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   303
    text_area.getPainter.removeExtension(text_area_extension)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   304
  }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   305
}