src/Tools/jEdit/src/pretty_text_area.scala
changeset 49412 4cac648e0f85
parent 49398 0fa4389c04f9
child 49413 8c9925d31617
equal deleted inserted replaced
49411:1da54e9bda68 49412:4cac648e0f85
     8 
     8 
     9 
     9 
    10 import isabelle._
    10 import isabelle._
    11 
    11 
    12 import java.awt.{Font, FontMetrics}
    12 import java.awt.{Font, FontMetrics}
       
    13 
       
    14 import org.gjt.sp.jedit.{jEdit, View}
    13 import org.gjt.sp.jedit.textarea.{AntiAlias, JEditEmbeddedTextArea}
    15 import org.gjt.sp.jedit.textarea.{AntiAlias, JEditEmbeddedTextArea}
    14 import org.gjt.sp.jedit.jEdit
       
    15 import org.gjt.sp.util.SyntaxUtilities
    16 import org.gjt.sp.util.SyntaxUtilities
       
    17 
    16 import scala.swing.{BorderPanel, Component}
    18 import scala.swing.{BorderPanel, Component}
    17 
    19 
    18 
    20 
    19 class Pretty_Text_Area extends BorderPanel
    21 object Pretty_Text_Area
       
    22 {
       
    23   def document_state(formatted_body: XML.Body): Document.State =
       
    24   {
       
    25     val text = formatted_body.iterator.flatMap(XML.content).mkString
       
    26     val markup: List[XML.Elem] = Nil  // FIXME
       
    27 
       
    28     val command = Command.unparsed(text)
       
    29     val node_name = command.node_name
       
    30     val exec_id = Document.new_id()
       
    31 
       
    32     val edits: List[Document.Edit_Text] =
       
    33       List(node_name -> Document.Node.Edits(List(Text.Edit.insert(0, text))))
       
    34 
       
    35     val state0 = Document.State.init.define_command(command)
       
    36     val version0 = state0.history.tip.version.get_finished
       
    37     val nodes0 = version0.nodes
       
    38 
       
    39     val nodes1 = nodes0 + (node_name -> nodes0(node_name).update_commands(Linear_Set(command)))
       
    40     val version1 = Document.Version.make(version0.syntax, nodes1)
       
    41     val state1 =
       
    42       state0.continue_history(Future.value(version0), edits, Future.value(version1))._2
       
    43         .define_version(version1, state0.the_assignment(version0))
       
    44         .assign(version1.id, List(command.id -> Some(exec_id)))._2
       
    45 
       
    46     state1
       
    47   }
       
    48 }
       
    49 
       
    50 class Pretty_Text_Area(view: View) extends BorderPanel
    20 {
    51 {
    21   Swing_Thread.require()
    52   Swing_Thread.require()
    22 
       
    23   val text_area = new JEditEmbeddedTextArea
       
    24 
    53 
    25   private var current_font_metrics: FontMetrics = null
    54   private var current_font_metrics: FontMetrics = null
    26   private var current_font_family = "Dialog"
    55   private var current_font_family = "Dialog"
    27   private var current_font_size: Int = 12
    56   private var current_font_size: Int = 12
    28   private var current_margin: Int = 0
    57   private var current_margin: Int = 0
    29   private var current_body: XML.Body = Nil
    58   private var current_body: XML.Body = Nil
       
    59 
       
    60   def get_rendering(): Isabelle_Rendering =
       
    61   {
       
    62     val body =
       
    63       Pretty.formatted(current_body, current_margin, Pretty.font_metric(current_font_metrics))
       
    64     Isabelle_Rendering(Pretty_Text_Area.document_state(body).snapshot(), Isabelle.options.value)
       
    65   }
       
    66 
       
    67   val text_area = new JEditEmbeddedTextArea
       
    68   val rich_text_area = new Rich_Text_Area(view, text_area, get_rendering _)
    30 
    69 
    31   def refresh()
    70   def refresh()
    32   {
    71   {
    33     Swing_Thread.require()
    72     Swing_Thread.require()
    34 
    73 
    71 
   110 
    72     current_body = body
   111     current_body = body
    73     refresh()
   112     refresh()
    74   }
   113   }
    75 
   114 
       
   115   rich_text_area.activate()
    76   layout(Component.wrap(text_area)) = BorderPanel.Position.Center
   116   layout(Component.wrap(text_area)) = BorderPanel.Position.Center
    77 }
   117 }
    78 
   118