промежуточный. в процессе рефакторинга объектов с настройками
This commit is contained in:
10
.idea/workspace.xml
generated
10
.idea/workspace.xml
generated
@@ -7,15 +7,11 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/src/_VisualDVM/ProjectData/SapforData/SapforProperties.java" 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/Common/Properties.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Common/Properties.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Common/Utils/Utils_.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Common/Utils/Utils_.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Global.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Global.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/GlobalProperties.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/GlobalProperties.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingMenuBar.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingMenuBar.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Visual/Menus/MainMenuBar/SynchronizationSettingsMenu.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Visual/Menus/MainMenuBar/SynchronizationSettingsMenu.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Visual/Menus/MainMenuBar/VersionsComparisonMenu.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Visual/Menus/MainMenuBar/VersionsComparisonMenu.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Visual/Menus/MainMenuBar/VisualiserSettingsMenu/CompactnessSettingsMenu.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Visual/Menus/MainMenuBar/VisualiserSettingsMenu/CompactnessSettingsMenu.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Visual/Menus/PropertiesSubmenu.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Visual/Menus/PropertiesSubmenu.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
||||
@@ -1,3 +1,66 @@
|
||||
package Common;
|
||||
import Common.Utils.Utils_;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.LinkedHashMap;
|
||||
public class Properties {
|
||||
protected LinkedHashMap<String,JMenuItem> controls= new LinkedHashMap<>();
|
||||
private File file=null; //файл где хранятся настройки.
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
public void Update() {
|
||||
try {
|
||||
Utils_.jsonToFile(this, getFile());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public Properties(){}
|
||||
public Properties(File file_in){
|
||||
setFile(file_in);
|
||||
}
|
||||
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);
|
||||
Update();
|
||||
return true;
|
||||
//--
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public String getFieldDescription(String fieldName) {
|
||||
return "?";
|
||||
}
|
||||
public JMenuItem getMenuItem(String fieldName){return null;}
|
||||
//отобразить на контроле значение поля.
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package Common.Utils;
|
||||
import Common.CommonConstants;
|
||||
import Common.Passes.PassException;
|
||||
import Common.Properties;
|
||||
import _VisualDVM.GlobalProperties;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -518,4 +520,22 @@ public class Utils_ {
|
||||
public static int fromBoolean(boolean flag) {
|
||||
return flag ? 1 : 0;
|
||||
}
|
||||
//--
|
||||
public static <T extends Properties> T SynschronizeProperties(File propertiesFile, Class<T> properties_class) {
|
||||
T res= null;
|
||||
try {
|
||||
res= properties_class.newInstance();
|
||||
if (propertiesFile.exists()){
|
||||
//файл существует. нужно его ссчитать.
|
||||
res = (T) Utils_.jsonFromFile(propertiesFile, properties_class);
|
||||
}
|
||||
res.setFile(propertiesFile);
|
||||
//перезаписываем файл в любом случае, так как может измениться формат.
|
||||
Utils_.jsonToFile(res, propertiesFile);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user