src/Tools/jEdit/src/document_view.scala
changeset 46227 4aa84f84d5e8
parent 46205 07e334ad2e2a
child 46229 d8286601e7df
equal deleted inserted replaced
46226:e88e980ed735 46227:4aa84f84d5e8
   298                 val line_range = proper_line_range(start(i), end(i))
   298                 val line_range = proper_line_range(start(i), end(i))
   299 
   299 
   300                 // gutter icons
   300                 // gutter icons
   301                 Isabelle_Rendering.gutter_message(snapshot, line_range) match {
   301                 Isabelle_Rendering.gutter_message(snapshot, line_range) match {
   302                   case Some(icon) =>
   302                   case Some(icon) =>
   303                     val icn = icon.icon
   303                     val x0 = (FOLD_MARKER_SIZE + width - border_width - icon.getIconWidth) max 10
   304                     val x0 = (FOLD_MARKER_SIZE + width - border_width - icn.getIconWidth) max 10
   304                     val y0 = y + i * line_height + (((line_height - icon.getIconHeight) / 2) max 0)
   305                     val y0 = y + i * line_height + (((line_height - icn.getIconHeight) / 2) max 0)
   305                     icon.paintIcon(gutter, gfx, x0, y0)
   306                     icn.paintIcon(gutter, gfx, x0, y0)
       
   307                   case None =>
   306                   case None =>
   308                 }
   307                 }
   309               }
   308               }
   310             }
   309             }
   311           }
   310           }
   353   private val overview = new JPanel(new BorderLayout)
   352   private val overview = new JPanel(new BorderLayout)
   354   {
   353   {
   355     private val WIDTH = 10
   354     private val WIDTH = 10
   356     private val HEIGHT = 2
   355     private val HEIGHT = 2
   357 
   356 
       
   357     private def line_to_y(line: Int): Int =
       
   358       (line * getHeight) / (text_area.getBuffer.getLineCount max text_area.getVisibleLines)
       
   359 
       
   360     private def y_to_line(y: Int): Int =
       
   361       (y * (text_area.getBuffer.getLineCount max text_area.getVisibleLines)) / getHeight
       
   362 
   358     setPreferredSize(new Dimension(WIDTH, 0))
   363     setPreferredSize(new Dimension(WIDTH, 0))
   359 
   364 
   360     setRequestFocusEnabled(false)
   365     setRequestFocusEnabled(false)
   361 
   366 
   362     addMouseListener(new MouseAdapter {
   367     addMouseListener(new MouseAdapter {
   384 
   389 
   385       val buffer = model.buffer
   390       val buffer = model.buffer
   386       Isabelle.buffer_lock(buffer) {
   391       Isabelle.buffer_lock(buffer) {
   387         val snapshot = update_snapshot()
   392         val snapshot = update_snapshot()
   388 
   393 
   389         def line_range(command: Command, start: Text.Offset): Option[(Int, Int)] =
   394         for {
   390         {
   395           line <- 0 until buffer.getLineCount
   391           try {
   396           range <-
   392             val line1 = buffer.getLineOfOffset(snapshot.convert(start))
   397             try {
   393             val line2 = buffer.getLineOfOffset(snapshot.convert(start + command.length)) + 1
   398               Some(proper_line_range(buffer.getLineStartOffset(line), buffer.getLineEndOffset(line)))
   394             Some((line1, line2))
   399             }
   395           }
   400             catch { case e: ArrayIndexOutOfBoundsException => None }
   396           catch { case e: ArrayIndexOutOfBoundsException => None }
   401           color <- Isabelle_Rendering.overview_color(snapshot, range)
       
   402         } {
       
   403           val y = line_to_y(line)
       
   404           val h = (line_to_y(line + 1) - y) max 2
       
   405           gfx.setColor(color)
       
   406           gfx.fillRect(0, y, getWidth - 1, h)
   397         }
   407         }
   398         for {
   408       }
   399           (command, start) <- snapshot.node.command_starts
   409     }
   400           if !command.is_ignored
       
   401           (line1, line2) <- line_range(command, start)
       
   402           val y = line_to_y(line1)
       
   403           val height = HEIGHT * (line2 - line1)
       
   404           color <- Isabelle_Rendering.overview_color(snapshot, command)
       
   405         } {
       
   406           gfx.setColor(color)
       
   407           gfx.fillRect(0, y, getWidth - 1, height)
       
   408         }
       
   409       }
       
   410     }
       
   411 
       
   412     private def line_to_y(line: Int): Int =
       
   413       (line * getHeight) / (text_area.getBuffer.getLineCount max text_area.getVisibleLines)
       
   414 
       
   415     private def y_to_line(y: Int): Int =
       
   416       (y * (text_area.getBuffer.getLineCount max text_area.getVisibleLines)) / getHeight
       
   417   }
   410   }
   418 
   411 
   419 
   412 
   420   /* main actor */
   413   /* main actor */
   421 
   414