src/Tools/Graphview/graph_file.scala
author wenzelm
Sun Jan 25 20:16:27 2015 +0100 (2015-01-25)
changeset 59443 5b552b4f63a5
parent 59441 ab2c3597f1d3
child 59459 985fc55e9f27
permissions -rw-r--r--
support for off-line graph output, without GUI thread;
wenzelm@59441
     1
/*  Title:      Tools/Graphview/graph_file.scala
wenzelm@59441
     2
    Author:     Makarius
wenzelm@59441
     3
wenzelm@59441
     4
File system operations for graph output.
wenzelm@59441
     5
*/
wenzelm@59441
     6
wenzelm@59441
     7
package isabelle.graphview
wenzelm@59441
     8
wenzelm@59441
     9
wenzelm@59441
    10
import isabelle._
wenzelm@59441
    11
wenzelm@59441
    12
import java.io.{File => JFile}
wenzelm@59441
    13
import java.awt.{Color, Graphics2D}
wenzelm@59441
    14
wenzelm@59441
    15
wenzelm@59441
    16
object Graph_File
wenzelm@59441
    17
{
wenzelm@59443
    18
  def write(file: JFile, visualizer: Visualizer)
wenzelm@59441
    19
  {
wenzelm@59441
    20
    val box = visualizer.bounding_box()
wenzelm@59441
    21
    val w = box.width.ceil.toInt
wenzelm@59441
    22
    val h = box.height.ceil.toInt
wenzelm@59441
    23
wenzelm@59441
    24
    def paint(gfx: Graphics2D)
wenzelm@59441
    25
    {
wenzelm@59441
    26
      gfx.setColor(Color.WHITE)
wenzelm@59441
    27
      gfx.fillRect(0, 0, w, h)
wenzelm@59441
    28
      gfx.translate(- box.x, - box.y)
wenzelm@59441
    29
      visualizer.paint_all_visible(gfx)
wenzelm@59441
    30
    }
wenzelm@59441
    31
wenzelm@59441
    32
    val name = file.getName
wenzelm@59441
    33
    if (name.endsWith(".png")) Graphics_File.write_png(file, paint _, w, h)
wenzelm@59441
    34
    else if (name.endsWith(".pdf")) Graphics_File.write_pdf(file, paint _, w, h)
wenzelm@59441
    35
    else error("Bad type of file: " + quote(name) + " (.png or .pdf expected)")
wenzelm@59441
    36
  }
wenzelm@59443
    37
wenzelm@59443
    38
  def write(options: Options, file: JFile, graph: Graph_Display.Graph)
wenzelm@59443
    39
  {
wenzelm@59443
    40
    val model = new Model(graph.transitive_reduction_acyclic)
wenzelm@59443
    41
wenzelm@59443
    42
    val the_options = options
wenzelm@59443
    43
    val visualizer = new Visualizer(model) { def options = the_options }
wenzelm@59443
    44
    visualizer.update_layout()
wenzelm@59443
    45
wenzelm@59443
    46
    write(file, visualizer)
wenzelm@59443
    47
  }
wenzelm@59441
    48
}