src/Tools/jEdit/src/jedit/PhaseOverviewPanel.scala
author wenzelm
Mon Dec 29 21:01:55 2008 +0100 (2008-12-29)
changeset 34458 e2aa32bb73c0
parent 34456 14367c0715e8
child 34503 7d0726f19d04
permissions -rw-r--r--
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm@34408
     1
/*
wenzelm@34458
     2
 * Information on command status left of scrollbar (with panel)
wenzelm@34408
     3
 *
wenzelm@34408
     4
 * @author Fabian Immler, TU Munich
wenzelm@34408
     5
 */
wenzelm@34408
     6
immler@34403
     7
package isabelle.jedit
immler@34403
     8
immler@34403
     9
import isabelle.prover.Command
immler@34404
    10
import isabelle.utils.Delay
immler@34403
    11
immler@34403
    12
import javax.swing._
immler@34403
    13
import java.awt.event._
immler@34403
    14
import java.awt._
immler@34403
    15
import org.gjt.sp.jedit.gui.RolloverButton;
immler@34403
    16
import org.gjt.sp.jedit.textarea.JEditTextArea;
immler@34404
    17
import org.gjt.sp.jedit.buffer.JEditBuffer;
immler@34403
    18
import org.gjt.sp.jedit._
immler@34403
    19
immler@34406
    20
class PhaseOverviewPanel(prover : isabelle.prover.Prover) extends JPanel(new BorderLayout) {
immler@34403
    21
immler@34403
    22
  private val WIDTH = 10
immler@34403
    23
	private val HILITE_HEIGHT = 2
immler@34406
    24
  var textarea : JEditTextArea = null
immler@34403
    25
immler@34406
    26
  val repaint_delay = new isabelle.utils.Delay(100, () => repaint())
wenzelm@34456
    27
  prover.command_info += (_ => repaint_delay.delay_or_ignore())
immler@34406
    28
    
immler@34403
    29
  setRequestFocusEnabled(false);
immler@34403
    30
immler@34403
    31
  addMouseListener(new MouseAdapter {
immler@34403
    32
    override def mousePressed(evt : MouseEvent) {
immler@34403
    33
      val line = yToLine(evt.getY)
immler@34403
    34
      if(line >= 0 && line < textarea.getLineCount())
immler@34403
    35
        textarea.setCaretPosition(textarea.getLineStartOffset(line))
immler@34403
    36
    }
immler@34403
    37
  })
immler@34403
    38
immler@34403
    39
	override def addNotify	{
immler@34403
    40
		super.addNotify();
immler@34403
    41
		ToolTipManager.sharedInstance.registerComponent(this);
immler@34403
    42
	}
immler@34403
    43
immler@34403
    44
	override def removeNotify()
immler@34403
    45
	{
immler@34403
    46
		super.removeNotify
immler@34403
    47
		ToolTipManager.sharedInstance.unregisterComponent(this);
immler@34403
    48
	}
immler@34403
    49
immler@34403
    50
	override def getToolTipText(evt : MouseEvent) : String =
immler@34403
    51
	{
immler@34403
    52
		val buffer = textarea.getBuffer
immler@34403
    53
		val lineCount = buffer.getLineCount
immler@34403
    54
		val line = yToLine(evt.getY())
immler@34403
    55
		if(line >= 0 && line < textarea.getLineCount)
immler@34403
    56
		{
immler@34403
    57
      "TODO: Tooltip"
immler@34403
    58
    } else ""
immler@34403
    59
	}
immler@34403
    60
immler@34404
    61
  private def paintCommand(command : Command, buffer : JEditBuffer, gfx : Graphics) {
immler@34404
    62
      val line1 = buffer.getLineOfOffset(command.start)
immler@34404
    63
      val line2 = buffer.getLineOfOffset(command.stop - 1) + 1
immler@34404
    64
      val y = lineToY(line1)
immler@34404
    65
      val height = lineToY(line2) - y - 1
wenzelm@34458
    66
      val (light, dark) = command.status match {
wenzelm@34458
    67
        case Command.Status.UNPROCESSED => (Color.yellow, new Color(128,128,0))
wenzelm@34458
    68
        case Command.Status.FINISHED => (Color.green, new Color(0, 128, 0))
wenzelm@34458
    69
        case Command.Status.FAILED => (Color.red, new Color(128,0,0))
immler@34404
    70
      }
immler@34404
    71
immler@34404
    72
      gfx.setColor(light)
immler@34404
    73
      gfx.fillRect(0, y, getWidth - 1, 1 max height)
immler@34404
    74
      if(height > 2){
immler@34404
    75
        gfx.setColor(dark)
immler@34404
    76
        gfx.drawRect(0, y, getWidth - 1, height)
immler@34404
    77
      }
immler@34404
    78
immler@34404
    79
  }
immler@34404
    80
immler@34403
    81
	override def paintComponent(gfx : Graphics) {
immler@34403
    82
		super.paintComponent(gfx)
immler@34403
    83
immler@34403
    84
		val buffer = textarea.getBuffer
immler@34406
    85
    for(c <- prover.document.commands)
immler@34404
    86
      paintCommand(c, buffer, gfx)
immler@34406
    87
    
immler@34403
    88
	}
immler@34403
    89
immler@34403
    90
	override def getPreferredSize : Dimension =
immler@34403
    91
	{
immler@34403
    92
		new Dimension(10,0)
immler@34403
    93
	}
immler@34403
    94
immler@34403
    95
immler@34403
    96
	private def lineToY(line : Int) : Int =
immler@34403
    97
	{
immler@34403
    98
		(line * getHeight) / textarea.getBuffer.getLineCount
immler@34403
    99
	}
immler@34403
   100
immler@34403
   101
	private def yToLine(y : Int) : Int =
immler@34403
   102
	{
immler@34403
   103
		(y * textarea.getBuffer.getLineCount) / getHeight
immler@34403
   104
	}
immler@34403
   105
immler@34403
   106
}