1 package com.zanthan.sequence;
2
3 import java.awt.Dimension;
4 import java.awt.Toolkit;
5 import java.awt.image.BufferedImage;
6 import java.io.File;
7 import java.io.IOException;
8
9 import javax.imageio.ImageIO;
10
11 import ch.elca.el4j.util.codingsupport.annotations.FindBugsSuppressWarnings;
12
13
14
15
16
17
18
19
20
21
22
23 public class Fasade {
24
25
26
27
28
29
30
31
32
33 public void createSequenceDiagram(String graph, String filename) {
34 Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
35 int width = size.width / 2;
36 int height = size.height / 2;
37 createSequenceDiagram(graph, filename, width, height);
38 }
39
40
41
42
43
44
45
46
47
48
49
50
51
52 @FindBugsSuppressWarnings(value = "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE",
53 justification = "It is not important if the file really was newly created")
54 public void createSequenceDiagram(String graph, String filename,
55 int width, int height) {
56 Display disp = new Display(null);
57 disp.setSize(width, height);
58 disp.init(graph);
59
60 BufferedImage bi = new BufferedImage(width, height,
61 BufferedImage.TYPE_INT_ARGB);
62 disp.paintComponent(bi.createGraphics());
63 File file = new File(filename);
64 try {
65 file.createNewFile();
66 ImageIO.write(bi, "png", file);
67 } catch (IOException ioe) {
68 ioe.printStackTrace();
69
70 }
71 }
72 }