src/Tools/Graphview/graph_file.scala
author wenzelm
Mon Mar 25 17:21:26 2019 +0100 (2 months ago)
changeset 69981 3dced198b9ec
parent 61176 9791f631c20d
permissions -rw-r--r--
more strict AFP properties;
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@59459
    18
  def write(file: JFile, graphview: Graphview)
wenzelm@59441
    19
  {
wenzelm@59459
    20
    val box = graphview.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@61176
    26
      gfx.setColor(graphview.background_color)
wenzelm@59441
    27
      gfx.fillRect(0, 0, w, h)
wenzelm@59441
    28
      gfx.translate(- box.x, - box.y)
wenzelm@59460
    29
      graphview.paint(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 the_options = options
wenzelm@59462
    41
    val graphview =
wenzelm@59462
    42
      new Graphview(graph.transitive_reduction_acyclic) { def options = the_options }
wenzelm@59459
    43
    graphview.update_layout()
wenzelm@59443
    44
wenzelm@59459
    45
    write(file, graphview)
wenzelm@59443
    46
  }
wenzelm@59441
    47
}