From 2b119cc7eb2a2fa45071e314190c1b60ba853de1 Mon Sep 17 00:00:00 2001 From: 02090095 Date: Fri, 10 Nov 2023 02:22:44 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BB=D1=83=D0=B6=D0=B5=D0=B1=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 6 +- .../Json/SapforVersion_json.java | 41 +---- .../UI/Main/SapforVersionComparisonState.java | 22 +++ .../UI/Main/SapforVersionsComparisonForm.java | 141 +++++++++++++----- 4 files changed, 139 insertions(+), 71 deletions(-) create mode 100644 src/Visual_DVM_2021/UI/Main/SapforVersionComparisonState.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c0dc5b98..63c5b386 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,9 +7,11 @@ + + - + diff --git a/src/SapforTestingSystem/Json/SapforVersion_json.java b/src/SapforTestingSystem/Json/SapforVersion_json.java index a4b72f58..a9373e57 100644 --- a/src/SapforTestingSystem/Json/SapforVersion_json.java +++ b/src/SapforTestingSystem/Json/SapforVersion_json.java @@ -22,10 +22,10 @@ public class SapforVersion_json implements Serializable { public File Home = null; public LinkedHashMap files = new LinkedHashMap<>(); //-- - public String parse_out = ""; - public String parse_err = ""; - public String out = ""; - public String err = ""; + public ProjectFile parse_out = null; + public ProjectFile parse_err = null; + public ProjectFile out = null; + public ProjectFile err = null; //-- public SapforVersion_json(String version_in, String description_in) { version = version_in; @@ -56,35 +56,10 @@ public class SapforVersion_json implements Serializable { } } } - File parse_out_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_out_file).toFile(); - File parse_err_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_err_file).toFile(); - File out_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile(); - File err_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.err_file).toFile(); - //-- - try { - if (parse_out_file.exists()) - parse_out = FileUtils.readFileToString(parse_out_file); - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - if (parse_err_file.exists()) - parse_err = FileUtils.readFileToString(parse_err_file); - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - if (out_file.exists()) - out = FileUtils.readFileToString(out_file); - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - if (err_file.exists()) - err = FileUtils.readFileToString(err_file); - } catch (Exception ex) { - ex.printStackTrace(); - } + parse_out = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_out_file).toFile()); + parse_err = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_err_file).toFile()); + out = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile()); + err = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.err_file).toFile()); } public boolean isMatch(SapforVersion_json version_json) { if (!description.equals(version_json.description)) { diff --git a/src/Visual_DVM_2021/UI/Main/SapforVersionComparisonState.java b/src/Visual_DVM_2021/UI/Main/SapforVersionComparisonState.java new file mode 100644 index 00000000..056d716a --- /dev/null +++ b/src/Visual_DVM_2021/UI/Main/SapforVersionComparisonState.java @@ -0,0 +1,22 @@ +package Visual_DVM_2021.UI.Main; +public enum SapforVersionComparisonState { + //названия только для изображений. + CompilationOutput, + CompilationErrors, + RunOutput, + RunErrors; + public String getDescription(){ + switch (this){ + case CompilationOutput: + return "Поток вывода парсера"; + case CompilationErrors: + return "Поток ошибок парсера"; + case RunOutput: + return "Поток вывода преобразования"; + case RunErrors: + return "Поток ошибок преобразования"; + default: + return "?"; + } + } +} diff --git a/src/Visual_DVM_2021/UI/Main/SapforVersionsComparisonForm.java b/src/Visual_DVM_2021/UI/Main/SapforVersionsComparisonForm.java index 69476e80..57cb8e28 100644 --- a/src/Visual_DVM_2021/UI/Main/SapforVersionsComparisonForm.java +++ b/src/Visual_DVM_2021/UI/Main/SapforVersionsComparisonForm.java @@ -1,13 +1,20 @@ package Visual_DVM_2021.UI.Main; +import Common.Constants; import Common.Current; import Common.Global; +import Common.UI.Menus_2023.MenuBarButton; import Common.Utils.Utils; import GlobalData.Settings.SettingName; import ProjectData.Files.ProjectFile; import SapforTestingSystem.Json.SapforVersion_json; import javax.swing.*; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Vector; public class SapforVersionsComparisonForm extends ComparisonForm { + //-- + protected LinkedHashMap buttons = null; //почти полный клон VersionsComparsionForm. В будущем нужен рефакторинг. Наверное. Current current; private final JComboBox cbFile; @@ -27,29 +34,61 @@ public class SapforVersionsComparisonForm extends ComparisonForm { - file = (cbFile.getSelectedItem() instanceof ProjectFile) ? - ((ProjectFile) cbFile.getSelectedItem()) : null; - //-->> - if (isMaster()) { - if (isReady() && !getSlave().selectSameFile(file)) - DoShowPass(true); - } else { - if (isReady()) { - if (getMaster().isReady()) { - boolean ExtensionsOn = Global.db.settings.get(SettingName.ExtensionsOn).toBoolean(); - String name1 = ExtensionsOn ? getMaster().file.file.getName() : Utils.getFileNameWithoutExtension(getMaster().file.file); - String name2 = ExtensionsOn ? file.file.getName() : Utils.getFileNameWithoutExtension(file.file); - if (Global.db.settings.get(SettingName.ComparsionDiffMergeOn).toBoolean()) { - if (name1.equalsIgnoreCase(name2)) - master.DoComparePass(true); - } else - master.DoShowPass(true); - } else { - master.DoShowPass(true); + SelectFile(((cbFile.getSelectedItem() instanceof ProjectFile) ? ((ProjectFile) cbFile.getSelectedItem()) : null)); + }); + //-- + buttons = new LinkedHashMap<>(); + int i = 4; + for (SapforVersionComparisonState state : SapforVersionComparisonState.values()) { + MenuBarButton button = new MenuBarButton(); + button.setIcon("/icons/" + state.toString() + ".png"); + button.setToolTipText(state.getDescription()); + button.addActionListener(e -> { + if (object != null) { + ProjectFile projectFile = null; + switch (state) { + case CompilationOutput: + projectFile = object.parse_out; + break; + case CompilationErrors: + projectFile = object.parse_err; + break; + case RunOutput: + projectFile = object.out; + break; + case RunErrors: + projectFile = object.err; + break; } + SelectFile(projectFile); + } + }); + tools.add(button, i); + buttons.put(state, button); + ++i; + } + } + public void SelectFile(ProjectFile file_in) { + file = file_in; + if (isMaster()) { + if (isReady() && !getSlave().selectSameFile(file)) + DoShowPass(true); + } else { + if (isReady()) { + if (getMaster().isReady()) { + boolean ExtensionsOn = Global.db.settings.get(SettingName.ExtensionsOn).toBoolean(); + String name1 = ExtensionsOn ? getMaster().file.file.getName() : Utils.getFileNameWithoutExtension(getMaster().file.file); + String name2 = ExtensionsOn ? file.file.getName() : Utils.getFileNameWithoutExtension(file.file); + if (Global.db.settings.get(SettingName.ComparsionDiffMergeOn).toBoolean()) { + if (name1.equalsIgnoreCase(name2)) + master.DoComparePass(true); + } else + master.DoShowPass(true); + } else { + master.DoShowPass(true); } } - }); + } } @Override protected Current getCurrentObjectName() { @@ -57,7 +96,9 @@ public class SapforVersionsComparisonForm extends ComparisonForm data_names = new Vector<>(Arrays.asList( + Constants.parse_out_file, + Constants.parse_err_file, + Constants.out_file, + Constants.err_file)); + String file_name = file_in.file.getName(); + if (data_names.contains(file_name)) { + SapforVersionComparisonState state = null; + switch (file_name) { + case Constants.parse_out_file: + state = SapforVersionComparisonState.CompilationOutput; + break; + case Constants.parse_err_file: + state = SapforVersionComparisonState.CompilationErrors; + break; + case Constants.out_file: + state = SapforVersionComparisonState.RunOutput; + break; + case Constants.err_file: + state = SapforVersionComparisonState.RunErrors; + break; + } + if (state != null) { + buttons.get(state).doClick(); + } + return true; + } else { + cbFile.setSelectedIndex(-1); + for (int i = 0; i < cbFile.getItemCount(); ++i) { + ProjectFile projectFile = cbFile.getItemAt(i); + if (Global.db.settings.get(SettingName.ExtensionsOn).toBoolean()) { + //если учитываем расширения, ищем полное совпадение + if (projectFile.file.getName().equals(file_name)) { + cbFile.setSelectedIndex(i); + return true; + } + } else { + if (Utils.getNameWithoutExtension(projectFile.file.getName()).equals( + Utils.getNameWithoutExtension(file_name))) { + cbFile.setSelectedIndex(i); + return true; + } } } + return (cbFile.getSelectedItem() != null) && (cbFile.getSelectedItem() instanceof ProjectFile); } - return (cbFile.getSelectedItem() != null) && (cbFile.getSelectedItem() instanceof ProjectFile); } }