рефакторинг сохранения форм. не было единого интерфейса
This commit is contained in:
@@ -12,20 +12,20 @@ public class DBForm extends DBObject {
|
||||
public int Height = 0;
|
||||
public DBForm(String type_, Window window) {
|
||||
type = type_;
|
||||
Init(window);
|
||||
Fill(window);
|
||||
}
|
||||
public DBForm() {
|
||||
}
|
||||
public void Init(Window window) {
|
||||
X = window.getX();
|
||||
Y = window.getY();
|
||||
Width = window.getWidth();
|
||||
Height = window.getHeight();
|
||||
}
|
||||
public void Apply(Window window) {
|
||||
window.setSize(Width, Height);
|
||||
window.setLocation(X, Y);
|
||||
}
|
||||
public void Fill(Window window) {
|
||||
X = window.getX();
|
||||
Y = window.getY();
|
||||
Width = window.getWidth();
|
||||
Height = window.getHeight();
|
||||
}
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return type;
|
||||
|
||||
27
src/Common/Database/Objects/Grid/TableVisualData.java
Normal file
27
src/Common/Database/Objects/Grid/TableVisualData.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package Common.Database.Objects.Grid;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
public class TableVisualData extends DBObject {
|
||||
@Description("PRIMARY KEY, UNIQUE") //имя таблицы
|
||||
public String name = null;
|
||||
//todo запаковать в json (?)
|
||||
@Description("DEFAULT ''")
|
||||
public String sizes = ""; //ширины столбцов запакованные через |. вводить объекты ради них нецелесообразно.
|
||||
public TableVisualData() {
|
||||
}
|
||||
public TableVisualData(String name_in) {
|
||||
name = name_in;
|
||||
sizes = "";
|
||||
}
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return name;
|
||||
}
|
||||
public Vector<Integer> unpack() {
|
||||
return Arrays.stream(sizes.split("\\|")).map(Integer::parseInt).collect(Collectors.toCollection(Vector::new));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package Common.Database.Objects.Grid;
|
||||
import Common.Database.Tables.DBTable;
|
||||
public class TablesVisualDatasDBTable extends DBTable<String, TableVisualData> {
|
||||
public TablesVisualDatasDBTable() {
|
||||
super(String.class, TableVisualData.class);
|
||||
}
|
||||
}
|
||||
22
src/Common/Database/Objects/Splitter/Splitter.java
Normal file
22
src/Common/Database/Objects/Splitter/Splitter.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package Common.Database.Objects.Splitter;
|
||||
import Common.CommonConstants;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
|
||||
import javax.swing.*;
|
||||
public class Splitter extends DBObject {
|
||||
@Description("PRIMARY KEY, UNIQUE")
|
||||
public String name = "";
|
||||
@Description("DEFAULT -1")
|
||||
public int position = CommonConstants.Nan;
|
||||
public Splitter() {
|
||||
}
|
||||
public Splitter(JSplitPane splitPane) {
|
||||
name = splitPane.getName();
|
||||
position = splitPane.getDividerLocation();
|
||||
}
|
||||
@Override
|
||||
public Object getPK() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
50
src/Common/Database/Objects/Splitter/SplittersDBTable.java
Normal file
50
src/Common/Database/Objects/Splitter/SplittersDBTable.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package Common.Database.Objects.Splitter;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import Common.Utils.Utils_;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Vector;
|
||||
public class SplittersDBTable extends DBTable<String, Splitter> {
|
||||
public SplittersDBTable() {
|
||||
super(String.class, Splitter.class);
|
||||
}
|
||||
private Vector<JSplitPane> InitSplitters(Object form) throws Exception {
|
||||
Vector<JSplitPane> res = new Vector<>();
|
||||
Class c = form.getClass();
|
||||
for (Field field : c.getFields()) {
|
||||
if (field.getType().getSimpleName().equals("JSplitPane")) {
|
||||
JSplitPane splitPane = (JSplitPane) field.get(form);
|
||||
splitPane.setName(field.getName());
|
||||
res.add(splitPane);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public void Load(Object form) {
|
||||
try {
|
||||
Vector<JSplitPane> splitters = InitSplitters(form);
|
||||
for (JSplitPane splitPane : splitters) {
|
||||
if (Data.containsKey(splitPane.getName())) {
|
||||
splitPane.setDividerLocation(Data.get(splitPane.getName()).position);
|
||||
} else {
|
||||
getDb().Insert(new Splitter(splitPane));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Utils_.MainLog.PrintException(ex);
|
||||
}
|
||||
}
|
||||
public void Save(Object form) {
|
||||
try {
|
||||
Vector<JSplitPane> splitters = InitSplitters(form);
|
||||
for (JSplitPane splitPane : splitters) {
|
||||
Splitter splitter = Data.get(splitPane.getName());
|
||||
splitter.position = splitPane.getDividerLocation();
|
||||
getDb().Update(splitter);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Utils_.MainLog.PrintException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package Common.Database;
|
||||
import Common.Database.Objects.DBForm.FormsDBTable;
|
||||
import Common.Database.Objects.Grid.TablesVisualDatasDBTable;
|
||||
import Common.Database.Objects.PassStats.PassStatsDBTable;
|
||||
import Common.Database.Objects.Splitter.SplittersDBTable;
|
||||
import Common.Database.SQLITE.SQLiteDatabase;
|
||||
import _VisualDVM.GlobalData.Grid.TablesVisualDatasDBTable;
|
||||
import _VisualDVM.GlobalData.Splitter.SplittersDBTable;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -137,10 +137,10 @@ public abstract class MainModule_<D extends VisualiserDatabase, U extends UIModu
|
||||
public boolean confirmPassesStart() {
|
||||
return false;
|
||||
}
|
||||
public boolean confirmPassesDone(){
|
||||
public boolean confirmPassesDone() {
|
||||
return false;
|
||||
}
|
||||
public boolean focusPassesResult(){
|
||||
public boolean focusPassesResult() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
package Common;
|
||||
public class Module {
|
||||
|
||||
}
|
||||
|
||||
@@ -204,19 +204,18 @@ public class Pass<T> {
|
||||
Stack<Pass> ToDo = new Stack<>();
|
||||
Vector<String> ToPrint = new Vector<>();
|
||||
createStack_r(ToDo, ToPrint);
|
||||
|
||||
if (
|
||||
UI.isActive()&&MainModule_.instance.confirmPassesStart() && !ToPrint.isEmpty() &&
|
||||
!UI.Question("Выполнить проход(ы):\n" + String.join("\n", ToPrint))
|
||||
UI.isActive() && MainModule_.instance.confirmPassesStart() && !ToPrint.isEmpty() &&
|
||||
!UI.Question("Выполнить проход(ы):\n" + String.join("\n", ToPrint))
|
||||
) return false;
|
||||
while (ToDo.size() > 1) {
|
||||
if (!ToDo.pop().start()) return false;
|
||||
}
|
||||
if (start(args)) {
|
||||
if (UI.isActive()&&MainModule_.instance.focusPassesResult())
|
||||
if (UI.isActive() && MainModule_.instance.focusPassesResult())
|
||||
FocusResult();
|
||||
//-
|
||||
if (UI.isActive()&&MainModule_.instance.confirmPassesDone() && !ToPrint.isEmpty()
|
||||
if (UI.isActive() && MainModule_.instance.confirmPassesDone() && !ToPrint.isEmpty()
|
||||
) {
|
||||
UI.Info("Проход(ы)\n\n" + String.join("\n", ToPrint) +
|
||||
"\nуспешно выполнен(ы)!");
|
||||
|
||||
3
src/Common/Properties.java
Normal file
3
src/Common/Properties.java
Normal file
@@ -0,0 +1,3 @@
|
||||
package Common;
|
||||
public class Properties {
|
||||
}
|
||||
@@ -66,9 +66,9 @@ public class Utils_ {
|
||||
public static void jsonToFile(Object json_object, File file) throws Exception {
|
||||
FileUtils.writeStringToFile(file, gson.toJson(json_object));
|
||||
}
|
||||
public static JsonObject getPropertiesAsJsonObject() throws Exception{
|
||||
public static JsonObject getPropertiesAsJsonObject() throws Exception {
|
||||
File propertiesFile = new File(System.getProperty("user.dir"), "properties");
|
||||
if (!propertiesFile.exists()){
|
||||
if (!propertiesFile.exists()) {
|
||||
System.out.println("Файл properties не найден!");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package Common.Visual;
|
||||
import Common.CommonConstants;
|
||||
import Common.Current_;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Objects.Grid.TableVisualData;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Database.Tables.FKBehaviour;
|
||||
@@ -14,7 +15,6 @@ import Common.Visual.Tables.DBObjectSelector;
|
||||
import Common.Visual.Tables.DataTable;
|
||||
import Common.Visual.Tables.Grid.GridAnchestor;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Grid.TableVisualData;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableColumn;
|
||||
|
||||
10
src/Common/Visual/FormWithSplitters.java
Normal file
10
src/Common/Visual/FormWithSplitters.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package Common.Visual;
|
||||
import Common.MainModule_;
|
||||
public interface FormWithSplitters {
|
||||
default void LoadSplitters() {
|
||||
MainModule_.instance.getDb().splitters.Load(this);
|
||||
}
|
||||
default void SaveSplitters() {
|
||||
MainModule_.instance.getDb().splitters.Save(this);
|
||||
}
|
||||
}
|
||||
42
src/Common/Visual/SavedForm.java
Normal file
42
src/Common/Visual/SavedForm.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package Common.Visual;
|
||||
import Common.Database.Objects.DBForm.DBForm;
|
||||
import Common.MainModule_;
|
||||
|
||||
import java.awt.*;
|
||||
public interface SavedForm {
|
||||
default String getFormKey() {
|
||||
return null;
|
||||
}
|
||||
int getDefaultWidth();
|
||||
int getDefaultHeight();
|
||||
default void LoadWindowParameters() {
|
||||
if (this instanceof Window) {
|
||||
Window window = (Window) this;
|
||||
if ((getFormKey() != null) && MainModule_.instance.getDb().forms.Data.containsKey(getFormKey())) {
|
||||
DBForm dbForm = MainModule_.instance.getDb().forms.Data.get(getFormKey());
|
||||
dbForm.Apply(window);
|
||||
return;
|
||||
} else {
|
||||
window.setSize(getDefaultWidth(), getDefaultHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
default void SaveWindowParameters() {
|
||||
if ((this instanceof Window) && (getFormKey() != null)) {
|
||||
Window window = (Window) this;
|
||||
DBForm dbForm = null;
|
||||
try {
|
||||
if (MainModule_.instance.getDb().forms.containsKey(getFormKey())) {
|
||||
dbForm = MainModule_.instance.getDb().forms.get(getFormKey());
|
||||
dbForm.Fill(window);
|
||||
MainModule_.instance.getDb().Update(dbForm);
|
||||
} else {
|
||||
dbForm = new DBForm(getFormKey(), window);
|
||||
MainModule_.instance.getDb().Insert(dbForm);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public class StyledTree extends JTree implements ThemeElement {
|
||||
setFont(MainModule_.instance.getUI().getTheme().Fonts.get(VisualiserFonts.TreePlain));
|
||||
setToggleClickCount(0); //отключение сворачивание разворачивания по двойному клику
|
||||
//--
|
||||
if (getRendererClass()!=null)
|
||||
if (getRendererClass() != null)
|
||||
setCellRenderer(MainModule_.instance.getUI().getTreeRenderer(getRendererClass()));
|
||||
//--
|
||||
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
|
||||
@@ -8,7 +8,7 @@ import javax.swing.text.DefaultFormatter;
|
||||
import java.awt.*;
|
||||
public class UI {
|
||||
public static boolean isActive() {
|
||||
return (MainModule_.instance!=null)&&MainModule_.instance.hasUI();
|
||||
return (MainModule_.instance != null) && MainModule_.instance.hasUI();
|
||||
}
|
||||
//---
|
||||
public static void Clear(Container container) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import javax.swing.tree.TreeCellRenderer;
|
||||
import java.awt.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Stack;
|
||||
|
||||
public class UIModule_ {
|
||||
public LinkedHashMap<Class<? extends DataSet>, DataMenuBar> menuBars = new LinkedHashMap<>();
|
||||
public Stack<Component> windowsStack = new Stack<>();
|
||||
@@ -92,45 +91,42 @@ public class UIModule_ {
|
||||
public TableCellRenderer getTableRenderer(Class key) {
|
||||
TableCellRenderer res = null;
|
||||
if (tableRenderers.containsKey(key))
|
||||
res= tableRenderers.get(key);
|
||||
res = tableRenderers.get(key);
|
||||
else {
|
||||
try {
|
||||
res = (TableCellRenderer) key.newInstance();
|
||||
}
|
||||
catch (Exception ex){
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
tableRenderers.put(key,res);
|
||||
tableRenderers.put(key, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public TableCellEditor getTableEditor(Class key) {
|
||||
TableCellEditor res = null;
|
||||
if (tableEditors.containsKey(key))
|
||||
res= tableEditors.get(key);
|
||||
res = tableEditors.get(key);
|
||||
else {
|
||||
try {
|
||||
res = (TableCellEditor) key.newInstance();
|
||||
}
|
||||
catch (Exception ex){
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
tableEditors.put(key,res);
|
||||
tableEditors.put(key, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public TreeCellRenderer getTreeRenderer(Class key) {
|
||||
TreeCellRenderer res = null;
|
||||
if (treeRenderers.containsKey(key))
|
||||
res= treeRenderers.get(key);
|
||||
res = treeRenderers.get(key);
|
||||
else {
|
||||
try {
|
||||
res = (TreeCellRenderer) key.newInstance();
|
||||
}
|
||||
catch (Exception ex){
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
treeRenderers.put(key,res);
|
||||
treeRenderers.put(key, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package Common.Visual.Windows;
|
||||
import Common.Database.Objects.DBForm.DBForm;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.SavedForm;
|
||||
import Common.Visual.Themes.ThemeElement;
|
||||
import _VisualDVM.Global;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
public abstract class Form extends JFrame implements ThemeElement {
|
||||
private DBForm dbInfo = null;
|
||||
public abstract class Form extends JFrame implements ThemeElement, SavedForm {
|
||||
public Form() {
|
||||
if (getIconPath() != null) setIconImage(Utils_.getIcon(getIconPath()).getImage());
|
||||
SetListener();
|
||||
@@ -27,9 +25,6 @@ public abstract class Form extends JFrame implements ThemeElement {
|
||||
public String getUTitleText() {
|
||||
return "";
|
||||
}
|
||||
protected String getFormKey() {
|
||||
return null;
|
||||
}
|
||||
protected void SetListener() {
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@@ -39,9 +34,11 @@ public abstract class Form extends JFrame implements ThemeElement {
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 800;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return 450;
|
||||
}
|
||||
@@ -72,25 +69,6 @@ public abstract class Form extends JFrame implements ThemeElement {
|
||||
}
|
||||
public void AfterClose() {
|
||||
}
|
||||
public void LoadWindowParameters() throws Exception {
|
||||
if (getFormKey() != null)
|
||||
if (Global.mainModule.getDb().forms.Data.containsKey(getFormKey())) {
|
||||
dbInfo = Global.mainModule.getDb().forms.Data.get(getFormKey());
|
||||
dbInfo.Apply(this);
|
||||
return;
|
||||
}
|
||||
setSize(getDefaultWidth(), getDefaultHeight());
|
||||
setLocationRelativeTo(getRelative());
|
||||
}
|
||||
public void SaveWindowParameters() throws Exception {
|
||||
if (getFormKey() != null) {
|
||||
if (dbInfo != null) {
|
||||
dbInfo.Init(this);
|
||||
Global.mainModule.getDb().Update(dbInfo);
|
||||
} else
|
||||
Global.mainModule.getDb().Insert(new DBForm(getFormKey(), this));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void applyTheme() {
|
||||
//todo -> применение темы.
|
||||
|
||||
Reference in New Issue
Block a user