промежуточный. в процессе рефакторинга объектов с настройками

This commit is contained in:
2025-01-14 00:47:19 +03:00
parent 63112eed7b
commit 483089e954
5 changed files with 103 additions and 81 deletions

View File

@@ -27,7 +27,7 @@ public class Global {
//Режим
public static Mode mode = Mode.Undefined;
//--------------------------------------------------
public static GlobalProperties properties = new GlobalProperties();
public static GlobalProperties properties = null;
//---
public static boolean files_multiselection = false;
public static boolean versions_multiselection = false;
@@ -55,16 +55,7 @@ public class Global {
public static ComponentsServer componentsServer = new ComponentsServer();
public static TestingServer testingServer = new TestingServer();
public static PerformanceAnalyzer performanceAnalyzer = null;
public static void SynschronizeProperties() {
try {
File new_propertiesFile = new File(Utils_.getHomeDirectory(), "properties");
if (new_propertiesFile.exists())
properties = (GlobalProperties) Utils_.jsonFromFile(new_propertiesFile, GlobalProperties.class);
Utils_.jsonToFile(properties, new_propertiesFile);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void CheckVisualiserDirectories() {
Utils_.CheckDirectory(ComponentsDirectory = new File(Utils_.getHomeDirectory(), Constants.ComponentsDirectoryName));
Utils_.CheckAndCleanDirectory(TempDirectory = new File(Utils_.getHomeDirectory(), Constants.TempDirectoryName));
@@ -221,7 +212,6 @@ public class Global {
// FoldParserManager.get().addFoldParserMapping("text/FortranSPF", new FortranFolder()); блоки кода. todo
//light_editor.xml-------->>
mainModule.ActivateDB();
/*
mainModule.set(Current.Account, new Account() {
{
@@ -276,8 +266,11 @@ public class Global {
public static void Init(String... args) {
System.out.println("VisualSapfor.jar started..");
System.out.println("home directory is" + Utils_.Brackets(Utils_.getHomePath()));
//---
SynschronizeProperties();
//--->
properties=Utils_.SynschronizeProperties(
Paths.get(System.getProperty("user.dir"), "properties").toFile(),
GlobalProperties.class);
//--->
mode = properties.Mode;
System.out.println("mode is " + mode);
try {

View File

@@ -1,5 +1,6 @@
package _VisualDVM;
import Common.CommonConstants;
import Common.Properties;
import Common.Utils.Utils_;
import Common.Visual.Controls.StableMenuItem;
import Common.Visual.Windows.Dialog.SliderNumberForm;
@@ -14,8 +15,7 @@ import java.lang.reflect.Field;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.Locale;
public class GlobalProperties {
LinkedHashMap<String,JMenuItem> controls= new LinkedHashMap<>();
public class GlobalProperties extends Properties {
@Expose
public _VisualDVM.Mode Mode = _VisualDVM.Mode.Normal; //todo унаследовать от предка.
@Expose
@@ -202,9 +202,14 @@ public class GlobalProperties {
Kernels=p.Kernels;
}
//--
public GlobalProperties() {
public GlobalProperties(File file_in) {
super(file_in);
}
public GlobalProperties(){
}
//-----------------
@Override
public String getFieldDescription(String fieldName) {
switch (fieldName) {
case "Kernels":
@@ -262,46 +267,8 @@ public class GlobalProperties {
}
}
//-----------------
public void Update() {
try {
Utils_.jsonToFile(this, getFile());
} 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;
}
public File getFile() {
return Paths.get(System.getProperty("user.dir"), "properties").toFile();
}
//-----------------
public Object getValue(String fieldName){
Object res=null;
try {
res = this.getClass().getField(fieldName).get(this);
}
catch (Exception ex){
ex.printStackTrace();
}
return res;
}
//создать контрол
//обобщить для наследования.возможно переделать проход.
@Override
public JMenuItem getMenuItem(String fieldName){
final JMenuItem menuItem;
if (controls.containsKey(fieldName))
@@ -320,21 +287,4 @@ public class GlobalProperties {
}
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();
}
}
}