diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Agile Software Development/TestApp/src/testapp/GraphGenerator.java | |
| download | Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2 | |
Diffstat (limited to 'Master/Agile Software Development/TestApp/src/testapp/GraphGenerator.java')
| -rw-r--r-- | Master/Agile Software Development/TestApp/src/testapp/GraphGenerator.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Master/Agile Software Development/TestApp/src/testapp/GraphGenerator.java b/Master/Agile Software Development/TestApp/src/testapp/GraphGenerator.java new file mode 100644 index 0000000..06645d2 --- /dev/null +++ b/Master/Agile Software Development/TestApp/src/testapp/GraphGenerator.java @@ -0,0 +1,81 @@ +/* + * Class to generate the graphic out of the .dot file + */ +package testapp; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import javax.swing.SwingWorker; +import java.util.logging.*; +/** + * + * @author eisenhauer + */ +public class GraphGenerator extends SwingWorker<File,Object> { + int retVal=-1; + Process proc; + File dotFile = null; + public GraphGenerator(File dotFile) { + super(); + this.dotFile = dotFile; + } + + @Override + protected File doInBackground() throws Exception { + return getImageFileForGraph(); + } + + @Override + protected void done() { + try { + if (retVal == 0) { + AppFrame af = AppFrame.getInstance(); + if (af != null) { + af.setImage(get()); + //TODO + //dotFile.delete(); + } + } + return; + } catch (InterruptedException ie) { + ie.printStackTrace(); + } catch (ExecutionException ee) { + ee.printStackTrace(); + } + } + + //Convert the .dot file to a .png grafic + public File getImageFileForGraph(File dotFile) { + File tmpFile = null; + if (!dotFile.canRead()) { + return null; + } + try { + tmpFile = File.createTempFile("tmp", ".png"); + File dotPath = new File(App.getInstance().getAppPath() + "/lib/graphviz/bin/"); + File dotExe = new File(dotPath.toString()+"/dot.exe"); + String dotArgType = "-Tpng"; + String dotArgOutfile = "-o"+tmpFile.toString(); + String dotArgInfile = dotFile.toString(); + String graphvizCmd = dotExe.toString(); + String[] cmd = new String[] + {graphvizCmd,dotArgType,dotArgOutfile,dotArgInfile}; + ProcessBuilder procBuilder = new ProcessBuilder(cmd); + procBuilder.redirectErrorStream(true); + proc = procBuilder.start(); + try { + retVal = proc.waitFor(); + } catch (InterruptedException ie) { + ie.printStackTrace(); + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } + return tmpFile; + } + public File getImageFileForGraph() { + //File dotFile = new File(System.getProperty("user.dir")+"/dist/resource/test.dot"); + return getImageFileForGraph(dotFile); + } +} |
