src/Tools/jEdit/src/document_view.scala
author wenzelm
Fri Sep 07 13:58:54 2012 +0200 (2012-09-07)
changeset 49195 9d10bd85c1be
parent 48921 5d8d409b897e
child 49196 1d63ceb0d177
permissions -rw-r--r--
more explicit Delay operations;
wenzelm@43282
     1
/*  Title:      Tools/jEdit/src/document_view.scala
wenzelm@36760
     2
    Author:     Fabian Immler, TU Munich
wenzelm@36760
     3
    Author:     Makarius
wenzelm@36760
     4
wenzelm@36760
     5
Document view connected to jEdit text area.
wenzelm@36760
     6
*/
wenzelm@34408
     7
immler@34403
     8
package isabelle.jedit
immler@34403
     9
wenzelm@34760
    10
wenzelm@36015
    11
import isabelle._
wenzelm@36015
    12
wenzelm@44379
    13
import scala.collection.mutable
wenzelm@45460
    14
import scala.collection.immutable.SortedMap
wenzelm@34784
    15
import scala.actors.Actor._
wenzelm@34784
    16
wenzelm@43520
    17
import java.lang.System
wenzelm@45744
    18
import java.text.BreakIterator
wenzelm@46572
    19
import java.awt.{Color, Graphics2D, Point}
wenzelm@48921
    20
import java.awt.event.{MouseMotionAdapter, MouseAdapter, MouseEvent,
wenzelm@39741
    21
  FocusAdapter, FocusEvent, WindowEvent, WindowAdapter}
wenzelm@46572
    22
import javax.swing.{Popup, PopupFactory, SwingUtilities, BorderFactory}
wenzelm@34784
    23
import javax.swing.event.{CaretListener, CaretEvent}
wenzelm@34734
    24
wenzelm@43404
    25
import org.gjt.sp.util.Log
wenzelm@43404
    26
wenzelm@42839
    27
import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug}
wenzelm@34709
    28
import org.gjt.sp.jedit.gui.RolloverButton
wenzelm@39176
    29
import org.gjt.sp.jedit.options.GutterOptionPane
wenzelm@47392
    30
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter}
wenzelm@43369
    31
import org.gjt.sp.jedit.syntax.{SyntaxStyle}
wenzelm@34784
    32
wenzelm@34784
    33
wenzelm@34784
    34
object Document_View
wenzelm@34784
    35
{
wenzelm@34784
    36
  /* document view of text area */
wenzelm@34784
    37
wenzelm@34784
    38
  private val key = new Object
wenzelm@34784
    39
wenzelm@39741
    40
  def apply(text_area: JEditTextArea): Option[Document_View] =
wenzelm@34784
    41
  {
wenzelm@38223
    42
    Swing_Thread.require()
wenzelm@34784
    43
    text_area.getClientProperty(key) match {
wenzelm@34784
    44
      case doc_view: Document_View => Some(doc_view)
wenzelm@34784
    45
      case _ => None
wenzelm@34784
    46
    }
wenzelm@34784
    47
  }
wenzelm@34784
    48
wenzelm@39741
    49
  def exit(text_area: JEditTextArea)
wenzelm@34784
    50
  {
wenzelm@38223
    51
    Swing_Thread.require()
wenzelm@34788
    52
    apply(text_area) match {
wenzelm@39636
    53
      case None =>
wenzelm@34784
    54
      case Some(doc_view) =>
wenzelm@34784
    55
        doc_view.deactivate()
wenzelm@34784
    56
        text_area.putClientProperty(key, null)
wenzelm@34784
    57
    }
wenzelm@34784
    58
  }
wenzelm@43397
    59
wenzelm@43397
    60
  def init(model: Document_Model, text_area: JEditTextArea): Document_View =
wenzelm@43397
    61
  {
wenzelm@43397
    62
    exit(text_area)
wenzelm@43397
    63
    val doc_view = new Document_View(model, text_area)
wenzelm@43397
    64
    text_area.putClientProperty(key, doc_view)
wenzelm@43397
    65
    doc_view.activate()
wenzelm@43397
    66
    doc_view
wenzelm@43397
    67
  }
wenzelm@34784
    68
}
immler@34403
    69
wenzelm@34733
    70
wenzelm@43376
    71
class Document_View(val model: Document_Model, val text_area: JEditTextArea)
immler@34654
    72
{
wenzelm@34784
    73
  private val session = model.session
wenzelm@34784
    74
immler@34403
    75
wenzelm@43419
    76
  /* robust extension body */
wenzelm@43404
    77
wenzelm@43404
    78
  def robust_body[A](default: A)(body: => A): A =
wenzelm@43417
    79
  {
wenzelm@43417
    80
    try {
wenzelm@43417
    81
      Swing_Thread.require()
wenzelm@43417
    82
      if (model.buffer == text_area.getBuffer) body
wenzelm@43417
    83
      else {
wenzelm@43650
    84
        Log.log(Log.ERROR, this, ERROR("Inconsistent document model"))
wenzelm@43417
    85
        default
wenzelm@43404
    86
      }
wenzelm@43404
    87
    }
wenzelm@43417
    88
    catch { case t: Throwable => Log.log(Log.ERROR, this, t); default }
wenzelm@43417
    89
  }
wenzelm@43404
    90
wenzelm@43404
    91
wenzelm@44378
    92
  /* visible text range */
wenzelm@38881
    93
wenzelm@46815
    94
  // NB: TextArea.getScreenLineEndOffset of last line is beyond Buffer.getLength
wenzelm@38881
    95
  def proper_line_range(start: Text.Offset, end: Text.Offset): Text.Range =
wenzelm@46812
    96
    Text.Range(start, end min model.buffer.getLength)
wenzelm@38881
    97
wenzelm@46583
    98
  def visible_range(): Option[Text.Range] =
wenzelm@38881
    99
  {
wenzelm@46583
   100
    val n = text_area.getVisibleLines
wenzelm@46583
   101
    if (n > 0) {
wenzelm@46583
   102
      val start = text_area.getScreenLineStartOffset(0)
wenzelm@46583
   103
      val raw_end = text_area.getScreenLineEndOffset(n - 1)
wenzelm@46583
   104
      Some(proper_line_range(start, if (raw_end >= 0) raw_end else model.buffer.getLength))
wenzelm@46583
   105
    }
wenzelm@46583
   106
    else None
wenzelm@38881
   107
  }
wenzelm@38881
   108
wenzelm@44378
   109
  def invalidate_range(range: Text.Range)
wenzelm@39132
   110
  {
wenzelm@39132
   111
    text_area.invalidateLineRange(
wenzelm@39132
   112
      model.buffer.getLineOfOffset(range.start),
wenzelm@39132
   113
      model.buffer.getLineOfOffset(range.stop))
wenzelm@39132
   114
  }
wenzelm@39132
   115
wenzelm@38881
   116
wenzelm@44379
   117
  /* perspective */
wenzelm@44379
   118
wenzelm@44379
   119
  def perspective(): Text.Perspective =
wenzelm@44379
   120
  {
wenzelm@44379
   121
    Swing_Thread.require()
wenzelm@44776
   122
    val buffer_range = model.buffer_range()
wenzelm@44473
   123
    Text.Perspective(
wenzelm@44379
   124
      for {
wenzelm@44379
   125
        i <- 0 until text_area.getVisibleLines
wenzelm@46997
   126
        start = text_area.getScreenLineStartOffset(i)
wenzelm@46997
   127
        stop = text_area.getScreenLineEndOffset(i)
wenzelm@44379
   128
        if start >= 0 && stop >= 0
wenzelm@46997
   129
        range <- buffer_range.try_restrict(Text.Range(start, stop))
wenzelm@44583
   130
        if !range.is_singularity
wenzelm@44379
   131
      }
wenzelm@44583
   132
      yield range)
wenzelm@44379
   133
  }
wenzelm@44379
   134
wenzelm@44437
   135
  private def update_perspective = new TextAreaExtension
wenzelm@44437
   136
  {
wenzelm@44437
   137
    override def paintScreenLineRange(gfx: Graphics2D,
wenzelm@44437
   138
      first_line: Int, last_line: Int, physical_lines: Array[Int],
wenzelm@44437
   139
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
wenzelm@44437
   140
    {
wenzelm@44437
   141
      model.update_perspective()
wenzelm@44437
   142
    }
wenzelm@44437
   143
  }
wenzelm@44437
   144
wenzelm@44379
   145
wenzelm@39740
   146
  /* HTML popups */
wenzelm@39740
   147
wenzelm@39740
   148
  private var html_popup: Option[Popup] = None
wenzelm@34834
   149
wenzelm@39740
   150
  private def exit_popup() { html_popup.map(_.hide) }
wenzelm@38881
   151
wenzelm@39740
   152
  private val html_panel =
wenzelm@43661
   153
    new HTML_Panel(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
wenzelm@39741
   154
  html_panel.setBorder(BorderFactory.createLineBorder(Color.black))
wenzelm@38884
   155
wenzelm@39740
   156
  private def html_panel_resize()
wenzelm@39740
   157
  {
wenzelm@39740
   158
    Swing_Thread.now {
wenzelm@39740
   159
      html_panel.resize(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
wenzelm@39740
   160
    }
wenzelm@39740
   161
  }
wenzelm@38884
   162
wenzelm@39740
   163
  private def init_popup(snapshot: Document.Snapshot, x: Int, y: Int)
wenzelm@39740
   164
  {
wenzelm@39740
   165
    exit_popup()
wenzelm@40154
   166
/* FIXME broken
wenzelm@39740
   167
    val offset = text_area.xyToOffset(x, y)
wenzelm@39740
   168
    val p = new Point(x, y); SwingUtilities.convertPointToScreen(p, text_area.getPainter)
wenzelm@34784
   169
wenzelm@39740
   170
    // FIXME snapshot.cumulate
wenzelm@45665
   171
    snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Rendering.popup) match {
wenzelm@39740
   172
      case Text.Info(_, Some(msg)) #:: _ =>
wenzelm@39740
   173
        val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60)
wenzelm@39740
   174
        html_panel.render_sync(List(msg))
wenzelm@39742
   175
        Thread.sleep(10)  // FIXME !?
wenzelm@39740
   176
        popup.show
wenzelm@39740
   177
        html_popup = Some(popup)
wenzelm@39740
   178
      case _ =>
immler@34403
   179
    }
wenzelm@40154
   180
*/
immler@34678
   181
  }
immler@34403
   182
immler@34403
   183
wenzelm@48921
   184
  /* subexpression highlighting and hyperlinks */
wenzelm@39131
   185
wenzelm@46205
   186
  @volatile private var _highlight_range: Option[Text.Info[Color]] = None
wenzelm@46205
   187
  def highlight_range(): Option[Text.Info[Color]] = _highlight_range
wenzelm@39740
   188
wenzelm@48921
   189
  @volatile private var _hyperlink_range: Option[Text.Info[Hyperlink]] = None
wenzelm@48921
   190
  def hyperlink_range(): Option[Text.Info[Hyperlink]] = _hyperlink_range
wenzelm@48921
   191
wenzelm@40338
   192
  private var control: Boolean = false
wenzelm@40338
   193
wenzelm@39740
   194
  private def exit_control()
wenzelm@39740
   195
  {
wenzelm@39740
   196
    exit_popup()
wenzelm@43381
   197
    _highlight_range = None
wenzelm@48921
   198
    _hyperlink_range = None
wenzelm@39740
   199
  }
wenzelm@39740
   200
wenzelm@39131
   201
  private val focus_listener = new FocusAdapter {
wenzelm@39742
   202
    override def focusLost(e: FocusEvent) {
wenzelm@48921
   203
      // FIXME exit_control !?
wenzelm@48921
   204
      _highlight_range = None
wenzelm@48921
   205
      _hyperlink_range = None
wenzelm@39742
   206
    }
wenzelm@39131
   207
  }
wenzelm@39131
   208
wenzelm@39741
   209
  private val window_listener = new WindowAdapter {
wenzelm@39741
   210
    override def windowIconified(e: WindowEvent) { exit_control() }
wenzelm@39742
   211
    override def windowDeactivated(e: WindowEvent) { exit_control() }
wenzelm@39741
   212
  }
wenzelm@39741
   213
wenzelm@48921
   214
  private val mouse_listener = new MouseAdapter {
wenzelm@48921
   215
    override def mouseClicked(e: MouseEvent) {
wenzelm@48921
   216
      hyperlink_range match {
wenzelm@48921
   217
        case Some(Text.Info(range, link)) => link.follow(text_area.getView)
wenzelm@48921
   218
        case None =>
wenzelm@48921
   219
      }
wenzelm@48921
   220
    }
wenzelm@48921
   221
  }
wenzelm@48921
   222
wenzelm@39131
   223
  private val mouse_motion_listener = new MouseMotionAdapter {
wenzelm@39131
   224
    override def mouseMoved(e: MouseEvent) {
wenzelm@46920
   225
      Swing_Thread.assert()
wenzelm@46920
   226
wenzelm@40338
   227
      control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown
wenzelm@39740
   228
      val x = e.getX()
wenzelm@39740
   229
      val y = e.getY()
wenzelm@39740
   230
wenzelm@39740
   231
      if (!model.buffer.isLoaded) exit_control()
wenzelm@39132
   232
      else
wenzelm@46920
   233
        Isabelle.buffer_lock(model.buffer) {
wenzelm@47027
   234
          val snapshot = model.snapshot()
wenzelm@39740
   235
wenzelm@39740
   236
          if (control) init_popup(snapshot, x, y)
wenzelm@39740
   237
wenzelm@48921
   238
          def update_range[A](
wenzelm@48921
   239
            rendering: (Document.Snapshot, Text.Range) => Option[Text.Info[A]],
wenzelm@48921
   240
            info: Option[Text.Info[A]]): Option[Text.Info[A]] =
wenzelm@48921
   241
          {
wenzelm@48921
   242
            for (Text.Info(range, _) <- info) invalidate_range(range)
wenzelm@48921
   243
            val new_info =
wenzelm@48921
   244
              if (control) {
wenzelm@48921
   245
                val offset = text_area.xyToOffset(x, y)
wenzelm@48921
   246
                rendering(snapshot, Text.Range(offset, offset + 1))
wenzelm@48921
   247
              }
wenzelm@48921
   248
              else None
wenzelm@48921
   249
            for (Text.Info(range, _) <- info) invalidate_range(range)
wenzelm@48921
   250
            new_info
wenzelm@48921
   251
          }
wenzelm@48921
   252
          _highlight_range = update_range(Isabelle_Rendering.subexp, _highlight_range)
wenzelm@48921
   253
          _hyperlink_range = update_range(Isabelle_Rendering.hyperlink, _hyperlink_range)
wenzelm@39132
   254
        }
wenzelm@39131
   255
    }
wenzelm@39131
   256
  }
wenzelm@39131
   257
wenzelm@39131
   258
wenzelm@43381
   259
  /* text area painting */
wenzelm@39044
   260
wenzelm@43381
   261
  private val text_area_painter = new Text_Area_Painter(this)
wenzelm@39700
   262
wenzelm@43381
   263
  private val tooltip_painter = new TextAreaExtension
wenzelm@43381
   264
  {
wenzelm@34784
   265
    override def getToolTipText(x: Int, y: Int): String =
wenzelm@34784
   266
    {
wenzelm@43404
   267
      robust_body(null: String) {
wenzelm@47027
   268
        val snapshot = model.snapshot()
wenzelm@38845
   269
        val offset = text_area.xyToOffset(x, y)
wenzelm@45460
   270
        val range = Text.Range(offset, offset + 1)
wenzelm@46178
   271
        val tip =
wenzelm@46178
   272
          if (control) Isabelle_Rendering.tooltip(snapshot, range)
wenzelm@46178
   273
          else Isabelle_Rendering.tooltip_message(snapshot, range)
wenzelm@46178
   274
        tip.map(Isabelle.tooltip(_)) getOrElse null
wenzelm@34784
   275
      }
wenzelm@34734
   276
    }
immler@34678
   277
  }
immler@34513
   278
wenzelm@42825
   279
  private val gutter_painter = new TextAreaExtension
wenzelm@39175
   280
  {
wenzelm@39175
   281
    override def paintScreenLineRange(gfx: Graphics2D,
wenzelm@39175
   282
      first_line: Int, last_line: Int, physical_lines: Array[Int],
wenzelm@39175
   283
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
wenzelm@39175
   284
    {
wenzelm@43404
   285
      robust_body(()) {
wenzelm@46920
   286
        Swing_Thread.assert()
wenzelm@46920
   287
wenzelm@43404
   288
        val gutter = text_area.getGutter
wenzelm@43404
   289
        val width = GutterOptionPane.getSelectionAreaWidth
wenzelm@43404
   290
        val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3)
wenzelm@43404
   291
        val FOLD_MARKER_SIZE = 12
wenzelm@43419
   292
wenzelm@43404
   293
        if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) {
wenzelm@46920
   294
          Isabelle.buffer_lock(model.buffer) {
wenzelm@47027
   295
            val snapshot = model.snapshot()
wenzelm@43404
   296
            for (i <- 0 until physical_lines.length) {
wenzelm@43404
   297
              if (physical_lines(i) != -1) {
wenzelm@43404
   298
                val line_range = proper_line_range(start(i), end(i))
wenzelm@43419
   299
wenzelm@43404
   300
                // gutter icons
wenzelm@46178
   301
                Isabelle_Rendering.gutter_message(snapshot, line_range) match {
wenzelm@46178
   302
                  case Some(icon) =>
wenzelm@46227
   303
                    val x0 = (FOLD_MARKER_SIZE + width - border_width - icon.getIconWidth) max 10
wenzelm@46227
   304
                    val y0 = y + i * line_height + (((line_height - icon.getIconHeight) / 2) max 0)
wenzelm@46227
   305
                    icon.paintIcon(gutter, gfx, x0, y0)
wenzelm@46178
   306
                  case None =>
wenzelm@43404
   307
                }
wenzelm@39175
   308
              }
wenzelm@39175
   309
            }
wenzelm@39175
   310
          }
wenzelm@39175
   311
        }
wenzelm@39175
   312
      }
wenzelm@39175
   313
    }
wenzelm@39175
   314
  }
wenzelm@39175
   315
wenzelm@39175
   316
wenzelm@43448
   317
  /* caret range */
wenzelm@43448
   318
wenzelm@43448
   319
  def caret_range(): Text.Range =
wenzelm@46229
   320
    Isabelle.buffer_lock(model.buffer) {
wenzelm@46229
   321
      def text(i: Text.Offset): Char = model.buffer.getText(i, 1).charAt(0)
wenzelm@46229
   322
      val caret = text_area.getCaretPosition
wenzelm@46229
   323
      try {
wenzelm@46229
   324
        val c = text(caret)
wenzelm@46229
   325
        if (Character.isHighSurrogate(c) && Character.isLowSurrogate(text(caret + 1)))
wenzelm@46229
   326
          Text.Range(caret, caret + 2)
wenzelm@46229
   327
        else if (Character.isLowSurrogate(c) && Character.isHighSurrogate(text(caret - 1)))
wenzelm@46229
   328
          Text.Range(caret - 1, caret + 1)
wenzelm@46229
   329
        else Text.Range(caret, caret + 1)
wenzelm@46229
   330
      }
wenzelm@46229
   331
      catch { case _: ArrayIndexOutOfBoundsException => Text.Range(caret, caret + 1) }
wenzelm@43448
   332
    }
wenzelm@43448
   333
wenzelm@43448
   334
wenzelm@37129
   335
  /* caret handling */
wenzelm@34810
   336
wenzelm@37849
   337
  def selected_command(): Option[Command] =
wenzelm@38223
   338
  {
wenzelm@38223
   339
    Swing_Thread.require()
wenzelm@47027
   340
    model.snapshot().node.command_at(text_area.getCaretPosition).map(_._1)
wenzelm@38223
   341
  }
wenzelm@34810
   342
wenzelm@46740
   343
  private val delay_caret_update =
wenzelm@46740
   344
    Swing_Thread.delay_last(session.input_delay) {
wenzelm@44805
   345
      session.caret_focus.event(Session.Caret_Focus)
wenzelm@34810
   346
    }
wenzelm@46740
   347
wenzelm@46740
   348
  private val caret_listener = new CaretListener {
wenzelm@49195
   349
    override def caretUpdate(e: CaretEvent) { delay_caret_update.invoke() }
wenzelm@34810
   350
  }
wenzelm@34810
   351
wenzelm@34810
   352
wenzelm@46572
   353
  /* text status overview left of scrollbar */
wenzelm@34784
   354
wenzelm@47993
   355
  private object overview extends Text_Overview(this)
wenzelm@46572
   356
  {
wenzelm@46571
   357
    val delay_repaint =
wenzelm@46571
   358
      Swing_Thread.delay_first(Isabelle.session.update_delay) { repaint() }
wenzelm@34784
   359
  }
immler@34403
   360
wenzelm@34784
   361
wenzelm@39740
   362
  /* main actor */
wenzelm@39740
   363
wenzelm@39740
   364
  private val main_actor = actor {
wenzelm@39740
   365
    loop {
wenzelm@39740
   366
      react {
wenzelm@44608
   367
        case changed: Session.Commands_Changed =>
wenzelm@39740
   368
          val buffer = model.buffer
wenzelm@46918
   369
          Swing_Thread.later {
wenzelm@46918
   370
            Isabelle.buffer_lock(buffer) {
wenzelm@46918
   371
              if (model.buffer == text_area.getBuffer) {
wenzelm@47027
   372
                val snapshot = model.snapshot()
wenzelm@39740
   373
wenzelm@47027
   374
                if (changed.assignment ||
wenzelm@46918
   375
                    (changed.nodes.contains(model.name) &&
wenzelm@46918
   376
                     changed.commands.exists(snapshot.node.commands.contains)))
wenzelm@49195
   377
                  overview.delay_repaint.invoke()
wenzelm@39740
   378
wenzelm@46918
   379
                visible_range() match {
wenzelm@46918
   380
                  case Some(visible) =>
wenzelm@47027
   381
                    if (changed.assignment) invalidate_range(visible)
wenzelm@46918
   382
                    else {
wenzelm@46918
   383
                      val visible_cmds =
wenzelm@46918
   384
                        snapshot.node.command_range(snapshot.revert(visible)).map(_._1)
wenzelm@46918
   385
                      if (visible_cmds.exists(changed.commands)) {
wenzelm@46918
   386
                        for {
wenzelm@46918
   387
                          line <- 0 until text_area.getVisibleLines
wenzelm@46997
   388
                          start = text_area.getScreenLineStartOffset(line) if start >= 0
wenzelm@46997
   389
                          end = text_area.getScreenLineEndOffset(line) if end >= 0
wenzelm@46997
   390
                          range = proper_line_range(start, end)
wenzelm@46997
   391
                          line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1)
wenzelm@46918
   392
                          if line_cmds.exists(changed.commands)
wenzelm@46918
   393
                        } text_area.invalidateScreenLineRange(line, line)
wenzelm@46918
   394
                      }
wenzelm@46918
   395
                    }
wenzelm@46918
   396
                  case None =>
wenzelm@46583
   397
                }
wenzelm@46918
   398
              }
wenzelm@39740
   399
            }
wenzelm@39740
   400
          }
wenzelm@39740
   401
wenzelm@39740
   402
        case Session.Global_Settings => html_panel_resize()
wenzelm@39740
   403
wenzelm@39740
   404
        case bad => System.err.println("command_change_actor: ignoring bad message " + bad)
wenzelm@39740
   405
      }
wenzelm@39740
   406
    }
wenzelm@39740
   407
  }
wenzelm@39740
   408
wenzelm@39740
   409
wenzelm@34784
   410
  /* activation */
wenzelm@34784
   411
wenzelm@34808
   412
  private def activate()
wenzelm@34784
   413
  {
wenzelm@42825
   414
    val painter = text_area.getPainter
wenzelm@44437
   415
    painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_perspective)
wenzelm@43387
   416
    painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, tooltip_painter)
wenzelm@43381
   417
    text_area_painter.activate()
wenzelm@42825
   418
    text_area.getGutter.addExtension(gutter_painter)
wenzelm@39131
   419
    text_area.addFocusListener(focus_listener)
wenzelm@39741
   420
    text_area.getView.addWindowListener(window_listener)
wenzelm@48921
   421
    painter.addMouseListener(mouse_listener)
wenzelm@42825
   422
    painter.addMouseMotionListener(mouse_motion_listener)
wenzelm@34810
   423
    text_area.addCaretListener(caret_listener)
wenzelm@34810
   424
    text_area.addLeftOfScrollBar(overview)
wenzelm@39740
   425
    session.commands_changed += main_actor
wenzelm@39740
   426
    session.global_settings += main_actor
wenzelm@34784
   427
  }
wenzelm@34784
   428
wenzelm@34808
   429
  private def deactivate()
wenzelm@34784
   430
  {
wenzelm@42825
   431
    val painter = text_area.getPainter
wenzelm@39740
   432
    session.commands_changed -= main_actor
wenzelm@39740
   433
    session.global_settings -= main_actor
wenzelm@39131
   434
    text_area.removeFocusListener(focus_listener)
wenzelm@39741
   435
    text_area.getView.removeWindowListener(window_listener)
wenzelm@42825
   436
    painter.removeMouseMotionListener(mouse_motion_listener)
wenzelm@48921
   437
    painter.removeMouseListener(mouse_listener)
wenzelm@49195
   438
    text_area.removeCaretListener(caret_listener); delay_caret_update.revoke()
wenzelm@49195
   439
    text_area.removeLeftOfScrollBar(overview); overview.delay_repaint.revoke()
wenzelm@42825
   440
    text_area.getGutter.removeExtension(gutter_painter)
wenzelm@43381
   441
    text_area_painter.deactivate()
wenzelm@43381
   442
    painter.removeExtension(tooltip_painter)
wenzelm@44437
   443
    painter.removeExtension(update_perspective)
wenzelm@39740
   444
    exit_popup()
wenzelm@34784
   445
  }
wenzelm@42825
   446
}