src/Tools/jEdit/src/document_view.scala
author wenzelm
Wed Jun 15 13:36:08 2011 +0200 (2011-06-15 ago)
changeset 43393 f4141da52e92
parent 43392 fe4b8c52b1cc
child 43397 dba359c0ae3b
permissions -rw-r--r--
more precise caret painting, working around existing painter (which is reinstalled by jEdit occasionally);
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@34784
    13
import scala.actors.Actor._
wenzelm@34784
    14
wenzelm@39740
    15
import java.awt.{BorderLayout, Graphics, Color, Dimension, Graphics2D, Point}
wenzelm@39741
    16
import java.awt.event.{MouseAdapter, MouseMotionAdapter, MouseEvent,
wenzelm@39741
    17
  FocusAdapter, FocusEvent, WindowEvent, WindowAdapter}
wenzelm@39741
    18
import javax.swing.{JPanel, ToolTipManager, Popup, PopupFactory, SwingUtilities, BorderFactory}
wenzelm@34784
    19
import javax.swing.event.{CaretListener, CaretEvent}
wenzelm@34734
    20
wenzelm@42839
    21
import org.gjt.sp.jedit.{jEdit, OperatingSystem, Debug}
wenzelm@34709
    22
import org.gjt.sp.jedit.gui.RolloverButton
wenzelm@39176
    23
import org.gjt.sp.jedit.options.GutterOptionPane
wenzelm@34784
    24
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, TextAreaExtension, TextAreaPainter}
wenzelm@43369
    25
import org.gjt.sp.jedit.syntax.{SyntaxStyle}
wenzelm@34784
    26
wenzelm@34784
    27
wenzelm@34784
    28
object Document_View
wenzelm@34784
    29
{
wenzelm@34784
    30
  /* document view of text area */
wenzelm@34784
    31
wenzelm@34784
    32
  private val key = new Object
wenzelm@34784
    33
wenzelm@39741
    34
  def init(model: Document_Model, text_area: JEditTextArea): Document_View =
wenzelm@34784
    35
  {
wenzelm@38223
    36
    Swing_Thread.require()
wenzelm@34784
    37
    val doc_view = new Document_View(model, text_area)
wenzelm@34784
    38
    text_area.putClientProperty(key, doc_view)
wenzelm@34784
    39
    doc_view.activate()
wenzelm@34784
    40
    doc_view
wenzelm@34784
    41
  }
wenzelm@34784
    42
wenzelm@39741
    43
  def apply(text_area: JEditTextArea): Option[Document_View] =
wenzelm@34784
    44
  {
wenzelm@38223
    45
    Swing_Thread.require()
wenzelm@34784
    46
    text_area.getClientProperty(key) match {
wenzelm@34784
    47
      case doc_view: Document_View => Some(doc_view)
wenzelm@34784
    48
      case _ => None
wenzelm@34784
    49
    }
wenzelm@34784
    50
  }
wenzelm@34784
    51
wenzelm@39741
    52
  def exit(text_area: JEditTextArea)
wenzelm@34784
    53
  {
wenzelm@38223
    54
    Swing_Thread.require()
wenzelm@34788
    55
    apply(text_area) match {
wenzelm@39636
    56
      case None =>
wenzelm@34784
    57
      case Some(doc_view) =>
wenzelm@34784
    58
        doc_view.deactivate()
wenzelm@34784
    59
        text_area.putClientProperty(key, null)
wenzelm@34784
    60
    }
wenzelm@34784
    61
  }
wenzelm@34784
    62
}
immler@34403
    63
wenzelm@34733
    64
wenzelm@43376
    65
class Document_View(val model: Document_Model, val text_area: JEditTextArea)
immler@34654
    66
{
wenzelm@34784
    67
  private val session = model.session
wenzelm@34784
    68
immler@34403
    69
wenzelm@42838
    70
  /** token handling **/
wenzelm@42838
    71
wenzelm@38881
    72
  /* visible line ranges */
wenzelm@38881
    73
wenzelm@38883
    74
  // simplify slightly odd result of TextArea.getScreenLineEndOffset etc.
wenzelm@38881
    75
  // NB: jEdit already normalizes \r\n and \r to \n
wenzelm@38881
    76
  def proper_line_range(start: Text.Offset, end: Text.Offset): Text.Range =
wenzelm@38881
    77
  {
wenzelm@38883
    78
    val stop = if (start < end) end - 1 else end min model.buffer.getLength
wenzelm@38881
    79
    Text.Range(start, stop)
wenzelm@38881
    80
  }
wenzelm@38881
    81
wenzelm@38881
    82
  def screen_lines_range(): Text.Range =
wenzelm@38881
    83
  {
wenzelm@38881
    84
    val start = text_area.getScreenLineStartOffset(0)
wenzelm@38881
    85
    val raw_end = text_area.getScreenLineEndOffset(text_area.getVisibleLines - 1 max 0)
wenzelm@38881
    86
    proper_line_range(start, if (raw_end >= 0) raw_end else model.buffer.getLength)
wenzelm@38881
    87
  }
wenzelm@38881
    88
wenzelm@39132
    89
  def invalidate_line_range(range: Text.Range)
wenzelm@39132
    90
  {
wenzelm@39132
    91
    text_area.invalidateLineRange(
wenzelm@39132
    92
      model.buffer.getLineOfOffset(range.start),
wenzelm@39132
    93
      model.buffer.getLineOfOffset(range.stop))
wenzelm@39132
    94
  }
wenzelm@39132
    95
wenzelm@38881
    96
wenzelm@39740
    97
  /* HTML popups */
wenzelm@39740
    98
wenzelm@39740
    99
  private var html_popup: Option[Popup] = None
wenzelm@34834
   100
wenzelm@39740
   101
  private def exit_popup() { html_popup.map(_.hide) }
wenzelm@38881
   102
wenzelm@39740
   103
  private val html_panel =
wenzelm@39741
   104
    new HTML_Panel(Isabelle.system, Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
wenzelm@39741
   105
  html_panel.setBorder(BorderFactory.createLineBorder(Color.black))
wenzelm@38884
   106
wenzelm@39740
   107
  private def html_panel_resize()
wenzelm@39740
   108
  {
wenzelm@39740
   109
    Swing_Thread.now {
wenzelm@39740
   110
      html_panel.resize(Isabelle.font_family(), scala.math.round(Isabelle.font_size()))
wenzelm@39740
   111
    }
wenzelm@39740
   112
  }
wenzelm@38884
   113
wenzelm@39740
   114
  private def init_popup(snapshot: Document.Snapshot, x: Int, y: Int)
wenzelm@39740
   115
  {
wenzelm@39740
   116
    exit_popup()
wenzelm@40154
   117
/* FIXME broken
wenzelm@39740
   118
    val offset = text_area.xyToOffset(x, y)
wenzelm@39740
   119
    val p = new Point(x, y); SwingUtilities.convertPointToScreen(p, text_area.getPainter)
wenzelm@34784
   120
wenzelm@39740
   121
    // FIXME snapshot.cumulate
wenzelm@39740
   122
    snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.popup) match {
wenzelm@39740
   123
      case Text.Info(_, Some(msg)) #:: _ =>
wenzelm@39740
   124
        val popup = PopupFactory.getSharedInstance().getPopup(text_area, html_panel, p.x, p.y + 60)
wenzelm@39740
   125
        html_panel.render_sync(List(msg))
wenzelm@39742
   126
        Thread.sleep(10)  // FIXME !?
wenzelm@39740
   127
        popup.show
wenzelm@39740
   128
        html_popup = Some(popup)
wenzelm@39740
   129
      case _ =>
immler@34403
   130
    }
wenzelm@40154
   131
*/
immler@34678
   132
  }
immler@34403
   133
immler@34403
   134
wenzelm@39131
   135
  /* subexpression highlighting */
wenzelm@39131
   136
wenzelm@39178
   137
  private def subexp_range(snapshot: Document.Snapshot, x: Int, y: Int)
wenzelm@39178
   138
    : Option[(Text.Range, Color)] =
wenzelm@39132
   139
  {
wenzelm@39132
   140
    val offset = text_area.xyToOffset(x, y)
wenzelm@39178
   141
    snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.subexp) match {
wenzelm@39178
   142
      case Text.Info(_, Some((range, color))) #:: _ => Some((snapshot.convert(range), color))
wenzelm@39177
   143
      case _ => None
wenzelm@39177
   144
    }
wenzelm@39132
   145
  }
wenzelm@39132
   146
wenzelm@43381
   147
  @volatile private var _highlight_range: Option[(Text.Range, Color)] = None
wenzelm@43381
   148
  def highlight_range(): Option[(Text.Range, Color)] = _highlight_range
wenzelm@39131
   149
wenzelm@39740
   150
wenzelm@39740
   151
  /* CONTROL-mouse management */
wenzelm@39740
   152
wenzelm@40338
   153
  private var control: Boolean = false
wenzelm@40338
   154
wenzelm@39740
   155
  private def exit_control()
wenzelm@39740
   156
  {
wenzelm@39740
   157
    exit_popup()
wenzelm@43381
   158
    _highlight_range = None
wenzelm@39740
   159
  }
wenzelm@39740
   160
wenzelm@39131
   161
  private val focus_listener = new FocusAdapter {
wenzelm@39742
   162
    override def focusLost(e: FocusEvent) {
wenzelm@43381
   163
      _highlight_range = None // FIXME exit_control !?
wenzelm@39742
   164
    }
wenzelm@39131
   165
  }
wenzelm@39131
   166
wenzelm@39741
   167
  private val window_listener = new WindowAdapter {
wenzelm@39741
   168
    override def windowIconified(e: WindowEvent) { exit_control() }
wenzelm@39742
   169
    override def windowDeactivated(e: WindowEvent) { exit_control() }
wenzelm@39741
   170
  }
wenzelm@39741
   171
wenzelm@39131
   172
  private val mouse_motion_listener = new MouseMotionAdapter {
wenzelm@39131
   173
    override def mouseMoved(e: MouseEvent) {
wenzelm@40338
   174
      control = if (OperatingSystem.isMacOS()) e.isMetaDown else e.isControlDown
wenzelm@39740
   175
      val x = e.getX()
wenzelm@39740
   176
      val y = e.getY()
wenzelm@39740
   177
wenzelm@39740
   178
      if (!model.buffer.isLoaded) exit_control()
wenzelm@39132
   179
      else
wenzelm@39132
   180
        Isabelle.swing_buffer_lock(model.buffer) {
wenzelm@39740
   181
          val snapshot = model.snapshot
wenzelm@39740
   182
wenzelm@39740
   183
          if (control) init_popup(snapshot, x, y)
wenzelm@39740
   184
wenzelm@43381
   185
          _highlight_range map { case (range, _) => invalidate_line_range(range) }
wenzelm@43381
   186
          _highlight_range = if (control) subexp_range(snapshot, x, y) else None
wenzelm@43381
   187
          _highlight_range map { case (range, _) => invalidate_line_range(range) }
wenzelm@39132
   188
        }
wenzelm@39131
   189
    }
wenzelm@39131
   190
  }
wenzelm@39131
   191
wenzelm@39131
   192
wenzelm@43381
   193
  /* text area painting */
wenzelm@39044
   194
wenzelm@43381
   195
  private val text_area_painter = new Text_Area_Painter(this)
wenzelm@39700
   196
wenzelm@43381
   197
  private val tooltip_painter = new TextAreaExtension
wenzelm@43381
   198
  {
wenzelm@34784
   199
    override def getToolTipText(x: Int, y: Int): String =
wenzelm@34784
   200
    {
wenzelm@38845
   201
      Isabelle.swing_buffer_lock(model.buffer) {
wenzelm@38845
   202
        val snapshot = model.snapshot()
wenzelm@38845
   203
        val offset = text_area.xyToOffset(x, y)
wenzelm@40338
   204
        if (control) {
wenzelm@40338
   205
          snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.tooltip) match
wenzelm@40338
   206
          {
wenzelm@40338
   207
            case Text.Info(_, Some(text)) #:: _ => Isabelle.tooltip(text)
wenzelm@40338
   208
            case _ => null
wenzelm@40338
   209
          }
wenzelm@40338
   210
        }
wenzelm@40338
   211
        else {
wenzelm@40338
   212
          // FIXME snapshot.cumulate
wenzelm@40338
   213
          snapshot.select_markup(Text.Range(offset, offset + 1))(Isabelle_Markup.popup) match
wenzelm@40338
   214
          {
wenzelm@40338
   215
            case Text.Info(_, Some(text)) #:: _ => Isabelle.tooltip(text)
wenzelm@40338
   216
            case _ => null
wenzelm@40338
   217
          }
wenzelm@39174
   218
        }
wenzelm@34784
   219
      }
wenzelm@34734
   220
    }
immler@34678
   221
  }
immler@34513
   222
wenzelm@42825
   223
  private val gutter_painter = new TextAreaExtension
wenzelm@39175
   224
  {
wenzelm@39175
   225
    override def paintScreenLineRange(gfx: Graphics2D,
wenzelm@39175
   226
      first_line: Int, last_line: Int, physical_lines: Array[Int],
wenzelm@39175
   227
      start: Array[Int], end: Array[Int], y: Int, line_height: Int)
wenzelm@39175
   228
    {
wenzelm@39176
   229
      val gutter = text_area.getGutter
wenzelm@39176
   230
      val width = GutterOptionPane.getSelectionAreaWidth
wenzelm@39176
   231
      val border_width = jEdit.getIntegerProperty("view.gutter.borderWidth", 3)
wenzelm@39176
   232
      val FOLD_MARKER_SIZE = 12
wenzelm@39176
   233
wenzelm@39176
   234
      if (gutter.isSelectionAreaEnabled && !gutter.isExpanded && width >= 12 && line_height >= 12) {
wenzelm@39176
   235
        Isabelle.swing_buffer_lock(model.buffer) {
wenzelm@39176
   236
          val snapshot = model.snapshot()
wenzelm@39175
   237
          for (i <- 0 until physical_lines.length) {
wenzelm@39175
   238
            if (physical_lines(i) != -1) {
wenzelm@39175
   239
              val line_range = proper_line_range(start(i), end(i))
wenzelm@39175
   240
wenzelm@39175
   241
              // gutter icons
wenzelm@39181
   242
              val icons =
wenzelm@39740
   243
                (for (Text.Info(_, Some(icon)) <- // FIXME snapshot.cumulate
wenzelm@39181
   244
                  snapshot.select_markup(line_range)(Isabelle_Markup.gutter_message).iterator)
wenzelm@39181
   245
                yield icon).toList.sortWith(_ >= _)
wenzelm@39181
   246
              icons match {
wenzelm@39181
   247
                case icon :: _ =>
wenzelm@39181
   248
                  val icn = icon.icon
wenzelm@39181
   249
                  val x0 = (FOLD_MARKER_SIZE + width - border_width - icn.getIconWidth) max 10
wenzelm@39181
   250
                  val y0 = y + i * line_height + (((line_height - icn.getIconHeight) / 2) max 0)
wenzelm@39181
   251
                  icn.paintIcon(gutter, gfx, x0, y0)
wenzelm@39181
   252
                case Nil =>
wenzelm@39175
   253
              }
wenzelm@39175
   254
            }
wenzelm@39175
   255
          }
wenzelm@39175
   256
        }
wenzelm@39175
   257
      }
wenzelm@39175
   258
    }
wenzelm@39175
   259
  }
wenzelm@39175
   260
wenzelm@39175
   261
wenzelm@37129
   262
  /* caret handling */
wenzelm@34810
   263
wenzelm@37849
   264
  def selected_command(): Option[Command] =
wenzelm@38223
   265
  {
wenzelm@38223
   266
    Swing_Thread.require()
wenzelm@38151
   267
    model.snapshot().node.proper_command_at(text_area.getCaretPosition)
wenzelm@38223
   268
  }
wenzelm@34810
   269
wenzelm@37849
   270
  private val caret_listener = new CaretListener {
wenzelm@37849
   271
    private val delay = Swing_Thread.delay_last(session.input_delay) {
wenzelm@37849
   272
      session.perspective.event(Session.Perspective)
wenzelm@34810
   273
    }
wenzelm@37849
   274
    override def caretUpdate(e: CaretEvent) { delay() }
wenzelm@34810
   275
  }
wenzelm@34810
   276
wenzelm@34810
   277
wenzelm@34784
   278
  /* overview of command status left of scrollbar */
wenzelm@34784
   279
wenzelm@34834
   280
  private val overview = new JPanel(new BorderLayout)
wenzelm@34784
   281
  {
wenzelm@34784
   282
    private val WIDTH = 10
wenzelm@34784
   283
    private val HEIGHT = 2
wenzelm@34784
   284
wenzelm@34806
   285
    setPreferredSize(new Dimension(WIDTH, 0))
wenzelm@34806
   286
wenzelm@34784
   287
    setRequestFocusEnabled(false)
wenzelm@34784
   288
wenzelm@34784
   289
    addMouseListener(new MouseAdapter {
wenzelm@34784
   290
      override def mousePressed(event: MouseEvent) {
wenzelm@34784
   291
        val line = y_to_line(event.getY)
wenzelm@34784
   292
        if (line >= 0 && line < text_area.getLineCount)
wenzelm@34784
   293
          text_area.setCaretPosition(text_area.getLineStartOffset(line))
wenzelm@34784
   294
      }
wenzelm@34784
   295
    })
wenzelm@34784
   296
wenzelm@34784
   297
    override def addNotify() {
wenzelm@34784
   298
      super.addNotify()
wenzelm@34784
   299
      ToolTipManager.sharedInstance.registerComponent(this)
wenzelm@34784
   300
    }
immler@34403
   301
wenzelm@34784
   302
    override def removeNotify() {
wenzelm@34784
   303
      ToolTipManager.sharedInstance.unregisterComponent(this)
wenzelm@34784
   304
      super.removeNotify
wenzelm@34784
   305
    }
wenzelm@34784
   306
wenzelm@34784
   307
    override def paintComponent(gfx: Graphics)
wenzelm@34784
   308
    {
wenzelm@34784
   309
      super.paintComponent(gfx)
wenzelm@38640
   310
      Swing_Thread.assert()
wenzelm@39737
   311
wenzelm@34784
   312
      val buffer = model.buffer
wenzelm@38843
   313
      Isabelle.buffer_lock(buffer) {
wenzelm@38640
   314
        val snapshot = model.snapshot()
wenzelm@39737
   315
wenzelm@39737
   316
        def line_range(command: Command, start: Text.Offset): Option[(Int, Int)] =
wenzelm@39737
   317
        {
wenzelm@39737
   318
          try {
wenzelm@39737
   319
            val line1 = buffer.getLineOfOffset(snapshot.convert(start))
wenzelm@39737
   320
            val line2 = buffer.getLineOfOffset(snapshot.convert(start + command.length)) + 1
wenzelm@39737
   321
            Some((line1, line2))
wenzelm@39737
   322
          }
wenzelm@39737
   323
          catch { case e: ArrayIndexOutOfBoundsException => None }
wenzelm@39737
   324
        }
wenzelm@39182
   325
        for {
wenzelm@39182
   326
          (command, start) <- snapshot.node.command_starts
wenzelm@39182
   327
          if !command.is_ignored
wenzelm@39737
   328
          (line1, line2) <- line_range(command, start)
wenzelm@39182
   329
          val y = line_to_y(line1)
wenzelm@39182
   330
          val height = HEIGHT * (line2 - line1)
wenzelm@39182
   331
          color <- Isabelle_Markup.overview_color(snapshot, command)
wenzelm@39182
   332
        } {
wenzelm@39182
   333
          gfx.setColor(color)
wenzelm@39182
   334
          gfx.fillRect(0, y, getWidth - 1, height)
wenzelm@37188
   335
        }
wenzelm@34784
   336
      }
wenzelm@34784
   337
    }
wenzelm@34784
   338
wenzelm@34784
   339
    private def line_to_y(line: Int): Int =
wenzelm@34784
   340
      (line * getHeight) / (text_area.getBuffer.getLineCount max text_area.getVisibleLines)
wenzelm@34784
   341
wenzelm@34784
   342
    private def y_to_line(y: Int): Int =
wenzelm@34784
   343
      (y * (text_area.getBuffer.getLineCount max text_area.getVisibleLines)) / getHeight
wenzelm@34784
   344
  }
immler@34403
   345
wenzelm@34784
   346
wenzelm@39740
   347
  /* main actor */
wenzelm@39740
   348
wenzelm@39740
   349
  private val main_actor = actor {
wenzelm@39740
   350
    loop {
wenzelm@39740
   351
      react {
wenzelm@39740
   352
        case Session.Commands_Changed(changed) =>
wenzelm@39740
   353
          val buffer = model.buffer
wenzelm@39740
   354
          Isabelle.swing_buffer_lock(buffer) {
wenzelm@39740
   355
            val snapshot = model.snapshot()
wenzelm@39740
   356
wenzelm@39740
   357
            if (changed.exists(snapshot.node.commands.contains))
wenzelm@39740
   358
              overview.repaint()
wenzelm@39740
   359
wenzelm@39740
   360
            val visible_range = screen_lines_range()
wenzelm@39740
   361
            val visible_cmds = snapshot.node.command_range(snapshot.revert(visible_range)).map(_._1)
wenzelm@39740
   362
            if (visible_cmds.exists(changed)) {
wenzelm@39740
   363
              for {
wenzelm@39740
   364
                line <- 0 until text_area.getVisibleLines
wenzelm@39740
   365
                val start = text_area.getScreenLineStartOffset(line) if start >= 0
wenzelm@39740
   366
                val end = text_area.getScreenLineEndOffset(line) if end >= 0
wenzelm@39740
   367
                val range = proper_line_range(start, end)
wenzelm@39740
   368
                val line_cmds = snapshot.node.command_range(snapshot.revert(range)).map(_._1)
wenzelm@39740
   369
                if line_cmds.exists(changed)
wenzelm@39740
   370
              } text_area.invalidateScreenLineRange(line, line)
wenzelm@39740
   371
wenzelm@39740
   372
              // FIXME danger of deadlock!?
wenzelm@39740
   373
              // FIXME potentially slow!?
wenzelm@39740
   374
              model.buffer.propertiesChanged()
wenzelm@39740
   375
            }
wenzelm@39740
   376
          }
wenzelm@39740
   377
wenzelm@39740
   378
        case Session.Global_Settings => html_panel_resize()
wenzelm@39740
   379
wenzelm@39740
   380
        case bad => System.err.println("command_change_actor: ignoring bad message " + bad)
wenzelm@39740
   381
      }
wenzelm@39740
   382
    }
wenzelm@39740
   383
  }
wenzelm@39740
   384
wenzelm@39740
   385
wenzelm@34784
   386
  /* activation */
wenzelm@34784
   387
wenzelm@34808
   388
  private def activate()
wenzelm@34784
   389
  {
wenzelm@42825
   390
    val painter = text_area.getPainter
wenzelm@43387
   391
    painter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, tooltip_painter)
wenzelm@43381
   392
    text_area_painter.activate()
wenzelm@42825
   393
    text_area.getGutter.addExtension(gutter_painter)
wenzelm@39131
   394
    text_area.addFocusListener(focus_listener)
wenzelm@39741
   395
    text_area.getView.addWindowListener(window_listener)
wenzelm@42825
   396
    painter.addMouseMotionListener(mouse_motion_listener)
wenzelm@34810
   397
    text_area.addCaretListener(caret_listener)
wenzelm@34810
   398
    text_area.addLeftOfScrollBar(overview)
wenzelm@39740
   399
    session.commands_changed += main_actor
wenzelm@39740
   400
    session.global_settings += main_actor
wenzelm@34784
   401
  }
wenzelm@34784
   402
wenzelm@34808
   403
  private def deactivate()
wenzelm@34784
   404
  {
wenzelm@42825
   405
    val painter = text_area.getPainter
wenzelm@39740
   406
    session.commands_changed -= main_actor
wenzelm@39740
   407
    session.global_settings -= main_actor
wenzelm@39131
   408
    text_area.removeFocusListener(focus_listener)
wenzelm@39741
   409
    text_area.getView.removeWindowListener(window_listener)
wenzelm@42825
   410
    painter.removeMouseMotionListener(mouse_motion_listener)
wenzelm@39131
   411
    text_area.removeCaretListener(caret_listener)
wenzelm@34810
   412
    text_area.removeLeftOfScrollBar(overview)
wenzelm@42825
   413
    text_area.getGutter.removeExtension(gutter_painter)
wenzelm@43381
   414
    text_area_painter.deactivate()
wenzelm@43381
   415
    painter.removeExtension(tooltip_painter)
wenzelm@39740
   416
    exit_popup()
wenzelm@34784
   417
  }
wenzelm@42825
   418
}