кнопки для отображения служебных файлов.

This commit is contained in:
2023-11-10 02:22:44 +03:00
parent 93278dc925
commit 2b119cc7eb
4 changed files with 139 additions and 71 deletions

6
.idea/workspace.xml generated
View File

@@ -7,9 +7,11 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment=""> <list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/UI/Main/SapforVersionComparisonState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/properties" beforeDir="false" afterPath="$PROJECT_DIR$/properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/SapforTestingSystem/Json/SapforVersion_json.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/SapforTestingSystem/Json/SapforVersion_json.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/SapforTestingSystem/Json/SapforVersion_json.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/SapforTestingSystem/Json/SapforVersion_json.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/UI/Main/SapforPackagesComparisonForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/UI/Main/SapforPackagesComparisonForm.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/UI/Main/SapforVersionsComparisonForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/UI/Main/SapforVersionsComparisonForm.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -30,9 +32,9 @@
<option name="RECENT_TEMPLATES"> <option name="RECENT_TEMPLATES">
<list> <list>
<option value="FxmlFile" /> <option value="FxmlFile" />
<option value="Enum" />
<option value="Interface" /> <option value="Interface" />
<option value="Class" /> <option value="Class" />
<option value="Enum" />
</list> </list>
</option> </option>
</component> </component>

View File

@@ -22,10 +22,10 @@ public class SapforVersion_json implements Serializable {
public File Home = null; public File Home = null;
public LinkedHashMap<String, ProjectFile> files = new LinkedHashMap<>(); public LinkedHashMap<String, ProjectFile> files = new LinkedHashMap<>();
//-- //--
public String parse_out = ""; public ProjectFile parse_out = null;
public String parse_err = ""; public ProjectFile parse_err = null;
public String out = ""; public ProjectFile out = null;
public String err = ""; public ProjectFile err = null;
//-- //--
public SapforVersion_json(String version_in, String description_in) { public SapforVersion_json(String version_in, String description_in) {
version = version_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(); parse_out = new ProjectFile(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(); parse_err = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_err_file).toFile());
File out_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile(); out = new ProjectFile(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile());
File err_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.err_file).toFile(); err = new ProjectFile(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();
}
} }
public boolean isMatch(SapforVersion_json version_json) { public boolean isMatch(SapforVersion_json version_json) {
if (!description.equals(version_json.description)) { if (!description.equals(version_json.description)) {

View File

@@ -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 "?";
}
}
}

View File

@@ -1,13 +1,20 @@
package Visual_DVM_2021.UI.Main; package Visual_DVM_2021.UI.Main;
import Common.Constants;
import Common.Current; import Common.Current;
import Common.Global; import Common.Global;
import Common.UI.Menus_2023.MenuBarButton;
import Common.Utils.Utils; import Common.Utils.Utils;
import GlobalData.Settings.SettingName; import GlobalData.Settings.SettingName;
import ProjectData.Files.ProjectFile; import ProjectData.Files.ProjectFile;
import SapforTestingSystem.Json.SapforVersion_json; import SapforTestingSystem.Json.SapforVersion_json;
import javax.swing.*; import javax.swing.*;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Vector;
public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_json> { public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_json> {
//--
protected LinkedHashMap<SapforVersionComparisonState, JButton> buttons = null;
//почти полный клон VersionsComparsionForm. В будущем нужен рефакторинг. Наверное. //почти полный клон VersionsComparsionForm. В будущем нужен рефакторинг. Наверное.
Current current; Current current;
private final JComboBox<ProjectFile> cbFile; private final JComboBox<ProjectFile> cbFile;
@@ -27,9 +34,42 @@ public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_j
tools.add(cbFile, 3); tools.add(cbFile, 3);
//-- //--
cbFile.addActionListener(e -> { cbFile.addActionListener(e -> {
file = (cbFile.getSelectedItem() instanceof ProjectFile) ? SelectFile(((cbFile.getSelectedItem() instanceof ProjectFile) ? ((ProjectFile) cbFile.getSelectedItem()) : null));
((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 (isMaster()) {
if (isReady() && !getSlave().selectSameFile(file)) if (isReady() && !getSlave().selectSameFile(file))
DoShowPass(true); DoShowPass(true);
@@ -49,7 +89,6 @@ public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_j
} }
} }
} }
});
} }
@Override @Override
protected Current getCurrentObjectName() { protected Current getCurrentObjectName() {
@@ -57,7 +96,9 @@ public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_j
} }
@Override @Override
protected String getText() { protected String getText() {
return isReady() ? Utils.ReadAllText(file.file) : "объект не назначен"; return isReady() ?
(file.file.exists() ? Utils.ReadAllText(file.file) : "файл не найден")
: "объект не назначен";
} }
@Override @Override
public boolean isReady() { public boolean isReady() {
@@ -78,18 +119,45 @@ public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_j
} }
public boolean selectSameFile(ProjectFile file_in) { public boolean selectSameFile(ProjectFile file_in) {
file = null; file = null;
Vector<String> 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); cbFile.setSelectedIndex(-1);
for (int i = 0; i < cbFile.getItemCount(); ++i) { for (int i = 0; i < cbFile.getItemCount(); ++i) {
ProjectFile projectFile = cbFile.getItemAt(i); ProjectFile projectFile = cbFile.getItemAt(i);
if (Global.db.settings.get(SettingName.ExtensionsOn).toBoolean()) { if (Global.db.settings.get(SettingName.ExtensionsOn).toBoolean()) {
//если учитываем расширения, ищем полное совпадение //если учитываем расширения, ищем полное совпадение
if (projectFile.file.getName().equals(file_in.file.getName())) { if (projectFile.file.getName().equals(file_name)) {
cbFile.setSelectedIndex(i); cbFile.setSelectedIndex(i);
return true; return true;
} }
} else { } else {
if (Utils.getNameWithoutExtension(projectFile.file.getName()).equals( if (Utils.getNameWithoutExtension(projectFile.file.getName()).equals(
Utils.getNameWithoutExtension(file_in.file.getName()))) { Utils.getNameWithoutExtension(file_name))) {
cbFile.setSelectedIndex(i); cbFile.setSelectedIndex(i);
return true; return true;
} }
@@ -97,4 +165,5 @@ public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_j
} }
return (cbFile.getSelectedItem() != null) && (cbFile.getSelectedItem() instanceof ProjectFile); return (cbFile.getSelectedItem() != null) && (cbFile.getSelectedItem() instanceof ProjectFile);
} }
}
} }