промежуточный. перенос настроек в проект. есть баги. завтра доделываю, версия не вполне рабочая

This commit is contained in:
2025-01-16 02:26:51 +03:00
parent 483089e954
commit 0f7b65f467
92 changed files with 511 additions and 648 deletions

View File

@@ -1,13 +1,16 @@
package Common;
import Common.Utils.Utils_;
import Common.Visual.Controls.StableMenuItem;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
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; //файл где хранятся настройки.
protected LinkedHashMap<String, JMenuItem> controls = new LinkedHashMap<>();
private File file = null; //файл где хранятся настройки.
public File getFile() {
return file;
}
@@ -21,8 +24,9 @@ public class Properties {
e.printStackTrace();
}
}
public Properties(){}
public Properties(File file_in){
public Properties() {
}
public Properties(File file_in) {
setFile(file_in);
}
public boolean updateField(String name, Object newValue) {
@@ -45,21 +49,40 @@ public class Properties {
public String getFieldDescription(String fieldName) {
return "?";
}
public JMenuItem getMenuItem(String fieldName){return null;}
//отобразить на контроле значение поля.
public void Mark(String fieldName, JMenuItem control){
String description= getFieldDescription(fieldName);
public boolean controlAction(String fieldName, JMenuItem control
){
return false;
}
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) {
if (controlAction(fieldName, menuItem))
Mark(fieldName, menuItem);
}
});
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){
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);
control.setIcon(Utils_.getIcon(flag ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));
} else {
control.setText(description + " : " + value);
}
}
catch (Exception ex){
} catch (Exception ex) {
ex.printStackTrace();
}
}