src/Tools/jEdit/src/jedit/TheoryView.scala
changeset 34391 7b5f44553aaf
parent 34387 d67fe0cb1106
child 34392 a02d46bca7e4
equal deleted inserted replaced
34390:fe1afce19eb1 34391:7b5f44553aaf
    29         case Phase.FINISHED => new Color(192, 255, 192)
    29         case Phase.FINISHED => new Color(192, 255, 192)
    30         case Phase.FAILED => new Color(255, 192, 192)
    30         case Phase.FAILED => new Color(255, 192, 192)
    31         case _ => Color.red
    31         case _ => Color.red
    32       }
    32       }
    33   }
    33   }
    34   
    34 
       
    35   def chooseColor(status : String) : Color = {
       
    36     //TODO: as properties!
       
    37     status match {
       
    38       case "ident" => new Color(192, 192, 255)
       
    39       case "literal" => new Color(192, 255, 255)
       
    40       case "fixed_decl" => new Color(192, 192, 192)
       
    41       case "prop" => new Color(255, 192 ,255)
       
    42       case "typ" => new Color(192, 192, 128)
       
    43       case "term" => new Color(192, 128, 192)
       
    44       case "method" => new Color(128, 192, 192)
       
    45       case "doc_source" => new Color(128, 128, 192)
       
    46       case "ML_source" => new Color(128, 192, 128)
       
    47       case "local_fact_decl" => new Color(192, 128, 128)
       
    48       case _ => Color.red
       
    49     }
       
    50   }
    35   def withView(view : TextArea, f : (TheoryView) => Unit) {
    51   def withView(view : TextArea, f : (TheoryView) => Unit) {
    36     if (view != null && view.getBuffer() != null)
    52     if (view != null && view.getBuffer() != null)
    37       view.getBuffer().getProperty(ISABELLE_THEORY_PROPERTY) match {
    53       view.getBuffer().getProperty(ISABELLE_THEORY_PROPERTY) match {
    38         case null => null
    54         case null => null
    39         case view: TheoryView => f(view)
    55         case view: TheoryView => f(view)
   145   {
   161   {
   146     if (textArea != null)
   162     if (textArea != null)
   147       textArea.invalidateLineRange(textArea.getFirstPhysicalLine, 
   163       textArea.invalidateLineRange(textArea.getFirstPhysicalLine, 
   148                                    textArea.getLastPhysicalLine)
   164                                    textArea.getLastPhysicalLine)
   149   }
   165   }
   150   
   166 
       
   167   def encolor(gfx : Graphics2D, y : Int, height : Int, begin : Int, finish : Int, color : Color){
       
   168       val fm = textArea.getPainter.getFontMetrics
       
   169       val startP = textArea.offsetToXY(begin)
       
   170       val stopP = if (finish < buffer.getLength()) textArea.offsetToXY(finish)
       
   171                   else { var p = textArea.offsetToXY(finish - 1)
       
   172                          p.x = p.x + fm.charWidth(' ')
       
   173                          p }
       
   174 			
       
   175       if (startP != null && stopP != null) {
       
   176         gfx.setColor(color)
       
   177         gfx.fillRect(startP.x, y, stopP.x - startP.x, height)
       
   178       }
       
   179   }
       
   180 
   151   override def paintValidLine(gfx : Graphics2D, screenLine : Int,
   181   override def paintValidLine(gfx : Graphics2D, screenLine : Int,
   152                               pl : Int, start : Int, end : Int, y : Int)
   182                               pl : Int, start : Int, end : Int, y : Int)
   153   {	
   183   {	
   154     var fm = textArea.getPainter().getFontMetrics()
   184     val fm = textArea.getPainter.getFontMetrics
   155     var savedColor = gfx.getColor()
   185     var savedColor = gfx.getColor
   156     var e = prover.document.getNextCommandContaining(fromCurrent(start))
   186     var e = prover.document.getNextCommandContaining(fromCurrent(start))
   157     
   187 
       
   188     //Encolor Phase
   158     while (e != null && toCurrent(e.start) < end) {
   189     while (e != null && toCurrent(e.start) < end) {
   159       val begin = Math.max(start, toCurrent(e.start))
   190       val begin = Math.max(start, toCurrent(e.start))
   160       val startP = textArea.offsetToXY(begin)
       
   161 
       
   162       val finish = Math.min(end - 1, toCurrent(e.stop))
   191       val finish = Math.min(end - 1, toCurrent(e.stop))
   163       val stopP = if (finish < buffer.getLength()) textArea.offsetToXY(finish) 
   192       encolor(gfx, y, fm.getHeight, begin, finish, chooseColor(e))
   164                   else { var p = textArea.offsetToXY(finish - 1) 
   193       // paint details of command
   165                          p.x = p.x + fm.charWidth(' ') 
   194       var dy = 0
   166                          p }
   195       for(status <- e.statuses){
   167 			
   196         dy += 1
   168       if (startP != null && stopP != null) {
   197         val begin = Math.max(start, toCurrent(status.start + e.start))
   169         gfx.setColor(chooseColor(e))
   198         val finish = Math.min(end - 1, toCurrent(status.stop + e.start))
   170         gfx.fillRect(startP.x, y, stopP.x - startP.x, fm.getHeight())
   199         encolor(gfx, y + dy, fm.getHeight - dy, begin, finish, chooseColor(status.kind))
   171       }
   200       }
   172       
       
   173       e = e.next
   201       e = e.next
   174     }
   202     }
   175     
   203 
   176     gfx.setColor(savedColor)
   204     gfx.setColor(savedColor)
   177   }
   205   }
   178 	
   206 	
   179   def content(start : Int, stop : Int) = buffer.getText(start, stop - start)
   207   def content(start : Int, stop : Int) = buffer.getText(start, stop - start)
   180   def length = buffer.getLength()
   208   def length = buffer.getLength()