src/Tools/jEdit/src/document_view.scala
author wenzelm
Fri Sep 14 13:52:16 2012 +0200 (2012-09-14)
changeset 49356 6e0c0ffb6ec7
parent 49288 2c9272cb4568
child 49357 34ac36642a31
permissions -rw-r--r--
more static handling of rendering options;
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@49356
   235
          val rendering = Isabelle_Rendering(snapshot, Isabelle.options.value)
wenzelm@39740
   236
wenzelm@39740
   237
          if (control) init_popup(snapshot, x, y)
wenzelm@39740
   238
wenzelm@48921
   239
          def update_range[A](
wenzelm@49356
   240
            rendering: Text.Range => Option[Text.Info[A]],
wenzelm@48921
   241
            info: Option[Text.Info[A]]): Option[Text.Info[A]] =
wenzelm@48921
   242
          {
wenzelm@48921
   243
            for (Text.Info(range, _) <- info) invalidate_range(range)
wenzelm@48921
   244
            val new_info =
wenzelm@48921
   245
              if (control) {
wenzelm@48921
   246
                val offset = text_area.xyToOffset(x, y)
wenzelm@49356
   247
                rendering(Text.Range(offset, offset + 1))
wenzelm@48921
   248
              }
wenzelm@48921
   249
              else None
wenzelm@48921
   250
            for (Text.Info(range, _) <- info) invalidate_range(range)
wenzelm@48921
   251
            new_info
wenzelm@48921
   252
          }
wenzelm@49356
   253
          _highlight_range = update_range(rendering.subexp, _highlight_range)
wenzelm@49356
   254
          _hyperlink_range = update_range(rendering.hyperlink, _hyperlink_range)
wenzelm@39132
   255
        }
wenzelm@39131
   256
    }
wenzelm@39131
   257
  }
wenzelm@39131
   258
wenzelm@39131
   259
wenzelm@43381
   260
  /* text area painting */
wenzelm@39044
   261
wenzelm@43381
   262
  private val text_area_painter = new Text_Area_Painter(this)
wenzelm@39700
   263
wenzelm@43381
   264
  private val tooltip_painter = new TextAreaExtension
wenzelm@43381
   265
  {
wenzelm@34784
   266
    override def getToolTipText(x: Int, y: Int): String =
wenzelm@34784
   267
    {
wenzelm@43404
   268
      robust_body(null: String) {
wenzelm@49356
   269
        val rendering = Isabelle_Rendering(model.snapshot(), Isabelle.options.value)
wenzelm@38845
   270
        val offset = text_area.xyToOffset(x, y)
wenzelm@45460
   271
        val range = Text.Range(offset, offset + 1)
wenzelm@46178
   272
        val tip =
wenzelm@49356
   273
          if (control) rendering.tooltip(range)
wenzelm@49356
   274
          else rendering.tooltip_message(range)
wenzelm@46178
   275
        tip.map(Isabelle.tooltip(_)) getOrElse null
wenzelm@34784
   276
      }
wenzelm@34734
   277
    }
immler@34678
   278
  }
immler@34513
   279
wenzelm@42825
   280
  private val gutter_painter = new TextAreaExtension
wenzelm@39175
   281
  {
wenzelm@39175
   282
    override def paintScreenLineRange(gfx: Graphics2D,
wenzelm@39175
   283
      first_line: Int, last_line: Int, physical_lines: Array[Int],
wenzelm@39175
   284
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
wenzelm@39175
   285
    {
wenzelm@43404
   286
      robust_body(()) {
wenzelm@46920
   287
        Swing_Thread.assert()
wenzelm@46920
   288
wenzelm@43404
   289
        val gutter = text_area.getGutter
wenzelm@43404
   290
        val width = GutterOptionPane.getSelectionAreaWidth
wenzelm@43404
   291
        val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3)
wenzelm@43404
   292
        val FOLD_MARKER_SIZE = 12
wenzelm@43419
   293
wenzelm@43404
   294
        if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) {
wenzelm@46920
   295
          Isabelle.buffer_lock(model.buffer) {
wenzelm@49356
   296
            val rendering = Isabelle_Rendering(model.snapshot(), Isabelle.options.value)
wenzelm@49356
   297
wenzelm@43404
   298
            for (i <- 0 until physical_lines.length) {
wenzelm@43404
   299
              if (physical_lines(i) != -1) {
wenzelm@43404
   300
                val line_range = proper_line_range(start(i), end(i))
wenzelm@43419
   301
wenzelm@43404
   302
                // gutter icons
wenzelm@49356
   303
                rendering.gutter_message(line_range) match {
wenzelm@46178
   304
                  case Some(icon) =>
wenzelm@46227
   305
                    val x0 = (FOLD_MARKER_SIZE + width - border_width - icon.getIconWidth) max 10
wenzelm@46227
   306
                    val y0 = y + i * line_height + (((line_height - icon.getIconHeight) / 2) max 0)
wenzelm@46227
   307
                    icon.paintIcon(gutter, gfx, x0, y0)
wenzelm@46178
   308
                  case None =>
wenzelm@43404
   309
                }
wenzelm@39175
   310
              }
wenzelm@39175
   311
            }
wenzelm@39175
   312
          }
wenzelm@39175
   313
        }
wenzelm@39175
   314
      }
wenzelm@39175
   315
    }
wenzelm@39175
   316
  }
wenzelm@39175
   317
wenzelm@39175
   318
wenzelm@43448
   319
  /* caret range */
wenzelm@43448
   320
wenzelm@43448
   321
  def caret_range(): Text.Range =
wenzelm@46229
   322
    Isabelle.buffer_lock(model.buffer) {
wenzelm@46229
   323
      def text(i: Text.Offset): Char = model.buffer.getText(i, 1).charAt(0)
wenzelm@46229
   324
      val caret = text_area.getCaretPosition
wenzelm@46229
   325
      try {
wenzelm@46229
   326
        val c = text(caret)
wenzelm@46229
   327
        if (Character.isHighSurrogate(c) && Character.isLowSurrogate(text(caret + 1)))
wenzelm@46229
   328
          Text.Range(caret, caret + 2)
wenzelm@46229
   329
        else if (Character.isLowSurrogate(c) && Character.isHighSurrogate(text(caret - 1)))
wenzelm@46229
   330
          Text.Range(caret - 1, caret + 1)
wenzelm@46229
   331
        else Text.Range(caret, caret + 1)
wenzelm@46229
   332
      }
wenzelm@46229
   333
      catch { case _: ArrayIndexOutOfBoundsException => Text.Range(caret, caret + 1) }
wenzelm@43448
   334
    }
wenzelm@43448
   335
wenzelm@43448
   336
wenzelm@37129
   337
  /* caret handling */
wenzelm@34810
   338
wenzelm@37849
   339
  def selected_command(): Option[Command] =
wenzelm@38223
   340
  {
wenzelm@38223
   341
    Swing_Thread.require()
wenzelm@47027
   342
    model.snapshot().node.command_at(text_area.getCaretPosition).map(_._1)
wenzelm@38223
   343
  }
wenzelm@34810
   344
wenzelm@46740
   345
  private val delay_caret_update =
wenzelm@49288
   346
    Swing_Thread.delay_last(Time.seconds(Isabelle.options.real("editor_input_delay"))) {
wenzelm@44805
   347
      session.caret_focus.event(Session.Caret_Focus)
wenzelm@34810
   348
    }
wenzelm@46740
   349
wenzelm@46740
   350
  private val caret_listener = new CaretListener {
wenzelm@49195
   351
    override def caretUpdate(e: CaretEvent) { delay_caret_update.invoke() }
wenzelm@34810
   352
  }
wenzelm@34810
   353
wenzelm@34810
   354
wenzelm@46572
   355
  /* text status overview left of scrollbar */
wenzelm@34784
   356
wenzelm@47993
   357
  private object overview extends Text_Overview(this)
wenzelm@46572
   358
  {
wenzelm@46571
   359
    val delay_repaint =
wenzelm@49288
   360
      Swing_Thread.delay_first(
wenzelm@49288
   361
        Time.seconds(Isabelle.options.real("editor_update_delay"))) { repaint() }
wenzelm@34784
   362
  }
immler@34403
   363
wenzelm@34784
   364
wenzelm@39740
   365
  /* main actor */
wenzelm@39740
   366
wenzelm@39740
   367
  private val main_actor = actor {
wenzelm@39740
   368
    loop {
wenzelm@39740
   369
      react {
wenzelm@49196
   370
        case _: Session.Raw_Edits =>
wenzelm@49196
   371
          Swing_Thread.later {
wenzelm@49288
   372
            overview.delay_repaint.postpone(
wenzelm@49288
   373
              Time.seconds(Isabelle.options.real("editor_input_delay")))
wenzelm@49196
   374
          }
wenzelm@49196
   375
wenzelm@44608
   376
        case changed: Session.Commands_Changed =>
wenzelm@39740
   377
          val buffer = model.buffer
wenzelm@46918
   378
          Swing_Thread.later {
wenzelm@46918
   379
            Isabelle.buffer_lock(buffer) {
wenzelm@46918
   380
              if (model.buffer == text_area.getBuffer) {
wenzelm@47027
   381
                val snapshot = model.snapshot()
wenzelm@39740
   382
wenzelm@47027
   383
                if (changed.assignment ||
wenzelm@46918
   384
                    (changed.nodes.contains(model.name) &&
wenzelm@46918
   385
                     changed.commands.exists(snapshot.node.commands.contains)))
wenzelm@49196
   386
                  Swing_Thread.later { overview.delay_repaint.invoke() }
wenzelm@39740
   387
wenzelm@46918
   388
                visible_range() match {
wenzelm@46918
   389
                  case Some(visible) =>
wenzelm@47027
   390
                    if (changed.assignment) invalidate_range(visible)
wenzelm@46918
   391
                    else {
wenzelm@46918
   392
                      val visible_cmds =
wenzelm@46918
   393
                        snapshot.node.command_range(snapshot.revert(visible)).map(_._1)
wenzelm@46918
   394
                      if (visible_cmds.exists(changed.commands)) {
wenzelm@46918
   395
                        for {
wenzelm@46918
   396
                          line <- 0 until text_area.getVisibleLines
wenzelm@46997
   397
                          start = text_area.getScreenLineStartOffset(line) if start >= 0
wenzelm@46997
   398
                          end = text_area.getScreenLineEndOffset(line) if end >= 0
wenzelm@46997
   399
                          range = proper_line_range(start, end)
wenzelm@46997
   400
                          line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1)
wenzelm@46918
   401
                          if line_cmds.exists(changed.commands)
wenzelm@46918
   402
                        } text_area.invalidateScreenLineRange(line, line)
wenzelm@46918
   403
                      }
wenzelm@46918
   404
                    }
wenzelm@46918
   405
                  case None =>
wenzelm@46583
   406
                }
wenzelm@46918
   407
              }
wenzelm@39740
   408
            }
wenzelm@39740
   409
          }
wenzelm@39740
   410
wenzelm@39740
   411
        case Session.Global_Settings => html_panel_resize()
wenzelm@39740
   412
wenzelm@39740
   413
        case bad => System.err.println("command_change_actor: ignoring bad message " + bad)
wenzelm@39740
   414
      }
wenzelm@39740
   415
    }
wenzelm@39740
   416
  }
wenzelm@39740
   417
wenzelm@39740
   418
wenzelm@34784
   419
  /* activation */
wenzelm@34784
   420
wenzelm@34808
   421
  private def activate()
wenzelm@34784
   422
  {
wenzelm@42825
   423
    val painter = text_area.getPainter
wenzelm@44437
   424
    painter.addExtension(TextAreaPainter.LOWEST_LAYER, update_perspective)
wenzelm@43387
   425
    painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, tooltip_painter)
wenzelm@43381
   426
    text_area_painter.activate()
wenzelm@42825
   427
    text_area.getGutter.addExtension(gutter_painter)
wenzelm@39131
   428
    text_area.addFocusListener(focus_listener)
wenzelm@39741
   429
    text_area.getView.addWindowListener(window_listener)
wenzelm@48921
   430
    painter.addMouseListener(mouse_listener)
wenzelm@42825
   431
    painter.addMouseMotionListener(mouse_motion_listener)
wenzelm@34810
   432
    text_area.addCaretListener(caret_listener)
wenzelm@34810
   433
    text_area.addLeftOfScrollBar(overview)
wenzelm@49196
   434
    session.raw_edits += main_actor
wenzelm@39740
   435
    session.commands_changed += main_actor
wenzelm@39740
   436
    session.global_settings += main_actor
wenzelm@34784
   437
  }
wenzelm@34784
   438
wenzelm@34808
   439
  private def deactivate()
wenzelm@34784
   440
  {
wenzelm@42825
   441
    val painter = text_area.getPainter
wenzelm@49196
   442
    session.raw_edits -= main_actor
wenzelm@39740
   443
    session.commands_changed -= main_actor
wenzelm@39740
   444
    session.global_settings -= main_actor
wenzelm@39131
   445
    text_area.removeFocusListener(focus_listener)
wenzelm@39741
   446
    text_area.getView.removeWindowListener(window_listener)
wenzelm@42825
   447
    painter.removeMouseMotionListener(mouse_motion_listener)
wenzelm@48921
   448
    painter.removeMouseListener(mouse_listener)
wenzelm@49195
   449
    text_area.removeCaretListener(caret_listener); delay_caret_update.revoke()
wenzelm@49195
   450
    text_area.removeLeftOfScrollBar(overview); overview.delay_repaint.revoke()
wenzelm@42825
   451
    text_area.getGutter.removeExtension(gutter_painter)
wenzelm@43381
   452
    text_area_painter.deactivate()
wenzelm@43381
   453
    painter.removeExtension(tooltip_painter)
wenzelm@44437
   454
    painter.removeExtension(update_perspective)
wenzelm@39740
   455
    exit_popup()
wenzelm@34784
   456
  }
wenzelm@42825
   457
}