Files
VisualSapfor/src/_VisualDVM/GlobalProperties.java

342 lines
13 KiB
Java
Raw Normal View History

2024-10-09 22:01:19 +03:00
package _VisualDVM;
import Common.CommonConstants;
2024-10-11 00:00:30 +03:00
import Common.Utils.Utils_;
2024-10-14 15:19:13 +03:00
import Common.Visual.Controls.StableMenuItem;
import Common.Visual.Windows.Dialog.SliderNumberForm;
2024-10-14 12:14:01 +03:00
import _VisualDVM.Passes.PassCode;
2023-09-17 22:13:42 +03:00
import com.google.gson.annotations.Expose;
2024-10-08 23:21:42 +03:00
import javax.swing.*;
2025-01-11 01:42:24 +03:00
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
2023-09-17 22:13:42 +03:00
import java.io.File;
2024-10-08 23:21:42 +03:00
import java.lang.reflect.Field;
2023-09-17 22:13:42 +03:00
import java.nio.file.Paths;
2025-01-11 01:42:24 +03:00
import java.util.LinkedHashMap;
2024-10-08 23:21:42 +03:00
public class GlobalProperties {
2025-01-11 01:42:24 +03:00
LinkedHashMap<String,JMenuItem> controls= new LinkedHashMap<>();
2023-09-17 22:13:42 +03:00
@Expose
2024-10-14 16:16:41 +03:00
public _VisualDVM.Mode Mode = _VisualDVM.Mode.Normal;
2024-02-14 21:46:07 +03:00
@Expose
public String ServerAddress = "alex-freenas.ddns.net";
2024-02-14 21:46:07 +03:00
@Expose
public String ServerUserName = "testuser";
2024-02-16 21:44:13 +03:00
@Expose
2024-02-19 18:01:17 +03:00
public int ServerUserSHHPort = 23;
@Expose
2024-02-16 21:44:13 +03:00
public int ComponentsServerPort = 7995;
@Expose
public int TestingServerPort = 7998;
2023-09-17 22:13:42 +03:00
@Expose
public int SocketTimeout = 5000;
@Expose
public boolean OldServer = false;
@Expose
public String SMTPHost = "smtp.mail.ru";
@Expose
public int SMTPPort = 465;
@Expose
public int MailSocketPort = 465;
@Expose
public boolean collapseCredentials = false;
@Expose
public boolean collapseFileGraphs = false;
@Expose
public boolean collapseFileMessages = false;
@Expose
public boolean collapseProjectTrees = false;
2023-09-17 22:13:42 +03:00
@Expose
public String BackupWorkspace = "_sapfor_x64_backups";
@Expose
2025-01-11 14:26:24 +03:00
public String Workspace ="";
@Expose
public String ProjectsSearchDirectory="";
@Expose
2025-01-11 18:13:25 +03:00
public int EditorFontSize=14;
@Expose
2023-09-17 22:13:42 +03:00
public int BackupHour = 5;
@Expose
public int BackupMinute = 0;
@Expose
public boolean EmailAdminsOnStart = false;
@Expose
public boolean AutoUpdateSearch = true;
@Expose
public boolean AutoBugReportsLoad = true;
@Expose
public boolean AutoTestsLoad = true;
@Expose
2023-09-17 22:13:42 +03:00
public boolean ConfirmPassesStart = true;
@Expose
public boolean ShowPassesDone = true;
@Expose
public boolean FocusPassesResult = true;
@Expose
public String ProjectDBName = "new_project_base.sqlite";
@Expose
public String BugReportsDBName = "bug_reports.sqlite";
@Expose
public String TestsDBName = "tests.sqlite";
@Expose
public int ComponentsWindowWidth = 650;
@Expose
public int ComponentsWindowHeight = 250;
@Expose
public String VisualiserPath = "";
@Expose
public String Sapfor_FPath = "";
@Expose
public String Visualizer_2Path = "";
@Expose
public String InstructionPath = "";
@Expose
public String PerformanceAnalyzerPath = "";
@Expose
public int ComponentsBackUpsCount = 10;
@Expose
public boolean AutoCheckTesting = false; // проверять ли задачи тестирования при включенном визуализаторе.
@Expose
public int CheckTestingIntervalSeconds = 10; //интервал автопроверки тестирования
@Expose
public boolean EmailOnTestingProgress = false; //включено ли оповещение по email о результатах тестирования.
@Expose
2024-10-08 23:21:42 +03:00
public boolean eraseTestingWorkspaces = true; //удалять ли рабочее пространство пакетов тестирования после его завершения
@Expose
public int lastMachineId = CommonConstants.Nan;
@Expose
public int lastUserId = CommonConstants.Nan;
@Expose
public int lastCompilerId = CommonConstants.Nan;
//--
@Expose
public boolean RegisterOn = false;
@Expose
public boolean SpacesOn = false;
@Expose
public boolean EmptyLinesOn = false;
@Expose
public boolean FortranWrapsOn = false;
@Expose
public boolean ExtensionsOn = false;
@Expose
public boolean ComparsionDiffMergeOn = false;
@Expose
public int BugReportsAgeLimit = 2;
2025-01-11 19:32:54 +03:00
@Expose
public int FastAccessPassesCount=10;
public GlobalProperties(GlobalProperties p) {
super();
Mode = p.Mode;
ServerAddress = p.ServerAddress;
ServerUserName = p.ServerUserName;
ServerUserSHHPort = p.ServerUserSHHPort;
ComponentsServerPort = p.ComponentsServerPort;
TestingServerPort = p.TestingServerPort;
SocketTimeout = p.SocketTimeout;
OldServer = p.OldServer;
SMTPHost = p.SMTPHost;
SMTPPort = p.SMTPPort;
MailSocketPort = p.MailSocketPort;
collapseCredentials = p.collapseCredentials;
collapseFileGraphs = p.collapseFileGraphs;
collapseFileMessages = p.collapseFileMessages;
collapseProjectTrees = p.collapseProjectTrees;
BackupWorkspace = p.BackupWorkspace;
BackupHour = p.BackupHour;
BackupMinute = p.BackupMinute;
EmailAdminsOnStart = p.EmailAdminsOnStart;
AutoUpdateSearch = p.AutoUpdateSearch;
ConfirmPassesStart = p.ConfirmPassesStart;
ShowPassesDone = p.ShowPassesDone;
FocusPassesResult = p.FocusPassesResult;
ProjectDBName = p.ProjectDBName;
BugReportsDBName = p.BugReportsDBName;
TestsDBName = p.TestsDBName;
ComponentsWindowWidth = p.ComponentsWindowWidth;
ComponentsWindowHeight = p.ComponentsWindowHeight;
VisualiserPath = p.VisualiserPath;
Sapfor_FPath = p.Sapfor_FPath;
Visualizer_2Path = p.Visualizer_2Path;
InstructionPath = p.InstructionPath;
PerformanceAnalyzerPath = p.PerformanceAnalyzerPath;
ComponentsBackUpsCount = p.ComponentsBackUpsCount;
AutoCheckTesting = p.AutoCheckTesting;
CheckTestingIntervalSeconds = p.CheckTestingIntervalSeconds;
EmailOnTestingProgress = p.EmailOnTestingProgress;
eraseTestingWorkspaces = p.eraseTestingWorkspaces;
//-
lastMachineId = p.lastMachineId;
lastUserId = p.lastUserId;
lastCompilerId = p.lastCompilerId;
}
2024-10-14 15:19:13 +03:00
//--
public GlobalProperties() {
}
//-----------------
public String getFieldDescription(String fieldName) {
switch (fieldName) {
2025-01-11 19:32:54 +03:00
case "FastAccessPassesCount":
return "Число проходов на панели быстрого доступа";
2025-01-11 14:26:24 +03:00
case "Workspace":
return "Рабочее пространство визуализатора";
case "BugReportsAgeLimit":
return "Срок хранения отчетов об ошибках (месяцы)";
case "ExtensionsOn":
return "Учитывать расширения файлов";
case "FortranWrapsOn":
return "Учитывать переносы";
case "EmptyLinesOn":
return "Учитывать пустые строки";
case "SpacesOn":
return "Учитывать пробелы и табуляции";
case "RegisterOn":
return "Учитывать регистр";
case "ComparsionDiffMergeOn":
return "Автоматическое сравнение";
case "AutoBugReportsLoad":
return "Автоматическая синхронизация отчётов об ошибках";
case "AutoTestsLoad":
return "Автоматическая синхронизация системы тестирования";
2024-10-14 15:19:13 +03:00
case "ShowPassesDone":
return "Сообщать об успешном выполнении проходов";
case "ConfirmPassesStart":
return "Запрашивать подтверждения начала выполнения проходов";
case "FocusPassesResult":
return "Переходить на результирующую вкладку проходов по их завершении";
case "collapseCredentials":
return "Свернуть раздел машин";
case "collapseFileGraphs":
return "Свернуть раздел графов файла";
case "collapseFileMessages":
return "Свернуть раздел сообщений файла";
case "collapseProjectTrees":
return "Свернуть раздел деревьев проекта";
case "AutoUpdateSearch":
return "Автоматический поиск обновлений";
2024-10-14 15:19:13 +03:00
default:
return "?";
}
}
2024-10-08 23:21:42 +03:00
//-----------------
public boolean getFlag(String fieldName) {
boolean field = false;
try {
field = (boolean) getClass().getField(fieldName).get(this);
//
} catch (Exception ex) {
ex.printStackTrace();
}
return field;
}
public void switchFlag(String fieldName) {
boolean field = false;
try {
field = (boolean) getClass().getField(fieldName).get(this);
getClass().getField(fieldName).set(this, !field);
//
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void Update() {
try {
2024-10-11 00:00:30 +03:00
Utils_.jsonToFile(this, getFile());
2024-10-08 23:21:42 +03:00
} catch (Exception e) {
e.printStackTrace();
}
}
//--
public boolean updateField(String name, Object newValue) {
try {
Field field = getClass().getField(name);
Object oldValue = field.get(this);
//---
if (newValue.equals(oldValue))
return false;
//--
field.set(this, newValue);
this.Update();
return true;
//--
} catch (Exception exception) {
exception.printStackTrace();
}
return false;
}
2025-01-11 14:26:24 +03:00
//выкинуть(?)
2024-10-08 23:21:42 +03:00
public void switchAndUpdateFlag(String name) {
try {
Field field = getClass().getField(name);
boolean oldValue = (boolean) field.get(this);
boolean newValue = !oldValue;
//---
field.set(this, newValue);
this.Update();
//--
} catch (Exception exception) {
exception.printStackTrace();
}
}
public File getFile() {
return Paths.get(System.getProperty("user.dir"), "properties").toFile();
}
//-----------------
2025-01-11 14:26:24 +03:00
//выкинуть.
public void addFlagMenuItem(JMenu menu, String fieldName) {
JMenuItem menu_item = new StableMenuItem(getFieldDescription(fieldName),
getFlag(fieldName) ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png");
//-
menu_item.addActionListener(e -> {
if (Global.mainModule.getPass(PassCode.UpdateProperty).Do(fieldName, !getFlag(fieldName)))
menu_item.setIcon(Utils_.getIcon(getFlag(fieldName) ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));
});
menu.add(menu_item);
}
2025-01-11 01:42:24 +03:00
public Object getValue(String fieldName){
Object res=null;
try {
res = this.getClass().getField(fieldName).get(this);
}
catch (Exception ex){
ex.printStackTrace();
}
return res;
}
//создать контрол
public JMenuItem getMenuItem(String fieldName){
final JMenuItem menuItem;
if (controls.containsKey(fieldName))
menuItem = controls.get(fieldName);
else {
menuItem = new StableMenuItem();
Mark(fieldName,menuItem);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
2025-01-11 02:09:44 +03:00
if (Global.mainModule.getPass(PassCode.UpdateProperty).Do(fieldName))
Mark(fieldName, menuItem);
2025-01-11 01:42:24 +03:00
}
});
controls.put(fieldName,menuItem);
}
return menuItem;
}
//отобразить на контроле значение поля.
public void Mark(String fieldName, JMenuItem control){
String description= getFieldDescription(fieldName);
try {
Object value = this.getClass().getField(fieldName).get(this);
if (value instanceof Boolean){
Boolean flag = (Boolean) value;
control.setText(description);
control.setIcon(Utils_.getIcon(flag? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));
}else {
control.setText(description+" : "+value);
}
}
catch (Exception ex){
ex.printStackTrace();
}
}
2023-09-17 22:13:42 +03:00
}