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