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