src/Tools/jEdit/src/isabelle_rendering.scala
changeset 46227 4aa84f84d5e8
parent 46224 9cb98d34f593
child 46228 302d3ecff25d
equal deleted inserted replaced
46226:e88e980ed735 46227:4aa84f84d5e8
     8 
     8 
     9 
     9 
    10 import isabelle._
    10 import isabelle._
    11 
    11 
    12 import java.awt.Color
    12 import java.awt.Color
       
    13 import javax.swing.Icon
    13 
    14 
    14 import org.lobobrowser.util.gui.ColorFactory
    15 import org.lobobrowser.util.gui.ColorFactory
    15 import org.gjt.sp.jedit.syntax.{Token => JEditToken}
    16 import org.gjt.sp.jedit.syntax.{Token => JEditToken}
    16 
    17 
    17 import scala.collection.immutable.SortedMap
    18 import scala.collection.immutable.SortedMap
    30   val unprocessed1_color = new Color(255, 160, 160, 50)
    31   val unprocessed1_color = new Color(255, 160, 160, 50)
    31   val running_color = new Color(97, 0, 97)
    32   val running_color = new Color(97, 0, 97)
    32   val running1_color = new Color(97, 0, 97, 100)
    33   val running1_color = new Color(97, 0, 97, 100)
    33 
    34 
    34   val light_color = new Color(240, 240, 240)
    35   val light_color = new Color(240, 240, 240)
    35   val regular_color = new Color(192, 192, 192)
    36   val writeln_color = new Color(192, 192, 192)
    36   val warning_color = new Color(255, 140, 0)
    37   val warning_color = new Color(255, 140, 0)
    37   val error_color = new Color(178, 34, 34)
    38   val error_color = new Color(178, 34, 34)
    38   val error1_color = new Color(178, 34, 34, 50)
    39   val error1_color = new Color(178, 34, 34, 50)
    39   val bad_color = new Color(255, 106, 106, 100)
    40   val bad_color = new Color(255, 106, 106, 100)
    40   val hilite_color = new Color(255, 204, 102, 100)
    41   val hilite_color = new Color(255, 204, 102, 100)
    43   val subexp_color = new Color(80, 80, 80, 50)
    44   val subexp_color = new Color(80, 80, 80, 50)
    44 
    45 
    45   val keyword1_color = get_color("#006699")
    46   val keyword1_color = get_color("#006699")
    46   val keyword2_color = get_color("#009966")
    47   val keyword2_color = get_color("#009966")
    47 
    48 
    48   class Icon(val priority: Int, val icon: javax.swing.Icon)
    49   private val writeln_pri = 1
    49   {
    50   private val warning_pri = 2
    50     def >= (that: Icon): Boolean = this.priority >= that.priority
    51   private val legacy_pri = 3
    51   }
    52   private val error_pri = 4
    52   val warning_icon = new Icon(1, Isabelle.load_icon("16x16/status/dialog-information.png"))
       
    53   val legacy_icon = new Icon(2, Isabelle.load_icon("16x16/status/dialog-warning.png"))
       
    54   val error_icon = new Icon(3, Isabelle.load_icon("16x16/status/dialog-error.png"))
       
    55 
    53 
    56 
    54 
    57   /* command overview */
    55   /* command overview */
    58 
    56 
    59   def overview_color(snapshot: Document.Snapshot, command: Command): Option[Color] =
    57   def overview_color(snapshot: Document.Snapshot, range: Text.Range): Option[Color] =
    60   {
    58   {
    61     if (snapshot.is_outdated) None
    59     if (snapshot.is_outdated) None
    62     else {
    60     else {
    63       val state = snapshot.state.command_state(snapshot.version, command)
    61       val results =
    64       val status = Protocol.command_status(state.status)
    62         snapshot.cumulate_markup[(Protocol.Status, Int)](
    65 
    63           range, (Protocol.Status.init, 0),
    66       if (status.is_unprocessed) Some(unprocessed_color)
    64           Some(Protocol.command_status_markup + Isabelle_Markup.WARNING + Isabelle_Markup.ERROR),
    67       else if (status.is_running) Some(running_color)
    65           {
    68       else if (status.is_finished) {
    66             case ((status, pri), Text.Info(_, XML.Elem(markup, _))) =>
    69         if (state.results.exists(r => Protocol.is_error(r._2))) Some(error_color)
    67               if (markup.name == Isabelle_Markup.WARNING) (status, pri max warning_pri)
    70         else if (state.results.exists(r => Protocol.is_warning(r._2))) Some(warning_color)
    68               else if (markup.name == Isabelle_Markup.ERROR) (status, pri max error_pri)
       
    69               else (Protocol.command_status(status, markup), pri)
       
    70           })
       
    71       if (results.isEmpty) None
       
    72       else {
       
    73         val (status, pri) =
       
    74           ((Protocol.Status.init, 0) /: results) {
       
    75             case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) }
       
    76 
       
    77         if (pri == warning_pri) Some(warning_color)
       
    78         else if (pri == error_pri) Some(error_color)
       
    79         else if (status.is_unprocessed) Some(unprocessed_color)
       
    80         else if (status.is_running) Some(running_color)
       
    81         else if (status.is_failed) Some(error_color)
    71         else None
    82         else None
    72       }
    83       }
    73       else if (status.is_failed) Some(error_color)
       
    74       else None
       
    75     }
    84     }
    76   }
    85   }
    77 
    86 
    78 
    87 
    79   /* markup selectors */
    88   /* markup selectors */
    92               Pretty.string_of(List(msg), margin = Isabelle.Int_Property("tooltip-margin")))
   101               Pretty.string_of(List(msg), margin = Isabelle.Int_Property("tooltip-margin")))
    93         }).toList.flatMap(_.info)
   102         }).toList.flatMap(_.info)
    94     if (msgs.isEmpty) None else Some(cat_lines(msgs.iterator.map(_._2)))
   103     if (msgs.isEmpty) None else Some(cat_lines(msgs.iterator.map(_._2)))
    95   }
   104   }
    96 
   105 
       
   106   private val gutter_icons = Map(
       
   107     warning_pri -> Isabelle.load_icon("16x16/status/dialog-information.png"),
       
   108     legacy_pri -> Isabelle.load_icon("16x16/status/dialog-warning.png"),
       
   109     error_pri -> Isabelle.load_icon("16x16/status/dialog-error.png"))
       
   110 
    97   def gutter_message(snapshot: Document.Snapshot, range: Text.Range): Option[Icon] =
   111   def gutter_message(snapshot: Document.Snapshot, range: Text.Range): Option[Icon] =
    98     snapshot.select_markup(range,
   112   {
    99       Some(Set(Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)),
   113     val results =
   100       {
   114       snapshot.cumulate_markup[Int](range, 0,
   101         case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.WARNING, _), body)) =>
   115         Some(Set(Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)),
   102           body match {
   116         {
   103             case List(XML.Elem(Markup(Isabelle_Markup.LEGACY, _), _)) => legacy_icon
   117           case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.WARNING, _), body))) =>
   104             case _ => warning_icon
   118             body match {
   105           }
   119               case List(XML.Elem(Markup(Isabelle_Markup.LEGACY, _), _)) => pri max legacy_pri
   106         case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ERROR, _), _)) => error_icon
   120               case _ => pri max warning_pri
   107       }).map(_.info).toList.sortWith(_ >= _).headOption
   121             }
       
   122           case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ERROR, _), _))) =>
       
   123             pri max error_pri
       
   124         })
       
   125     val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
       
   126     gutter_icons.get(pri)
       
   127   }
       
   128 
       
   129   private val squiggly_colors = Map(
       
   130     writeln_pri -> writeln_color,
       
   131     warning_pri -> warning_color,
       
   132     error_pri -> error_color)
   108 
   133 
   109   def squiggly_underline(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] =
   134   def squiggly_underline(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] =
   110     snapshot.select_markup(range,
   135   {
   111       Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)),
   136     val results =
   112       {
   137       snapshot.cumulate_markup[Int](range, 0,
   113         case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.WRITELN, _), _)) => regular_color
   138         Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)),
   114         case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.WARNING, _), _)) => warning_color
   139         {
   115         case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ERROR, _), _)) => error_color
   140           case (pri, Text.Info(_, XML.Elem(Markup(name, _), _))) =>
   116       })
   141             name match {
       
   142               case Isabelle_Markup.WRITELN => pri max writeln_pri
       
   143               case Isabelle_Markup.WARNING => pri max warning_pri
       
   144               case Isabelle_Markup.ERROR => pri max error_pri
       
   145               case _ => pri
       
   146             }
       
   147         })
       
   148     for {
       
   149       Text.Info(r, pri) <- results
       
   150       color <- squiggly_colors.get(pri)
       
   151     } yield Text.Info(r, color)
       
   152   }
   117 
   153 
   118   def background1(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] =
   154   def background1(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] =
   119     for {
   155     for {
   120       Text.Info(r, result) <-
   156       Text.Info(r, result) <-
   121         snapshot.cumulate_markup[(Option[Protocol.Status], Option[Color])](
   157         snapshot.cumulate_markup[(Option[Protocol.Status], Option[Color])](
   122           range, (Some(Protocol.Status()), None),
   158           range, (Some(Protocol.Status.init), None),
   123           Some(Protocol.command_status_markup + Isabelle_Markup.BAD + Isabelle_Markup.HILITE),
   159           Some(Protocol.command_status_markup + Isabelle_Markup.BAD + Isabelle_Markup.HILITE),
   124           {
   160           {
   125             case (((Some(status), color), Text.Info(_, XML.Elem(markup, _))))
   161             case (((Some(status), color), Text.Info(_, XML.Elem(markup, _))))
   126             if (Protocol.command_status_markup(markup.name)) =>
   162             if (Protocol.command_status_markup(markup.name)) =>
   127               (Some(Protocol.command_status(status, markup)), color)
   163               (Some(Protocol.command_status(status, markup)), color)