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