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;
|
2025-02-28 22:54:37 +03:00
|
|
|
|
import Common.Visual.Windows.Dialog.VDirectoryChooser;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import _VisualDVM.Global;
|
2025-02-28 22:54:37 +03:00
|
|
|
|
import _VisualDVM.Passes.PassCode;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.ProjectData.SapforData.Functions.UI.Graph.FunctionsGraphForm;
|
2025-02-28 22:54:37 +03:00
|
|
|
|
import _VisualDVM.Utils;
|
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> {
|
2025-02-28 22:54:37 +03:00
|
|
|
|
VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор папки для сохранения скриншота графа функций");
|
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_("Граф процедур пуст");
|
2025-02-28 22:54:37 +03:00
|
|
|
|
Utils.ChooseDocumentsDirectory(directoryChooser);
|
|
|
|
|
|
File dir = directoryChooser.ShowDialog();
|
|
|
|
|
|
if (dir == null) {
|
|
|
|
|
|
Log.Writeln_("Папка не выбрана.");
|
|
|
|
|
|
}else {
|
|
|
|
|
|
Global.mainModule.getPass(PassCode.UpdateProperty).Do("DocumentsDirectory", dir.getAbsolutePath());
|
|
|
|
|
|
target = new File(dir, Utils_.getDateName("Graph")+".png");
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void body() throws Exception {
|
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 {
|
2025-02-28 22:54:37 +03:00
|
|
|
|
if (UI.Question("Изображение графа процедур успешно сохранено\n"
|
|
|
|
|
|
+ "в папке " + Utils_.Brackets(target.getParent())+"\n"
|
|
|
|
|
|
+ "под именем "+Utils_.Brackets(target.getName())+"\n"
|
|
|
|
|
|
+ "Открыть его"
|
|
|
|
|
|
)){
|
|
|
|
|
|
try {
|
|
|
|
|
|
Desktop.getDesktop().open(target);
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
Utils_.MainLog.PrintException(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|