src/Tools/jEdit/src/text_overview.scala
changeset 75393 87ebf5a50283
parent 73367 77ef8bef0593
child 75394 42267c650205
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
    14 import java.awt.{Graphics, Graphics2D, BorderLayout, Dimension, Color}
    14 import java.awt.{Graphics, Graphics2D, BorderLayout, Dimension, Color}
    15 import java.awt.event.{MouseAdapter, MouseEvent}
    15 import java.awt.event.{MouseAdapter, MouseEvent}
    16 import javax.swing.{JPanel, ToolTipManager}
    16 import javax.swing.{JPanel, ToolTipManager}
    17 
    17 
    18 
    18 
    19 class Text_Overview(doc_view: Document_View) extends JPanel(new BorderLayout)
    19 class Text_Overview(doc_view: Document_View) extends JPanel(new BorderLayout) {
    20 {
       
    21   /* GUI components */
    20   /* GUI components */
    22 
    21 
    23   private val text_area = doc_view.text_area
    22   private val text_area = doc_view.text_area
    24   private val buffer = doc_view.model.buffer
    23   private val buffer = doc_view.model.buffer
    25 
    24 
    31   setPreferredSize(new Dimension(WIDTH, 0))
    30   setPreferredSize(new Dimension(WIDTH, 0))
    32 
    31 
    33   setRequestFocusEnabled(false)
    32   setRequestFocusEnabled(false)
    34 
    33 
    35   addMouseListener(new MouseAdapter {
    34   addMouseListener(new MouseAdapter {
    36     override def mousePressed(event: MouseEvent): Unit =
    35     override def mousePressed(event: MouseEvent): Unit = {
    37     {
       
    38       val line = (event.getY * lines()) / getHeight
    36       val line = (event.getY * lines()) / getHeight
    39       if (line >= 0 && line < text_area.getLineCount)
    37       if (line >= 0 && line < text_area.getLineCount)
    40         text_area.setCaretPosition(text_area.getLineStartOffset(line))
    38         text_area.setCaretPosition(text_area.getLineStartOffset(line))
    41     }
    39     }
    42   })
    40   })
    43 
    41 
    44   override def addNotify(): Unit =
    42   override def addNotify(): Unit = {
    45   {
       
    46     super.addNotify()
    43     super.addNotify()
    47     ToolTipManager.sharedInstance.registerComponent(this)
    44     ToolTipManager.sharedInstance.registerComponent(this)
    48   }
    45   }
    49 
    46 
    50   override def removeNotify(): Unit =
    47   override def removeNotify(): Unit = {
    51   {
       
    52     ToolTipManager.sharedInstance.unregisterComponent(this)
    48     ToolTipManager.sharedInstance.unregisterComponent(this)
    53     super.removeNotify
    49     super.removeNotify
    54   }
    50   }
    55 
    51 
    56 
    52 
    78   private var current_overview = Overview()
    74   private var current_overview = Overview()
    79 
    75 
    80   private val delay_repaint =
    76   private val delay_repaint =
    81     Delay.first(PIDE.options.seconds("editor_update_delay"), gui = true) { repaint() }
    77     Delay.first(PIDE.options.seconds("editor_update_delay"), gui = true) { repaint() }
    82 
    78 
    83   override def paintComponent(gfx: Graphics): Unit =
    79   override def paintComponent(gfx: Graphics): Unit = {
    84   {
       
    85     super.paintComponent(gfx)
    80     super.paintComponent(gfx)
    86     GUI_Thread.assert {}
    81     GUI_Thread.assert {}
    87 
    82 
    88     doc_view.rich_text_area.robust_body(()) {
    83     doc_view.rich_text_area.robust_body(()) {
    89       JEdit_Lib.buffer_lock(buffer) {
    84       JEdit_Lib.buffer_lock(buffer) {
   126           val rendering = doc_view.get_rendering()
   121           val rendering = doc_view.get_rendering()
   127           val overview = get_overview()
   122           val overview = get_overview()
   128 
   123 
   129           if (rendering.snapshot.is_outdated || is_running()) invoke()
   124           if (rendering.snapshot.is_outdated || is_running()) invoke()
   130           else {
   125           else {
   131             val line_offsets =
   126             val line_offsets = {
   132             {
       
   133               val line_manager = JEdit_Lib.buffer_line_manager(buffer)
   127               val line_manager = JEdit_Lib.buffer_line_manager(buffer)
   134               val a = new Array[Int](line_manager.getLineCount)
   128               val a = new Array[Int](line_manager.getLineCount)
   135               for (i <- 1 until a.length) a(i) = line_manager.getLineEndOffset(i - 1)
   129               for (i <- 1 until a.length) a(i) = line_manager.getLineEndOffset(i - 1)
   136               a
   130               a
   137             }
   131             }
   141                 val line_count = overview.line_count
   135                 val line_count = overview.line_count
   142                 val char_count = overview.char_count
   136                 val char_count = overview.char_count
   143                 val L = overview.L
   137                 val L = overview.L
   144                 val H = overview.H
   138                 val H = overview.H
   145 
   139 
   146                 @tailrec def loop(l: Int, h: Int, p: Int, q: Int, colors: List[Color_Info])
   140                 @tailrec def loop(
   147                   : List[Color_Info] =
   141                   l: Int,
   148                 {
   142                   h: Int,
       
   143                   p: Int,
       
   144                   q: Int,
       
   145                   colors: List[Color_Info]
       
   146                 ): List[Color_Info] = {
   149                   Exn.Interrupt.expose()
   147                   Exn.Interrupt.expose()
   150 
   148 
   151                   if (l < line_count && h < H) {
   149                   if (l < line_count && h < H) {
   152                     val p1 = p + H
   150                     val p1 = p + H
   153                     val q1 = q + HEIGHT * L
   151                     val q1 = q + HEIGHT * L