src/Tools/jEdit/src/jedit/document_view.scala
author wenzelm
Sun, 10 Jan 2010 20:14:21 +0100
changeset 34855 81d0410dc3ac
parent 34834 df9af932e418
child 34856 aa9e22d9f9a7
permissions -rw-r--r--
iterators for ranges of commands/starts -- avoid extra array per document; try/finally for saved_color; misc tuning;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34408
ad7b6c4813c8 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     1
/*
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
     2
 * Document view connected to jEdit text area
34408
ad7b6c4813c8 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     3
 *
ad7b6c4813c8 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     4
 * @author Fabian Immler, TU Munich
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
     5
 * @author Makarius
34408
ad7b6c4813c8 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     6
 */
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
34823
2f3ea37c5958 renamed Proof_Document to Document;
wenzelm
parents: 34811
diff changeset
    11
import isabelle.proofdocument.{Command, Document, Session}
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
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}
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    22
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
object Document_View
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    25
{
34823
2f3ea37c5958 renamed Proof_Document to Document;
wenzelm
parents: 34811
diff changeset
    26
  def choose_color(command: Command, doc: Document): Color =
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    27
  {
34832
d785f72ef388 more explicit treatment of command/document state;
wenzelm
parents: 34824
diff changeset
    28
    doc.current_state(command).status match {
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    29
      case Command.Status.UNPROCESSED => new Color(255, 228, 225)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    30
      case Command.Status.FINISHED => new Color(234, 248, 255)
34794
a4a457e393a4 imitate PG 4 colors;
wenzelm
parents: 34789
diff changeset
    31
      case Command.Status.FAILED => new Color(255, 193, 193)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    32
      case _ => Color.red
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    33
    }
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
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    37
  /* 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
    38
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    39
  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
    40
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    41
  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
    42
  {
34789
30528e68f774 some explicit Swing_Thread guards;
wenzelm
parents: 34788
diff changeset
    43
    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
    44
    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
    45
    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
    46
    doc_view.activate()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    47
    doc_view
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
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34784
diff changeset
    50
  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
    51
  {
34789
30528e68f774 some explicit Swing_Thread guards;
wenzelm
parents: 34788
diff changeset
    52
    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
    53
    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
    54
      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
    55
      case _ => None
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    56
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    57
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    58
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    59
  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
    60
  {
34789
30528e68f774 some explicit Swing_Thread guards;
wenzelm
parents: 34788
diff changeset
    61
    Swing_Thread.assert()
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34784
diff changeset
    62
    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
    63
      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
    64
      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
    65
        doc_view.deactivate()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    66
        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
    67
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    68
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    69
}
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
    70
34733
a3ad6d51db1d misc tuning and unification;
wenzelm
parents: 34711
diff changeset
    71
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    72
class Document_View(model: Document_Model, text_area: TextArea)
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
    73
{
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    74
  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
    75
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
    76
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    77
  /* visible document -- owned by Swing thread */
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    78
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    79
  @volatile private var document = model.recent_document()
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    80
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    81
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    82
  /* buffer of changed commands -- owned by Swing thread */
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    83
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    84
  @volatile private var changed_commands: Set[Command] = Set()
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    85
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    86
  private val changed_delay = Swing_Thread.delay_first(100) {
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    87
    if (!changed_commands.isEmpty) {
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    88
      document = model.recent_document()
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    89
      for (cmd <- changed_commands if document.commands.contains(cmd)) { // FIXME cover doc states as well!!?
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    90
        update_syntax(cmd)
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    91
        invalidate_line(cmd)
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    92
        overview.repaint()
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    93
      }
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    94
      changed_commands = Set()
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    95
    }
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    96
  }
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    97
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
    98
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
    99
  /* command change actor */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   100
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   101
  private case object Exit
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   102
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   103
  private val command_change_actor = actor {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   104
    loop {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   105
      react {
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   106
        case command: Command =>  // FIXME rough filtering according to document family!?
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   107
          Swing_Thread.now {
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   108
            changed_commands += command
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   109
            changed_delay()
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   110
          }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   111
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   112
        case Exit => reply(()); exit()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   113
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   114
        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
   115
      }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   116
    }
34678
acaac03ced00 tuned whitespace
immler@in.tum.de
parents: 34654
diff changeset
   117
  }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   118
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   119
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   120
  /* text_area_extension */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   121
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   122
  private val text_area_extension = new TextAreaExtension
34678
acaac03ced00 tuned whitespace
immler@in.tum.de
parents: 34654
diff changeset
   123
  {
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   124
    override def paintValidLine(gfx: Graphics2D,
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   125
      screen_line: Int, physical_line: Int, start: Int, end: Int, y: Int)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   126
    {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   127
      def from_current(pos: Int) = model.from_current(document, pos)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   128
      def to_current(pos: Int) = model.to_current(document, pos)
34855
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   129
      val metrics = text_area.getPainter.getFontMetrics
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   130
      val saved_color = gfx.getColor
34855
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   131
      try {
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   132
        for ((command, command_start) <-
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   133
          document.command_range(from_current(start), from_current(end)))
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   134
        {
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   135
          val begin = start max to_current(command_start)
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   136
          val finish = (end - 1) min to_current(command_start + command.length)
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   137
          encolor(gfx, y, metrics.getHeight, begin, finish,
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   138
            Document_View.choose_color(command, document), true)
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   139
        }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   140
      }
34855
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   141
      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
   142
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   143
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   144
    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
   145
    {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   146
      val offset = model.from_current(document, text_area.xyToOffset(x, y))
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   147
      document.command_at(offset) match {
34855
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   148
        case Some((command, command_start)) =>
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   149
          document.current_state(command).type_at(offset - command_start).getOrElse(null)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   150
        case None => null
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   151
      }
34734
wenzelm
parents: 34733
diff changeset
   152
    }
34678
acaac03ced00 tuned whitespace
immler@in.tum.de
parents: 34654
diff changeset
   153
  }
34513
411017e76e98 respect current offsets
immler@in.tum.de
parents: 34503
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
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   156
  /* caret_listener */
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   157
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   158
  private var _selected_command: Command = null
34811
wenzelm
parents: 34810
diff changeset
   159
  private def selected_command = _selected_command
wenzelm
parents: 34810
diff changeset
   160
  private def selected_command_=(cmd: Command)
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   161
  {
34811
wenzelm
parents: 34810
diff changeset
   162
    _selected_command = cmd
wenzelm
parents: 34810
diff changeset
   163
    session.results.event(cmd)
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   164
  }
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   165
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   166
  private val caret_listener = new CaretListener
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   167
  {
34855
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   168
    override def caretUpdate(e: CaretEvent)
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   169
    {
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   170
      document.command_at(e.getDot) match {
34855
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   171
        case Some((command, command_start)) if (selected_command != command) =>
81d0410dc3ac iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents: 34834
diff changeset
   172
          selected_command = command
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   173
        case _ =>
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   174
      }
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   175
    }
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   176
  }
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   177
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   178
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   179
  /* (re)painting */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   180
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   181
  private val update_delay = Swing_Thread.delay_first(500) { model.buffer.propertiesChanged() }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   182
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   183
  private def update_syntax(cmd: Command)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   184
  {
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   185
    val (line1, line2) = model.lines_of_command(document, cmd)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   186
    if (line2 >= text_area.getFirstLine &&
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   187
      line1 <= text_area.getFirstLine + text_area.getVisibleLines)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   188
        update_delay()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   189
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   190
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   191
  private def invalidate_line(cmd: Command) =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   192
  {
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   193
    val (start, stop) = model.lines_of_command(document, cmd)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   194
    text_area.invalidateLineRange(start, stop)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   195
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   196
    if (selected_command == cmd)
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   197
      session.results.event(cmd)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   198
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   199
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   200
  private def invalidate_all() =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   201
    text_area.invalidateLineRange(text_area.getFirstPhysicalLine,
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   202
      text_area.getLastPhysicalLine)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   203
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   204
  private def encolor(gfx: Graphics2D,
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   205
    y: Int, height: Int, begin: Int, finish: Int, color: Color, fill: Boolean)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   206
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   207
    val start = text_area.offsetToXY(begin)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   208
    val stop =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   209
      if (finish < model.buffer.getLength) text_area.offsetToXY(finish)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   210
      else {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   211
        val p = text_area.offsetToXY(finish - 1)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   212
        val metrics = text_area.getPainter.getFontMetrics
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   213
        p.x = p.x + (metrics.charWidth(' ') max metrics.getMaxAdvance)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   214
        p
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   215
      }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   216
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   217
    if (start != null && stop != null) {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   218
      gfx.setColor(color)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   219
      if (fill) gfx.fillRect(start.x, y, stop.x - start.x, height)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   220
      else gfx.drawRect(start.x, y, stop.x - start.x, height)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   221
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   222
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   223
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
  /* 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
   226
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   227
  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
   228
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   229
    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
   230
    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
   231
34806
wenzelm
parents: 34794
diff changeset
   232
    setPreferredSize(new Dimension(WIDTH, 0))
wenzelm
parents: 34794
diff changeset
   233
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   234
    setRequestFocusEnabled(false)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   235
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   236
    addMouseListener(new MouseAdapter {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   237
      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
   238
        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
   239
        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
   240
          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
   241
      }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   242
    })
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   243
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   244
    override def addNotify() {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   245
      super.addNotify()
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   246
      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
   247
    }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   248
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   249
    override def removeNotify() {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   250
      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
   251
      super.removeNotify
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   252
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   253
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   254
    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
   255
    {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   256
      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
   257
      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
   258
      else ""
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   259
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   260
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   261
    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
   262
    {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   263
      super.paintComponent(gfx)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   264
      val buffer = model.buffer
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   265
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   266
      for (command <- document.commands) {
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   267
        val line1 = buffer.getLineOfOffset(model.to_current(document, command.start(document)))
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   268
        val line2 = buffer.getLineOfOffset(model.to_current(document, command.stop(document))) + 1
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   269
        val y = line_to_y(line1)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   270
        val height = HEIGHT * (line2 - line1)
34834
df9af932e418 slightly more uniform/robust handling of visible document;
wenzelm
parents: 34832
diff changeset
   271
        gfx.setColor(Document_View.choose_color(command, document))
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   272
        gfx.fillRect(0, y, getWidth - 1, height)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   273
      }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   274
    }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   275
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   276
    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
   277
      (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
   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 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
   280
      (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
   281
  }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   282
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   283
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   284
  /* activation */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   285
34808
e462572536e9 eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents: 34806
diff changeset
   286
  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
   287
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   288
    text_area.getPainter.
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   289
      addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, text_area_extension)
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   290
    text_area.addCaretListener(caret_listener)
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   291
    text_area.addLeftOfScrollBar(overview)
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   292
    session.command_change += command_change_actor
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   293
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   294
34808
e462572536e9 eliminated global Session.document_0 -- did not work due to hardwired id;
wenzelm
parents: 34806
diff changeset
   295
  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
   296
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   297
    session.command_change -= command_change_actor
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34777
diff changeset
   298
    command_change_actor !? Exit
34810
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   299
    text_area.removeLeftOfScrollBar(overview)
9ad3431a34a5 tuned caret_listener/selected_command;
wenzelm
parents: 34808
diff changeset
   300
    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
   301
    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
   302
  }
34403
6c812a3cb170 information on command-phase left of scrollbar (with panel)
immler@in.tum.de
parents:
diff changeset
   303
}