2024-10-14 12:14:01 +03:00
|
|
|
|
package _VisualDVM.Passes.All;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import Common.Passes.Pass;
|
|
|
|
|
|
import Common.Passes.PassException;
|
2024-10-11 00:00:30 +03:00
|
|
|
|
import Common.Utils.Utils_;
|
2024-10-15 15:13:57 +03:00
|
|
|
|
import Common.Visual.UI;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import _VisualDVM.Global;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.ProjectData.SapforData.Functions.UI.Graph.FunctionsGraphForm;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import com.mxgraph.io.mxCodec;
|
|
|
|
|
|
import com.mxgraph.util.mxCellRenderer;
|
|
|
|
|
|
import com.mxgraph.util.mxXmlUtils;
|
|
|
|
|
|
import com.mxgraph.util.png.mxPngEncodeParam;
|
|
|
|
|
|
import com.mxgraph.util.png.mxPngImageEncoder;
|
|
|
|
|
|
import com.mxgraph.view.mxGraph;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
|
import java.nio.file.Paths;
|
2024-10-09 23:37:58 +03:00
|
|
|
|
public class SaveGraph extends Pass<File> {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
FunctionsGraphForm graphForm = null;
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean needsAnimation() {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getIconPath() {
|
|
|
|
|
|
return "/icons/ScreenShot.png";
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean canStart(Object... args) {
|
2024-10-15 02:32:52 +03:00
|
|
|
|
graphForm = Global.mainModule.getUI().getMainWindow().getProjectWindow().getFunctionsWindow().getFunctionsGraphWindow();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (!graphForm.isShown())
|
|
|
|
|
|
Log.Writeln_("Сначала отобразите граф");
|
2024-10-13 22:08:13 +03:00
|
|
|
|
if (Global.mainModule.getProject().functionsGraph.isEmpty())
|
2023-09-17 22:13:42 +03:00
|
|
|
|
Log.Writeln_("Граф процедур пуст");
|
|
|
|
|
|
return Log.isEmpty();
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void body() throws Exception {
|
2025-01-29 15:20:24 +03:00
|
|
|
|
target = Paths.get(Global.visualiser.getWorkspace().getAbsolutePath(), "Graph.png").toFile();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (target.exists() && !target.delete())
|
2024-10-11 00:00:30 +03:00
|
|
|
|
throw new PassException("Не удается удалить предыдущий файл " + Utils_.Brackets(target.getAbsolutePath()));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
//-
|
2024-10-17 20:09:01 +03:00
|
|
|
|
mxGraph graph = graphForm.getControl().getGraph();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
BufferedImage image = mxCellRenderer.createBufferedImage(graph,
|
|
|
|
|
|
null, 1, Color.WHITE,
|
2024-10-17 20:09:01 +03:00
|
|
|
|
graphForm.getControl().isAntiAlias(),
|
2023-09-17 22:13:42 +03:00
|
|
|
|
null,
|
2024-10-17 20:09:01 +03:00
|
|
|
|
graphForm.getControl().getCanvas());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
// Creates the URL-encoded XML data
|
|
|
|
|
|
mxCodec codec = new mxCodec();
|
|
|
|
|
|
String xml = URLEncoder.encode(mxXmlUtils.getXml(codec.encode(graph.getModel())), "UTF-8");
|
|
|
|
|
|
mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image);
|
|
|
|
|
|
param.setCompressedText(new String[]{"graph", xml});
|
|
|
|
|
|
// Saves as a PNG file
|
|
|
|
|
|
FileOutputStream outputStream = new FileOutputStream(target);
|
|
|
|
|
|
mxPngImageEncoder encoder = new mxPngImageEncoder(outputStream, param);
|
|
|
|
|
|
encoder.encode(image);
|
|
|
|
|
|
outputStream.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void showDone() throws Exception {
|
2024-10-15 15:13:57 +03:00
|
|
|
|
UI.Info("Граф успешно сохранен в файл: " + Utils_.Brackets(target.getAbsolutePath()));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|