View Javadoc

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   * This class is a fasade for the Sequence library.
16   * It is located in the pacakge com.zanathan.sequence to access classes that
17   * have other than public visability.
18   *
19   * @svnLink $Revision: 4010 $;$Date: 2009-12-01 10:59:54 +0100 (Di, 01. Dez 2009) $;$Author: jonasha $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/detailed_statistics/common/src/main/java/com/zanthan/sequence/Fasade.java $
20   *
21   * @author David Stefan (DST)
22   */
23  public class Fasade {
24  
25  	/**
26  	 * Create a Sequence Diagram of the given graph.
27  	 *
28  	 * @param graph
29  	 *            The graph to create the diagram for
30  	 * @param filename
31  	 *            The file to save the graph in
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  	 * Create a Sequence Diagram of the given graph.
42  	 *
43  	 * @param graph
44  	 *            The graph to create the diagram for
45  	 * @param filename
46  	 *            The file to save the graph in
47  	 * @param width
48  	 *            The width of the diagram
49  	 * @param height
50  	 *            The height of the diagram
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  }